Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/hooks/useContactImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import type {ContactImportResult} from '@libs/ContactImport/types';
import useContactPermissions from '@libs/ContactPermission/useContactPermissions';
import getContacts from '@libs/ContactUtils';
import type {SearchOption} from '@libs/OptionsListUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails} from '@src/types/onyx';
import useLocalize from './useLocalize';
import useOnyx from './useOnyx';

/**
* Return type of the useContactImport hook.
Expand All @@ -28,14 +31,15 @@ function useContactImport(): UseContactImportResult {
const [contactPermissionState, setContactPermissionState] = useState<PermissionStatus>(RESULTS.UNAVAILABLE);
const [contacts, setContacts] = useState<Array<SearchOption<PersonalDetails>>>([]);
const {localeCompare} = useLocalize();
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});

const importAndSaveContacts = useCallback(() => {
contactImport().then(({contactList, permissionStatus}: ContactImportResult) => {
setContactPermissionState(permissionStatus);
const usersFromContact = getContacts(contactList, localeCompare);
const usersFromContact = getContacts(contactList, localeCompare, countryCode);
setContacts(usersFromContact);
});
}, [localeCompare]);
}, [localeCompare, countryCode]);

useContactPermissions({
importAndSaveContacts,
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ContactUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function sortEmailObjects(emails: StringHolder[], localeCompare: LocaleContextPr
});
}

const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: LocaleContextProps['localeCompare']): Array<SearchOption<PersonalDetails>> => {
const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: LocaleContextProps['localeCompare'], countryCode: number): Array<SearchOption<PersonalDetails>> => {
return deviceContacts
.map((contact) => {
const email = sortEmailObjects(contact?.emailAddresses ?? [], localeCompare)?.at(0) ?? '';
Expand All @@ -47,6 +47,7 @@ const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: Locale
email,
phone: phoneNumber,
avatar: avatarSource,
countryCode,
});
})
.filter((contact): contact is SearchOption<PersonalDetails> => contact !== null);
Expand Down
5 changes: 3 additions & 2 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import filterArrayByMatch from '@libs/filterArrayByMatch';
import {isReportMessageAttachment} from '@libs/isReportMessageAttachment';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import {translateLocal} from '@libs/Localize';
import {appendCountryCode, appendCountryCodeWithCountryCode, getPhoneNumberWithoutSpecialChars} from '@libs/LoginUtils';
import {appendCountryCodeWithCountryCode, getPhoneNumberWithoutSpecialChars} from '@libs/LoginUtils';
import {MaxHeap} from '@libs/MaxHeap';
import {MinHeap} from '@libs/MinHeap';
import {getForReportAction} from '@libs/ModifiedExpenseMessage';
Expand Down Expand Up @@ -1471,6 +1471,7 @@ function getUserToInviteContactOption({
email = '',
phone = '',
avatar = '',
countryCode = CONST.DEFAULT_COUNTRY_CODE,
}: GetUserToInviteConfig): SearchOption<PersonalDetails> | null {
// If email is provided, use it as the primary identifier
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand All @@ -1479,7 +1480,7 @@ function getUserToInviteContactOption({
// Handle phone number parsing for either provided phone or searchValue
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const phoneToCheck = phone || searchValue;
const parsedPhoneNumber = parsePhoneNumber(appendCountryCode(Str.removeSMSDomain(phoneToCheck)));
const parsedPhoneNumber = parsePhoneNumber(appendCountryCodeWithCountryCode(Str.removeSMSDomain(phoneToCheck), countryCode));

const isCurrentUserLogin = isCurrentUser({login: effectiveSearchValue} as PersonalDetails);
const isInSelectedOption = selectedOptions.some((option) => 'login' in option && option.login === effectiveSearchValue);
Expand Down
8 changes: 5 additions & 3 deletions src/pages/MissingPersonalDetails/substeps/PhoneNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React, {useCallback} from 'react';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import SingleFieldStep from '@components/SubStepForms/SingleFieldStep';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePersonalDetailsFormSubmit from '@hooks/usePersonalDetailsFormSubmit';
import {appendCountryCode, formatE164PhoneNumber} from '@libs/LoginUtils';
import {appendCountryCodeWithCountryCode, formatE164PhoneNumber} from '@libs/LoginUtils';
import {isRequiredFulfilled, isValidPhoneNumber} from '@libs/ValidationUtils';
import type {CustomSubStepProps} from '@pages/MissingPersonalDetails/types';
import CONST from '@src/CONST';
Expand All @@ -14,12 +15,13 @@ const STEP_FIELDS = [INPUT_IDS.PHONE_NUMBER];

function PhoneNumberStep({isEditing, onNext, onMove, personalDetailsValues}: CustomSubStepProps) {
const {translate} = useLocalize();
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: true});

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM> => {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM> = {};
const phoneNumber = values[INPUT_IDS.PHONE_NUMBER];
const phoneNumberWithCountryCode = appendCountryCode(phoneNumber);
const phoneNumberWithCountryCode = appendCountryCodeWithCountryCode(phoneNumber, countryCode);

if (!isRequiredFulfilled(phoneNumber)) {
errors[INPUT_IDS.PHONE_NUMBER] = translate('common.error.fieldRequired');
Expand All @@ -32,7 +34,7 @@ function PhoneNumberStep({isEditing, onNext, onMove, personalDetailsValues}: Cus

return errors;
},
[translate],
[translate, countryCode],
);

const handleSubmit = usePersonalDetailsFormSubmit({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {searchInServer} from '@libs/actions/Report';
import {READ_COMMANDS} from '@libs/API/types';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import HttpUtils from '@libs/HttpUtils';
import {appendCountryCode} from '@libs/LoginUtils';
import {appendCountryCodeWithCountryCode} from '@libs/LoginUtils';
import {navigateAfterOnboardingWithMicrotaskQueue} from '@libs/navigateAfterOnboarding';
import type {MemberForList} from '@libs/OptionsListUtils';
import {filterAndOrderOptions, formatMemberForList, getHeaderMessage, getMemberInviteOptions, getSearchValueForPhoneOrEmail} from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -58,13 +58,13 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo
const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false);
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {canBeMissing: true, initWithStoredValues: false});
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: false});
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const session = useSession();
const {isBetaEnabled} = usePermissions();
const {options, areOptionsInitialized} = useOptionsList({
shouldInitialize: didScreenTransitionEnd,
});
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});

const welcomeNoteSubject = useMemo(
() => `# ${currentUserPersonalDetails?.displayName ?? ''} invited you to ${policy?.name ?? 'a workspace'}`,
Expand Down Expand Up @@ -295,7 +295,11 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo
}
if (
usersToInvite.length === 0 &&
excludedUsers[parsePhoneNumber(appendCountryCode(searchValue)).possible ? addSMSDomainIfPhoneNumber(appendCountryCode(searchValue)) : searchValue]
excludedUsers[
parsePhoneNumber(appendCountryCodeWithCountryCode(searchValue, countryCode)).possible
? addSMSDomainIfPhoneNumber(appendCountryCodeWithCountryCode(searchValue, countryCode))
: searchValue
]
) {
return translate('messages.userIsAlreadyMember', {login: searchValue, name: policy?.name ?? ''});
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/iou/request/MoneyRequestAttendeeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
action,
isPaidGroupPolicy,
searchTerm,
countryCode,
]);

const chatOptions = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import {getEarliestErrorField} from '@libs/ErrorUtils';
import {appendCountryCode, formatE164PhoneNumber} from '@libs/LoginUtils';
import {appendCountryCodeWithCountryCode, formatE164PhoneNumber} from '@libs/LoginUtils';
import Navigation from '@libs/Navigation/Navigation';
import {isRequiredFulfilled, isValidPhoneNumber} from '@libs/ValidationUtils';
import {clearPhoneNumberError, updatePhoneNumber as updatePhone} from '@userActions/PersonalDetails';
Expand All @@ -25,6 +25,7 @@ import type {PrivatePersonalDetails} from '@src/types/onyx';
function PhoneNumberPage() {
const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS, {canBeMissing: true});
const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const styles = useThemeStyles();
const {translate} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();
Expand Down Expand Up @@ -57,7 +58,7 @@ function PhoneNumberPage() {
return errors;
}

const phoneNumberWithCountryCode = appendCountryCode(phoneNumberValue);
const phoneNumberWithCountryCode = appendCountryCodeWithCountryCode(phoneNumberValue, countryCode);

if (!isValidPhoneNumber(phoneNumberWithCountryCode)) {
errors[INPUT_IDS.PHONE_NUMBER] = translate('common.error.phoneNumber');
Expand All @@ -70,7 +71,7 @@ function PhoneNumberPage() {

return errors;
},
[translate, validateLoginError],
[translate, validateLoginError, countryCode],
);

return (
Expand Down
11 changes: 6 additions & 5 deletions src/pages/signin/LoginForm/BaseLoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {isMobileWebKit} from '@libs/Browser';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import {getLatestErrorMessage} from '@libs/ErrorUtils';
import isInputAutoFilled from '@libs/isInputAutoFilled';
import {appendCountryCode, getPhoneNumberWithoutSpecialChars} from '@libs/LoginUtils';
import {appendCountryCodeWithCountryCode, getPhoneNumberWithoutSpecialChars} from '@libs/LoginUtils';
import {parsePhoneNumber} from '@libs/PhoneNumber';
import StringUtils from '@libs/StringUtils';
import {isNumericWithSpecialChars} from '@libs/ValidationUtils';
Expand All @@ -44,6 +44,7 @@ function BaseLoginForm({blurOnSubmit = false, isVisible, ref}: BaseLoginFormProp
const {login, setLogin} = useLogin();
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
const [closeAccount] = useOnyx(ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM, {canBeMissing: true});
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
Expand All @@ -67,7 +68,7 @@ function BaseLoginForm({blurOnSubmit = false, isVisible, ref}: BaseLoginFormProp
return false;
}

const phoneLogin = appendCountryCode(getPhoneNumberWithoutSpecialChars(loginTrim));
const phoneLogin = appendCountryCodeWithCountryCode(getPhoneNumberWithoutSpecialChars(loginTrim), countryCode);
const parsedPhoneNumber = parsePhoneNumber(phoneLogin);

if (!Str.isValidEmail(loginTrim) && !parsedPhoneNumber.possible) {
Expand All @@ -82,7 +83,7 @@ function BaseLoginForm({blurOnSubmit = false, isVisible, ref}: BaseLoginFormProp
setFormError(undefined);
return true;
},
[setFormError],
[setFormError, countryCode],
);

/**
Expand Down Expand Up @@ -138,12 +139,12 @@ function BaseLoginForm({blurOnSubmit = false, isVisible, ref}: BaseLoginFormProp

const loginTrim = StringUtils.removeInvisibleCharacters(login.trim());

const phoneLogin = appendCountryCode(getPhoneNumberWithoutSpecialChars(loginTrim));
const phoneLogin = appendCountryCodeWithCountryCode(getPhoneNumberWithoutSpecialChars(loginTrim), countryCode);
const parsedPhoneNumber = parsePhoneNumber(phoneLogin);

// Check if this login has an account associated with it or not
beginSignIn(parsedPhoneNumber.possible && parsedPhoneNumber.number?.e164 ? parsedPhoneNumber.number.e164 : loginTrim);
}, [login, account, closeAccount, isOffline, validate]);
}, [login, account, closeAccount, isOffline, validate, countryCode]);

useEffect(() => {
// Call clearAccountMessages on the login page (home route).
Expand Down
10 changes: 7 additions & 3 deletions src/pages/workspace/WorkspaceInvitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {searchInServer} from '@libs/actions/Report';
import {READ_COMMANDS} from '@libs/API/types';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import HttpUtils from '@libs/HttpUtils';
import {appendCountryCode} from '@libs/LoginUtils';
import {appendCountryCodeWithCountryCode} from '@libs/LoginUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import {filterAndOrderOptions, formatMemberForList, getHeaderMessage, getMemberInviteOptions, getSearchValueForPhoneOrEmail, getUserToInviteOption} from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -55,7 +55,7 @@ function WorkspaceInvitePage({route, policy}: WorkspaceInvitePageProps) {
const [usersToInvite, setUsersToInvite] = useState<OptionData[]>([]);
const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false);
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const firstRenderRef = useRef(true);
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: false});
const [invitedEmailsToAccountIDsDraft] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`, {canBeMissing: true});
Expand Down Expand Up @@ -283,7 +283,11 @@ function WorkspaceInvitePage({route, policy}: WorkspaceInvitePageProps) {
}
if (
usersToInvite.length === 0 &&
excludedUsers[parsePhoneNumber(appendCountryCode(searchValue)).possible ? addSMSDomainIfPhoneNumber(appendCountryCode(searchValue)) : searchValue]
excludedUsers[
parsePhoneNumber(appendCountryCodeWithCountryCode(searchValue, countryCode)).possible
? addSMSDomainIfPhoneNumber(appendCountryCodeWithCountryCode(searchValue, countryCode))
: searchValue
]
) {
return translate('messages.userIsAlreadyMember', {login: searchValue, name: policyName});
}
Expand Down
Loading
Loading