From 3a96bc8a3b3cfda86d316656c43895d3ee5b0d6c Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Fri, 17 Oct 2025 08:14:41 +0200 Subject: [PATCH 1/5] refactor LoginUtils to not use appendCountryCode method --- src/libs/LoginUtils.ts | 4 ++-- src/pages/TeachersUnite/KnowATeacherPage.tsx | 7 ++++--- .../settings/Profile/Contacts/NewContactMethodPage.tsx | 9 +++++---- .../Security/MergeAccounts/AccountDetailsPage.tsx | 4 ++-- tests/unit/LoginUtilsTest.ts | 6 +++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/libs/LoginUtils.ts b/src/libs/LoginUtils.ts index c53e05b93d44..c00b2fbaa55e 100644 --- a/src/libs/LoginUtils.ts +++ b/src/libs/LoginUtils.ts @@ -92,12 +92,12 @@ function validateNumber(values: string): string { * Check number is valid and attach country code * @returns a valid phone number with country code */ -function getPhoneLogin(partnerUserID: string): string { +function getPhoneLogin(partnerUserID: string, countryCode: number): string { if (partnerUserID.length === 0) { return ''; } - return appendCountryCode(getPhoneNumberWithoutSpecialChars(partnerUserID)); + return appendCountryCodeWithCountryCode(getPhoneNumberWithoutSpecialChars(partnerUserID), countryCode); } /** diff --git a/src/pages/TeachersUnite/KnowATeacherPage.tsx b/src/pages/TeachersUnite/KnowATeacherPage.tsx index f88e294d2af4..ba63f08f34f2 100644 --- a/src/pages/TeachersUnite/KnowATeacherPage.tsx +++ b/src/pages/TeachersUnite/KnowATeacherPage.tsx @@ -26,12 +26,13 @@ function KnowATeacherPage() { const {translate} = useLocalize(); const {isProduction} = useEnvironment(); const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true}); + const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: true}); /** * Submit form to pass firstName, partnerUserID and lastName */ const onSubmit = (values: FormOnyxValues) => { - const phoneLogin = getPhoneLogin(values.partnerUserID); + const phoneLogin = getPhoneLogin(values.partnerUserID, countryCode); const validateIfNumber = validateNumber(phoneLogin); const contactMethod = (validateIfNumber || values.partnerUserID).trim().toLowerCase(); const firstName = values.firstName.trim(); @@ -48,7 +49,7 @@ function KnowATeacherPage() { const validate = useCallback( (values: FormOnyxValues) => { const errors = getFieldRequiredErrors(values, [INPUT_IDS.FIRST_NAME, INPUT_IDS.LAST_NAME]); - const phoneLogin = getPhoneLogin(values.partnerUserID); + const phoneLogin = getPhoneLogin(values.partnerUserID, countryCode); const validateIfNumber = validateNumber(phoneLogin); if (!isValidDisplayName(values.firstName)) { @@ -87,7 +88,7 @@ function KnowATeacherPage() { return errors; }, - [loginList, translate], + [loginList, translate, countryCode], ); return ( diff --git a/src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx b/src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx index 0910fd29dba4..45efd48725b2 100644 --- a/src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx +++ b/src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx @@ -33,24 +33,25 @@ function NewContactMethodPage({route}: NewContactMethodPageProps) { const {translate} = useLocalize(); const loginInputRef = useRef(null); const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true}); + const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: true}); const navigateBackTo = route?.params?.backTo; const handleValidateMagicCode = useCallback( (values: FormOnyxValues) => { - const phoneLogin = getPhoneLogin(values.phoneOrEmail); + const phoneLogin = getPhoneLogin(values.phoneOrEmail, countryCode); const validateIfNumber = validateNumber(phoneLogin); const submitDetail = (validateIfNumber || values.phoneOrEmail).trim().toLowerCase(); resetValidateActionCodeSent(); addPendingContactMethod(submitDetail); Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD_CONFIRM_MAGIC_CODE.getRoute(submitDetail, navigateBackTo)); }, - [navigateBackTo], + [countryCode, navigateBackTo], ); const validate = useCallback( (values: FormOnyxValues): Errors => { - const phoneLogin = getPhoneLogin(values.phoneOrEmail); + const phoneLogin = getPhoneLogin(values.phoneOrEmail, countryCode); const validateIfNumber = validateNumber(phoneLogin); const errors = {}; @@ -82,7 +83,7 @@ function NewContactMethodPage({route}: NewContactMethodPageProps) { // the loginList gets updated, causing this function to run again. // https://github.com/Expensify/App/issues/20610 // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - [translate], + [translate, countryCode], ); const onBackButtonPress = useCallback(() => { diff --git a/src/pages/settings/Security/MergeAccounts/AccountDetailsPage.tsx b/src/pages/settings/Security/MergeAccounts/AccountDetailsPage.tsx index 8d5900fbab11..3f8a870fefcb 100644 --- a/src/pages/settings/Security/MergeAccounts/AccountDetailsPage.tsx +++ b/src/pages/settings/Security/MergeAccounts/AccountDetailsPage.tsx @@ -72,7 +72,7 @@ function AccountDetailsPage() { const {params} = useRoute>(); const [email, setEmail] = useState(params?.email ?? ''); const {inputCallbackRef} = useAutoFocusInput(); - + const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: true}); const validateCodeSent = getValidateCodeForAccountMerge?.validateCodeSent; const latestError = getLatestErrorMessage(getValidateCodeForAccountMerge); const errorKey = getValidateCodeErrorKey(latestError); @@ -145,7 +145,7 @@ function AccountDetailsPage() { } else if (login.trim() === userEmailOrPhone) { addErrorMessage(errors, INPUT_IDS.PHONE_OR_EMAIL, translate('common.error.email')); } else { - const phoneLogin = getPhoneLogin(login); + const phoneLogin = getPhoneLogin(login, countryCode); const validateIfNumber = validateNumber(phoneLogin); if (!Str.isValidEmail(login) && !validateIfNumber) { diff --git a/tests/unit/LoginUtilsTest.ts b/tests/unit/LoginUtilsTest.ts index 3b0d788d6591..0673880812db 100644 --- a/tests/unit/LoginUtilsTest.ts +++ b/tests/unit/LoginUtilsTest.ts @@ -79,17 +79,17 @@ describe('LoginUtils', () => { describe('getPhoneLogin', () => { it('Should return valid phone number with country code if provided phone number is valid and with country code', () => { const givenPhone = '+12345678901'; - const parsedPhone = LoginUtils.getPhoneLogin(givenPhone); + const parsedPhone = LoginUtils.getPhoneLogin(givenPhone, 1); expect(parsedPhone).toBe('+12345678901'); }); it('Should return valid phone number with country code if provided phone number is valid and without country code', () => { const givenPhone = '2345678901'; - const parsedPhone = LoginUtils.getPhoneLogin(givenPhone); + const parsedPhone = LoginUtils.getPhoneLogin(givenPhone, 1); expect(parsedPhone).toBe('+12345678901'); }); it('Should return empty string if provided phone number is empty', () => { const givenPhone = ''; - const parsedPhone = LoginUtils.getPhoneLogin(givenPhone); + const parsedPhone = LoginUtils.getPhoneLogin(givenPhone, 1); expect(parsedPhone).toBe(''); }); }); From e2ec616d5c6f40b26cf21f94b9b1cfba0d23ea15 Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Fri, 17 Oct 2025 09:02:35 +0200 Subject: [PATCH 2/5] Refactor getHeaderMessage to include countryCode parameter across multiple components. --- src/libs/ContactUtils.ts | 3 ++- src/libs/OptionsListUtils/index.ts | 10 ++++++++-- src/pages/InviteReportParticipantsPage.tsx | 2 ++ .../BaseOnboardingWorkspaceInvite.tsx | 4 ++-- src/pages/Share/ShareTab.tsx | 4 ++-- .../iou/request/MoneyRequestAccountantSelector.tsx | 5 ++++- src/pages/iou/request/MoneyRequestAttendeeSelector.tsx | 4 +++- .../iou/request/MoneyRequestParticipantsSelector.tsx | 2 ++ .../AboutPage/ShareLogList/BaseShareLogList.tsx | 2 ++ .../Profile/CustomStatus/VacationDelegatePage.tsx | 4 +++- .../settings/Security/AddDelegate/AddDelegatePage.tsx | 2 +- src/pages/tasks/TaskAssigneeSelectorModal.tsx | 4 +++- src/pages/tasks/TaskShareDestinationSelectorModal.tsx | 5 +++-- src/pages/workspace/WorkspaceInvitePage.tsx | 4 ++-- .../workspace/companyCards/assignCard/AssigneeStep.tsx | 4 ++-- .../workspace/expensifyCard/issueNew/AssigneeStep.tsx | 4 ++-- .../EditInviteReceiptPartnerPolicyPage.tsx | 6 ++++-- .../receiptPartners/InviteReceiptPartnerPolicyPage.tsx | 4 ++-- 18 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/libs/ContactUtils.ts b/src/libs/ContactUtils.ts index 34576062b426..f5945491a4ce 100644 --- a/src/libs/ContactUtils.ts +++ b/src/libs/ContactUtils.ts @@ -28,7 +28,7 @@ function sortEmailObjects(emails: StringHolder[], localeCompare: LocaleContextPr }); } -const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: LocaleContextProps['localeCompare']): Array> => { +const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: LocaleContextProps['localeCompare'], countryCode: number): Array> => { return deviceContacts .map((contact) => { const email = sortEmailObjects(contact?.emailAddresses ?? [], localeCompare)?.at(0) ?? ''; @@ -47,6 +47,7 @@ const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: Locale email, phone: phoneNumber, avatar: avatarSource, + countryCode, }); }) .filter((contact): contact is SearchOption => contact !== null); diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 87c41ba1b026..ae472c2b7cc0 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -2205,8 +2205,14 @@ function getMemberInviteOptions( /** * Helper method that returns the text to be used for the header's message and title (if any) */ -function getHeaderMessage(hasSelectableOptions: boolean, hasUserToInvite: boolean, searchValue: string, hasMatchedParticipant = false): string { - const isValidPhone = parsePhoneNumber(appendCountryCode(searchValue)).possible; +function getHeaderMessage( + hasSelectableOptions: boolean, + hasUserToInvite: boolean, + searchValue: string, + hasMatchedParticipant = false, + countryCode: OnyxEntry = CONST.DEFAULT_COUNTRY_CODE, +): string { + const isValidPhone = parsePhoneNumber(appendCountryCodeWithCountryCode(searchValue, countryCode)).possible; const isValidEmail = Str.isValidEmail(searchValue); diff --git a/src/pages/InviteReportParticipantsPage.tsx b/src/pages/InviteReportParticipantsPage.tsx index 3120b9d23e12..343efd515060 100644 --- a/src/pages/InviteReportParticipantsPage.tsx +++ b/src/pages/InviteReportParticipantsPage.tsx @@ -165,6 +165,8 @@ function InviteReportParticipantsPage({report, didScreenTransitionEnd}: InviteRe selectedOptionsForDisplay.length + availableOptions.recentReports.length + availableOptions.personalDetails.length !== 0, !!availableOptions.userToInvite, processedLogin, + false, + countryCode, ); }, [searchTerm, availableOptions, selectedOptionsForDisplay, excludedUsers, translate, reportName, countryCode]); diff --git a/src/pages/OnboardingWorkspaceInvite/BaseOnboardingWorkspaceInvite.tsx b/src/pages/OnboardingWorkspaceInvite/BaseOnboardingWorkspaceInvite.tsx index 2f11adbd48de..45e3f1681508 100644 --- a/src/pages/OnboardingWorkspaceInvite/BaseOnboardingWorkspaceInvite.tsx +++ b/src/pages/OnboardingWorkspaceInvite/BaseOnboardingWorkspaceInvite.tsx @@ -299,8 +299,8 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo ) { return translate('messages.userIsAlreadyMember', {login: searchValue, name: policy?.name ?? ''}); } - return getHeaderMessage(personalDetails.length !== 0, usersToInvite.length > 0, searchValue); - }, [excludedUsers, translate, debouncedSearchTerm, policy?.name, usersToInvite, personalDetails.length]); + return getHeaderMessage(personalDetails.length !== 0, usersToInvite.length > 0, searchValue, false, countryCode); + }, [excludedUsers, translate, debouncedSearchTerm, policy?.name, usersToInvite, personalDetails.length, countryCode]); const footerContent = useMemo( () => ( diff --git a/src/pages/Share/ShareTab.tsx b/src/pages/Share/ShareTab.tsx index 51b2761d6e89..deb115ce6f48 100644 --- a/src/pages/Share/ShareTab.tsx +++ b/src/pages/Share/ShareTab.tsx @@ -105,9 +105,9 @@ function ShareTab({ref}: ShareTabProps) { const [sections, header] = useMemo(() => { const newSections = []; newSections.push({title: textInputValue.trim() === '' ? translate('search.recentChats') : undefined, data: styledRecentReports}); - const headerMessage = getHeaderMessage(styledRecentReports.length !== 0, false, textInputValue.trim(), false); + const headerMessage = getHeaderMessage(styledRecentReports.length !== 0, false, textInputValue.trim(), false, countryCode); return [newSections, headerMessage]; - }, [textInputValue, styledRecentReports, translate]); + }, [textInputValue, styledRecentReports, translate, countryCode]); const onSelectRow = (item: OptionData) => { let reportID = item?.reportID ?? CONST.DEFAULT_NUMBER_ID; diff --git a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx index 94630e1cc437..997d2258c38a 100644 --- a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx @@ -166,6 +166,8 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType (chatOptions.personalDetails ?? []).length + (chatOptions.recentReports ?? []).length !== 0, !!chatOptions?.userToInvite, debouncedSearchTerm.trim(), + false, + countryCode, ); return [newSections, headerMessage]; @@ -177,8 +179,9 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType chatOptions.userToInvite, debouncedSearchTerm, personalDetails, - translate, reportAttributesDerived, + translate, + countryCode, ]); const selectAccountant = useCallback( diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 2611479983ce..a7fc6772f40e 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -213,6 +213,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde !!chatOptions?.userToInvite, cleanSearchTerm, attendees.some((attendee) => getPersonalDetailSearchTerms(attendee).join(' ').toLowerCase().includes(cleanSearchTerm)), + countryCode, ); return [newSections, headerMessage]; @@ -225,8 +226,9 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde cleanSearchTerm, attendees, personalDetails, - translate, reportAttributesDerived, + translate, + countryCode, ]); const addAttendeeToSelection = useCallback( diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index f53b35276fcf..be51bd9d2707 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -260,6 +260,7 @@ function MoneyRequestParticipantsSelector({ !!chatOptions?.userToInvite, debouncedSearchTerm.trim(), participants.some((participant) => getPersonalDetailSearchTerms(participant).join(' ').toLowerCase().includes(cleanSearchTerm)), + countryCode, ), [ chatOptions.personalDetails, @@ -270,6 +271,7 @@ function MoneyRequestParticipantsSelector({ cleanSearchTerm, debouncedSearchTerm, participants, + countryCode, ], ); /** diff --git a/src/pages/settings/AboutPage/ShareLogList/BaseShareLogList.tsx b/src/pages/settings/AboutPage/ShareLogList/BaseShareLogList.tsx index 0d0193f6c2ed..72ca099d33ae 100644 --- a/src/pages/settings/AboutPage/ShareLogList/BaseShareLogList.tsx +++ b/src/pages/settings/AboutPage/ShareLogList/BaseShareLogList.tsx @@ -63,6 +63,8 @@ function BaseShareLogList({onAttachLogToReport}: BaseShareLogListProps) { (filteredOptions.recentReports?.length || 0) + (filteredOptions.personalDetails?.length || 0) !== 0, !!filteredOptions.userToInvite, debouncedSearchValue.trim(), + false, + countryCode, ); return {...filteredOptions, headerMessage}; diff --git a/src/pages/settings/Profile/CustomStatus/VacationDelegatePage.tsx b/src/pages/settings/Profile/CustomStatus/VacationDelegatePage.tsx index 02982f8cd71f..a10168efd351 100644 --- a/src/pages/settings/Profile/CustomStatus/VacationDelegatePage.tsx +++ b/src/pages/settings/Profile/CustomStatus/VacationDelegatePage.tsx @@ -56,7 +56,7 @@ function useOptions() { countryCode, ); - const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0, !!userToInvite, ''); + const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0, !!userToInvite, '', false, countryCode); return { userToInvite, @@ -76,6 +76,8 @@ function useOptions() { (filteredOptions.recentReports?.length || 0) + (filteredOptions.personalDetails?.length || 0) !== 0, !!filteredOptions.userToInvite, debouncedSearchValue, + false, + countryCode, ); return { diff --git a/src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx b/src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx index 73a38e5a89c1..eaa5020f188a 100644 --- a/src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx +++ b/src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx @@ -57,7 +57,7 @@ function useOptions() { countryCode, ); - const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0, !!userToInvite, ''); + const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0, !!userToInvite, '', false, countryCode); if (isLoading) { // eslint-disable-next-line react-compiler/react-compiler diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 855796c72c15..4165e23b08a9 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -61,7 +61,7 @@ function useOptions() { countryCode, ); - const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0 || !!currentUserOption, !!userToInvite, ''); + const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0 || !!currentUserOption, !!userToInvite, '', false, countryCode); if (isLoading) { // eslint-disable-next-line react-compiler/react-compiler @@ -98,6 +98,8 @@ function useOptions() { (filteredOptions.recentReports?.length || 0) + (filteredOptions.personalDetails?.length || 0) !== 0 || !!filteredOptions.currentUserOption, !!filteredOptions.userToInvite, debouncedSearchValue, + false, + countryCode, ); return { diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx index 2925fe8cecc5..82029faa6d16 100644 --- a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx +++ b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx @@ -69,6 +69,7 @@ function TaskShareDestinationSelectorModal() { const {translate} = useLocalize(); const {isOffline} = useNetwork(); const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true}); + const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: true}); const {searchTerm, setSearchTerm, availableOptions, areOptionsInitialized, onListEndReached} = useSearchSelector({ selectionMode: CONST.SEARCH_SELECTOR.SELECTION_MODE_SINGLE, @@ -95,8 +96,8 @@ function TaskShareDestinationSelectorModal() { const textInputHint = useMemo(() => (isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''), [isOffline, translate]); const headerMessage = useMemo(() => { - return getHeaderMessage(filteredOptions.recentReports && filteredOptions.recentReports.length !== 0, false, searchTerm); - }, [filteredOptions.recentReports, searchTerm]); + return getHeaderMessage(filteredOptions.recentReports && filteredOptions.recentReports.length !== 0, false, searchTerm, false, countryCode); + }, [filteredOptions.recentReports, searchTerm, countryCode]); const sections = useMemo( () => diff --git a/src/pages/workspace/WorkspaceInvitePage.tsx b/src/pages/workspace/WorkspaceInvitePage.tsx index d1d359db00bc..a2387ef1c719 100644 --- a/src/pages/workspace/WorkspaceInvitePage.tsx +++ b/src/pages/workspace/WorkspaceInvitePage.tsx @@ -287,8 +287,8 @@ function WorkspaceInvitePage({route, policy}: WorkspaceInvitePageProps) { ) { return translate('messages.userIsAlreadyMember', {login: searchValue, name: policyName}); } - return getHeaderMessage(personalDetails.length !== 0, usersToInvite.length > 0, searchValue); - }, [excludedUsers, translate, debouncedSearchTerm, policyName, usersToInvite, personalDetails.length]); + return getHeaderMessage(personalDetails.length !== 0, usersToInvite.length > 0, searchValue, false, countryCode); + }, [excludedUsers, translate, debouncedSearchTerm, policyName, usersToInvite, personalDetails.length, countryCode]); const footerContent = useMemo( () => ( diff --git a/src/pages/workspace/companyCards/assignCard/AssigneeStep.tsx b/src/pages/workspace/companyCards/assignCard/AssigneeStep.tsx index c1049c9dbcab..96737cd32af3 100644 --- a/src/pages/workspace/companyCards/assignCard/AssigneeStep.tsx +++ b/src/pages/workspace/companyCards/assignCard/AssigneeStep.tsx @@ -169,8 +169,8 @@ function AssigneeStep({policy, feed}: AssigneeStepProps) { const headerMessage = useMemo(() => { const searchValue = debouncedSearchTerm.trim().toLowerCase(); - return getHeaderMessage(sections[0].data.length !== 0, false, searchValue); - }, [debouncedSearchTerm, sections]); + return getHeaderMessage(sections[0].data.length !== 0, false, searchValue, false, countryCode); + }, [debouncedSearchTerm, sections, countryCode]); return ( { const searchValue = debouncedSearchTerm.trim().toLowerCase(); - return getHeaderMessage(sections[0].data.length !== 0, false, searchValue); - }, [debouncedSearchTerm, sections]); + return getHeaderMessage(sections[0].data.length !== 0, false, searchValue, false, countryCode); + }, [debouncedSearchTerm, sections, countryCode]); return ( { const searchValue = debouncedSearchTerm.trim().toLowerCase(); - return getHeaderMessage(sections?.at(0)?.data.length !== 0, false, searchValue); - }, [debouncedSearchTerm, sections]); + return getHeaderMessage(sections?.at(0)?.data.length !== 0, false, searchValue, false, countryCode); + }, [debouncedSearchTerm, sections, countryCode]); const handleConfirm = useCallback(() => { if (selectedOptions.length === 0) { From b0fb642631c75050f1741536682980b4ca47313f Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Fri, 17 Oct 2025 09:03:42 +0200 Subject: [PATCH 3/5] revert unnecessary changes --- src/libs/ContactUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ContactUtils.ts b/src/libs/ContactUtils.ts index f5945491a4ce..34576062b426 100644 --- a/src/libs/ContactUtils.ts +++ b/src/libs/ContactUtils.ts @@ -28,7 +28,7 @@ function sortEmailObjects(emails: StringHolder[], localeCompare: LocaleContextPr }); } -const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: LocaleContextProps['localeCompare'], countryCode: number): Array> => { +const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: LocaleContextProps['localeCompare']): Array> => { return deviceContacts .map((contact) => { const email = sortEmailObjects(contact?.emailAddresses ?? [], localeCompare)?.at(0) ?? ''; @@ -47,7 +47,6 @@ const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: Locale email, phone: phoneNumber, avatar: avatarSource, - countryCode, }); }) .filter((contact): contact is SearchOption => contact !== null); From a9cc6e04d9dc585d9d213f9ef870bb5439378c39 Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Fri, 17 Oct 2025 09:25:53 +0200 Subject: [PATCH 4/5] revert unnecessary changes --- src/libs/LoginUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/LoginUtils.ts b/src/libs/LoginUtils.ts index c00b2fbaa55e..c53e05b93d44 100644 --- a/src/libs/LoginUtils.ts +++ b/src/libs/LoginUtils.ts @@ -92,12 +92,12 @@ function validateNumber(values: string): string { * Check number is valid and attach country code * @returns a valid phone number with country code */ -function getPhoneLogin(partnerUserID: string, countryCode: number): string { +function getPhoneLogin(partnerUserID: string): string { if (partnerUserID.length === 0) { return ''; } - return appendCountryCodeWithCountryCode(getPhoneNumberWithoutSpecialChars(partnerUserID), countryCode); + return appendCountryCode(getPhoneNumberWithoutSpecialChars(partnerUserID)); } /** From 3c002cca7025c81f63d53d2519ce55f255facbbb Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Fri, 17 Oct 2025 10:01:09 +0200 Subject: [PATCH 5/5] remove unnecessary changes --- src/pages/TeachersUnite/KnowATeacherPage.tsx | 7 +++---- .../settings/Profile/Contacts/NewContactMethodPage.tsx | 9 ++++----- .../Security/MergeAccounts/AccountDetailsPage.tsx | 3 +-- tests/unit/LoginUtilsTest.ts | 6 +++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/pages/TeachersUnite/KnowATeacherPage.tsx b/src/pages/TeachersUnite/KnowATeacherPage.tsx index ba63f08f34f2..f88e294d2af4 100644 --- a/src/pages/TeachersUnite/KnowATeacherPage.tsx +++ b/src/pages/TeachersUnite/KnowATeacherPage.tsx @@ -26,13 +26,12 @@ function KnowATeacherPage() { const {translate} = useLocalize(); const {isProduction} = useEnvironment(); const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true}); - const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: true}); /** * Submit form to pass firstName, partnerUserID and lastName */ const onSubmit = (values: FormOnyxValues) => { - const phoneLogin = getPhoneLogin(values.partnerUserID, countryCode); + const phoneLogin = getPhoneLogin(values.partnerUserID); const validateIfNumber = validateNumber(phoneLogin); const contactMethod = (validateIfNumber || values.partnerUserID).trim().toLowerCase(); const firstName = values.firstName.trim(); @@ -49,7 +48,7 @@ function KnowATeacherPage() { const validate = useCallback( (values: FormOnyxValues) => { const errors = getFieldRequiredErrors(values, [INPUT_IDS.FIRST_NAME, INPUT_IDS.LAST_NAME]); - const phoneLogin = getPhoneLogin(values.partnerUserID, countryCode); + const phoneLogin = getPhoneLogin(values.partnerUserID); const validateIfNumber = validateNumber(phoneLogin); if (!isValidDisplayName(values.firstName)) { @@ -88,7 +87,7 @@ function KnowATeacherPage() { return errors; }, - [loginList, translate, countryCode], + [loginList, translate], ); return ( diff --git a/src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx b/src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx index 45efd48725b2..0910fd29dba4 100644 --- a/src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx +++ b/src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx @@ -33,25 +33,24 @@ function NewContactMethodPage({route}: NewContactMethodPageProps) { const {translate} = useLocalize(); const loginInputRef = useRef(null); const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true}); - const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: true}); const navigateBackTo = route?.params?.backTo; const handleValidateMagicCode = useCallback( (values: FormOnyxValues) => { - const phoneLogin = getPhoneLogin(values.phoneOrEmail, countryCode); + const phoneLogin = getPhoneLogin(values.phoneOrEmail); const validateIfNumber = validateNumber(phoneLogin); const submitDetail = (validateIfNumber || values.phoneOrEmail).trim().toLowerCase(); resetValidateActionCodeSent(); addPendingContactMethod(submitDetail); Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD_CONFIRM_MAGIC_CODE.getRoute(submitDetail, navigateBackTo)); }, - [countryCode, navigateBackTo], + [navigateBackTo], ); const validate = useCallback( (values: FormOnyxValues): Errors => { - const phoneLogin = getPhoneLogin(values.phoneOrEmail, countryCode); + const phoneLogin = getPhoneLogin(values.phoneOrEmail); const validateIfNumber = validateNumber(phoneLogin); const errors = {}; @@ -83,7 +82,7 @@ function NewContactMethodPage({route}: NewContactMethodPageProps) { // the loginList gets updated, causing this function to run again. // https://github.com/Expensify/App/issues/20610 // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - [translate, countryCode], + [translate], ); const onBackButtonPress = useCallback(() => { diff --git a/src/pages/settings/Security/MergeAccounts/AccountDetailsPage.tsx b/src/pages/settings/Security/MergeAccounts/AccountDetailsPage.tsx index 3f8a870fefcb..7cbb03362ae9 100644 --- a/src/pages/settings/Security/MergeAccounts/AccountDetailsPage.tsx +++ b/src/pages/settings/Security/MergeAccounts/AccountDetailsPage.tsx @@ -72,7 +72,6 @@ function AccountDetailsPage() { const {params} = useRoute>(); const [email, setEmail] = useState(params?.email ?? ''); const {inputCallbackRef} = useAutoFocusInput(); - const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: true}); const validateCodeSent = getValidateCodeForAccountMerge?.validateCodeSent; const latestError = getLatestErrorMessage(getValidateCodeForAccountMerge); const errorKey = getValidateCodeErrorKey(latestError); @@ -145,7 +144,7 @@ function AccountDetailsPage() { } else if (login.trim() === userEmailOrPhone) { addErrorMessage(errors, INPUT_IDS.PHONE_OR_EMAIL, translate('common.error.email')); } else { - const phoneLogin = getPhoneLogin(login, countryCode); + const phoneLogin = getPhoneLogin(login); const validateIfNumber = validateNumber(phoneLogin); if (!Str.isValidEmail(login) && !validateIfNumber) { diff --git a/tests/unit/LoginUtilsTest.ts b/tests/unit/LoginUtilsTest.ts index 0673880812db..3b0d788d6591 100644 --- a/tests/unit/LoginUtilsTest.ts +++ b/tests/unit/LoginUtilsTest.ts @@ -79,17 +79,17 @@ describe('LoginUtils', () => { describe('getPhoneLogin', () => { it('Should return valid phone number with country code if provided phone number is valid and with country code', () => { const givenPhone = '+12345678901'; - const parsedPhone = LoginUtils.getPhoneLogin(givenPhone, 1); + const parsedPhone = LoginUtils.getPhoneLogin(givenPhone); expect(parsedPhone).toBe('+12345678901'); }); it('Should return valid phone number with country code if provided phone number is valid and without country code', () => { const givenPhone = '2345678901'; - const parsedPhone = LoginUtils.getPhoneLogin(givenPhone, 1); + const parsedPhone = LoginUtils.getPhoneLogin(givenPhone); expect(parsedPhone).toBe('+12345678901'); }); it('Should return empty string if provided phone number is empty', () => { const givenPhone = ''; - const parsedPhone = LoginUtils.getPhoneLogin(givenPhone, 1); + const parsedPhone = LoginUtils.getPhoneLogin(givenPhone); expect(parsedPhone).toBe(''); }); });