Skip to content

Commit

Permalink
Merge pull request #40165 from abzokhattab/enable-creating-group-with…
Browse files Browse the repository at this point in the history
…-one-other-participant

Enable creating a group chat with one other participant
  • Loading branch information
marcaaron authored Apr 17, 2024
2 parents 8f6ebe4 + 2b18ce9 commit 97632e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,6 @@ export default {
localTime: 'Local time',
},
newChatPage: {
createChat: 'Create chat',
startGroup: 'Start group',
addToGroup: 'Add to group',
},
Expand Down
1 change: 0 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,6 @@ export default {
localTime: 'Hora local',
},
newChatPage: {
createChat: 'Crear chat',
startGroup: 'Grupo de inicio',
addToGroup: 'Añadir al grupo',
},
Expand Down
39 changes: 17 additions & 22 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,18 @@ function NewChatPage({isGroupChat}: NewChatPageProps) {
[selectedOptions, setSelectedOptions, styles, translate],
);

const footerContent = useMemo(() => {
/**
* Creates a new group chat with all the selected options and the current user,
* or navigates to the existing chat if one with those participants already exists.
*/
const createGroup = () => {
if (selectedOptions.length === 1) {
createChat();
}
if (!personalData || !personalData.login || !personalData.accountID) {
return;
}
const selectedParticipants: SelectedParticipant[] = selectedOptions.map((option: OptionData) => ({login: option.login ?? '', accountID: option.accountID ?? -1}));
const logins = [...selectedParticipants, {login: personalData.login, accountID: personalData.accountID}];
Report.setGroupDraft({participants: logins});
Navigation.navigate(ROUTES.NEW_CHAT_CONFIRM);
};

return (
const createGroup = useCallback(() => {
if (!personalData || !personalData.login || !personalData.accountID) {
return;
}
const selectedParticipants: SelectedParticipant[] = selectedOptions.map((option: OptionData) => ({login: option.login ?? '', accountID: option.accountID ?? -1}));
const logins = [...selectedParticipants, {login: personalData.login, accountID: personalData.accountID}];
Report.setGroupDraft({participants: logins});
Navigation.navigate(ROUTES.NEW_CHAT_CONFIRM);
}, [selectedOptions, personalData]);

const footerContent = useMemo(
() => (
<>
<ReferralProgramCTA
referralContentType={CONST.REFERRAL_PROGRAM.CONTENT_TYPES.START_CHAT}
Expand All @@ -272,14 +265,15 @@ function NewChatPage({isGroupChat}: NewChatPageProps) {
{!!selectedOptions.length && (
<Button
success
text={selectedOptions.length > 1 ? translate('common.next') : translate('newChatPage.createChat')}
text={translate('common.next')}
onPress={createGroup}
pressOnEnter
/>
)}
</>
);
}, [createChat, personalData, selectedOptions, styles.mb5, translate]);
),
[createGroup, selectedOptions.length, styles.mb5, translate],
);

return (
<View
Expand All @@ -302,6 +296,7 @@ function NewChatPage({isGroupChat}: NewChatPageProps) {
textInputLabel={translate('optionsSelector.nameEmailOrPhoneNumber')}
headerMessage={headerMessage}
onSelectRow={createChat}
onConfirm={(e, option) => (selectedOptions.length > 0 ? createGroup() : createChat(option))}
rightHandSideComponent={itemRightSideComponent}
footerContent={footerContent}
showLoadingPlaceholder={!areOptionsInitialized}
Expand Down

0 comments on commit 97632e6

Please sign in to comment.