Skip to content

Commit

Permalink
Merge pull request #34028 from BhuvaneshPatil/32839-select-members-fr…
Browse files Browse the repository at this point in the history
…om-onyx

Select members from ONYX on page open, remove them on unmounting
  • Loading branch information
cristipaval authored Jan 15, 2024
2 parents 60de4ac + 92f51e2 commit bea694d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ const propTypes = {
}).isRequired,

isLoadingReportData: PropTypes.bool,
invitedEmailsToAccountIDsDraft: PropTypes.objectOf(PropTypes.number),
...policyPropTypes,
};

const defaultProps = {
personalDetails: {},
betas: [],
isLoadingReportData: true,
invitedEmailsToAccountIDsDraft: {},
...policyDefaultProps,
};

Expand All @@ -81,7 +83,10 @@ function WorkspaceInvitePage(props) {

useEffect(() => {
setSearchTerm(SearchInputManager.searchInput);
}, []);
return () => {
Policy.setWorkspaceInviteMembersDraft(props.route.params.policyID, {});
};
}, [props.route.params.policyID]);

useEffect(() => {
Policy.clearErrors(props.route.params.policyID);
Expand All @@ -105,6 +110,12 @@ function WorkspaceInvitePage(props) {
_.each(inviteOptions.personalDetails, (detail) => (detailsMap[detail.login] = OptionsListUtils.formatMemberForList(detail)));

const newSelectedOptions = [];
_.each(_.keys(props.invitedEmailsToAccountIDsDraft), (login) => {
if (!_.has(detailsMap, login)) {
return;
}
newSelectedOptions.push({...detailsMap[login], isSelected: true});
});
_.each(selectedOptions, (option) => {
newSelectedOptions.push(_.has(detailsMap, option.login) ? {...detailsMap[option.login], isSelected: true} : option);
});
Expand Down Expand Up @@ -323,5 +334,8 @@ export default compose(
isLoadingReportData: {
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
},
invitedEmailsToAccountIDsDraft: {
key: ({route}) => `${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`,
},
}),
)(WorkspaceInvitePage);

0 comments on commit bea694d

Please sign in to comment.