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

fix: Selected members disappear from search result after returning from confirmation page #41231

Merged
merged 10 commits into from
May 13, 2024
1 change: 1 addition & 0 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2443,6 +2443,7 @@ export {
getReportOption,
getTaxRatesSection,
getFirstKeyForList,
getUserToInviteOption,
};

export type {MemberForList, CategorySection, CategoryTreeSection, Options, OptionList, SearchOption, PayeePersonalDetails, Category, Tax, TaxRatesOption, Option, OptionTree};
30 changes: 24 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,32 @@ 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 selectedParticipants: OptionData[] = [];
newGroupDraft.participants.forEach((p) => {
if (p.accountID === personalData.accountID) {
return;
}
const participant = listOptions.personalDetails.find((option) => option.accountID === p.accountID);
if (participant) {
selectedParticipants.push(participant);
return;
}
const userToInvite = OptionsListUtils.getUserToInviteOption({
searchValue: p.login,
betas,
});
if (!userToInvite) {
return;
}
selectedParticipants.push(userToInvite);
});
const newSelectedOptions = selectedParticipants.map((participant) => ({
...participant,
reportID: participant?.reportID ?? '',
isSelected: true,
}));
setSelectedOptions(newSelectedOptions);
tienifr marked this conversation as resolved.
Show resolved Hide resolved
}, [newGroupDraft, personalData, personalDetails]);
}, [newGroupDraft, listOptions.personalDetails, betas, personalData]);
tienifr marked this conversation as resolved.
Show resolved Hide resolved

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