diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 082952e58f9e..b62f3af5a3d6 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2443,6 +2443,7 @@ export { getReportOption, getTaxRatesSection, getFirstKeyForList, + getUserToInviteOption, }; export type {MemberForList, CategorySection, CategoryTreeSection, Options, OptionList, SearchOption, PayeePersonalDetails, Category, Tax, TaxRatesOption, Option, OptionTree}; diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 37f0c30fe5cb..36be521215fa 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -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, @@ -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}; }