Skip to content

Commit

Permalink
Merge pull request #1738 from barun1997/feature/participants-select
Browse files Browse the repository at this point in the history
Create IOU participant selection step.
  • Loading branch information
Julesssss authored Mar 17, 2021
2 parents 5cc1a81 + f085f11 commit 6c556f0
Show file tree
Hide file tree
Showing 5 changed files with 485 additions and 59 deletions.
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({
// 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,

// Callback to add participants in IOUModal
onAddParticipants: PropTypes.func.isRequired,

// All of the personal details for everyone
personalDetails: PropTypes.objectOf(personalDetailsPropTypes).isRequired,

// All reports shared with the user
reports: PropTypes.shape({
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: '',
};
}

/**
* 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;
}

/**
* 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

0 comments on commit 6c556f0

Please sign in to comment.