diff --git a/src/ROUTES.ts b/src/ROUTES.ts index fa40bfad4e63..68493ee63c85 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -84,15 +84,15 @@ const ROUTES = { }, PROFILE: { route: 'a/:accountID', - getRoute: (accountID?: string | number, backTo?: string, login?: string) => { - const baseRoute = getUrlWithBackToParam(`a/${accountID as string}`, backTo); + getRoute: (accountID?: number, backTo?: string, login?: string) => { + const baseRoute = getUrlWithBackToParam(`a/${accountID}`, backTo); const loginParam = login ? `?login=${encodeURIComponent(login)}` : ''; return `${baseRoute}${loginParam}` as const; }, }, PROFILE_AVATAR: { route: 'a/:accountID/avatar', - getRoute: (accountID: string | number) => `a/${accountID as string}/avatar` as const, + getRoute: (accountID: number) => `a/${accountID}/avatar` as const, }, GET_ASSISTANCE: { @@ -411,7 +411,7 @@ const ROUTES = { }, PRIVATE_NOTES_EDIT: { route: 'r/:reportID/notes/:accountID/edit', - getRoute: (reportID: string, accountID: string | number, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/notes/${accountID as string}/edit` as const, backTo), + getRoute: (reportID: string, accountID: number, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/notes/${accountID}/edit` as const, backTo), }, ROOM_MEMBERS: { route: 'r/:reportID/members', @@ -419,7 +419,7 @@ const ROUTES = { }, ROOM_MEMBER_DETAILS: { route: 'r/:reportID/members/:accountID', - getRoute: (reportID: string, accountID: string | number, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/members/${accountID as string}` as const, backTo), + getRoute: (reportID: string, accountID: number, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/members/${accountID}` as const, backTo), }, ROOM_INVITE: { route: 'r/:reportID/invite/:role?', diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx index 7de4802b3a0f..9b202d3b4308 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx @@ -14,11 +14,11 @@ import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalD import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; -import * as LoginUtils from '@libs/LoginUtils'; +import {formatPhoneNumber} from '@libs/LocalePhoneNumber'; +import {areEmailsFromSamePrivateDomain} from '@libs/LoginUtils'; import Navigation from '@libs/Navigation/Navigation'; -import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; -import * as ReportUtils from '@libs/ReportUtils'; +import {getAccountIDsByLogins, getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils'; +import {isArchivedNonExpenseReport} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -49,7 +49,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona } // If the emails are not in the same private domain, we also return the displayText - if (!LoginUtils.areEmailsFromSamePrivateDomain(displayText, currentUserPersonalDetails.login ?? '')) { + if (!areEmailsFromSamePrivateDomain(displayText, currentUserPersonalDetails.login ?? '')) { return displayText; } @@ -60,16 +60,16 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona if (!isEmpty(htmlAttribAccountID) && personalDetails?.[htmlAttribAccountID]) { const user = personalDetails[htmlAttribAccountID]; accountID = parseInt(htmlAttribAccountID, 10); - mentionDisplayText = LocalePhoneNumber.formatPhoneNumber(user?.login ?? '') || PersonalDetailsUtils.getDisplayNameOrDefault(user); + mentionDisplayText = formatPhoneNumber(user?.login ?? '') || getDisplayNameOrDefault(user); mentionDisplayText = getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, user?.login ?? '') ?? ''; - navigationRoute = ROUTES.PROFILE.getRoute(htmlAttribAccountID, Navigation.getReportRHPActiveRoute()); + navigationRoute = ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute()); } else if ('data' in tnodeClone && !isEmptyObject(tnodeClone.data)) { // We need to remove the LTR unicode and leading @ from data as it is not part of the login mentionDisplayText = tnodeClone.data.replace(CONST.UNICODE.LTR, '').slice(1); // We need to replace tnode.data here because we will pass it to TNodeChildrenRenderer below asMutable(tnodeClone).data = tnodeClone.data.replace(mentionDisplayText, Str.removeSMSDomain(getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID) ?? '')); - accountID = PersonalDetailsUtils.getAccountIDsByLogins([mentionDisplayText])?.at(0) ?? -1; + accountID = getAccountIDsByLogins([mentionDisplayText])?.at(0) ?? -1; navigationRoute = ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute(), mentionDisplayText); mentionDisplayText = Str.removeSMSDomain(mentionDisplayText); } else { @@ -91,12 +91,12 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona if (isDisabled) { return; } - showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs)); + showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, reportNameValuePairs)); }} onPress={(event) => { event.preventDefault(); if (!isEmpty(htmlAttribAccountID)) { - Navigation.navigate(ROUTES.PROFILE.getRoute(htmlAttribAccountID, Navigation.getReportRHPActiveRoute())); + Navigation.navigate(ROUTES.PROFILE.getRoute(parseInt(htmlAttribAccountID, 10), Navigation.getReportRHPActiveRoute())); return; } Navigation.navigate(ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute(), mentionDisplayText)); diff --git a/src/components/RoomHeaderAvatars.tsx b/src/components/RoomHeaderAvatars.tsx index fa6fd600361f..aaff5fc2e84b 100644 --- a/src/components/RoomHeaderAvatars.tsx +++ b/src/components/RoomHeaderAvatars.tsx @@ -24,7 +24,7 @@ function RoomHeaderAvatars({icons, reportID}: RoomHeaderAvatarsProps) { } if (icon.id) { - Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(icon.id)); + Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(Number(icon.id))); } }; diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.tsx b/src/pages/PrivateNotes/PrivateNotesListPage.tsx index 2271eee7c54e..d2cdda140bb8 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.tsx +++ b/src/pages/PrivateNotes/PrivateNotesListPage.tsx @@ -71,16 +71,17 @@ function PrivateNotesListPage({report, accountID: sessionAccountID}: PrivateNote */ const privateNotes = useMemo(() => { const privateNoteBrickRoadIndicator = (accountID: number) => (report.privateNotes?.[accountID].errors ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined); - return Object.keys(report.privateNotes ?? {}).map((accountID: string) => { - const privateNote = report.privateNotes?.[Number(accountID)]; + return Object.keys(report.privateNotes ?? {}).map((privateNoteAccountID: string) => { + const accountID = Number(privateNoteAccountID); + const privateNote = report.privateNotes?.[accountID]; return { reportID: report.reportID, - accountID, - title: Number(sessionAccountID) === Number(accountID) ? translate('privateNotes.myNote') : personalDetailsList?.[accountID]?.login ?? '', + accountID: privateNoteAccountID, + title: Number(sessionAccountID) === accountID ? translate('privateNotes.myNote') : personalDetailsList?.[privateNoteAccountID]?.login ?? '', action: () => Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, accountID, backTo)), - brickRoadIndicator: privateNoteBrickRoadIndicator(Number(accountID)), + brickRoadIndicator: privateNoteBrickRoadIndicator(accountID), note: privateNote?.note ?? '', - disabled: Number(sessionAccountID) !== Number(accountID), + disabled: Number(sessionAccountID) !== accountID, }; }); }, [report, personalDetailsList, sessionAccountID, translate, backTo]); diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index 4fa2fe25797b..485d612fc5ac 100755 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -24,16 +24,24 @@ import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; -import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; +import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils'; import {parsePhoneNumber} from '@libs/PhoneNumber'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as UserUtils from '@libs/UserUtils'; -import * as ValidationUtils from '@libs/ValidationUtils'; +import { + findSelfDMReportID, + getChatByParticipants, + getReportNotificationPreference, + hasAutomatedExpensifyAccountIDs, + isConciergeChatReport, + isHiddenForCurrentUser as isReportHiddenForCurrentUser, + navigateToPrivateNotes, +} from '@libs/ReportUtils'; +import {generateAccountID} from '@libs/UserUtils'; +import {isValidAccountRoute} from '@libs/ValidationUtils'; import type {ProfileNavigatorParamList} from '@navigation/types'; -import * as LinkActions from '@userActions/Link'; -import * as PersonalDetailsActions from '@userActions/PersonalDetails'; -import * as ReportActions from '@userActions/Report'; -import * as SessionActions from '@userActions/Session'; +import {openExternalLink} from '@userActions/Link'; +import {openPublicProfilePage} from '@userActions/PersonalDetails'; +import {hasErrorInPrivateNotes} from '@userActions/Report'; +import {checkIfActionIsAllowed, isAnonymousUser as isAnonymousUserSession} from '@userActions/Session'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -85,14 +93,12 @@ function ProfilePage({route}: ProfilePageProps) { selector: (account) => account?.guideCalendarLink, }); - const accountID = Number(route.params?.accountID ?? -1); + const accountID = Number(route.params?.accountID ?? CONST.DEFAULT_NUMBER_ID); const isCurrentUser = session?.accountID === accountID; const reportKey = useMemo(() => { - const reportID = isCurrentUser - ? ReportUtils.findSelfDMReportID() - : ReportUtils.getChatByParticipants(session?.accountID ? [accountID, session.accountID] : [], reports)?.reportID ?? '-1'; + const reportID = isCurrentUser ? findSelfDMReportID() : getChatByParticipants(session?.accountID ? [accountID, session.accountID] : [], reports)?.reportID; - if (SessionActions.isAnonymousUser() || !reportID) { + if (isAnonymousUserSession() || !reportID) { return `${ONYXKEYS.COLLECTION.REPORT}0` as const; } return `${ONYXKEYS.COLLECTION.REPORT}${reportID}` as const; @@ -102,7 +108,7 @@ function ProfilePage({route}: ProfilePageProps) { const styles = useThemeStyles(); const {translate, formatPhoneNumber} = useLocalize(); - const isValidAccountID = ValidationUtils.isValidAccountRoute(accountID); + const isValidAccountID = isValidAccountRoute(accountID); const loginParams = route.params?.login; const details = useMemo((): OnyxEntry => { @@ -120,11 +126,11 @@ function ProfilePage({route}: ProfilePageProps) { return foundDetails; } // If we don't have the personal details in Onyx, we can create an optimistic account - const optimisticAccountID = UserUtils.generateAccountID(loginParams); + const optimisticAccountID = generateAccountID(loginParams); return {accountID: optimisticAccountID, login: loginParams, displayName: loginParams}; }, [personalDetails, accountID, loginParams, isValidAccountID]); - const displayName = formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details, undefined, undefined, isCurrentUser)); + const displayName = formatPhoneNumber(getDisplayNameOrDefault(details, undefined, undefined, isCurrentUser)); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const fallbackIcon = details?.fallbackIcon ?? ''; const login = details?.login ?? ''; @@ -134,7 +140,7 @@ function ProfilePage({route}: ProfilePageProps) { // If we have a reportID param this means that we // arrived here via the ParticipantsPage and should be allowed to navigate back to it - const shouldShowLocalTime = !ReportUtils.hasAutomatedExpensifyAccountIDs([accountID]) && !isEmptyObject(timezone) && isParticipantValidated; + const shouldShowLocalTime = !hasAutomatedExpensifyAccountIDs([accountID]) && !isEmptyObject(timezone) && isParticipantValidated; let pronouns = details?.pronouns ?? ''; if (pronouns?.startsWith(CONST.PRONOUNS.PREFIX)) { const localeKey = pronouns.replace(CONST.PRONOUNS.PREFIX, ''); @@ -156,17 +162,17 @@ function ProfilePage({route}: ProfilePageProps) { const navigateBackTo = route?.params?.backTo; - const notificationPreferenceValue = ReportUtils.getReportNotificationPreference(report); + const notificationPreferenceValue = getReportNotificationPreference(report); - const shouldShowNotificationPreference = !isEmptyObject(report) && !isCurrentUser && !ReportUtils.isHiddenForCurrentUser(notificationPreferenceValue); + const shouldShowNotificationPreference = !isEmptyObject(report) && !isCurrentUser && !isReportHiddenForCurrentUser(notificationPreferenceValue); const notificationPreference = shouldShowNotificationPreference ? translate(`notificationPreferencesPage.notificationPreferences.${notificationPreferenceValue}` as TranslationPaths) : ''; // eslint-disable-next-line rulesdir/prefer-early-return useEffect(() => { - if (ValidationUtils.isValidAccountRoute(accountID) && !loginParams) { - PersonalDetailsActions.openPublicProfilePage(accountID); + if (isValidAccountRoute(accountID) && !loginParams) { + openPublicProfilePage(accountID); } }, [accountID, loginParams]); @@ -177,13 +183,13 @@ function ProfilePage({route}: ProfilePageProps) { } // If it's a self DM, we only want to show the Message button if the self DM report exists because we don't want to optimistically create a report for self DM - if ((!isCurrentUser || report) && !SessionActions.isAnonymousUser()) { + if ((!isCurrentUser || report) && !isAnonymousUserSession()) { result.push(PromotedActions.message({reportID: report?.reportID, accountID, login: loginParams})); } return result; }, [accountID, isCurrentUser, loginParams, report]); - const isConcierge = ReportUtils.isConciergeChatReport(report); + const isConcierge = isConciergeChatReport(report); return ( @@ -197,7 +203,7 @@ function ProfilePage({route}: ProfilePageProps) { Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(String(accountID)))} + onPress={() => Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(accountID))} accessibilityLabel={translate('common.profile')} accessibilityRole={CONST.ROLE.BUTTON} disabled={!hasAvatar} @@ -239,7 +245,7 @@ function ProfilePage({route}: ProfilePageProps) { )} {/* Don't display email if current user is anonymous */} - {!(isCurrentUser && SessionActions.isAnonymousUser()) && login ? ( + {!(isCurrentUser && isAnonymousUserSession()) && login ? ( - + ReportUtils.navigateToPrivateNotes(report, session, navigateBackTo)} + onPress={() => navigateToPrivateNotes(report, session, navigateBackTo)} wrapperStyle={styles.breakAll} shouldShowRightIcon - brickRoadIndicator={ReportActions.hasErrorInPrivateNotes(report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} + brickRoadIndicator={hasErrorInPrivateNotes(report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} /> )} {isConcierge && !!guideCalendarLink && ( @@ -296,8 +302,8 @@ function ProfilePage({route}: ProfilePageProps) { title={translate('videoChatButtonAndMenu.tooltip')} icon={Expensicons.Phone} isAnonymousAction={false} - onPress={SessionActions.checkIfActionIsAllowed(() => { - LinkActions.openExternalLink(guideCalendarLink); + onPress={checkIfActionIsAllowed(() => { + openExternalLink(guideCalendarLink); })} /> )} diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 3d4c1fdadbda..3e1092d0373a 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -23,7 +23,20 @@ import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils'; import {getReportActionMessage} from '@libs/ReportActionsUtils'; -import * as ReportUtils from '@libs/ReportUtils'; +import { + getDefaultWorkspaceAvatar, + getDisplayNameForParticipant, + getIcons, + getPolicyName, + getReportActionActorAccountID, + getWorkspaceIcon, + isIndividualInvoiceRoom, + isInvoiceReport as isInvoiceReportUtils, + isInvoiceRoom, + isOptimisticPersonalDetail, + isPolicyExpenseChat, + isTripRoom as isTripRoomReportUtils, +} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -59,7 +72,7 @@ type ReportActionItemSingleProps = Partial & { isHovered?: boolean; }; -const showUserDetails = (accountID: string) => { +const showUserDetails = (accountID: number | undefined) => { Navigation.navigate(ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute())); }; @@ -90,27 +103,27 @@ function ReportActionItemSingle({ const delegatePersonalDetails = action?.delegateAccountID ? personalDetails?.[action?.delegateAccountID] : undefined; const ownerAccountID = iouReport?.ownerAccountID ?? action?.childOwnerAccountID; const isReportPreviewAction = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW; - const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport, report); + const actorAccountID = getReportActionActorAccountID(action, iouReport, report); const [invoiceReceiverPolicy] = useOnyx( `${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`, ); - let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID); + let displayName = getDisplayNameForParticipant(actorAccountID); const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails?.[actorAccountID ?? CONST.DEFAULT_NUMBER_ID] ?? {}; const accountOwnerDetails = getPersonalDetailByEmail(login ?? ''); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing let actorHint = (login || (displayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''); - const isTripRoom = ReportUtils.isTripRoom(report); - const displayAllActors = isReportPreviewAction && !isTripRoom && !ReportUtils.isPolicyExpenseChat(report); - const isInvoiceReport = ReportUtils.isInvoiceReport(iouReport ?? null); - const isWorkspaceActor = isInvoiceReport || (ReportUtils.isPolicyExpenseChat(report) && (!actorAccountID || displayAllActors)); + const isTripRoom = isTripRoomReportUtils(report); + const displayAllActors = isReportPreviewAction && !isTripRoom && !isPolicyExpenseChat(report); + const isInvoiceReport = isInvoiceReportUtils(iouReport ?? null); + const isWorkspaceActor = isInvoiceReport || (isPolicyExpenseChat(report) && (!actorAccountID || displayAllActors)); let avatarSource = avatar; let avatarId: number | string | undefined = actorAccountID; if (isWorkspaceActor) { - displayName = ReportUtils.getPolicyName(report, undefined, policy); + displayName = getPolicyName(report, undefined, policy); actorHint = displayName; - avatarSource = ReportUtils.getWorkspaceIcon(report, policy).source; + avatarSource = getWorkspaceIcon(report, policy).source; avatarId = report?.policyID; } else if (delegatePersonalDetails) { displayName = delegatePersonalDetails?.displayName ?? ''; @@ -124,8 +137,8 @@ function ReportActionItemSingle({ let secondaryAvatar: Icon; const primaryDisplayName = displayName; if (displayAllActors) { - if (ReportUtils.isInvoiceRoom(report) && !ReportUtils.isIndividualInvoiceRoom(report)) { - const secondaryPolicyAvatar = invoiceReceiverPolicy?.avatarURL ?? ReportUtils.getDefaultWorkspaceAvatar(invoiceReceiverPolicy?.name); + if (isInvoiceRoom(report) && !isIndividualInvoiceRoom(report)) { + const secondaryPolicyAvatar = invoiceReceiverPolicy?.avatarURL ?? getDefaultWorkspaceAvatar(invoiceReceiverPolicy?.name); secondaryAvatar = { source: secondaryPolicyAvatar, @@ -137,7 +150,7 @@ function ReportActionItemSingle({ // The ownerAccountID and actorAccountID can be the same if a user submits an expense back from the IOU's original creator, in that case we need to use managerID to avoid displaying the same user twice const secondaryAccountId = ownerAccountID === actorAccountID || isInvoiceReport ? actorAccountID : ownerAccountID; const secondaryUserAvatar = personalDetails?.[secondaryAccountId ?? -1]?.avatar ?? FallbackAvatar; - const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId); + const secondaryDisplayName = getDisplayNameForParticipant(secondaryAccountId); secondaryAvatar = { source: secondaryUserAvatar, @@ -148,14 +161,14 @@ function ReportActionItemSingle({ } } else if (!isWorkspaceActor) { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const avatarIconIndex = report?.isOwnPolicyExpenseChat || ReportUtils.isPolicyExpenseChat(report) ? 0 : 1; - const reportIcons = ReportUtils.getIcons(report, {}); + const avatarIconIndex = report?.isOwnPolicyExpenseChat || isPolicyExpenseChat(report) ? 0 : 1; + const reportIcons = getIcons(report, {}); secondaryAvatar = reportIcons.at(avatarIconIndex) ?? {name: '', source: '', type: CONST.ICON_TYPE_AVATAR}; - } else if (ReportUtils.isInvoiceReport(iouReport)) { + } else if (isInvoiceReportUtils(iouReport)) { const secondaryAccountId = iouReport?.managerID ?? CONST.DEFAULT_NUMBER_ID; const secondaryUserAvatar = personalDetails?.[secondaryAccountId ?? -1]?.avatar ?? FallbackAvatar; - const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId); + const secondaryDisplayName = getDisplayNameForParticipant(secondaryAccountId); secondaryAvatar = { source: secondaryUserAvatar, @@ -197,14 +210,14 @@ function ReportActionItemSingle({ Navigation.navigate(ROUTES.REPORT_PARTICIPANTS.getRoute(iouReportID, Navigation.getReportRHPActiveRoute())); return; } - showUserDetails(action?.delegateAccountID ? String(action.delegateAccountID) : String(actorAccountID)); + showUserDetails(action?.delegateAccountID ? action.delegateAccountID : actorAccountID); } }, [isWorkspaceActor, reportID, actorAccountID, action?.delegateAccountID, iouReportID, displayAllActors]); const shouldDisableDetailPage = useMemo( () => CONST.RESTRICTED_ACCOUNT_IDS.includes(actorAccountID ?? CONST.DEFAULT_NUMBER_ID) || - (!isWorkspaceActor && ReportUtils.isOptimisticPersonalDetail(action?.delegateAccountID ? Number(action.delegateAccountID) : actorAccountID ?? CONST.DEFAULT_NUMBER_ID)), + (!isWorkspaceActor && isOptimisticPersonalDetail(action?.delegateAccountID ? Number(action.delegateAccountID) : actorAccountID ?? CONST.DEFAULT_NUMBER_ID)), [action, isWorkspaceActor, actorAccountID], ); diff --git a/src/pages/settings/Profile/ProfilePage.tsx b/src/pages/settings/Profile/ProfilePage.tsx index 5ceda907c49b..271a1c1df5c4 100755 --- a/src/pages/settings/Profile/ProfilePage.tsx +++ b/src/pages/settings/Profile/ProfilePage.tsx @@ -21,11 +21,11 @@ import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; +import {formatPhoneNumber} from '@libs/LocalePhoneNumber'; import Navigation from '@libs/Navigation/Navigation'; -import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; -import * as UserUtils from '@libs/UserUtils'; -import * as PersonalDetails from '@userActions/PersonalDetails'; +import {getFormattedAddress} from '@libs/PersonalDetailsUtils'; +import {getFullSizeAvatar, getLoginListBrickRoadIndicator, isDefaultAvatar} from '@libs/UserUtils'; +import {clearAvatarErrors, deleteAvatar, updateAvatar} from '@userActions/PersonalDetails'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -52,9 +52,9 @@ function ProfilePage() { }; const avatarURL = currentUserPersonalDetails?.avatar ?? ''; - const accountID = currentUserPersonalDetails?.accountID ?? '-1'; + const accountID = currentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID; - const contactMethodBrickRoadIndicator = UserUtils.getLoginListBrickRoadIndicator(loginList); + const contactMethodBrickRoadIndicator = getLoginListBrickRoadIndicator(loginList); const emojiCode = currentUserPersonalDetails?.status?.emojiCode ?? ''; const privateDetails = privatePersonalDetails ?? {}; const legalName = `${privateDetails.legalFirstName ?? ''} ${privateDetails.legalLastName ?? ''}`.trim(); @@ -70,7 +70,7 @@ function ProfilePage() { }, { description: translate('contacts.contactMethod'), - title: LocalePhoneNumber.formatPhoneNumber(currentUserPersonalDetails?.login ?? ''), + title: formatPhoneNumber(currentUserPersonalDetails?.login ?? ''), pageRoute: ROUTES.SETTINGS_CONTACT_METHODS.route, brickRoadIndicator: contactMethodBrickRoadIndicator, }, @@ -128,7 +128,7 @@ function ProfilePage() { }, { description: translate('privatePersonalDetails.address'), - title: PersonalDetailsUtils.getFormattedAddress(privateDetails), + title: getFormattedAddress(privateDetails), action: () => { if (isActingAsDelegate) { setIsNoDelegateAccessMenuVisible(true); @@ -173,19 +173,19 @@ function ProfilePage() { ) : ( Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(String(accountID)))} - previewSource={UserUtils.getFullSizeAvatar(avatarURL, accountID)} + onErrorClose={clearAvatarErrors} + onViewPhotoPress={() => Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(accountID))} + previewSource={getFullSizeAvatar(avatarURL, accountID)} originalFileName={currentUserPersonalDetails.originalFileName} headerTitle={translate('profilePage.profileAvatar')} fallbackIcon={currentUserPersonalDetails?.fallbackIcon}