Skip to content

Commit

Permalink
fix ctrl enter shortcut action
Browse files Browse the repository at this point in the history
  • Loading branch information
abzokhattab committed Apr 16, 2024
1 parent 87d207d commit 1e3de7a
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,24 @@ 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 (selectedOptions.length === 1) {
createChat();
}
if (!personalData || !personalData.login || !personalData.accountID) {
return;
}
const selectedParticipants = selectedOptions.map((option) => ({
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, createChat, personalData]);

const footerContent = useMemo(
() => (
<>
<ReferralProgramCTA
referralContentType={CONST.REFERRAL_PROGRAM.CONTENT_TYPES.START_CHAT}
Expand All @@ -272,14 +271,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 +302,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 1e3de7a

Please sign in to comment.