diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index ca7f8d4e2a06..250dfdbd74d5 100644 --- a/src/libs/SessionUtils.ts +++ b/src/libs/SessionUtils.ts @@ -1,4 +1,5 @@ import Onyx from 'react-native-onyx'; +import useOnyx from '@hooks/useOnyx'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -107,4 +108,18 @@ function checkIfShouldUseNewPartnerName(partnerUserID?: string): boolean { return false; } -export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, checkIfShouldUseNewPartnerName, isLoggingInAsDelegate}; +const AGENT_EMAIL_REGEX = /^agent_\d+@expensify\.ai$/; + +function isAgentEmail(email?: string): boolean { + if (!email) { + return false; + } + return AGENT_EMAIL_REGEX.test(email); +} + +function useIsAgentAccount(): boolean { + const [sessionEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email}); + return isAgentEmail(sessionEmail); +} + +export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, checkIfShouldUseNewPartnerName, isLoggingInAsDelegate, isAgentEmail, useIsAgentAccount}; diff --git a/src/pages/settings/Profile/ProfilePage.tsx b/src/pages/settings/Profile/ProfilePage.tsx index 502bc6f6fecf..221c755eeaa5 100755 --- a/src/pages/settings/Profile/ProfilePage.tsx +++ b/src/pages/settings/Profile/ProfilePage.tsx @@ -1,6 +1,7 @@ import {useRoute} from '@react-navigation/native'; import React, {useMemo} from 'react'; import {View} from 'react-native'; +import type {ValueOf} from 'type-fest'; import ActivityIndicator from '@components/ActivityIndicator'; import AvatarButtonWithIcon from '@components/AvatarButtonWithIcon'; import AvatarSkeleton from '@components/AvatarSkeleton'; @@ -29,12 +30,14 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {SettingsSplitNavigatorParamList} from '@libs/Navigation/types'; import {getDisplayNameOrDefault, getFormattedAddress} from '@libs/PersonalDetailsUtils'; +import {useIsAgentAccount} from '@libs/SessionUtils'; import type {SkeletonSpanReasonAttributes} from '@libs/telemetry/useSkeletonSpan'; import {getContactMethodsOptions, getLoginListBrickRoadIndicator} from '@libs/UserUtils'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import type {Route} from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -73,7 +76,15 @@ function ProfilePage() { const [vacationDelegate] = useOnyx(ONYXKEYS.NVP_PRIVATE_VACATION_DELEGATE); const {isActingAsDelegate} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); - const publicOptions = [ + const isAgentAccount = useIsAgentAccount(); + const publicOptions: Array<{ + description: string; + title: string; + pageRoute?: Route; + brickRoadIndicator?: ValueOf; + testID?: string; + sentryLabel?: string; + }> = [ { description: translate('displayNamePage.headerTitle'), title: formatPhoneNumber(getDisplayNameOrDefault(currentUserPersonalDetails)), @@ -86,9 +97,9 @@ function ProfilePage() { .map((login) => login?.menuItemTitle) .filter(Boolean) .join(', '), - pageRoute: ROUTES.SETTINGS_CONTACT_METHODS.route, - brickRoadIndicator: contactMethodBrickRoadIndicator, - testID: 'contact-method-menu-item', + pageRoute: isAgentAccount ? undefined : ROUTES.SETTINGS_CONTACT_METHODS.route, + brickRoadIndicator: isAgentAccount ? undefined : contactMethodBrickRoadIndicator, + testID: isAgentAccount ? undefined : 'contact-method-menu-item', sentryLabel: CONST.SENTRY_LABEL.SETTINGS_PROFILE.CONTACT_METHODS, }, { @@ -98,18 +109,24 @@ function ProfilePage() { brickRoadIndicator: isEmptyObject(vacationDelegate?.errors) ? undefined : CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR, sentryLabel: CONST.SENTRY_LABEL.SETTINGS_PROFILE.STATUS, }, - { - description: translate('pronounsPage.pronouns'), - title: getPronouns(), - pageRoute: ROUTES.SETTINGS_PRONOUNS, - sentryLabel: CONST.SENTRY_LABEL.SETTINGS_PROFILE.PRONOUNS, - }, - { - description: translate('timezonePage.timezone'), - title: currentUserPersonalDetails?.timezone?.selected ?? '', - pageRoute: ROUTES.SETTINGS_TIMEZONE, - sentryLabel: CONST.SENTRY_LABEL.SETTINGS_PROFILE.TIMEZONE, - }, + ...(!isAgentAccount + ? [ + { + description: translate('pronounsPage.pronouns'), + title: getPronouns(), + pageRoute: ROUTES.SETTINGS_PRONOUNS as Route, + testID: 'pronouns-menu-item', + sentryLabel: CONST.SENTRY_LABEL.SETTINGS_PROFILE.PRONOUNS, + }, + { + description: translate('timezonePage.timezone'), + title: currentUserPersonalDetails?.timezone?.selected ?? '', + pageRoute: ROUTES.SETTINGS_TIMEZONE as Route, + testID: 'timezone-menu-item', + sentryLabel: CONST.SENTRY_LABEL.SETTINGS_PROFILE.TIMEZONE, + }, + ] + : []), ]; const privateOptions = [ @@ -233,20 +250,24 @@ function ProfilePage() { )} - {publicOptions.map((detail, index) => ( - Navigation.navigate(detail.pageRoute)} - brickRoadIndicator={detail.brickRoadIndicator} - pressableTestID={detail?.testID} - sentryLabel={detail.sentryLabel} - /> - ))} + {publicOptions.map((detail, index) => { + const {pageRoute} = detail; + return ( + Navigation.navigate(pageRoute) : undefined} + brickRoadIndicator={detail.brickRoadIndicator} + pressableTestID={detail?.testID} + sentryLabel={detail.sentryLabel} + /> + ); + })}