Skip to content

Commit

Permalink
Merge pull request #41231 from tienifr/fix/39612
Browse files Browse the repository at this point in the history
fix: Selected members disappear from search result after returning from confirmation page
  • Loading branch information
neil-marcellini authored May 13, 2024
2 parents c04628a + 2611633 commit c5bf798
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,7 @@ export {
getReportOption,
getTaxRatesSection,
getFirstKeyForList,
getUserToInviteOption,
};

export type {MemberForList, CategorySection, CategoryTreeSection, Options, OptionList, SearchOption, PayeePersonalDetails, Category, Tax, TaxRatesOption, Option, OptionTree};
26 changes: 20 additions & 6 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function useOptions({isGroupChat}: NewChatPageProps) {
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [newGroupDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT);
const personalData = useCurrentUserPersonalDetails();
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const {didScreenTransitionEnd} = useScreenWrapperTranstionStatus();
const {options: listOptions, areOptionsInitialized} = useOptionsList({
shouldInitialize: didScreenTransitionEnd,
Expand Down Expand Up @@ -95,13 +94,28 @@ function useOptions({isGroupChat}: NewChatPageProps) {
if (!newGroupDraft?.participants) {
return;
}
const selectedParticipants = newGroupDraft.participants.filter((participant) => participant.accountID !== personalData.accountID);
const newSelectedOptions = selectedParticipants.map((participant): OptionData => {
const baseOption = OptionsListUtils.getParticipantsOption({accountID: participant.accountID, login: participant.login, reportID: ''}, personalDetails);
return {...baseOption, reportID: baseOption.reportID ?? '', isSelected: true};
const newSelectedOptions: OptionData[] = [];
newGroupDraft.participants.forEach((participant) => {
if (participant.accountID === personalData.accountID) {
return;
}
let participantOption: OptionData | undefined | null = listOptions.personalDetails.find((option) => option.accountID === participant.accountID);
if (!participantOption) {
participantOption = OptionsListUtils.getUserToInviteOption({
searchValue: participant.login,
betas,
});
}
if (!participantOption) {
return;
}
newSelectedOptions.push({
...participantOption,
isSelected: true,
});
});
setSelectedOptions(newSelectedOptions);
}, [newGroupDraft, personalData, personalDetails]);
}, [newGroupDraft?.participants, listOptions.personalDetails, betas, personalData.accountID]);

return {...options, searchTerm, debouncedSearchTerm, setSearchTerm, areOptionsInitialized: areOptionsInitialized && didScreenTransitionEnd, selectedOptions, setSelectedOptions};
}
Expand Down

0 comments on commit c5bf798

Please sign in to comment.