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
5 changes: 2 additions & 3 deletions src/libs/UserUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';

import CONST from '@src/CONST';
import type {LoginList, Logins, NewLogin, PrivatePersonalDetails, VacationDelegate} from '@src/types/onyx';
Expand All @@ -12,7 +12,6 @@ import {Str} from 'expensify-common';
import type {AvatarSource} from './UserAvatarUtils';

import hashCode from './hashCode';
import {formatPhoneNumber} from './LocalePhoneNumber';

type LoginListIndicator = ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | undefined;

Expand Down Expand Up @@ -227,7 +226,7 @@ function getContactMethod(primaryLogin: string | undefined, email: string | unde
/**
* Gets details about contact methods to be displayed as MenuItems
*/
function getContactMethodsOptions(translate: LocalizedTranslate, loginList?: LoginList, defaultEmail?: string) {
function getContactMethodsOptions(translate: LocalizedTranslate, formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], loginList?: LoginList, defaultEmail?: string) {
if (!loginList) {
return [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ContactMethodsPageProps = PlatformStackScreenProps<SettingsNavigatorParamLi

function ContactMethodsPage({route}: ContactMethodsPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {translate, formatPhoneNumber} = useLocalize();
const [loginList] = useOnyx(ONYXKEYS.LOGINS, {selector: expensifyLoginsSelector});
const [session] = useOnyx(ONYXKEYS.SESSION);
const navigateBackTo = route?.params?.backTo;
Expand All @@ -43,7 +43,7 @@ function ContactMethodsPage({route}: ContactMethodsPageProps) {
const {isAccountLocked} = useLockedAccountState();
const {showLockedAccountModal} = useLockedAccountActions();

const options = useMemo(() => getContactMethodsOptions(translate, loginList, session?.email), [translate, loginList, session?.email]);
const options = useMemo(() => getContactMethodsOptions(translate, formatPhoneNumber, loginList, session?.email), [translate, formatPhoneNumber, loginList, session?.email]);

const addNewContactMethod = useCallback(() => {
if (isActingAsDelegate) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Profile/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function ProfilePage() {
const pronounsKey = currentUserPersonalDetails?.pronouns?.replace(CONST.PRONOUNS.PREFIX, '') ?? '';
return pronounsKey ? translate(`pronouns.${pronounsKey}` as TranslationPaths) : translate('profilePage.selectYourPronouns');
};
const logins = useMemo(() => getContactMethodsOptions(translate, loginList, session?.email), [loginList, session?.email, translate]);
const logins = useMemo(() => getContactMethodsOptions(translate, formatPhoneNumber, loginList, session?.email), [loginList, session?.email, translate, formatPhoneNumber]);

const avatarURL = currentUserPersonalDetails?.avatar ?? '';
const accountID = currentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID;
Expand Down
23 changes: 21 additions & 2 deletions tests/unit/UserUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CONST from '@src/CONST';
import * as UserUtils from '@src/libs/UserUtils';
import type {LoginList} from '@src/types/onyx';

import {translateLocal} from '../utils/TestHelper';
import {formatPhoneNumber, translateLocal} from '../utils/TestHelper';

describe('UserUtils', () => {
describe('getContactMethodsOptions', () => {
Expand Down Expand Up @@ -65,11 +65,30 @@ describe('UserUtils', () => {

describe.each(TEST_CASES)('$name', ({loginList, defaultEmail, expectedIndicators}) => {
test('verifies indicator states', () => {
const options = UserUtils.getContactMethodsOptions(translateLocal, loginList, defaultEmail);
const options = UserUtils.getContactMethodsOptions(translateLocal, formatPhoneNumber, loginList, defaultEmail);
const indicators = options.map((o) => o?.indicator);
expect(indicators).toEqual(expectedIndicators);
});
});

it('formats SMS contact method titles using the passed formatter', () => {
const phoneLogin = '+18172057554@expensify.sms';
const formatPhoneNumberMock = jest.fn(() => '(817) 205-7554');
const options = UserUtils.getContactMethodsOptions(
translateLocal,
formatPhoneNumberMock,
{
[phoneLogin]: {
partnerUserID: phoneLogin,
validatedDate: '2024-01-01',
},
},
phoneLogin,
);

expect(options.at(0)?.menuItemTitle).toBe('(817) 205-7554');
expect(formatPhoneNumberMock).toHaveBeenCalledWith(phoneLogin);
});
});

describe('getLoginListBrickRoadIndicator', () => {
Expand Down
Loading