-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1738 from barun1997/feature/participants-select
Create IOU participant selection step.
- Loading branch information
Showing
5 changed files
with
485 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
130 changes: 130 additions & 0 deletions
130
src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.