Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create IOU participant selection step. #1738

Merged
merged 6 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/pages/iou/IOUModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class IOUModal extends Component {
this.navigateToPreviousStep = this.navigateToPreviousStep.bind(this);
this.navigateToNextStep = this.navigateToNextStep.bind(this);

this.addParticipants = this.addParticipants.bind(this);
this.state = {
currentStepIndex: 0,
participants: [],
iouAmount: 42,
};
}

Expand All @@ -54,7 +57,11 @@ class IOUModal extends Component {
*
* @returns {String}
*/

getTitleForStep() {
if (this.state.currentStepIndex === 1) {
return `${this.props.hasMultipleParticipants ? 'Split' : 'Request'} $${this.state.iouAmount}`;
}
return steps[this.state.currentStepIndex] || '';
}

Expand Down Expand Up @@ -82,6 +89,12 @@ class IOUModal extends Component {
}));
}

addParticipants(participants) {
this.setState({
participants,
});
}

render() {
const currentStep = steps[this.state.currentStepIndex];
return (
Expand Down Expand Up @@ -121,14 +134,16 @@ class IOUModal extends Component {
)}
{currentStep === Steps.IOUParticipants && (
<IOUParticipantsPage
participants={this.state.participants}
hasMultipleParticipants={this.props.hasMultipleParticipants}
onAddParticipants={this.addParticipants}
onStepComplete={this.navigateToNextStep}
/>
)}
{currentStep === Steps.IOUConfirm && (
<IOUConfirmPage
onConfirm={() => console.debug('create IOU report')}
participants={[]}
participants={this.state.participants}
iouAmount={42}
/>
)}
Expand Down
58 changes: 0 additions & 58 deletions src/pages/iou/steps/IOUParticipantsPage.js

This file was deleted.

130 changes: 130 additions & 0 deletions src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {getNewChatOptions} from '../../../../libs/OptionsListUtils';
import OptionsSelector from '../../../../components/OptionsSelector';
import ONYXKEYS from '../../../../ONYXKEYS';

const personalDetailsPropTypes = PropTypes.shape({
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
// The login of the person (either email or phone number)
login: PropTypes.string.isRequired,

// The URL of the person's avatar (there should already be a default avatar if
// the person doesn't have their own avatar uploaded yet)
avatar: PropTypes.string.isRequired,

// This is either the user's full name, or their login if full name is an empty string
displayName: PropTypes.string.isRequired,
});

const propTypes = {
// Callback to inform parent modal of success
onStepComplete: PropTypes.func.isRequired,

barun1997 marked this conversation as resolved.
Show resolved Hide resolved
// Callback to add participants in IOUModal
onAddParticipants: PropTypes.func.isRequired,

// All of the personal details for everyone
personalDetails: PropTypes.objectOf(personalDetailsPropTypes).isRequired,
Julesssss marked this conversation as resolved.
Show resolved Hide resolved

// All reports shared with the user
reports: PropTypes.shape({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be PropTypes.arrayOf(PropTypes.shape({...})) ?

Copy link
Contributor Author

@barun1997 barun1997 Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roryabraham The prop (props.reports), in this case, is an object with the given shape. The getNewGroupOptions function maps it into an array.

reportID: PropTypes.number,
reportName: PropTypes.string,
}).isRequired,
};

class IOUParticipantsRequest extends Component {
constructor(props) {
super(props);

this.addSingleParticipant = this.addSingleParticipant.bind(this);

const {personalDetails, userToInvite} = getNewChatOptions(
props.reports,
props.personalDetails,
'',
);

this.state = {
personalDetails,
userToInvite,
searchValue: '',
};
}

/**
barun1997 marked this conversation as resolved.
Show resolved Hide resolved
* Returns the sections needed for the OptionsSelector
*
* @returns {Array}
*/
getSections() {
const sections = [];
sections.push({
title: 'CONTACTS',
data: this.state.personalDetails,
shouldShow: this.state.personalDetails.length > 0,
indexOffset: 0,
});

if (this.state.userToInvite) {
sections.push({
undefined,
data: [this.state.userToInvite],
shouldShow: true,
indexOffset: 0,
});
}

return sections;
}

/**
barun1997 marked this conversation as resolved.
Show resolved Hide resolved
* Adds a single participant to the request
*
* @param {Object} option
*/
addSingleParticipant(option) {
this.props.onAddParticipants([option]);
this.props.onStepComplete();
}

render() {
const sections = this.getSections();
return (
<OptionsSelector
sections={sections}
value={this.state.searchValue}
onSelectRow={this.addSingleParticipant}
onChangeText={(searchValue = '') => {
const {personalDetails, userToInvite} = getNewChatOptions(
this.props.reports,
this.props.personalDetails,
searchValue,
);
this.setState({
searchValue,
userToInvite,
personalDetails,
});
}}
hideSectionHeaders
disableArrowKeysActions
hideAdditionalOptionStates
forceTextUnreadStyle
/>
);
}
}

IOUParticipantsRequest.displayName = 'IOUParticipantsRequest';
IOUParticipantsRequest.propTypes = propTypes;

export default withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
})(IOUParticipantsRequest);
Loading