diff --git a/src/components/AvatarWithDisplayName.tsx b/src/components/AvatarWithDisplayName.tsx index 16a0028d1d1d..67912c6814b8 100644 --- a/src/components/AvatarWithDisplayName.tsx +++ b/src/components/AvatarWithDisplayName.tsx @@ -213,7 +213,7 @@ function AvatarWithDisplayName({ const title = getReportName(report, getReportNameFromNames(derivedReportNames, report?.reportID)); const isParentReportArchived = useReportIsArchived(report?.parentReportID); const subtitle = getChatRoomSubtitle(report, policy, conciergeReportID, translate, true, isReportArchived); - const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, translate, derivedParentReportName, isParentReportArchived); + const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, translate, formatPhoneNumber, derivedParentReportName, isParentReportArchived); const isMoneyRequestOrReport = isMoneyRequestReport(report) || isMoneyRequest(report) || isTrackExpenseReport(report) || isInvoiceReport(report); const ownerPersonalDetails = getPersonalDetailsForAccountIDs(report?.ownerAccountID ? [report.ownerAccountID] : [], personalDetails); const displayNamesWithTooltips = getDisplayNamesWithTooltips(Object.values(ownerPersonalDetails), false, localeCompare, formatPhoneNumber, translate); diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index 40f9804a91d6..5c21328c7cf7 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -88,7 +88,7 @@ function KYCWall({ ); const [doesSubmitterPersonalDetailExist] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: doesSubmitterPersonalDetailExistSelector}); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const currentUserDetails = useCurrentUserPersonalDetails(); const currentUserAccountID = currentUserDetails.accountID; @@ -222,6 +222,7 @@ function KYCWall({ reportActionsList: filteredReportActions, doesEmployeePersonalDetailExist: doesSubmitterPersonalDetailExist ?? false, getCurrencyDecimals, + formatPhoneNumber, }) ?? {}; if (policyID && iouReport?.policyID) { savePreferredPaymentMethod(iouReport.policyID, policyID, CONST.LAST_PAYMENT_METHOD.IOU, lastPaymentMethod?.[iouReport?.policyID]); @@ -290,6 +291,7 @@ function KYCWall({ conciergeChat, localCurrency, getCurrencyDecimals, + formatPhoneNumber, ], ); diff --git a/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx b/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx index 912455e47c4e..51dd11315360 100644 --- a/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx +++ b/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx @@ -98,7 +98,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo const {isPaidAnimationRunning, isApprovedAnimationRunning, startAnimation, startApprovedAnimation, startSubmittingAnimation} = usePaymentAnimationsContext(); const {openHoldMenu, openPDFDownload, openHoldEducational, openRejectModal} = useMoneyReportHeaderModals(); - const {translate, localeCompare} = useLocalize(); + const {translate, localeCompare, formatPhoneNumber} = useLocalize(); const isInSidePanel = useIsInSidePanel(); const kycWallRef = useContext(KYCWallContext); @@ -219,6 +219,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo chatReportActions: getChatReportActions(payAsBusiness), delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); } else { startAnimation(); @@ -246,6 +247,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo delegateAccountID, isTrackIntentUser, conciergeChat, + formatPhoneNumber, }); if (currentSearchQueryJSON && !isOffline) { search({ @@ -433,6 +435,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo const runPaymentSelection = () => selectPaymentType({ getCurrencyDecimals, + formatPhoneNumber, event, iouPaymentType, triggerKYCFlow, diff --git a/src/components/MoneyReportHeaderPrimaryAction/PayPrimaryAction.tsx b/src/components/MoneyReportHeaderPrimaryAction/PayPrimaryAction.tsx index 7c398357739d..8db65025a90f 100644 --- a/src/components/MoneyReportHeaderPrimaryAction/PayPrimaryAction.tsx +++ b/src/components/MoneyReportHeaderPrimaryAction/PayPrimaryAction.tsx @@ -49,7 +49,7 @@ type PayPrimaryActionProps = { function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) { const {isPaidAnimationRunning, isApprovedAnimationRunning, stopAnimation, startAnimation, startApprovedAnimation} = usePaymentAnimationsContext(); const {isOffline} = useNetwork(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {accountID, email, login: currentUserLogin, localCurrencyCode} = useCurrentUserPersonalDetails(); const delegateAccountID = useDelegateAccountID(); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); @@ -164,6 +164,7 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) { chatReportActions: getChatReportActions(payAsBusiness), delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); } else { startAnimation(); @@ -189,6 +190,7 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) { delegateAccountID, isTrackIntentUser, conciergeChat, + formatPhoneNumber, }); if (currentSearchQueryJSON && !isOffline) { search({ diff --git a/src/components/MoneyReportHeaderPrimaryAction/SubmitPrimaryAction.tsx b/src/components/MoneyReportHeaderPrimaryAction/SubmitPrimaryAction.tsx index 1e998090ca5b..a070362af6bf 100644 --- a/src/components/MoneyReportHeaderPrimaryAction/SubmitPrimaryAction.tsx +++ b/src/components/MoneyReportHeaderPrimaryAction/SubmitPrimaryAction.tsx @@ -69,7 +69,7 @@ function SubmitPrimaryAction({reportID}: SubmitPrimaryActionProps) { function SubmitPrimaryActionContent({reportID}: SubmitPrimaryActionProps) { const {isSubmittingAnimationRunning, stopAnimation, startSubmittingAnimation} = usePaymentAnimationsContext(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const {isOffline} = useNetwork(); const {accountID, email} = useCurrentUserPersonalDetails(); @@ -195,6 +195,7 @@ function SubmitPrimaryActionContent({reportID}: SubmitPrimaryActionProps) { // Submit via PDF submits the report to the submitter (self); the backend keys off this to generate the PDF. managerEmail: shouldExportToPDF ? email : undefined, isTrackIntentUser, + formatPhoneNumber, }); if (currentSearchQueryJSON && !isOffline) { search({ diff --git a/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts b/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts index 7efbb5184e10..9671ae9afc49 100644 --- a/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts +++ b/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts @@ -4,6 +4,7 @@ import {useMoneyReportHeaderModals} from '@components/MoneyReportHeaderModalsCon import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; +import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport'; @@ -25,6 +26,7 @@ function useConfirmApproval(reportID: string | undefined, startApprovedAnimation const {accountID, email} = useCurrentUserPersonalDetails(); const {getCurrencyDecimals} = useCurrencyListActions(); const {isBetaEnabled} = usePermissions(); + const {formatPhoneNumber} = useLocalize(); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); const {openHoldMenu} = useMoneyReportHeaderModals(); @@ -76,6 +78,7 @@ function useConfirmApproval(reportID: string | undefined, startApprovedAnimation delegateEmail, delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); } }; diff --git a/src/components/Navigation/QuickCreationActionsBar/index.tsx b/src/components/Navigation/QuickCreationActionsBar/index.tsx index 9831e2751757..d17bdfaa0fcb 100644 --- a/src/components/Navigation/QuickCreationActionsBar/index.tsx +++ b/src/components/Navigation/QuickCreationActionsBar/index.tsx @@ -41,7 +41,7 @@ import {View} from 'react-native'; function QuickCreationActionsBar() { const styles = useThemeStyles(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const icons = useMemoizedLazyExpensifyIcons(['ReceiptPlus', 'DocumentPlus', 'LocationAdd', 'LuggageWithLinesPlus']); const [session] = useOnyx(ONYXKEYS.SESSION); @@ -99,17 +99,19 @@ function QuickCreationActionsBar() { return; } - const {reportID: createdReportID} = createNewReport( - currentUserPersonalDetails, - hasViolations, + const {reportID: createdReportID} = createNewReport({ + ownerPersonalDetails: currentUserPersonalDetails, + hasViolationsParam: hasViolations, isASAPSubmitBetaEnabled, - defaultChatEnabledPolicy, - allBetas, + policy: defaultChatEnabledPolicy, + betas: allBetas, isTrackIntentUser, getCurrencyDecimals, - false, + shouldNotifyNewAction: false, + formatPhoneNumber, shouldDismissEmptyReportsConfirmation, - ); + options: {}, + }); // Navigate to the Reports page first so getCreateReportRoute() resolves against // the Search/Reports fullscreen context before opening the created report modal. Navigation.navigate(getReportsRootRoute()); @@ -117,7 +119,7 @@ function QuickCreationActionsBar() { Navigation.navigate(getCreateReportRoute({reportID: createdReportID})); }); }, - [currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, allBetas, isTrackIntentUser, getCurrencyDecimals], + [currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, allBetas, isTrackIntentUser, getCurrencyDecimals, formatPhoneNumber], ); const {openCreateReportConfirmation} = useCreateEmptyReportConfirmation({ diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx index 97559a5a5e22..f90cf982d229 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx @@ -47,7 +47,7 @@ import useReportPreviewActionButtonData from './useReportPreviewActionButtonData function PayActionButton() { const {isOffline} = useNetwork(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const currentUserDetails = useCurrentUserPersonalDetails(); const currentUserAccountID = currentUserDetails.accountID; const currentUserEmail = currentUserDetails.email ?? ''; @@ -122,6 +122,7 @@ function PayActionButton() { chatReportActions: getChatReportActions(payAsBusiness), delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); } else { payMoneyRequest({ @@ -146,6 +147,7 @@ function PayActionButton() { delegateAccountID, isTrackIntentUser, conciergeChat, + formatPhoneNumber, }); } } diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/SubmitActionButton.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/SubmitActionButton.tsx index 1ed31c1323c0..096bcfac47d5 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/SubmitActionButton.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/SubmitActionButton.tsx @@ -50,7 +50,7 @@ function SubmitActionButton() { } function SubmitActionButtonContent() { - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const {showConfirmModal} = useConfirmModal(); const currentUserDetails = useCurrentUserPersonalDetails(); @@ -132,6 +132,7 @@ function SubmitActionButtonContent() { delegateAccountID, submitterLogin, isTrackIntentUser, + formatPhoneNumber, }); }); }; diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/useConfirmApproveReportAction.ts b/src/components/ReportActionItem/MoneyRequestReportPreview/useConfirmApproveReportAction.ts index 7ed2e561bbb1..8e4edc00cffc 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/useConfirmApproveReportAction.ts +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/useConfirmApproveReportAction.ts @@ -6,6 +6,7 @@ import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/ import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; @@ -26,6 +27,7 @@ import {useReportPreviewActions, useReportPreviewActionState} from './MoneyReque function useConfirmApproveReportAction(actionButtonData: ReturnType, transactions: Transaction[], hasViolations: boolean) { const currentUserDetails = useCurrentUserPersonalDetails(); const {getCurrencyDecimals} = useCurrencyListActions(); + const {formatPhoneNumber} = useLocalize(); const {isBetaEnabled} = usePermissions(); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); @@ -60,6 +62,7 @@ function useConfirmApproveReportAction(actionButtonData: ReturnType({ * by its own key only while it has none. */ const {isSelectAllChecked: isSelected, isIndeterminate} = useGroupCheckboxState({groupKey: item.keyForList, groupTransactions: reportItem.transactions ?? []}); - const {translate, dateFnsLocale} = useLocalize(); + const {translate, dateFnsLocale, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions(); const {isLargeScreenWidth} = useResponsiveLayout(); const {currentSearchHash, currentSearchKey} = useSearchQueryContext(); @@ -306,6 +306,7 @@ function ExpenseReportListItemInner({ // every row on unrelated violation changes. allViolations: liveViolationsForSnapshotTransactions, conciergeChat, + formatPhoneNumber, }); }, [ currentSearchHash, @@ -349,6 +350,7 @@ function ExpenseReportListItemInner({ isTrackIntentUser, liveViolationsForSnapshotTransactions, conciergeChat, + formatPhoneNumber, ]); const handleSelectionButtonPress = useCallback(() => { diff --git a/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx b/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx index 8b679f29440c..97b612934974 100644 --- a/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx +++ b/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx @@ -292,7 +292,7 @@ function ReportListItemHeaderInner({ }); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const {showConfirmModal} = useConfirmModal(); const {isSelected} = useRowSelection(reportItem.keyForList); @@ -340,6 +340,7 @@ function ReportListItemHeaderInner({ isTrackIntentUser, allViolations, conciergeChat, + formatPhoneNumber, }); }; return !isLargeScreenWidth ? ( diff --git a/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx b/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx index aeb3ce0b429a..0ff4d307d63f 100644 --- a/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx +++ b/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx @@ -201,7 +201,7 @@ function TransactionListItemInner({ const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const {showConfirmModal} = useConfirmModal(); const openReportSubmitToPopover = useOpenReportSubmitToPopover(); @@ -246,6 +246,7 @@ function TransactionListItemInner({ isTrackIntentUser, allViolations, conciergeChat, + formatPhoneNumber, }); }; diff --git a/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx b/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx index 02ab740fa344..88b9f27b739d 100644 --- a/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx +++ b/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx @@ -40,7 +40,7 @@ import {View} from 'react-native'; function SearchActionsBarCreateButton() { const styles = useThemeStyles(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const expensifyIcons = useMemoizedLazyExpensifyIcons(['Plus', 'Location', 'Document', 'Receipt', 'Coins', 'Cash', 'Transfer', 'MoneyCircle']); const createButtonRef = useRef(null); @@ -82,17 +82,19 @@ function SearchActionsBarCreateButton() { return; } - const {reportID: createdReportID} = createNewReport( - currentUserPersonalDetails, - hasViolations, + const {reportID: createdReportID} = createNewReport({ + ownerPersonalDetails: currentUserPersonalDetails, + hasViolationsParam: hasViolations, isASAPSubmitBetaEnabled, - defaultChatEnabledPolicy, - allBetas, + policy: defaultChatEnabledPolicy, + betas: allBetas, isTrackIntentUser, getCurrencyDecimals, - false, + shouldNotifyNewAction: false, + formatPhoneNumber, shouldDismissEmptyReportsConfirmation, - ); + options: {}, + }); Navigation.setNavigationActionToMicrotaskQueue(() => { Navigation.navigate( isSearchTopmostFullScreenRoute() @@ -101,7 +103,7 @@ function SearchActionsBarCreateButton() { ); }); }, - [currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, allBetas, isTrackIntentUser, getCurrencyDecimals], + [currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, allBetas, isTrackIntentUser, getCurrencyDecimals, formatPhoneNumber], ); const {openCreateReportConfirmation} = useCreateEmptyReportConfirmation({ diff --git a/src/components/Search/SearchRouter/useCreateNavigationSuggestions.ts b/src/components/Search/SearchRouter/useCreateNavigationSuggestions.ts index ff9f2dbd0ab3..d0ecdb39dedc 100644 --- a/src/components/Search/SearchRouter/useCreateNavigationSuggestions.ts +++ b/src/components/Search/SearchRouter/useCreateNavigationSuggestions.ts @@ -73,7 +73,7 @@ function replaceTopmostModalWithAction(action: () => void) { } function useCreateNavigationSuggestions(query = ''): NavigationSuggestionSourceItem[] { - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const icons = useMemoizedLazyExpensifyIcons(['Coins', 'Receipt', 'Cash', 'Transfer', 'MoneyCircle', 'Location', 'Document', 'ChatBubble', 'InvoiceGeneric', 'NewWorkspace']); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const {getCurrencyDecimals} = useCurrencyListActions(); @@ -122,17 +122,19 @@ function useCreateNavigationSuggestions(query = ''): NavigationSuggestionSourceI clearLastSearchParams(); } - const {reportID: createdReportID} = createNewReport( - currentUserPersonalDetails, - false, - isBetaEnabled(CONST.BETAS.ASAP_SUBMIT), - defaultChatEnabledPolicy, - allBetas, + const {reportID: createdReportID} = createNewReport({ + ownerPersonalDetails: currentUserPersonalDetails, + hasViolationsParam: false, + isASAPSubmitBetaEnabled: isBetaEnabled(CONST.BETAS.ASAP_SUBMIT), + policy: defaultChatEnabledPolicy, + betas: allBetas, isTrackIntentUser, getCurrencyDecimals, - false, + formatPhoneNumber, + shouldNotifyNewAction: false, shouldDismissEmptyReportsConfirmation, - ); + options: {}, + }); // Navigate to the Reports page first so getCreateReportRoute() resolves against // the Search/Reports fullscreen context before opening the created report modal. Navigation.navigate(getReportsRootRoute(), {forceReplace: isReportInSearch}); diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index 8b3486942da4..95055edb4046 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -115,7 +115,7 @@ function SettlementButton({ }: SettlementButtonProps) { const icons = useMemoizedLazyExpensifyIcons(['CheckCircle', 'ThumbsUp', 'Bank', 'Cash', 'Wallet', 'Building', 'User']); const styles = useThemeStyles(); - const {translate, localeCompare} = useLocalize(); + const {translate, localeCompare, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const {isOffline} = useNetwork(); const policy = usePolicy(policyID); @@ -524,6 +524,7 @@ function SettlementButton({ delegateEmail, delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); } return; diff --git a/src/hooks/useCreateNewReport.tsx b/src/hooks/useCreateNewReport.tsx index 30858bc40484..d2c978228090 100644 --- a/src/hooks/useCreateNewReport.tsx +++ b/src/hooks/useCreateNewReport.tsx @@ -10,6 +10,7 @@ import {useCallback} from 'react'; import {useCurrencyListActions} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; +import useLocalize from './useLocalize'; import useOnyx from './useOnyx'; import usePermissions from './usePermissions'; @@ -19,6 +20,7 @@ import usePermissions from './usePermissions'; */ function useCreateNewReport() { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); + const {formatPhoneNumber} = useLocalize(); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector}); @@ -34,19 +36,21 @@ function useCreateNewReport() { return useCallback( (policyID: string, shouldDismissEmptyReportsConfirmation = false) => { const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; - return createNewReport( - currentUserPersonalDetails, - hasViolations, + return createNewReport({ + ownerPersonalDetails: currentUserPersonalDetails, + hasViolationsParam: hasViolations, isASAPSubmitBetaEnabled, policy, betas, isTrackIntentUser, getCurrencyDecimals, - false, + shouldNotifyNewAction: false, + formatPhoneNumber, shouldDismissEmptyReportsConfirmation, - ); + options: {}, + }); }, - [betas, currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policies, isTrackIntentUser, getCurrencyDecimals], + [betas, currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policies, isTrackIntentUser, getCurrencyDecimals, formatPhoneNumber], ); } diff --git a/src/hooks/useHoldMenuSubmit.ts b/src/hooks/useHoldMenuSubmit.ts index a5d618fa40af..c0364854f7d3 100644 --- a/src/hooks/useHoldMenuSubmit.ts +++ b/src/hooks/useHoldMenuSubmit.ts @@ -21,6 +21,7 @@ import {personalDetailsLoginSelector} from '@selectors/PersonalDetails'; import {useCurrencyListActions} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDelegateAccountID from './useDelegateAccountID'; +import useLocalize from './useLocalize'; import useOnyx from './useOnyx'; import usePayChatReportActions from './usePayChatReportActions'; import usePermissions from './usePermissions'; @@ -61,6 +62,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment const currentUserDetails = useCurrentUserPersonalDetails(); const {getCurrencyDecimals} = useCurrencyListActions(); const delegateAccountID = useDelegateAccountID(); + const {formatPhoneNumber} = useLocalize(); const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.email ?? ''); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); @@ -102,6 +104,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment delegateEmail, delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); } else if (currentChatReport && paymentType) { payMoneyRequest({ @@ -127,6 +130,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment delegateAccountID, isTrackIntentUser, conciergeChat, + formatPhoneNumber, }); } onClose(); diff --git a/src/hooks/useLifecycleActions.tsx b/src/hooks/useLifecycleActions.tsx index a944197c58ed..ea7ac8890f0f 100644 --- a/src/hooks/useLifecycleActions.tsx +++ b/src/hooks/useLifecycleActions.tsx @@ -116,7 +116,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const {isOffline} = useNetwork(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const styles = useThemeStyles(); const {showConfirmModal} = useConfirmModal(); @@ -204,6 +204,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, delegateEmail, delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); if (skipAnimation) { clearSelectedTransactions(true); @@ -261,6 +262,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, delegateAccountID, submitterLogin, isTrackIntentUser, + formatPhoneNumber, }); refreshSearchAfterReportAction({ currentSearchQueryJSON, @@ -326,7 +328,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, CONST.IOU.REPORT_ACTION_TYPE.PAY, () => { startAnimation(); - markReportPaymentReceived(chatReport, moneyRequestReport, accountID, email ?? '', chatReportActions, isTrackIntentUser, getCurrencyDecimals); + markReportPaymentReceived(chatReport, moneyRequestReport, accountID, email ?? '', chatReportActions, isTrackIntentUser, getCurrencyDecimals, formatPhoneNumber); }, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, ); @@ -334,7 +336,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, } startAnimation(); - markReportPaymentReceived(chatReport, moneyRequestReport, accountID, email ?? '', chatReportActions, isTrackIntentUser, getCurrencyDecimals); + markReportPaymentReceived(chatReport, moneyRequestReport, accountID, email ?? '', chatReportActions, isTrackIntentUser, getCurrencyDecimals, formatPhoneNumber); }, }, [CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE]: { diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 1af2e40dfb48..d2406b42cde6 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -422,7 +422,7 @@ function getChatReportForBulkPay( } function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { - const {translate, localeCompare} = useLocalize(); + const {translate, localeCompare, formatPhoneNumber} = useLocalize(); const styles = useThemeStyles(); const theme = useTheme(); const {isOffline} = useNetwork(); @@ -1077,6 +1077,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { additionalOnyxData: getSearchApproveOnyxData(hash, reportID, currentSearchKey), shouldPlaySuccessSound: false, isTrackIntentUser, + formatPhoneNumber, }); if (!wouldNavigateToUpgrade && !wouldNavigateToRestricted) { @@ -1117,6 +1118,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { personalDetails, delegateAccountID, getCurrencyDecimals, + formatPhoneNumber, ]); const {expenseCount, uniqueReportCount} = useMemo(() => { @@ -1488,6 +1490,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { chatReportActions: allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${payChatReportID}`], delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); paidReportCount += 1; continue; @@ -1518,6 +1521,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { delegateAccountID, isTrackIntentUser, conciergeChat, + formatPhoneNumber, isFallbackChatReport, }); paidReportCount += 1; @@ -1568,6 +1572,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { isTrackIntentUser, conciergeChat, getCurrencyDecimals, + formatPhoneNumber, ], ); diff --git a/src/hooks/useSelectionModePayment.ts b/src/hooks/useSelectionModePayment.ts index 0c42b21a9f1a..c97be4eb2cbe 100644 --- a/src/hooks/useSelectionModePayment.ts +++ b/src/hooks/useSelectionModePayment.ts @@ -79,7 +79,7 @@ function useSelectionModePayment({ onPaid, confirmApproval, }: UseSelectionModePaymentParams) { - const {translate, localeCompare} = useLocalize(); + const {translate, localeCompare, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const {isOffline} = useNetwork(); const {isBetaEnabled} = usePermissions(); @@ -207,6 +207,7 @@ function useSelectionModePayment({ chatReportActions: getChatReportActions(payAsBusiness), delegateAccountID, isTrackIntentUser, + formatPhoneNumber, }); } else { payMoneyRequest({ @@ -231,6 +232,7 @@ function useSelectionModePayment({ delegateAccountID, isTrackIntentUser, conciergeChat, + formatPhoneNumber, }); refreshSearchAfterReportAction({ currentSearchQueryJSON, @@ -304,6 +306,7 @@ function useSelectionModePayment({ const invokePaymentSelect = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => { selectPaymentType({ getCurrencyDecimals, + formatPhoneNumber, event, iouPaymentType, triggerKYCFlow, diff --git a/src/libs/IOUAmountSubmission.ts b/src/libs/IOUAmountSubmission.ts index ce3dc6196dcd..fdb9b1c33ad0 100644 --- a/src/libs/IOUAmountSubmission.ts +++ b/src/libs/IOUAmountSubmission.ts @@ -263,7 +263,7 @@ function buildReportParticipants(args: SubmitAmountArgs) { type ParticipantOption = ReturnType[number]; function submitSkipConfirmationPayment(args: SubmitAmountArgs, ctx: SubmitAmountContext, participants: ParticipantOption[]): void { - const {report, selectedCurrency, paymentMethod, quickAction, delegateAccountID, getCurrencyDecimals} = args; + const {report, selectedCurrency, paymentMethod, quickAction, delegateAccountID, getCurrencyDecimals, formatPhoneNumber} = args; const {currentUserAccountID, newAmount: backendAmount} = ctx; const {optimisticChatReportID, chatReportID} = resolveOptimisticChatReportID([participants.at(0)?.accountID ?? CONST.DEFAULT_NUMBER_ID, currentUserAccountID], report); const sendMoneyParams = { @@ -281,7 +281,7 @@ function submitSkipConfirmationPayment(args: SubmitAmountArgs, ctx: SubmitAmount }; const executeSendMoneyWrite = (overrides?: {shouldDeferForSearch?: boolean}) => { - const mergedParams = {...sendMoneyParams, ...overrides}; + const mergedParams = {...sendMoneyParams, ...overrides, formatPhoneNumber}; if (paymentMethod === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { sendMoneyWithWallet(mergedParams); } else { @@ -375,6 +375,7 @@ function submitSkipConfirmationExpense(args: SubmitAmountArgs, ctx: SubmitAmount delegateAccountID, reportActionsList: undefined, getCurrencyDecimals, + formatPhoneNumber, }); } else { const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined; diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 69e8d1f73f91..7905e327ed7f 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -768,12 +768,13 @@ function getLastMessageTextForReport({ } } else if (isMoneyRequestAction(lastReportAction)) { // Non-React call path: pass the standalone util until this file's own convertToDisplayString threading PR. - const properSchemaForMoneyRequestMessage = getReportPreviewMessage(translate, convertToDisplayStringUtil, { + const properSchemaForMoneyRequestMessage = getReportPreviewMessage(translate, formatPhoneNumberPhoneUtils, convertToDisplayStringUtil, { reportOrID: report, iouReportAction: lastReportAction, shouldConsiderScanningReceiptOrPendingRoute: true, policy: null, isForListPreview: true, + formatPhoneNumber: formatPhoneNumberPhoneUtils, }); lastMessageTextFromReport = formatReportLastMessageText(Parser.htmlToText(properSchemaForMoneyRequestMessage)); } else if (isReportPreviewAction(lastReportAction)) { @@ -792,7 +793,7 @@ function getLastMessageTextForReport({ lastMessageTextFromReport = formatReportLastMessageText(reportName); } else { // Non-React call path: pass the standalone util until this file's own convertToDisplayString threading PR. - const reportPreviewMessage = getReportPreviewMessage(translate, convertToDisplayStringUtil, { + const reportPreviewMessage = getReportPreviewMessage(translate, formatPhoneNumberPhoneUtils, convertToDisplayStringUtil, { reportOrID: !isEmptyObject(iouReport) ? iouReport : null, iouReportAction: lastIOUMoneyReportAction ?? lastReportAction, shouldConsiderScanningReceiptOrPendingRoute: true, @@ -800,6 +801,7 @@ function getLastMessageTextForReport({ policy: null, isForListPreview: true, originalReportAction: lastReportAction, + formatPhoneNumber: formatPhoneNumberPhoneUtils, }); lastMessageTextFromReport = formatReportLastMessageText(Parser.htmlToText(reportPreviewMessage)); } @@ -807,7 +809,13 @@ function getLastMessageTextForReport({ lastMessageTextFromReport = getReimbursementQueuedActionMessage({reportAction: lastReportAction, translate, formatPhoneNumber: formatPhoneNumberPhoneUtils, report}); } else if (isReimbursementDeQueuedOrCanceledAction(lastReportAction)) { // Non-React call path: pass the standalone util until this file's own convertToDisplayString threading PR. - lastMessageTextFromReport = getReimbursementDeQueuedOrCanceledActionMessage(translate, lastReportAction, report?.ownerAccountID, convertToDisplayStringUtil); + lastMessageTextFromReport = getReimbursementDeQueuedOrCanceledActionMessage( + translate, + formatPhoneNumberPhoneUtils, + lastReportAction, + report?.ownerAccountID, + convertToDisplayStringUtil, + ); } else if (isDeletedParentAction(lastReportAction) && reportUtilsIsChatReport(report)) { lastMessageTextFromReport = getDeletedParentActionMessageForChatReport(lastReportAction); } else if (isPendingRemove(lastReportAction) && report?.reportID && isThreadParentMessage(lastReportAction, report.reportID)) { @@ -1101,12 +1109,13 @@ function getLastMessageTextForReport({ formatReportLastMessageText( Parser.htmlToText( // Non-React call path: pass the standalone util until this file's own convertToDisplayString threading PR. - getReportPreviewMessage(translate, convertToDisplayStringUtil, { + getReportPreviewMessage(translate, formatPhoneNumberPhoneUtils, convertToDisplayStringUtil, { reportOrID: report, iouReportAction: lastReportAction, shouldConsiderScanningReceiptOrPendingRoute: true, policy: null, isForListPreview: true, + formatPhoneNumber: formatPhoneNumberPhoneUtils, }), ), ) || lastVisibleMessage?.lastMessageText; diff --git a/src/libs/PaymentUtils.ts b/src/libs/PaymentUtils.ts index 0aba0848554b..7269609363c4 100644 --- a/src/libs/PaymentUtils.ts +++ b/src/libs/PaymentUtils.ts @@ -1,7 +1,7 @@ import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; import getBankIcon from '@components/Icon/BankIcons'; import type {ContinueActionParams} from '@components/KYCWall/types'; -import type {LocalizedTranslate} from '@components/LocaleContextProvider'; +import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider'; import type {PopoverMenuItem} from '@components/PopoverMenu'; import type {BankAccountMenuItem} from '@components/Search/types'; import type {PaymentActionParams} from '@components/SettlementButton/types'; @@ -58,6 +58,7 @@ type SelectPaymentTypeParams = { isTrackIntentUser: boolean | undefined; ownerLogin: string | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; type BusinessBankAccountOption = { @@ -234,6 +235,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => { isTrackIntentUser, ownerLogin, getCurrencyDecimals, + formatPhoneNumber, } = params; if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentAccountID)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); @@ -271,6 +273,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => { delegateAccountID, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, }); } return; diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index f4b225f67e7b..3ed7799930d6 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -571,7 +571,7 @@ function computeReportNameBasedOnReportAction({ if (isReimbursementDeQueuedOrCanceledAction(parentReportAction)) { // Non-React call path: pass the standalone util until this file's own convertToDisplayString threading PR. - return getReimbursementDeQueuedOrCanceledActionMessage(translate, parentReportAction, parentReport?.ownerAccountID, convertToDisplayString); + return getReimbursementDeQueuedOrCanceledActionMessage(translate, formatPhoneNumber, parentReportAction, parentReport?.ownerAccountID, convertToDisplayString); } if (isRejectedAction(parentReportAction)) { return translate('iou.rejectedThisReport'); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c1870dbf43b5..4a5d4f8b942d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -128,7 +128,6 @@ import {getEnvironmentURL} from './Environment/Environment'; import getEnvironment from './Environment/getEnvironment'; import {getMicroSecondOnyxErrorWithTranslationKey, isReceiptError} from './ErrorUtils'; import getAttachmentDetails from './fileDownload/getAttachmentDetails'; -import {formatPhoneNumber as formatPhoneNumberPhoneUtils} from './LocalePhoneNumber'; import {translateLocal} from './Localize'; import Log from './Log'; import {isEmailPublicDomain} from './LoginUtils'; @@ -4303,6 +4302,7 @@ function getReimbursementQueuedActionMessage({ */ function getReimbursementDeQueuedOrCanceledActionMessage( translate: LocalizedTranslate, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], reportAction: OnyxEntry>, reportOwnerAccountID: number | undefined, convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'], @@ -4314,7 +4314,7 @@ function getReimbursementDeQueuedOrCanceledActionMessage( if (originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN || originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.USER) { return translate('iou.adminCanceledRequest'); } - const submitterDisplayName = getDisplayNameForParticipant({accountID: reportOwnerAccountID, shouldUseShortForm: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) ?? ''; + const submitterDisplayName = getDisplayNameForParticipant({accountID: reportOwnerAccountID, shouldUseShortForm: true, formatPhoneNumber, translate}) ?? ''; return translate('iou.canceledRequest', formattedAmount, submitterDisplayName); } @@ -5787,6 +5787,7 @@ type GetReportPreviewMessageBaseParams = { isForListPreview?: boolean; /** This can be either a report preview action or the IOU action. This will be the original report preview action in cases where `iouReportAction` was unwrapped from a report preview action. Otherwise, it will be the same as `iouReportAction`. */ originalReportAction?: OnyxInputOrEntry; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; /** @@ -5818,6 +5819,7 @@ function getReportPreviewMessageForCopy( */ function getReportPreviewMessage( translate: LocalizedTranslate, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'], params: GetReportPreviewMessageBaseParams, ): string { @@ -5903,7 +5905,7 @@ function getReportPreviewMessage( const policyName = getPolicyName({report: parentReport ?? report, policy, unavailableTranslation: translate('workspace.common.unavailable')}); const payerName = isExpenseReport(report) ? policyName - : getDisplayNameForParticipant({accountID: report.managerID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}); + : getDisplayNameForParticipant({accountID: report.managerID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber, translate}); const formattedAmount = convertToDisplayString(totalAmount, report.currency); @@ -5960,7 +5962,7 @@ function getReportPreviewMessage( let actualPayerName = report.managerID === deprecatedCurrentUserAccountID && !isForListPreview ? '' - : getDisplayNameForParticipant({accountID: payerAccountID, shouldUseShortForm: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}); + : getDisplayNameForParticipant({accountID: payerAccountID, shouldUseShortForm: true, formatPhoneNumber, translate}); actualPayerName = actualPayerName && isForListPreview && !isPreviewMessageForParentChatReport ? `${actualPayerName}:` : actualPayerName; const payerDisplayName = isPreviewMessageForParentChatReport ? payerName : actualPayerName; @@ -5984,8 +5986,7 @@ function getReportPreviewMessage( } if (report.isWaitingOnBankAccount) { - const submitterDisplayName = - getDisplayNameForParticipant({accountID: report.ownerAccountID, shouldUseShortForm: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) ?? ''; + const submitterDisplayName = getDisplayNameForParticipant({accountID: report.ownerAccountID, shouldUseShortForm: true, formatPhoneNumber, translate}) ?? ''; return translate('iou.waitingOnBankAccount', submitterDisplayName); } @@ -6014,17 +6015,13 @@ function getReportPreviewMessage( // We only want to show the actor name in the preview if it's not the current user who took the action const requestorName = lastActorID && lastActorID !== deprecatedCurrentUserAccountID - ? getDisplayNameForParticipant({accountID: lastActorID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) + ? getDisplayNameForParticipant({accountID: lastActorID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber, translate}) : ''; return `${requestorName ? `${requestorName}: ` : ''}${translate('iou.expenseAmount', amountToDisplay, comment)}`; } if (containsNonReimbursable) { - return translate( - 'iou.payerSpentAmount', - formattedAmount, - getDisplayNameForParticipant({accountID: report.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) ?? '', - ); + return translate('iou.payerSpentAmount', formattedAmount, getDisplayNameForParticipant({accountID: report.ownerAccountID, formatPhoneNumber, translate}) ?? ''); } return translate('iou.payerOwesAmount', formattedAmount, payerName ?? '', comment); } @@ -6042,7 +6039,15 @@ function getReportPreviewMessage( * in {@link getReportPreviewMessage}. */ function getReportPreviewReportActionMessage(params: GetReportPreviewMessageBaseParams, getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']): string { - const {reportOrID, iouReportAction = null, shouldConsiderScanningReceiptOrPendingRoute = false, isPreviewMessageForParentChatReport = false, policy, isForListPreview = false} = params; + const { + reportOrID, + iouReportAction = null, + shouldConsiderScanningReceiptOrPendingRoute = false, + isPreviewMessageForParentChatReport = false, + policy, + isForListPreview = false, + formatPhoneNumber, + } = params; const originalReportAction = params.originalReportAction ?? iouReportAction; const report = typeof reportOrID === 'string' ? getReport(reportOrID, deprecatedAllReports) : reportOrID; const reportActionMessage = getReportActionHtml(iouReportAction); @@ -6121,7 +6126,7 @@ function getReportPreviewReportActionMessage(params: GetReportPreviewMessageBase const policyName = getPolicyName({report: parentReport ?? report, policy}); const payerName = isExpenseReport(report) ? policyName - : getDisplayNameForParticipant({accountID: report.managerID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber: formatPhoneNumberPhoneUtils}); + : getDisplayNameForParticipant({accountID: report.managerID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber}); const formattedAmount = convertToDisplayStringEnLocale(totalAmount, report.currency, getCurrencyDecimals); @@ -6178,7 +6183,7 @@ function getReportPreviewReportActionMessage(params: GetReportPreviewMessageBase let actualPayerName = report.managerID === deprecatedCurrentUserAccountID && !isForListPreview ? '' - : getDisplayNameForParticipant({accountID: payerAccountID, shouldUseShortForm: true, formatPhoneNumber: formatPhoneNumberPhoneUtils}); + : getDisplayNameForParticipant({accountID: payerAccountID, shouldUseShortForm: true, formatPhoneNumber}); actualPayerName = actualPayerName && isForListPreview && !isPreviewMessageForParentChatReport ? `${actualPayerName}:` : actualPayerName; const payerDisplayName = isPreviewMessageForParentChatReport ? payerName : actualPayerName; @@ -6211,7 +6216,7 @@ function getReportPreviewReportActionMessage(params: GetReportPreviewMessageBase } if (report.isWaitingOnBankAccount) { - const submitterDisplayName = getDisplayNameForParticipant({accountID: report.ownerAccountID, shouldUseShortForm: true, formatPhoneNumber: formatPhoneNumberPhoneUtils}) ?? ''; + const submitterDisplayName = getDisplayNameForParticipant({accountID: report.ownerAccountID, shouldUseShortForm: true, formatPhoneNumber}) ?? ''; return `started payment, but is waiting for ${submitterDisplayName} to add a personal bank account.`; } @@ -6240,13 +6245,13 @@ function getReportPreviewReportActionMessage(params: GetReportPreviewMessageBase // We only want to show the actor name in the preview if it's not the current user who took the action const requestorName = lastActorID && lastActorID !== deprecatedCurrentUserAccountID - ? getDisplayNameForParticipant({accountID: lastActorID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber: formatPhoneNumberPhoneUtils}) + ? getDisplayNameForParticipant({accountID: lastActorID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber}) : ''; return `${requestorName ? `${requestorName}: ` : ''}${amountToDisplay}${comment ? ` for ${comment}` : ''}`; } if (containsNonReimbursable) { - const ownerName = getDisplayNameForParticipant({accountID: report.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils}) ?? ''; + const ownerName = getDisplayNameForParticipant({accountID: report.ownerAccountID, formatPhoneNumber}) ?? ''; return `${ownerName} spent ${formattedAmount}`; } return `${payerName ?? ''} owes ${formattedAmount}${comment ? ` for ${comment}` : ''}`; @@ -6366,7 +6371,12 @@ function getModifiedExpenseOriginalMessage( /** * Get the payee name given a report. */ -function getPayeeName(report: OnyxEntry, translate: LocalizedTranslate, currentUserAccountID: number | undefined): string | undefined { +function getPayeeName( + report: OnyxEntry, + translate: LocalizedTranslate, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + currentUserAccountID: number | undefined, +): string | undefined { if (isEmptyObject(report)) { return undefined; } @@ -6378,7 +6388,7 @@ function getPayeeName(report: OnyxEntry, translate: LocalizedTranslate, if (participantsWithoutCurrentUser.length === 0) { return undefined; } - return getDisplayNameForParticipant({accountID: participantsWithoutCurrentUser.at(0), shouldUseShortForm: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}); + return getDisplayNameForParticipant({accountID: participantsWithoutCurrentUser.at(0), shouldUseShortForm: true, formatPhoneNumber, translate}); } // TODO: currentUserEmail will be required eventually so this becomes a pure function. Subscribe the data via useOnyx and pass it from the component. Refactor issue: https://github.com/Expensify/App/issues/66412 @@ -6487,6 +6497,7 @@ function getParentNavigationSubtitle( policy: OnyxEntry, conciergeReportID: string | undefined, translate: LocalizedTranslate, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], parentReportName: string | undefined, isParentReportArchived = false, ): ParentNavigationSummaryParams { @@ -6497,8 +6508,7 @@ function getParentNavigationSubtitle( const personalDetails = ownerAccountID ? allPersonalDetails?.[ownerAccountID] : undefined; const login = personalDetails ? personalDetails.login : null; - const reportOwnerDisplayName = - getDisplayNameForParticipant({accountID: ownerAccountID, shouldRemoveDomain: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) || login; + const reportOwnerDisplayName = getDisplayNameForParticipant({accountID: ownerAccountID, shouldRemoveDomain: true, formatPhoneNumber, translate}) || login; if (isExpenseReport(report)) { return { @@ -8077,6 +8087,7 @@ function buildOptimisticSubmittedReportAction( function buildOptimisticReportPreview( chatReport: OnyxInputOrEntry, iouReport: Report, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], comment = '', transaction: OnyxInputOrEntry = null, @@ -8085,7 +8096,7 @@ function buildOptimisticReportPreview( delegateAccountIDParam: number | undefined = undefined, ): ReportAction { const hasReceipt = hasReceiptTransactionUtils(transaction); - const message = getReportPreviewReportActionMessage({reportOrID: iouReport}, getCurrencyDecimals); + const message = getReportPreviewReportActionMessage({reportOrID: iouReport, formatPhoneNumber}, getCurrencyDecimals); const created = DateUtils.getDBTime(); const reportActorAccountID = (isInvoiceReport(iouReport) || isExpenseReport(iouReport) ? iouReport?.ownerAccountID : iouReport?.managerID) ?? -1; // Falls back to module-level delegateEmail (from Onyx.connect) for callers not yet migrated; will be removed in https://github.com/Expensify/App/issues/66425 @@ -8258,6 +8269,7 @@ function buildOptimisticDetachReceipt(reportID: string | undefined, transactionI function updateReportPreview( iouReport: OnyxEntry, reportPreviewAction: ReportAction, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], isPayRequest = false, comment = '', @@ -8277,7 +8289,7 @@ function updateReportPreview( } } - const message = getReportPreviewReportActionMessage({reportOrID: iouReport, iouReportAction: reportPreviewAction}, getCurrencyDecimals); + const message = getReportPreviewReportActionMessage({reportOrID: iouReport, iouReportAction: reportPreviewAction, formatPhoneNumber}, getCurrencyDecimals); const originalMessage = getOriginalMessage(reportPreviewAction); return { ...reportPreviewAction, diff --git a/src/libs/actions/IOU/Duplicate.ts b/src/libs/actions/IOU/Duplicate.ts index 1bee0dfaaa9d..a7e9c572c325 100644 --- a/src/libs/actions/IOU/Duplicate.ts +++ b/src/libs/actions/IOU/Duplicate.ts @@ -920,6 +920,7 @@ function duplicateExpenseTransaction({ currentUserLocalCurrency, delegateAccountID, reportActionsList: undefined, + formatPhoneNumber, }; return trackExpense(trackExpenseParams); } @@ -1014,20 +1015,20 @@ function duplicateReport({ } const newReportName = translate('common.copyOfReportName', sourceReportName); - const {reportPreviewReportActionID, ...newReport} = createNewReport( + const {reportPreviewReportActionID, ...newReport} = createNewReport({ ownerPersonalDetails, - false, + hasViolationsParam: false, isASAPSubmitBetaEnabled, - targetPolicy, + policy: targetPolicy, betas, isTrackIntentUser, getCurrencyDecimals, - false, - undefined, - { + shouldNotifyNewAction: false, + formatPhoneNumber, + options: { reportName: newReportName, }, - ); + }); const isCrossWorkspace = !!sourceReport && sourceReport.policyID !== targetPolicy.id; diff --git a/src/libs/actions/IOU/Hold.ts b/src/libs/actions/IOU/Hold.ts index 8fa1e5e63e4e..ebf2272e7c69 100644 --- a/src/libs/actions/IOU/Hold.ts +++ b/src/libs/actions/IOU/Hold.ts @@ -1,3 +1,5 @@ +import type {LocaleContextProps} from '@components/LocaleContextProvider'; + import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; import * as API from '@libs/API'; @@ -668,6 +670,7 @@ function getReportFromHoldRequestsOnyxData({ isApprovalFlow = false, delegateAccountID, getCurrencyDecimals, + formatPhoneNumber, }: { chatReport: OnyxTypes.Report; iouReport: OnyxEntry; @@ -678,6 +681,7 @@ function getReportFromHoldRequestsOnyxData({ isApprovalFlow?: boolean; delegateAccountID: number | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }): { optimisticHoldReportID: string; optimisticHoldActionID: string; @@ -737,6 +741,7 @@ function getReportFromHoldRequestsOnyxData({ const optimisticExpenseReportPreview = buildOptimisticReportPreview( chatReport, optimisticExpenseReport, + formatPhoneNumber, getCurrencyDecimals, '', firstHoldTransaction, diff --git a/src/libs/actions/IOU/MoneyRequest.ts b/src/libs/actions/IOU/MoneyRequest.ts index b6fd46e96813..0c1aa2a16be1 100644 --- a/src/libs/actions/IOU/MoneyRequest.ts +++ b/src/libs/actions/IOU/MoneyRequest.ts @@ -216,6 +216,7 @@ function createTransaction({ delegateAccountID, reportActionsList: undefined, getCurrencyDecimals, + formatPhoneNumber, }); } else { const existingTransactionID = getExistingTransactionID(transaction?.linkedTrackedExpenseReportAction); diff --git a/src/libs/actions/IOU/MoneyRequestBuilder.ts b/src/libs/actions/IOU/MoneyRequestBuilder.ts index b18120148341..1f1f302d3a9d 100644 --- a/src/libs/actions/IOU/MoneyRequestBuilder.ts +++ b/src/libs/actions/IOU/MoneyRequestBuilder.ts @@ -1634,11 +1634,12 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewReportAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { - reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, false, comment, optimisticTransaction); + reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, formatPhoneNumber, getCurrencyDecimals, false, comment, optimisticTransaction); } else { reportPreviewAction = buildOptimisticReportPreview( chatReport, iouReport, + formatPhoneNumber, getCurrencyDecimals, comment, optimisticTransaction, diff --git a/src/libs/actions/IOU/PayMoneyRequest.ts b/src/libs/actions/IOU/PayMoneyRequest.ts index de5e38a3f105..ab804b2e9f34 100644 --- a/src/libs/actions/IOU/PayMoneyRequest.ts +++ b/src/libs/actions/IOU/PayMoneyRequest.ts @@ -1,4 +1,5 @@ import type {PaymentMethod} from '@components/KYCWall/types'; +import type {LocaleContextProps} from '@components/LocaleContextProvider'; import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; @@ -77,6 +78,7 @@ type PayInvoiceArgs = { delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; type PayMoneyRequestData = { @@ -126,6 +128,7 @@ type PayMoneyRequestFunctionParams = { chatReportActions: OnyxEntry; isTrackIntentUser: boolean | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; isFallbackChatReport?: boolean; }; @@ -173,6 +176,7 @@ function getPayMoneyRequestParams({ chatReportActions, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, isFallbackChatReport, }: { initialChatReport: OnyxTypes.Report; @@ -199,6 +203,7 @@ function getPayMoneyRequestParams({ chatReportActions: OnyxEntry; isTrackIntentUser: boolean | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; isFallbackChatReport?: boolean; }): PayMoneyRequestData { // TODO: https://github.com/Expensify/App/issues/66512 @@ -299,7 +304,7 @@ function getPayMoneyRequestParams({ let optimisticReportPreviewAction = null; const reportPreviewAction = getReportPreviewReportAction(chatReport.reportID, iouReport?.reportID, chatReportActions); if (reportPreviewAction) { - optimisticReportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, true); + optimisticReportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, formatPhoneNumber, getCurrencyDecimals, true); } let optimisticNextStep = null; if (!isInvoiceReport) { @@ -500,7 +505,16 @@ function getPayMoneyRequestParams({ let optimisticHoldActionID; let optimisticHoldReportExpenseActionIDs; if (!full) { - const holdReportOnyxData = getReportFromHoldRequestsOnyxData({chatReport, iouReport, recipient, policy: reportPolicy, betas, delegateAccountID, getCurrencyDecimals}); + const holdReportOnyxData = getReportFromHoldRequestsOnyxData({ + chatReport, + iouReport, + recipient, + policy: reportPolicy, + betas, + delegateAccountID, + getCurrencyDecimals, + formatPhoneNumber, + }); onyxData.optimisticData?.push(...holdReportOnyxData.optimisticData); onyxData.successData?.push(...holdReportOnyxData.successData); @@ -887,6 +901,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) { chatReportActions, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, isFallbackChatReport, } = params; const policyForBillingRestriction = chatReportPolicy ?? (policy?.id === chatReport.policyID ? policy : undefined); @@ -924,6 +939,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) { chatReportActions, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, isFallbackChatReport, }); @@ -948,6 +964,7 @@ function markReportPaymentReceived( chatReportActions: OnyxEntry, isTrackIntentUser: boolean | undefined, getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], ) { if (!chatReport || !iouReport) { return; @@ -980,7 +997,7 @@ function markReportPaymentReceived( optimisticIOUReportAction.message = [{html: receivedPaymentMessage, text: receivedPaymentMessage, isEdited: false, type: CONST.REPORT.MESSAGE.TYPE.COMMENT}]; const reportPreviewAction = getReportPreviewReportAction(chatReport.reportID, iouReport.reportID, chatReportActions); - const optimisticReportPreviewAction = reportPreviewAction ? updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, true) : null; + const optimisticReportPreviewAction = reportPreviewAction ? updateReportPreview(iouReport, reportPreviewAction, formatPhoneNumber, getCurrencyDecimals, true) : null; const optimisticNextStep = buildOptimisticNextStep({report: iouReport, predictedNextStatus: CONST.REPORT.STATUS_NUM.REIMBURSED, isTrackIntentUser}); const optimisticData: Array> = [ @@ -1131,6 +1148,7 @@ function payInvoice({ delegateAccountID, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, }: PayInvoiceArgs) { const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID}; const { @@ -1169,6 +1187,7 @@ function payInvoice({ delegateAccountID, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, }); const paymentSelected = paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA ? CONST.IOU.PAYMENT_SELECTED.BBA : CONST.IOU.PAYMENT_SELECTED.PBA; diff --git a/src/libs/actions/IOU/PerDiem.ts b/src/libs/actions/IOU/PerDiem.ts index 9dd34328f413..1895b06f26bb 100644 --- a/src/libs/actions/IOU/PerDiem.ts +++ b/src/libs/actions/IOU/PerDiem.ts @@ -544,11 +544,12 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewReportAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { - reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, false, comment, optimisticTransaction); + reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, formatPhoneNumber, getCurrencyDecimals, false, comment, optimisticTransaction); } else { reportPreviewAction = buildOptimisticReportPreview( chatReport, iouReport, + formatPhoneNumber, getCurrencyDecimals, comment, optimisticTransaction, diff --git a/src/libs/actions/IOU/RejectMoneyRequest.ts b/src/libs/actions/IOU/RejectMoneyRequest.ts index 7fa89c256441..7723fd5b6057 100644 --- a/src/libs/actions/IOU/RejectMoneyRequest.ts +++ b/src/libs/actions/IOU/RejectMoneyRequest.ts @@ -1,3 +1,5 @@ +import type {LocaleContextProps} from '@components/LocaleContextProvider'; + import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; import * as API from '@libs/API'; @@ -122,6 +124,7 @@ type PrepareRejectMoneyRequestDataParams = { currentUserLogin: string; betas: OnyxEntry; delegateAccountID: number | undefined; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; options?: RejectMoneyRequestOptions; shouldUseBulkAction?: boolean; @@ -136,6 +139,7 @@ function prepareRejectMoneyRequestData({ currentUserLogin, betas, delegateAccountID, + formatPhoneNumber, getCurrencyDecimals, options, shouldUseBulkAction, @@ -516,7 +520,17 @@ function prepareRejectMoneyRequestData({ delegateAccountIDParam: delegateAccountID, }); - reportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, newExpenseReport, getCurrencyDecimals, undefined, transaction, undefined, undefined, delegateAccountID); + reportPreviewAction = buildOptimisticReportPreview( + policyExpenseChat, + newExpenseReport, + formatPhoneNumber, + getCurrencyDecimals, + undefined, + transaction, + undefined, + undefined, + delegateAccountID, + ); movedTransactionAction = buildOptimisticMovedTransactionAction(childReportID, newExpenseReport.reportID); createdIOUReportActionID = iouAction.reportActionID; expenseMovedReportActionID = movedTransactionAction.reportActionID; @@ -930,19 +944,44 @@ function prepareRejectMoneyRequestData({ return {optimisticData, successData, failureData, parameters, urlToNavigateBack: urlToNavigateBack as Route}; } +type RejectMoneyRequest = { + /** Transaction being rejected. */ + transactionID: string; + /** Report that owns the transaction. */ + reportID: string; + /** Parsed comment sent with the rejection. */ + comment: string; + /** Policy used to resolve permissions and delayed submission behavior. */ + policy: OnyxEntry; + /** Current user's account ID used for optimistic report updates. */ + currentUserAccountIDParam: number; + /** Current user's login used for optimistic personal details updates. */ + currentUserLogin: string; + /** Beta flags used to decide which rejection behavior is available. */ + betas: OnyxEntry; + /** Delegate account ID used when acting on behalf of another user. */ + delegateAccountID: number | undefined; + /** Formatter used when building optimistic personal details. */ + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + /** Currency helper used for optimistic monetary formatting. */ + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + /** Optional flags that alter the rejection flow. */ + options?: RejectMoneyRequestOptions; +}; -function rejectMoneyRequest( - transactionID: string, - reportID: string, - comment: string, - policy: OnyxEntry, - currentUserAccountIDParam: number, - currentUserLogin: string, - betas: OnyxEntry, - delegateAccountID: number | undefined, - getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], - options?: RejectMoneyRequestOptions, -): Route | undefined { +function rejectMoneyRequest({ + transactionID, + reportID, + comment, + policy, + currentUserAccountIDParam, + currentUserLogin, + betas, + delegateAccountID, + formatPhoneNumber, + getCurrencyDecimals, + options, +}: RejectMoneyRequest): Route | undefined { const data = prepareRejectMoneyRequestData({ transactionID, reportID, @@ -952,6 +991,7 @@ function rejectMoneyRequest( currentUserLogin, betas, delegateAccountID, + formatPhoneNumber, getCurrencyDecimals, options, }); diff --git a/src/libs/actions/IOU/ReportWorkflow.ts b/src/libs/actions/IOU/ReportWorkflow.ts index 245bd94c5182..7a4aa01504a6 100644 --- a/src/libs/actions/IOU/ReportWorkflow.ts +++ b/src/libs/actions/IOU/ReportWorkflow.ts @@ -119,6 +119,7 @@ type ApproveMoneyRequestFunctionParams = { additionalOnyxData?: AdditionalPayOnyxData; shouldPlaySuccessSound?: boolean; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; type SubmitReportFunctionParams = { @@ -147,6 +148,7 @@ type SubmitReportFunctionParams = { */ shouldExportToPDF?: boolean; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; function canApproveIOU( @@ -474,6 +476,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { shouldPlaySuccessSound = true, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, } = params; if (!expenseReport) { return; @@ -762,6 +765,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { betas, delegateAccountID, getCurrencyDecimals, + formatPhoneNumber, }); optimisticData.push(...holdReportOnyxData.optimisticData); @@ -1321,6 +1325,7 @@ function submitReport({ shouldExportToPDF, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, }: SubmitReportFunctionParams) { if (!expenseReport) { return; @@ -1603,6 +1608,7 @@ function submitReport({ betas, delegateAccountID, getCurrencyDecimals, + formatPhoneNumber, }); optimisticData.push(...holdReportOnyxData.optimisticData); diff --git a/src/libs/actions/IOU/SendInvoice.ts b/src/libs/actions/IOU/SendInvoice.ts index 68e8cd52b51b..a52406b55104 100644 --- a/src/libs/actions/IOU/SendInvoice.ts +++ b/src/libs/actions/IOU/SendInvoice.ts @@ -737,6 +737,7 @@ function getSendInvoiceInformation({ const reportPreviewAction = buildOptimisticReportPreview( chatReport, optimisticInvoiceReport, + formatPhoneNumber, getCurrencyDecimals, trimmedComment, optimisticTransaction, diff --git a/src/libs/actions/IOU/SendMoney.ts b/src/libs/actions/IOU/SendMoney.ts index c485f862ef50..4caca158457c 100644 --- a/src/libs/actions/IOU/SendMoney.ts +++ b/src/libs/actions/IOU/SendMoney.ts @@ -1,4 +1,5 @@ import type {PaymentMethodType} from '@components/KYCWall/types'; +import type {LocaleContextProps} from '@components/LocaleContextProvider'; import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; @@ -83,6 +84,7 @@ function getSendMoneyParams({ currentUserAccountID, delegateAccountID, getCurrencyDecimals, + formatPhoneNumber, }: { report: OnyxEntry; quickAction: OnyxEntry; @@ -99,6 +101,7 @@ function getSendMoneyParams({ currentUserAccountID: number; delegateAccountID: number | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }): SendMoneyParamsData { const recipientEmail = addSMSDomainIfPhoneNumber(recipient.login ?? ''); const recipientAccountID = Number(recipient.accountID); @@ -160,7 +163,17 @@ function getSendMoneyParams({ delegateAccountIDParam: delegateAccountID, }); - const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticIOUReport, getCurrencyDecimals, undefined, undefined, undefined, undefined, delegateAccountID); + const reportPreviewAction = buildOptimisticReportPreview( + chatReport, + optimisticIOUReport, + formatPhoneNumber, + getCurrencyDecimals, + undefined, + undefined, + undefined, + undefined, + delegateAccountID, + ); // Change the method to set for new reports because it doesn't exist yet, is faster, // and we need the data to be available when we navigate to the chat page @@ -511,6 +524,7 @@ type SendMoneyActionParams = { shouldDeferForSearch?: boolean; delegateAccountID: number | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; function executeSendMoney( @@ -518,8 +532,22 @@ function executeSendMoney( paymentMethodType: typeof CONST.IOU.PAYMENT_TYPE.ELSEWHERE | typeof CONST.IOU.PAYMENT_TYPE.EXPENSIFY, writeCommand: typeof WRITE_COMMANDS.SEND_MONEY_ELSEWHERE | typeof WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, ) { - const {report, quickAction, amount, currency, comment, currentUserAccountID, recipient, created, merchant, receipt, optimisticChatReportID, delegateAccountID, getCurrencyDecimals} = - actionParams; + const { + report, + quickAction, + amount, + currency, + comment, + currentUserAccountID, + recipient, + created, + merchant, + receipt, + optimisticChatReportID, + delegateAccountID, + formatPhoneNumber, + getCurrencyDecimals, + } = actionParams; const {shouldStartTracking = true, shouldDeferForSearch = false} = actionParams; const {params, optimisticData, successData, failureData} = getSendMoneyParams({ @@ -537,6 +565,7 @@ function executeSendMoney( optimisticChatReportID, currentUserAccountID, delegateAccountID, + formatPhoneNumber, getCurrencyDecimals, }); if (shouldStartTracking) { diff --git a/src/libs/actions/IOU/Split.ts b/src/libs/actions/IOU/Split.ts index 10eb3e5da269..b532713b0ee9 100644 --- a/src/libs/actions/IOU/Split.ts +++ b/src/libs/actions/IOU/Split.ts @@ -914,6 +914,7 @@ function completeSplitBill({ delegateAccountID, isTrackIntentUser, sessionEmail, + formatPhoneNumber, getCurrencyDecimals, }: CompleteSplitBillActionParams) { if (!reportAction) { @@ -1132,11 +1133,12 @@ function completeSplitBill({ let oneOnOneReportPreviewAction = getReportPreviewReportAction(oneOnOneChatReport?.reportID, oneOnOneIOUReport?.reportID); if (oneOnOneReportPreviewAction) { - oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction, getCurrencyDecimals); + oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction, formatPhoneNumber, getCurrencyDecimals); } else { oneOnOneReportPreviewAction = buildOptimisticReportPreview( oneOnOneChatReport, oneOnOneIOUReport, + formatPhoneNumber, getCurrencyDecimals, '', oneOnOneTransaction, @@ -1912,11 +1914,12 @@ function createSplitsAndOnyxData({ let oneOnOneReportPreviewAction = getReportPreviewReportAction(oneOnOneChatReport.reportID, oneOnOneIOUReport.reportID); if (oneOnOneReportPreviewAction) { - oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction, getCurrencyDecimals); + oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction, formatPhoneNumber, getCurrencyDecimals); } else { oneOnOneReportPreviewAction = buildOptimisticReportPreview( oneOnOneChatReport, oneOnOneIOUReport, + formatPhoneNumber, getCurrencyDecimals, '', oneOnOneTransaction, diff --git a/src/libs/actions/IOU/TrackExpense.ts b/src/libs/actions/IOU/TrackExpense.ts index 32216b419209..5249f7f9f3c4 100644 --- a/src/libs/actions/IOU/TrackExpense.ts +++ b/src/libs/actions/IOU/TrackExpense.ts @@ -209,6 +209,7 @@ type GetTrackExpenseInformationParams = { // TODO: Remove optional (?) once all callers are updated in follow-up PRs of https://github.com/Expensify/App/issues/66414 isDraftChatReport?: boolean; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; type DeleteTrackExpenseParams = { @@ -876,6 +877,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T currentUserLocalCurrency, policyType, getCurrencyDecimals, + formatPhoneNumber, } = params; const {payeeAccountID = currentUserAccountIDParam, payeeEmail = currentUserEmailParam, participant} = participantParams; const {policy} = policyParams; @@ -1163,9 +1165,19 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewReportAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { - reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, false, comment, optimisticTransaction); + reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, formatPhoneNumber, getCurrencyDecimals, false, comment, optimisticTransaction); } else { - reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimals, comment, optimisticTransaction, undefined, undefined, delegateAccountID); + reportPreviewAction = buildOptimisticReportPreview( + chatReport, + iouReport, + formatPhoneNumber, + getCurrencyDecimals, + comment, + optimisticTransaction, + undefined, + undefined, + delegateAccountID, + ); // Generated ReportPreview action is a parent report action of the iou report. // We are setting the iou report's parentReportActionID to display subtitle correctly in IOU page when offline. iouReport.parentReportActionID = reportPreviewAction.reportActionID; @@ -2458,6 +2470,7 @@ function trackExpense(params: CreateTrackExpenseParams) { isDraftChatReport, currentUserLocalCurrency, getCurrencyDecimals, + formatPhoneNumber, } = params; const {accountID: currentUserAccountIDParam, email: currentUserEmailParam = ''} = currentUser; const {participant, payeeAccountID, payeeEmail} = participantParams; @@ -2627,6 +2640,7 @@ function trackExpense(params: CreateTrackExpenseParams) { // Only "Submit to my employer" creates a Submit (submit2026) workspace from a draft; everything else keeps the default (team) type. policyType: action === CONST.IOU.ACTION.SUBMIT && policy?.type === CONST.POLICY.TYPE.SUBMIT ? CONST.POLICY.TYPE.SUBMIT : undefined, getCurrencyDecimals, + formatPhoneNumber, }) ?? {}; const activeReportID = isMoneyRequestReport ? report?.reportID : chatReport?.reportID; const onyxData: TrackedExpenseParams['onyxData'] = trackExpenseInformationOnyxData; diff --git a/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts b/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts index 86475e5dcbce..423e9811d0bc 100644 --- a/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts +++ b/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts @@ -53,6 +53,7 @@ type CreateTrackExpenseParams = { // TODO: Remove optional (?) once all callers are updated in follow-up PRs of https://github.com/Expensify/App/issues/66414 isDraftChatReport?: boolean; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; export type {CreateTrackExpenseParams, TrackExpenseAccountantParams}; diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 1bb653c6f6e4..2acc411d5716 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -227,6 +227,7 @@ type CreateWorkspaceFromIOUPaymentOptions = { reportActionsList: OnyxCollection; doesEmployeePersonalDetailExist: boolean; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; type PolicyCashExpenseMode = ValueOf; @@ -4312,6 +4313,7 @@ function createWorkspaceFromIOUPayment({ reportActionsList, doesEmployeePersonalDetailExist, getCurrencyDecimals, + formatPhoneNumber, }: CreateWorkspaceFromIOUPaymentOptions): WorkspaceFromIOUCreationData | undefined { // This flow only works for IOU reports if (!iouReport || !ReportUtils.isIOUReportUsingReport(iouReport)) { @@ -4714,7 +4716,7 @@ function createWorkspaceFromIOUPayment({ message: [ { type: CONST.REPORT.MESSAGE.TYPE.TEXT, - text: ReportUtils.getReportPreviewReportActionMessage({reportOrID: expenseReport, policy: newWorkspace}, getCurrencyDecimals), + text: ReportUtils.getReportPreviewReportActionMessage({reportOrID: expenseReport, policy: newWorkspace, formatPhoneNumber}, getCurrencyDecimals), }, ], created: DateUtils.getDBTime(), diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index e5000ab1329b..f99adaff75ed 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -4289,6 +4289,7 @@ type BuildNewReportOptimisticDataParams = { isTrackIntentUser: boolean | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; reportName?: string; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; function buildNewReportOptimisticData({ @@ -4303,6 +4304,7 @@ function buildNewReportOptimisticData({ isTrackIntentUser, getCurrencyDecimals, reportName, + formatPhoneNumber, }: BuildNewReportOptimisticDataParams) { const {accountID, login, email} = ownerPersonalDetails; const timeOfCreation = DateUtils.getDBTime(); @@ -4342,7 +4344,7 @@ function buildNewReportOptimisticData({ pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }; - const message = getReportPreviewReportActionMessage({reportOrID: optimisticReportData}, getCurrencyDecimals); + const message = getReportPreviewReportActionMessage({reportOrID: optimisticReportData, formatPhoneNumber}, getCurrencyDecimals); const createReportActionMessage = [ { html: message, @@ -4525,19 +4527,44 @@ function buildNewReportOptimisticData({ optimisticReportData, }; } +type CreateNewReportParams = { + /** Personal details for the user creating the report. */ + ownerPersonalDetails: CurrentUserPersonalDetails; + /** Whether the draft report has policy violations. */ + hasViolationsParam: boolean; + /** Whether ASAP submit is available for this policy. */ + isASAPSubmitBetaEnabled: boolean; + /** Policy used to build the report and optimistic data. */ + policy: OnyxEntry; + /** Beta flags used when creating the report. */ + betas: OnyxEntry; + /** Whether the user is a tracked intent user. */ + isTrackIntentUser: boolean | undefined; + /** Currency helper used for optimistic report formatting. */ + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + /** Whether the new report should trigger a new action notification. */ + shouldNotifyNewAction: boolean; + /** Formatter used for phone numbers in optimistic report data. */ + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + /** Whether the empty reports confirmation should be dismissed. */ + shouldDismissEmptyReportsConfirmation?: boolean; + /** Optional managed card transaction and report name overrides. */ + options: {managedCardTransactionID?: string; reportName?: string}; +}; -function createNewReport( - ownerPersonalDetails: CurrentUserPersonalDetails, - hasViolationsParam: boolean, - isASAPSubmitBetaEnabled: boolean, - policy: OnyxEntry, - betas: OnyxEntry, - isTrackIntentUser: boolean | undefined, - getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], +function createNewReport({ + ownerPersonalDetails, + hasViolationsParam, + isASAPSubmitBetaEnabled, + policy, + betas, + isTrackIntentUser, + getCurrencyDecimals, shouldNotifyNewAction = false, - shouldDismissEmptyReportsConfirmation?: boolean, - options: {managedCardTransactionID?: string; reportName?: string} = {}, -) { + formatPhoneNumber, + shouldDismissEmptyReportsConfirmation, + options = {}, +}: CreateNewReportParams) { const {managedCardTransactionID, reportName} = options; const optimisticReportID = generateReportID(); const reportActionID = rand64(); @@ -4555,6 +4582,7 @@ function createNewReport( isTrackIntentUser, getCurrencyDecimals, reportName, + formatPhoneNumber, }); if (shouldDismissEmptyReportsConfirmation) { @@ -7606,6 +7634,7 @@ function buildOptimisticChangePolicyData({ reportPreviewAction, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, }: { report: Report; parentReport: OnyxEntry; @@ -7621,6 +7650,7 @@ function buildOptimisticChangePolicyData({ reportPreviewAction: OnyxEntry; isTrackIntentUser: boolean | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }) { const optimisticData: Array< OnyxUpdate< @@ -7852,7 +7882,7 @@ function buildOptimisticChangePolicyData({ // and set it as a parent of the moved report const policyExpenseChat = optimisticPolicyExpenseChatReport ?? getPolicyExpenseChat(report.ownerAccountID, policy.id); // TODO: delegateAccountIDParam will be threaded in PR 15 (https://github.com/Expensify/App/issues/66425) - const optimisticReportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, report, getCurrencyDecimals, '', null, undefined, undefined, undefined); + const optimisticReportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, report, formatPhoneNumber, getCurrencyDecimals, '', null, undefined, undefined, undefined); const newPolicyExpenseChatReportID = policyExpenseChat?.reportID; @@ -8103,6 +8133,7 @@ function changeReportPolicy({ isTrackIntentUser, getCurrencyDecimals, reportTransactions, + formatPhoneNumber, }: { report: Report; parentReport: OnyxEntry; @@ -8119,6 +8150,7 @@ function changeReportPolicy({ isTrackIntentUser: boolean | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; reportTransactions: Transaction[]; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }) { if (!report || !policy || report.policyID === policy.id || !isExpenseReport(report) || shouldBlockChangeReportPolicyForCommuterExclusion(reportTransactions, policy)) { return; @@ -8138,6 +8170,7 @@ function changeReportPolicy({ reportPreviewAction, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, }); const params = { @@ -8173,6 +8206,7 @@ function changeReportPolicyAndInviteSubmitter({ isTrackIntentUser, getCurrencyDecimals, reportTransactions, + formatPhoneNumber, }: { report: Report; parentReport: OnyxEntry; @@ -8190,6 +8224,7 @@ function changeReportPolicyAndInviteSubmitter({ isTrackIntentUser: boolean | undefined; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; reportTransactions: Transaction[]; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }) { if ( !report.reportID || @@ -8252,6 +8287,7 @@ function changeReportPolicyAndInviteSubmitter({ reportPreviewAction, isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, }); const optimisticData = [...optimisticAddMembersData, ...optimisticChangePolicyData]; diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 892c0f3d50e9..dd69c321d864 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -262,6 +262,7 @@ type HandleActionButtonPressParams = { allViolations: OnyxCollection; conciergeChat: OnyxEntry; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; function handleActionButtonPress({ @@ -303,6 +304,7 @@ function handleActionButtonPress({ allViolations, conciergeChat, getCurrencyDecimals, + formatPhoneNumber, }: HandleActionButtonPressParams) { // The transactionIDList is needed to handle actions taken on `status:""` where transactions on single expense reports can be approved/paid. // We need the transactionID to display the loading indicator for that list item's action. @@ -356,6 +358,7 @@ function handleActionButtonPress({ isTrackIntentUser, conciergeChat, getCurrencyDecimals, + formatPhoneNumber, }); return; case CONST.SEARCH.ACTION_TYPES.APPROVE: @@ -390,6 +393,7 @@ function handleActionButtonPress({ ownerLogin: submitterLogin, allViolations, getCurrencyDecimals, + formatPhoneNumber, }); return; case CONST.SEARCH.ACTION_TYPES.SUBMIT: { @@ -592,6 +596,7 @@ type GetPayActionCallbackParams = { isTrackIntentUser: boolean | undefined; conciergeChat: OnyxEntry; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; function getPayActionCallback({ @@ -621,6 +626,7 @@ function getPayActionCallback({ isTrackIntentUser, conciergeChat, getCurrencyDecimals, + formatPhoneNumber, }: GetPayActionCallbackParams) { const lastPolicyPaymentMethod = getLastPolicyPaymentMethod(item.policyID, personalPolicyID, lastPaymentMethod, getReportType(item.reportID)); @@ -672,6 +678,7 @@ function getPayActionCallback({ isTrackIntentUser, conciergeChat, getCurrencyDecimals, + formatPhoneNumber, }); } @@ -694,6 +701,7 @@ type GetApproveActionCallbackParams = { ownerLogin: string | undefined; allViolations: OnyxCollection; getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }; function getApproveActionCallback({ @@ -715,6 +723,7 @@ function getApproveActionCallback({ ownerLogin, allViolations, getCurrencyDecimals, + formatPhoneNumber, }: GetApproveActionCallbackParams) { if (!item.reportID) { return; @@ -742,6 +751,7 @@ function getApproveActionCallback({ additionalOnyxData: getSearchApproveOnyxData(hash, item.reportID, currentSearchKey), isTrackIntentUser, getCurrencyDecimals, + formatPhoneNumber, }); } @@ -1602,19 +1612,43 @@ function exportToIntegrationOnSearch(hash: number, reportIDs: string[], connecti finallyData, }); } - -function rejectMoneyRequestInBulk( - reportID: string, - comment: string, - policy: OnyxEntry, - transactionIDs: string[], - currentUserAccountIDParam: number, - currentUserLogin: string, - betas: OnyxEntry, - delegateAccountID: number | undefined, - getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], - hash?: number, -) { +type RejectMoneyRequestInBulkParams = { + /** Report where the selected expenses belong. */ + reportID: string; + /** Parsed comment included with each rejection. */ + comment: string; + /** Policy used to determine delayed submission behavior. */ + policy: OnyxEntry; + /** Transaction IDs being rejected in bulk. */ + transactionIDs: string[]; + /** Current user's account ID used for optimistic updates. */ + currentUserAccountIDParam: number; + /** Current user's login used for optimistic personal details updates. */ + currentUserLogin: string; + /** Beta flags used to determine available rejection behavior. */ + betas: OnyxEntry; + /** Delegate account ID used when acting on behalf of another user. */ + delegateAccountID: number | undefined; + /** Currency helper used for optimistic monetary formatting. */ + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + /** Snapshot hash used to merge loading data into the search result. */ + hash?: number; + /** Formatter used when building optimistic personal details. */ + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; +}; +function rejectMoneyRequestInBulk({ + reportID, + comment, + policy, + transactionIDs, + currentUserAccountIDParam, + currentUserLogin, + betas, + delegateAccountID, + getCurrencyDecimals, + hash, + formatPhoneNumber, +}: RejectMoneyRequestInBulkParams) { const optimisticData: Array> = []; const finallyData: Array> = []; const successData: RejectMoneyRequestData['successData'] = []; @@ -1643,6 +1677,7 @@ function rejectMoneyRequestInBulk( delegateAccountID, getCurrencyDecimals, shouldUseBulkAction: true, + formatPhoneNumber, }); if (data) { optimisticData.push(...data.optimisticData); @@ -1670,19 +1705,44 @@ function rejectMoneyRequestInBulk( type TransactionReportInfo = { reportID?: string; }; +type RejectMoneyRequestsOnSearchParams = { + /** Search snapshot hash used for loading state. */ + hash: number; + /** Selected transactions mapped to their report metadata. */ + selectedTransactions: Record; + /** Parsed comment included with each rejection. */ + comment: string; + /** All policies available in Onyx for resolving report policy data. */ + allPolicies: OnyxCollection; + /** All reports available in Onyx for resolving report metadata. */ + allReports: OnyxCollection; + /** Current user's account ID used for optimistic updates. */ + currentUserAccountIDParam: number; + /** Current user's login used for optimistic personal details updates. */ + currentUserLogin: string; + /** Beta flags used to determine available rejection behavior. */ + betas: OnyxEntry; + /** Delegate account ID used when acting on behalf of another user. */ + delegateAccountID: number | undefined; + /** Currency helper used for optimistic monetary formatting. */ + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + /** Formatter used when building optimistic personal details. */ + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; +}; -function rejectMoneyRequestsOnSearch( - hash: number, - selectedTransactions: Record, - comment: string, - allPolicies: OnyxCollection, - allReports: OnyxCollection, - currentUserAccountIDParam: number, - currentUserLogin: string, - betas: OnyxEntry, - delegateAccountID: number | undefined, - getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], -) { +function rejectMoneyRequestsOnSearch({ + hash, + selectedTransactions, + comment, + allPolicies, + allReports, + currentUserAccountIDParam, + currentUserLogin, + betas, + delegateAccountID, + getCurrencyDecimals, + formatPhoneNumber, +}: RejectMoneyRequestsOnSearchParams) { const transactionIDs = Object.keys(selectedTransactions); const transactionsByReport = transactionIDs.reduce>((acc, transactionID) => { @@ -1714,7 +1774,19 @@ function rejectMoneyRequestsOnSearch( const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const isPolicyDelayedSubmissionEnabled = policy ? isDelayedSubmissionEnabled(policy) : false; if (isPolicyDelayedSubmissionEnabled && areAllExpensesSelected) { - rejectMoneyRequestInBulk(reportID, comment, policy, selectedTransactionIDs, currentUserAccountIDParam, currentUserLogin, betas, delegateAccountID, getCurrencyDecimals, hash); + rejectMoneyRequestInBulk({ + reportID, + comment, + policy, + transactionIDs: selectedTransactionIDs, + currentUserAccountIDParam, + currentUserLogin, + betas, + delegateAccountID, + formatPhoneNumber, + getCurrencyDecimals, + hash, + }); } else { // Share a single destination ID across all rejections from the same source report const sharedRejectedToReportID = generateReportID(); @@ -1723,10 +1795,22 @@ function rejectMoneyRequestsOnSearch( existingRejectedReport = nextRejectedReport; }; for (const transactionID of selectedTransactionIDs) { - rejectMoneyRequest(transactionID, reportID, comment, policy, currentUserAccountIDParam, currentUserLogin, betas, delegateAccountID, getCurrencyDecimals, { - sharedRejectedToReportID, - existingRejectedReport, - setExistingRejectedReport, + rejectMoneyRequest({ + transactionID, + reportID, + comment, + policy, + currentUserAccountIDParam, + currentUserLogin, + betas, + delegateAccountID, + formatPhoneNumber, + getCurrencyDecimals, + options: { + sharedRejectedToReportID, + existingRejectedReport, + setExistingRejectedReport, + }, }); } } diff --git a/src/pages/DynamicReportChangeWorkspacePage.tsx b/src/pages/DynamicReportChangeWorkspacePage.tsx index bbf7c62d8ff6..a51ce6ff4251 100644 --- a/src/pages/DynamicReportChangeWorkspacePage.tsx +++ b/src/pages/DynamicReportChangeWorkspacePage.tsx @@ -73,7 +73,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace const {isOffline} = useNetwork(); const styles = useThemeStyles(); const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); - const {translate, localeCompare} = useLocalize(); + const {translate, localeCompare, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const reportTransactions = useReportTransactions(reportID); @@ -186,6 +186,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace reportPreviewAction, isTrackIntentUser, reportTransactions, + formatPhoneNumber, }); refreshSearch(); return; @@ -207,6 +208,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace reportPreviewAction, isTrackIntentUser, reportTransactions, + formatPhoneNumber, }); refreshSearch(); }; diff --git a/src/pages/DynamicReportDetailsPage.tsx b/src/pages/DynamicReportDetailsPage.tsx index 446018e5cbf4..47c015426f6b 100644 --- a/src/pages/DynamicReportDetailsPage.tsx +++ b/src/pages/DynamicReportDetailsPage.tsx @@ -276,7 +276,7 @@ function DynamicReportDetailsPage({policy, report, route, reportMetadata, report const isReportArchived = useReportIsArchived(report?.reportID); const isArchivedRoom = useMemo(() => isArchivedNonExpenseReport(report, isReportArchived), [report, isReportArchived]); const shouldDisableRename = useMemo(() => shouldDisableRenameUtil(report, isReportArchived), [report, isReportArchived]); - const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, translate, derivedParentReportName, isParentReportArchived); + const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, translate, formatPhoneNumber, derivedParentReportName, isParentReportArchived); const base62ReportID = getBase62ReportID(Number(report.reportID)); const ancestors = useAncestors(report); diff --git a/src/pages/ReportSubmitToContent.tsx b/src/pages/ReportSubmitToContent.tsx index 320b55790813..272b63f0dcd1 100644 --- a/src/pages/ReportSubmitToContent.tsx +++ b/src/pages/ReportSubmitToContent.tsx @@ -80,7 +80,7 @@ function ReportSubmitToContent({ }: ReportSubmitToContentProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); - const {translate, localeCompare, dateFnsLocale} = useLocalize(); + const {translate, localeCompare, dateFnsLocale, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const isInLandscapeMode = useIsInLandscapeMode(); const {keyboardActiveHeight} = useKeyboardState(); @@ -315,6 +315,7 @@ function ReportSubmitToContent({ managerEmail: trimmed, managerAccountID: resolvedManagerAccountID, isTrackIntentUser, + formatPhoneNumber, onSubmitted: () => { if (currentSearchQueryJSON && !isOffline) { search({ diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 46791091eaf2..50b9e9346616 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -135,7 +135,7 @@ function EmptySearchViewContent({ onScroll, contentContainerStyle, }: EmptySearchViewContentProps) { - const {translate, dateFnsLocale} = useLocalize(); + const {translate, dateFnsLocale, formatPhoneNumber} = useLocalize(); const timezone = useCurrentTimezone(); const styles = useThemeStyles(); const isInLandscapeMode = useIsInLandscapeMode(); @@ -172,17 +172,19 @@ function EmptySearchViewContent({ return; } - const {reportID: createdReportID} = createNewReport( - currentUserPersonalDetails, - hasViolations, + const {reportID: createdReportID} = createNewReport({ + ownerPersonalDetails: currentUserPersonalDetails, + hasViolationsParam: hasViolations, isASAPSubmitBetaEnabled, - defaultChatEnabledPolicy, + policy: defaultChatEnabledPolicy, betas, isTrackIntentUser, getCurrencyDecimals, - false, + shouldNotifyNewAction: false, + formatPhoneNumber, shouldDismissEmptyReportsConfirmation, - ); + options: {}, + }); Navigation.setNavigationActionToMicrotaskQueue(() => { Navigation.navigate( ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({ diff --git a/src/pages/Search/SearchRejectReasonPage.tsx b/src/pages/Search/SearchRejectReasonPage.tsx index cc97433922a3..ecdca9490217 100644 --- a/src/pages/Search/SearchRejectReasonPage.tsx +++ b/src/pages/Search/SearchRejectReasonPage.tsx @@ -36,7 +36,7 @@ function SearchRejectReasonPage({route}: SearchRejectReasonPageProps) { const {reportID} = route.params ?? {}; const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const [betas] = useOnyx(ONYXKEYS.BETAS); @@ -62,18 +62,19 @@ function SearchRejectReasonPage({route}: SearchRejectReasonPageProps) { return; } - const urlToNavigateBack = rejectMoneyRequestsOnSearch( - currentSearchHash, - selectedTransactionsForReject, + const urlToNavigateBack = rejectMoneyRequestsOnSearch({ + hash: currentSearchHash, + selectedTransactions: selectedTransactionsForReject, comment, allPolicies, allReports, - currentUserAccountID, - currentUserLogin ?? '', + currentUserAccountIDParam: currentUserAccountID, + currentUserLogin: currentUserLogin ?? '', betas, delegateAccountID, getCurrencyDecimals, - ); + formatPhoneNumber, + }); if (route.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT_REJECT_TRANSACTIONS) { clearSelectedTransactions(true); } else { @@ -95,6 +96,7 @@ function SearchRejectReasonPage({route}: SearchRejectReasonPageProps) { betas, delegateAccountID, getCurrencyDecimals, + formatPhoneNumber, route.name, showDelegateNoAccessModal, clearSelectedTransactions, diff --git a/src/pages/Search/SearchTransactionsChangeReport.tsx b/src/pages/Search/SearchTransactionsChangeReport.tsx index 88ff61bff4ea..9ec9d7f01205 100644 --- a/src/pages/Search/SearchTransactionsChangeReport.tsx +++ b/src/pages/Search/SearchTransactionsChangeReport.tsx @@ -7,6 +7,7 @@ import useConditionalCreateEmptyReportConfirmation from '@hooks/useConditionalCr import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useHasPerDiemTransactions from '@hooks/useHasPerDiemTransactions'; +import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; import usePersonalPolicy from '@hooks/usePersonalPolicy'; @@ -39,6 +40,7 @@ type TransactionGroupListItem = ListItem & { }; function SearchTransactionsChangeReport() { + const {formatPhoneNumber} = useLocalize(); const {selectedTransactions} = useSearchSelectionContext(); const delegateAccountID = useDelegateAccountID(); const {clearSelectedTransactions} = useSearchSelectionActions(); @@ -154,18 +156,19 @@ function SearchTransactionsChangeReport() { }, []); const createReportForPolicy = (shouldDismissEmptyReportsConfirmation?: boolean) => { - const optimisticReport = createNewReport( - targetOwnerPersonalDetails, - hasViolations, + const optimisticReport = createNewReport({ + ownerPersonalDetails: targetOwnerPersonalDetails, + hasViolationsParam: hasViolations, isASAPSubmitBetaEnabled, - policyForMovingExpenses, + policy: policyForMovingExpenses, betas, isTrackIntentUser, getCurrencyDecimals, - false, + shouldNotifyNewAction: false, + formatPhoneNumber, shouldDismissEmptyReportsConfirmation, - {managedCardTransactionID}, - ); + options: {managedCardTransactionID}, + }); const policyTagList = policyForMovingExpenses?.id ? allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyForMovingExpenses.id}`] : {}; const reportsForCall = { ...reports, diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index 97a9db633cfd..165cb2eecba8 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -412,6 +412,7 @@ function SubmitDetailsPage({ currentUserLocalCurrency: currentUserPersonalDetails.localCurrencyCode ?? CONST.CURRENCY.USD, delegateAccountID, reportActionsList: undefined, + formatPhoneNumber, }); } else { const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined; diff --git a/src/pages/ShareCodePage.tsx b/src/pages/ShareCodePage.tsx index 88e57ddaf589..8379c03cc4de 100644 --- a/src/pages/ShareCodePage.tsx +++ b/src/pages/ShareCodePage.tsx @@ -130,7 +130,7 @@ function ShareCodePage({report, policy, backTo}: ShareCodePageProps) { } return ( - getParentNavigationSubtitle(report, policy, conciergeReportID, translate, derivedParentReportName, isParentReportArchived).workspaceName ?? + getParentNavigationSubtitle(report, policy, conciergeReportID, translate, formatPhoneNumber, derivedParentReportName, isParentReportArchived).workspaceName ?? getChatRoomSubtitle(report, policy, conciergeReportID, translate, false, isReportArchived) ); } diff --git a/src/pages/inbox/HeaderView.tsx b/src/pages/inbox/HeaderView.tsx index 918f2ee440ea..a711277e6a06 100644 --- a/src/pages/inbox/HeaderView.tsx +++ b/src/pages/inbox/HeaderView.tsx @@ -185,7 +185,15 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps) ? getReportStatusTooltipTranslation({stateNum: reportHeaderData?.stateNum, statusNum: reportHeaderData?.statusNum, translate}) : undefined; const isParentReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.parentReportID); - const parentNavigationSubtitleData = getParentNavigationSubtitle(parentNavigationReport, policy, conciergeReportID, translate, derivedParentReportName, isParentReportHeaderDataArchived); + const parentNavigationSubtitleData = getParentNavigationSubtitle( + parentNavigationReport, + policy, + conciergeReportID, + translate, + formatPhoneNumber, + derivedParentReportName, + isParentReportHeaderDataArchived, + ); const humanAgentAccountID = getHumanAgentAccountIDFromReportAction(parentReportAction); const humanAgentName = getHumanAgentFirstName(parentReportAction, personalDetails); const reportDescription = StringUtils.lineBreaksToSpaces(Parser.htmlToText(getReportDescription(report))); diff --git a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx index 999e9383a066..3b001d5b98b4 100644 --- a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx @@ -1031,7 +1031,7 @@ const ContextMenuActions: ContextMenuAction[] = [ const modifyExpenseMessage = Parser.htmlToMarkdown(modifyExpenseMessageWithHTML); Clipboard.setString(modifyExpenseMessage); } else if (isReimbursementDeQueuedOrCanceledAction(reportAction)) { - const displayMessage = getReimbursementDeQueuedOrCanceledActionMessage(translate, reportAction, report?.ownerAccountID, convertToDisplayString); + const displayMessage = getReimbursementDeQueuedOrCanceledActionMessage(translate, formatPhoneNumber, reportAction, report?.ownerAccountID, convertToDisplayString); Clipboard.setString(displayMessage); } else if (isMoneyRequestAction(reportAction)) { const displayMessage = getIOUReportActionDisplayMessage(translate, reportAction, convertToDisplayString, transaction, report, bankAccountList); diff --git a/src/pages/inbox/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/inbox/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index d7b6118bd80e..512c00bf9690 100644 --- a/src/pages/inbox/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/inbox/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -158,7 +158,7 @@ function AttachmentPickerWithMenuItems({ const isFocused = useIsFocused(); const theme = useTheme(); const styles = useThemeStyles(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {shouldUseNarrowLayout} = useResponsiveLayout(); const {calculatePopoverPosition} = usePopoverPosition(); const [popoverAnchorPosition, setPopoverAnchorPosition] = useState(null); @@ -207,17 +207,19 @@ function AttachmentPickerWithMenuItems({ onConfirm: (shouldDismissEmptyReportsConfirmation) => selectOption( () => - createNewReport( - currentUserPersonalDetails, + createNewReport({ + ownerPersonalDetails: currentUserPersonalDetails, + hasViolationsParam: hasViolations, isASAPSubmitBetaEnabled, - hasViolations, policy, betas, isTrackIntentUser, getCurrencyDecimals, - true, + shouldNotifyNewAction: true, + formatPhoneNumber, shouldDismissEmptyReportsConfirmation, - ), + options: {}, + }), true, ), }); @@ -226,7 +228,19 @@ function AttachmentPickerWithMenuItems({ if (shouldShowEmptyReportConfirmation) { openCreateReportConfirmation(); } else { - createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, betas, isTrackIntentUser, getCurrencyDecimals, true, false); + createNewReport({ + ownerPersonalDetails: currentUserPersonalDetails, + hasViolationsParam: hasViolations, + isASAPSubmitBetaEnabled, + policy, + betas, + isTrackIntentUser, + getCurrencyDecimals, + shouldNotifyNewAction: true, + formatPhoneNumber, + shouldDismissEmptyReportsConfirmation: false, + options: {}, + }); } }; @@ -270,7 +284,7 @@ function AttachmentPickerWithMenuItems({ [CONST.IOU.TYPE.PAY]: [ { icon: getIconForAction(CONST.IOU.TYPE.SEND, icons), - text: translate('iou.paySomeone', getPayeeName(report, translate, accountID)), + text: translate('iou.paySomeone', getPayeeName(report, translate, formatPhoneNumber, accountID)), shouldCallAfterModalHide: shouldUseNarrowLayout, sentryLabel: CONST.SENTRY_LABEL.REPORT.ATTACHMENT_PICKER_MENU_PAY_SOMEONE, onSelected: () => { @@ -336,6 +350,7 @@ function AttachmentPickerWithMenuItems({ icons, betas, draftTransactionIDs, + formatPhoneNumber, ]); const createReportOption: PopoverMenuItem[] = useMemo(() => { diff --git a/src/pages/inbox/report/actionContents/ReimbursementDeQueuedContent.tsx b/src/pages/inbox/report/actionContents/ReimbursementDeQueuedContent.tsx index 58598d797462..b5af51a31e07 100644 --- a/src/pages/inbox/report/actionContents/ReimbursementDeQueuedContent.tsx +++ b/src/pages/inbox/report/actionContents/ReimbursementDeQueuedContent.tsx @@ -18,10 +18,11 @@ type ReimbursementDeQueuedContentProps = { }; function ReimbursementDeQueuedContent({action, reportOwnerAccountID}: ReimbursementDeQueuedContentProps) { - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {convertToDisplayString} = useCurrencyListActions(); const message = getReimbursementDeQueuedOrCanceledActionMessage( translate, + formatPhoneNumber, action as OnyxEntry>, reportOwnerAccountID, convertToDisplayString, diff --git a/src/pages/inbox/sidebar/FABPopoverContent/menuItems/CreateReportMenuItem.tsx b/src/pages/inbox/sidebar/FABPopoverContent/menuItems/CreateReportMenuItem.tsx index d5d3eb73ac9e..af0aa22fb04e 100644 --- a/src/pages/inbox/sidebar/FABPopoverContent/menuItems/CreateReportMenuItem.tsx +++ b/src/pages/inbox/sidebar/FABPopoverContent/menuItems/CreateReportMenuItem.tsx @@ -37,7 +37,7 @@ const chatEnabledPaidGroupPoliciesSelector = (policies: OnyxCollection; function RejectReasonPage({route}: RejectReasonPageProps) { - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {getCurrencyDecimals} = useCurrencyListActions(); const {transactionID, reportID, backTo} = route.params; @@ -53,17 +53,18 @@ function RejectReasonPage({route}: RejectReasonPageProps) { return; } - const urlToNavigateBack = rejectMoneyRequest( + const urlToNavigateBack = rejectMoneyRequest({ transactionID, reportID, - values.comment, + comment: values.comment, policy, - currentUserAccountID, - currentUserLogin ?? '', + currentUserAccountIDParam: currentUserAccountID, + currentUserLogin: currentUserLogin ?? '', betas, delegateAccountID, + formatPhoneNumber, getCurrencyDecimals, - ); + }); removeTransaction(transactionID); // If the super wide rhp is not opened, dismiss the entire modal. if (superWideRHPRouteKeys.length > 0) { diff --git a/src/pages/iou/request/DistanceRequestStartPage.tsx b/src/pages/iou/request/DistanceRequestStartPage.tsx index cbe314836726..3e14665b1f7d 100644 --- a/src/pages/iou/request/DistanceRequestStartPage.tsx +++ b/src/pages/iou/request/DistanceRequestStartPage.tsx @@ -52,7 +52,7 @@ function DistanceRequestStartPage({ defaultSelectedTab = CONST.TAB_REQUEST.DISTANCE_MAP, }: DistanceRequestStartPageProps) { const styles = useThemeStyles(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {accountID: currentUserAccountID, login: currentUserLogin} = useCurrentUserPersonalDetails(); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${getNonEmptyStringOnyxID(route?.params.transactionID)}`); @@ -86,8 +86,8 @@ function DistanceRequestStartPage({ const tabTitles = { [CONST.IOU.TYPE.REQUEST]: translate('iou.trackDistance'), [CONST.IOU.TYPE.SUBMIT]: translate('iou.trackDistance'), - [CONST.IOU.TYPE.SEND]: translate('iou.paySomeone', getPayeeName(report, translate, currentUserAccountID)), - [CONST.IOU.TYPE.PAY]: translate('iou.paySomeone', getPayeeName(report, translate, currentUserAccountID)), + [CONST.IOU.TYPE.SEND]: translate('iou.paySomeone', getPayeeName(report, translate, formatPhoneNumber, currentUserAccountID)), + [CONST.IOU.TYPE.PAY]: translate('iou.paySomeone', getPayeeName(report, translate, formatPhoneNumber, currentUserAccountID)), [CONST.IOU.TYPE.SPLIT]: translate('iou.splitExpense'), [CONST.IOU.TYPE.SPLIT_EXPENSE]: translate('iou.splitExpense'), [CONST.IOU.TYPE.TRACK]: translate('iou.trackDistance'), diff --git a/src/pages/iou/request/IOURequestStartPage.tsx b/src/pages/iou/request/IOURequestStartPage.tsx index 2e65055a4fb9..92acbd83cdc9 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -67,7 +67,7 @@ function IOURequestStartPage({ defaultSelectedTab = CONST.TAB_REQUEST.SCAN, }: IOURequestStartPageProps) { const styles = useThemeStyles(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const shouldUseTab = iouType !== CONST.IOU.TYPE.SEND && iouType !== CONST.IOU.TYPE.PAY && iouType !== CONST.IOU.TYPE.INVOICE; const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); const [reportDraft] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportID}`); @@ -88,8 +88,8 @@ function IOURequestStartPage({ const tabTitles = { [CONST.IOU.TYPE.REQUEST]: translate('iou.createExpense'), [CONST.IOU.TYPE.SUBMIT]: translate('iou.createExpense'), - [CONST.IOU.TYPE.SEND]: translate('iou.paySomeone', getPayeeName(report, translate, currentUserPersonalDetails.accountID)), - [CONST.IOU.TYPE.PAY]: translate('iou.paySomeone', getPayeeName(report, translate, currentUserPersonalDetails.accountID)), + [CONST.IOU.TYPE.SEND]: translate('iou.paySomeone', getPayeeName(report, translate, formatPhoneNumber, currentUserPersonalDetails.accountID)), + [CONST.IOU.TYPE.PAY]: translate('iou.paySomeone', getPayeeName(report, translate, formatPhoneNumber, currentUserPersonalDetails.accountID)), [CONST.IOU.TYPE.SPLIT]: translate('iou.splitExpense'), [CONST.IOU.TYPE.SPLIT_EXPENSE]: translate('iou.splitExpense'), [CONST.IOU.TYPE.TRACK]: translate('iou.createExpense'), diff --git a/src/pages/iou/request/step/DynamicIOURequestEditReport.tsx b/src/pages/iou/request/step/DynamicIOURequestEditReport.tsx index 918f17e0cd22..7cc4de88d743 100644 --- a/src/pages/iou/request/step/DynamicIOURequestEditReport.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestEditReport.tsx @@ -9,6 +9,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useDynamicBackPath from '@hooks/useDynamicBackPath'; import useHasPerDiemTransactions from '@hooks/useHasPerDiemTransactions'; +import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; import usePersonalPolicy from '@hooks/usePersonalPolicy'; @@ -51,6 +52,7 @@ type TransactionGroupListItem = ListItem & { type DynamicIOURequestEditReportProps = WithWritableReportOrNotFoundProps; function DynamicIOURequestEditReport({route}: DynamicIOURequestEditReportProps) { + const {formatPhoneNumber} = useLocalize(); const {reportID, action, shouldTurnOffSelectionMode, transactionID: transactionIDFromParams} = route.params; const backPath = useDynamicBackPath(DYNAMIC_ROUTES.MONEY_REQUEST_EDIT_REPORT.path); const {selectedTransactionIDs} = useSearchSelectionContext(); @@ -166,18 +168,19 @@ function DynamicIOURequestEditReport({route}: DynamicIOURequestEditReportProps) return; } - const optimisticReport = createNewReport( + const optimisticReport = createNewReport({ ownerPersonalDetails, - hasViolations, + hasViolationsParam: hasViolations, isASAPSubmitBetaEnabled, - policyForMovingExpenses, + policy: policyForMovingExpenses, betas, isTrackIntentUser, getCurrencyDecimals, - false, + shouldNotifyNewAction: false, + formatPhoneNumber, shouldDismissEmptyReportsConfirmation, - {managedCardTransactionID}, - ); + options: {managedCardTransactionID}, + }); selectReport( { value: optimisticReport.reportID, diff --git a/src/pages/iou/request/step/DynamicIOURequestStepReport.tsx b/src/pages/iou/request/step/DynamicIOURequestStepReport.tsx index 71818411edd5..bf6cd5201d83 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepReport.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepReport.tsx @@ -5,6 +5,7 @@ import type {ListItem} from '@components/SelectionList/types'; import useConditionalCreateEmptyReportConfirmation from '@hooks/useConditionalCreateEmptyReportConfirmation'; import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useDynamicBackPath from '@hooks/useDynamicBackPath'; +import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import useOptimisticDraftTransactions from '@hooks/useOptimisticDraftTransactions'; import usePermissions from '@hooks/usePermissions'; @@ -61,6 +62,7 @@ const getIOUActionsSelector = (actions: OnyxEntry): ReportAction[ }; function DynamicIOURequestStepReport({route, transaction}: DynamicIOURequestStepReportProps) { + const {formatPhoneNumber} = useLocalize(); const {action, iouType, transactionID, reportID: reportIDFromRoute, reportActionID} = route.params; const backPath = useDynamicBackPath(DYNAMIC_ROUTES.MONEY_REQUEST_STEP_REPORT.path); const isUnreported = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; @@ -173,18 +175,19 @@ function DynamicIOURequestStepReport({route, transaction}: DynamicIOURequestStep } const policyForNewReport = isPerDiemTransaction && perDiemOriginalPolicy ? perDiemOriginalPolicy : policyForMovingExpenses; - const optimisticReport = createNewReport( + const optimisticReport = createNewReport({ ownerPersonalDetails, - hasViolations, + hasViolationsParam: hasViolations, isASAPSubmitBetaEnabled, - policyForNewReport, + policy: policyForNewReport, betas, isTrackIntentUser, getCurrencyDecimals, - false, + shouldNotifyNewAction: false, + formatPhoneNumber, shouldDismissEmptyReportsConfirmation, - {managedCardTransactionID: isUnreportedManagedCardTransaction ? transactionID : undefined}, - ); + options: {managedCardTransactionID: isUnreportedManagedCardTransaction ? transactionID : undefined}, + }); handleRegularReportSelection({value: optimisticReport.reportID, keyForList: optimisticReport.reportID, policyID: policyForNewReport?.id}, optimisticReport); }; diff --git a/src/pages/iou/request/step/DynamicIOURequestStepUpgrade.tsx b/src/pages/iou/request/step/DynamicIOURequestStepUpgrade.tsx index a812bd731e96..5388e1400b35 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepUpgrade.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepUpgrade.tsx @@ -62,7 +62,7 @@ function DynamicIOURequestStepUpgrade({ }: DynamicIOURequestStepUpgradeProps) { const styles = useThemeStyles(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {isOffline} = useNetwork(); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const delegateAccountID = useDelegateAccountID(); @@ -142,7 +142,18 @@ function DynamicIOURequestStepUpgrade({ if (upgradePath === CONST.UPGRADE_PATHS.REPORTS && policyID && selectedTransactionsKeys.includes(transactionID)) { const newPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; - const optimisticReport = createNewReport(ownerPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, newPolicy, betas, isTrackIntentUser, getCurrencyDecimals); + const optimisticReport = createNewReport({ + ownerPersonalDetails, + hasViolationsParam: hasViolations, + isASAPSubmitBetaEnabled, + policy: newPolicy, + betas, + isTrackIntentUser, + getCurrencyDecimals, + shouldNotifyNewAction: false, + formatPhoneNumber, + options: {}, + }); const policyTagList = policyID ? allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] : {}; const reportsForCall = { @@ -279,6 +290,7 @@ function DynamicIOURequestStepUpgrade({ isTrackIntentUser, delegateAccountID, getCurrencyDecimals, + formatPhoneNumber, ]); const participant = transaction?.participants?.[0]; diff --git a/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts b/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts index 73bdc829b150..26a92e51bc30 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts +++ b/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts @@ -333,6 +333,7 @@ function handleMoneyRequestStepDistanceNavigation({ delegateAccountID, reportActionsList: undefined, getCurrencyDecimals, + formatPhoneNumber, }); cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, { report, diff --git a/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts b/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts index c0b41bd5ff56..e89c0846922f 100644 --- a/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts +++ b/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts @@ -813,6 +813,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { reportActionsList: policyExpenseChatReportActions, currentUserLocalCurrency: currentUserPersonalDetails.localCurrencyCode ?? CONST.CURRENCY.USD, delegateAccountID, + formatPhoneNumber, }); } performPostBatchCleanup({ @@ -1224,6 +1225,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { shouldStartTracking, shouldDeferForSearch, delegateAccountID, + formatPhoneNumber, }; if (paymentMethod === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { diff --git a/tests/actions/IOU/RequestMoneyTest.ts b/tests/actions/IOU/RequestMoneyTest.ts index dd6d2cc4190d..aedce60190f3 100644 --- a/tests/actions/IOU/RequestMoneyTest.ts +++ b/tests/actions/IOU/RequestMoneyTest.ts @@ -1299,6 +1299,7 @@ describe('actions/IOU', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); mockFetch?.resume?.(); @@ -1372,6 +1373,7 @@ describe('actions/IOU', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1946,6 +1948,7 @@ describe('actions/IOU', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -2797,6 +2800,7 @@ describe('actions/IOU', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -2867,6 +2871,7 @@ describe('actions/IOU', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -3115,6 +3120,7 @@ describe('actions/IOU', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/HoldTest.ts b/tests/actions/IOUTest/HoldTest.ts index 584807792444..3d689a656586 100644 --- a/tests/actions/IOUTest/HoldTest.ts +++ b/tests/actions/IOUTest/HoldTest.ts @@ -26,7 +26,7 @@ import type {MockFetch} from '../../utils/TestHelper'; import createRandomPolicy from '../../utils/collections/policies'; import createMock from '../../utils/createMock'; -import {createGlobalFetchMock, getCurrencyDecimalsLocal} from '../../utils/TestHelper'; +import {createGlobalFetchMock, getCurrencyDecimalsLocal, formatPhoneNumber} from '../../utils/TestHelper'; import {hasDefinedProperty, isObject} from '../../utils/typeGuards'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; @@ -707,6 +707,7 @@ describe('actions/IOU/Hold', () => { delegateAccountID: undefined, betas: [], getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); const totalsUpdate = result.optimisticData.find((entry) => entry.onyxMethod === Onyx.METHOD.MERGE && entry.key === `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`); expect(totalsUpdate).toBeDefined(); @@ -734,6 +735,7 @@ describe('actions/IOU/Hold', () => { delegateAccountID: undefined, betas: [], getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); const restorationEntries = result.failureData.filter( (entry) => entry.onyxMethod === Onyx.METHOD.MERGE && entry.key === `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, @@ -766,6 +768,7 @@ describe('actions/IOU/Hold', () => { delegateAccountID: undefined, betas: [], getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); const totalsUpdates = result.optimisticData.filter((entry) => { const value = entry.value; @@ -799,6 +802,7 @@ describe('actions/IOU/Hold', () => { delegateAccountID: undefined, betas: [], getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); const totalsUpdates = result.optimisticData.filter((entry) => { const value = entry.value; diff --git a/tests/actions/IOUTest/PayMoneyRequestTest.ts b/tests/actions/IOUTest/PayMoneyRequestTest.ts index 1ee41471d74c..f2c9ca55f4b8 100644 --- a/tests/actions/IOUTest/PayMoneyRequestTest.ts +++ b/tests/actions/IOUTest/PayMoneyRequestTest.ts @@ -265,6 +265,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); return waitForBatchedUpdates(); }) @@ -481,6 +482,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); return waitForBatchedUpdates(); }) @@ -653,6 +655,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); return waitForBatchedUpdates(); }) @@ -710,6 +713,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -797,6 +801,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: DELEGATE_ACCOUNT_ID, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -885,6 +890,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); return waitForBatchedUpdates(); }) @@ -986,6 +992,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); const newExpenseReport = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${newExpenseReportID}`); @@ -1027,6 +1034,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1081,6 +1089,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1178,7 +1187,7 @@ describe('actions/IOU/PayMoneyRequest', () => { mockFetch?.pause?.(); - markReportPaymentReceived(chatReport, reimbursedReport, currentUserAccountID, currentUserEmail, mockChatReportActions, false, getCurrencyDecimalsLocal); + markReportPaymentReceived(chatReport, reimbursedReport, currentUserAccountID, currentUserEmail, mockChatReportActions, false, getCurrencyDecimalsLocal, formatPhoneNumber); await waitForBatchedUpdates(); const updatedChatReport = await new Promise>((resolve) => { @@ -1251,6 +1260,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1321,6 +1331,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1381,6 +1392,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1421,6 +1433,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1553,6 +1566,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); return waitForBatchedUpdates(); }) @@ -1975,6 +1989,7 @@ describe('actions/IOU/PayMoneyRequest', () => { delegateAccountID: undefined, isTrackIntentUser: false, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); } await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/RejectMoneyRequestTest.ts b/tests/actions/IOUTest/RejectMoneyRequestTest.ts index 2279939d80ea..7083641e36a4 100644 --- a/tests/actions/IOUTest/RejectMoneyRequestTest.ts +++ b/tests/actions/IOUTest/RejectMoneyRequestTest.ts @@ -22,7 +22,7 @@ import createRandomPolicy from '../../utils/collections/policies'; import {createRandomReport} from '../../utils/collections/reports'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; -import {getCurrencyDecimalsLocal, getGlobalFetchMock, getOnyxData} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, getGlobalFetchMock, getOnyxData, formatPhoneNumber} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; jest.mock('@src/libs/Navigation/Navigation', () => ({ @@ -154,17 +154,18 @@ describe('actions/IOU/RejectMoneyRequest', () => { if (!transaction?.transactionID || !iouReport?.reportID) { throw new Error('Required transaction or report data is missing'); } - const result = rejectMoneyRequest( - transaction.transactionID, - iouReport.reportID, + const result = rejectMoneyRequest({ + transactionID: transaction.transactionID, + reportID: iouReport.reportID, comment, policy, - TEST_USER_ACCOUNT_ID, - TEST_USER_EMAIL, - [CONST.BETAS.ALL], - undefined, - getCurrencyDecimalsLocal, - ); + currentUserAccountIDParam: TEST_USER_ACCOUNT_ID, + currentUserLogin: TEST_USER_EMAIL, + betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, + formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, + }); // Then: Should return navigation route to chat report expect(result).toBe(ROUTES.REPORT_WITH_ID.getRoute(iouReport.reportID)); @@ -180,7 +181,18 @@ describe('actions/IOU/RejectMoneyRequest', () => { if (!transaction?.transactionID || !iouReport?.reportID) { throw new Error('Required transaction or report data is missing'); } - rejectMoneyRequest(transaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined, getCurrencyDecimalsLocal); + rejectMoneyRequest({ + transactionID: transaction.transactionID, + reportID: iouReport.reportID, + comment, + policy, + currentUserAccountIDParam: TEST_USER_ACCOUNT_ID, + currentUserLogin: TEST_USER_EMAIL, + betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, + formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, + }); await waitForBatchedUpdates(); // Then: Verify violation is added @@ -236,7 +248,18 @@ describe('actions/IOU/RejectMoneyRequest', () => { if (!transaction?.transactionID || !iouReport?.reportID) { throw new Error('Required transaction or report data is missing'); } - rejectMoneyRequest(transaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined, getCurrencyDecimalsLocal); + rejectMoneyRequest({ + transactionID: transaction.transactionID, + reportID: iouReport.reportID, + comment, + policy, + currentUserAccountIDParam: TEST_USER_ACCOUNT_ID, + currentUserLogin: TEST_USER_EMAIL, + betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, + formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, + }); await waitForBatchedUpdates(); // Then: createdIOUReportActionID shouldn't be undefined @@ -275,39 +298,41 @@ describe('actions/IOU/RejectMoneyRequest', () => { throw new Error('Required transaction or report data is missing'); } - rejectMoneyRequest( - transaction.transactionID, - iouReport.reportID, + rejectMoneyRequest({ + transactionID: transaction.transactionID, + reportID: iouReport.reportID, comment, policy, - TEST_USER_ACCOUNT_ID, - TEST_USER_EMAIL, - [CONST.BETAS.ALL], - undefined, - getCurrencyDecimalsLocal, - { + currentUserAccountIDParam: TEST_USER_ACCOUNT_ID, + currentUserLogin: TEST_USER_EMAIL, + betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, + formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, + options: { sharedRejectedToReportID, existingRejectedReport, setExistingRejectedReport, }, - ); + }); - rejectMoneyRequest( - secondTransaction.transactionID, - iouReport.reportID, + rejectMoneyRequest({ + transactionID: secondTransaction.transactionID, + reportID: iouReport.reportID, comment, policy, - TEST_USER_ACCOUNT_ID, - TEST_USER_EMAIL, - [CONST.BETAS.ALL], - undefined, - getCurrencyDecimalsLocal, - { + currentUserAccountIDParam: TEST_USER_ACCOUNT_ID, + currentUserLogin: TEST_USER_EMAIL, + betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, + formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, + options: { sharedRejectedToReportID, existingRejectedReport, setExistingRejectedReport, }, - ); + }); await waitForBatchedUpdates(); let allReports: OnyxCollection; diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index 3341f6221b2f..1cbfdff3f827 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -299,6 +299,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); } return waitForBatchedUpdates(); @@ -414,6 +415,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -537,6 +539,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -645,6 +648,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -754,6 +758,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1076,6 +1081,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); } return waitForBatchedUpdates(); @@ -1355,6 +1361,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); } return waitForBatchedUpdates(); @@ -1531,6 +1538,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); } return waitForBatchedUpdates(); @@ -1606,6 +1614,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1725,6 +1734,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1789,6 +1799,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); const [, parameters, onyxData] = getRequiredWriteCall(apiWriteSpy.mock.calls); @@ -1856,6 +1867,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); const [, parameters, onyxData] = getRequiredWriteCall(apiWriteSpy.mock.calls); @@ -1909,6 +1921,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, submitterLogin: submitterEmail, shouldExportToPDF: true, + formatPhoneNumber, }); const pdfNvpKey = `${ONYXKEYS.COLLECTION.NVP_EXPENSIFY_REPORT_PDF_FILENAME}${expenseReport.reportID}`; @@ -1964,6 +1977,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, submitterLogin: submitterEmail, + formatPhoneNumber, }); const pdfNvpKey = `${ONYXKEYS.COLLECTION.NVP_EXPENSIFY_REPORT_PDF_FILENAME}${expenseReport.reportID}`; @@ -2036,6 +2050,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); const [, parameters, onyxData] = getRequiredWriteCall(apiWriteSpy.mock.calls); @@ -2129,6 +2144,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, submitterLogin: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); const [, parameters, onyxData] = getRequiredWriteCall(apiWriteSpy.mock.calls); @@ -2222,6 +2238,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); const [, parameters, onyxData] = getRequiredWriteCall(apiWriteSpy.mock.calls); @@ -2298,6 +2315,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -2370,6 +2388,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); const [, parameters, onyxData] = getRequiredWriteCall(apiWriteSpy.mock.calls); @@ -2441,6 +2460,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); expect(apiWriteSpy).toHaveBeenCalledTimes(1); @@ -2506,6 +2526,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); expect(apiWriteSpy).toHaveBeenCalledTimes(1); @@ -2551,6 +2572,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); const [, , onyxData] = getRequiredWriteCall(apiWriteSpy.mock.calls); @@ -2858,6 +2880,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: DELEGATE_EMAIL, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure @@ -2897,6 +2920,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, }); // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure @@ -2988,6 +3012,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure @@ -3031,6 +3056,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure @@ -3085,6 +3111,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic/failure data structure @@ -3842,6 +3869,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, delegateAccountID: undefined, ownerLogin: undefined, + formatPhoneNumber, }); beforeEach(() => { @@ -4031,6 +4059,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -4085,6 +4114,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -4138,6 +4168,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -4266,6 +4297,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -4299,6 +4331,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -4330,6 +4363,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -4391,6 +4425,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -4452,6 +4487,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); return waitForBatchedUpdates(); }) @@ -4585,6 +4621,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/SendMoneyTest.ts b/tests/actions/IOUTest/SendMoneyTest.ts index c1fc34aea282..8dd7c59d8da6 100644 --- a/tests/actions/IOUTest/SendMoneyTest.ts +++ b/tests/actions/IOUTest/SendMoneyTest.ts @@ -11,7 +11,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import Onyx from 'react-native-onyx'; -import {getCurrencyDecimalsLocal, getGlobalFetchMock} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, getGlobalFetchMock, formatPhoneNumber} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; const topMostReportID = '23423423'; @@ -117,6 +117,7 @@ describe('actions/IOU/SendMoney', () => { recipient: {accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}, delegateAccountID: DELEGATE_ACCOUNT_ID, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/TrackExpenseTest.ts b/tests/actions/IOUTest/TrackExpenseTest.ts index bc859a6afd44..1d82e2171883 100644 --- a/tests/actions/IOUTest/TrackExpenseTest.ts +++ b/tests/actions/IOUTest/TrackExpenseTest.ts @@ -214,6 +214,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -341,6 +342,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); await mockFetch?.resume?.(); @@ -451,6 +453,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); await mockFetch?.resume?.(); @@ -546,6 +549,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -606,6 +610,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -692,6 +697,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -752,6 +758,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -842,6 +849,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -902,6 +910,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -989,6 +998,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1049,6 +1059,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1155,6 +1166,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1215,6 +1227,7 @@ describe('actions/IOU/TrackExpense', () => { isSelfTourViewed: false, currentUserLocalCurrency: undefined, delegateAccountID: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1280,6 +1293,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }; } @@ -1543,6 +1557,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -1635,6 +1650,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -2007,6 +2023,7 @@ describe('actions/IOU/TrackExpense', () => { isSelfTourViewed: true, currentUserLocalCurrency: undefined, delegateAccountID: undefined, + formatPhoneNumber, }); // Then the result should contain valid track expense data @@ -2056,6 +2073,7 @@ describe('actions/IOU/TrackExpense', () => { isSelfTourViewed: false, currentUserLocalCurrency: undefined, delegateAccountID: undefined, + formatPhoneNumber, }); // Then the result should contain valid track expense data @@ -2107,6 +2125,7 @@ describe('actions/IOU/TrackExpense', () => { isSelfTourViewed: true, currentUserLocalCurrency: undefined, delegateAccountID: undefined, + formatPhoneNumber, }); // Then result should be valid @@ -2149,6 +2168,7 @@ describe('actions/IOU/TrackExpense', () => { isSelfTourViewed: false, currentUserLocalCurrency: undefined, delegateAccountID: undefined, + formatPhoneNumber, }); expect(resultWithoutTourViewed).toBeDefined(); @@ -2219,6 +2239,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: 'USD', delegateAccountID: undefined, isDraftChatReport: true, + formatPhoneNumber, }); // Then createdWorkspaceParams should be defined because the report is a draft @@ -2268,6 +2289,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: 'USD', delegateAccountID: undefined, isDraftChatReport: false, + formatPhoneNumber, }); // Then createdWorkspaceParams should be undefined because the report is not a draft @@ -2357,6 +2379,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -2666,6 +2689,7 @@ describe('actions/IOU/TrackExpense', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index e3d7bb005efc..4c1166506758 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -26,6 +26,7 @@ import createRandomTransaction from '../utils/collections/transaction'; import createMock from '../utils/createMock'; import getOnyxValue from '../utils/getOnyxValue'; import * as TestHelper from '../utils/TestHelper'; +import {formatPhoneNumber} from '../utils/TestHelper'; import { getOptionalNumberProperty, isGuidedSetupTask, @@ -7417,6 +7418,7 @@ describe('actions/Policy', () => { reportActionsList: {}, doesEmployeePersonalDetailExist: false, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -7458,6 +7460,7 @@ describe('actions/Policy', () => { reportActionsList: {}, doesEmployeePersonalDetailExist: false, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber, }); expect(result).toBeUndefined(); }); @@ -7516,6 +7519,7 @@ describe('actions/Policy', () => { reportActionsList, doesEmployeePersonalDetailExist: true, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber, }); // Verify the function returns a valid result (not undefined) @@ -7570,6 +7574,7 @@ describe('actions/Policy', () => { reportActionsList: {}, doesEmployeePersonalDetailExist: false, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); @@ -7640,6 +7645,7 @@ describe('actions/Policy', () => { reportActionsList: {}, doesEmployeePersonalDetailExist: false, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber, }); await waitForBatchedUpdates(); diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 268535048459..08c02c546a4a 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -2791,7 +2791,18 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); mockFetchData.pause(); - const {reportID} = Report.createNewReport({accountID}, true, false, policy, [CONST.BETAS.ALL], false, TestHelper.getCurrencyDecimalsLocal); + const {reportID} = Report.createNewReport({ + ownerPersonalDetails: {accountID}, + hasViolationsParam: true, + isASAPSubmitBetaEnabled: false, + policy, + betas: [CONST.BETAS.ALL], + isTrackIntentUser: false, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + shouldNotifyNewAction: false, + formatPhoneNumber: TestHelper.formatPhoneNumber, + options: {}, + }); const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); const reportPreviewAction = await new Promise>>((resolve) => { @@ -2857,7 +2868,20 @@ describe('actions/Report', () => { type: CONST.POLICY.TYPE.TEAM, }; - Report.createNewReport({accountID: 1234}, true, false, policy, [CONST.BETAS.ALL], false, TestHelper.getCurrencyDecimalsLocal, false, undefined, {managedCardTransactionID}); + Report.createNewReport({ + ownerPersonalDetails: {accountID: 1234}, + hasViolationsParam: true, + isASAPSubmitBetaEnabled: false, + policy, + betas: [CONST.BETAS.ALL], + isTrackIntentUser: false, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + shouldNotifyNewAction: false, + formatPhoneNumber: TestHelper.formatPhoneNumber, + options: { + managedCardTransactionID, + }, + }); expect(apiWriteSpy).toHaveBeenCalledWith(WRITE_COMMANDS.CREATE_APP_REPORT, expect.objectContaining({managedCardTransactionID}), expect.anything()); }); @@ -2878,7 +2902,18 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); mockFetchData.pause(); - Report.createNewReport({accountID}, true, false, policy, [CONST.BETAS.ALL], false, TestHelper.getCurrencyDecimalsLocal); + Report.createNewReport({ + ownerPersonalDetails: {accountID}, + hasViolationsParam: true, + isASAPSubmitBetaEnabled: false, + policy, + betas: [CONST.BETAS.ALL], + isTrackIntentUser: false, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + shouldNotifyNewAction: false, + formatPhoneNumber: TestHelper.formatPhoneNumber, + options: {}, + }); const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); await new Promise((resolve) => { @@ -2916,7 +2951,18 @@ describe('actions/Report', () => { } // When create new report - Report.createNewReport({accountID}, true, false, policy, [CONST.BETAS.ALL], false, TestHelper.getCurrencyDecimalsLocal); + Report.createNewReport({ + ownerPersonalDetails: {accountID}, + hasViolationsParam: true, + isASAPSubmitBetaEnabled: false, + policy, + betas: [CONST.BETAS.ALL], + isTrackIntentUser: false, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + shouldNotifyNewAction: false, + formatPhoneNumber: TestHelper.formatPhoneNumber, + options: {}, + }); // Then the parent report's hasOutstandingChildRequest property should remain unchanged await new Promise((resolve) => { @@ -2951,7 +2997,18 @@ describe('actions/Report', () => { } // When create new report - const optimisticReportData = Report.createNewReport({accountID}, true, false, policy, [CONST.BETAS.ALL], false, TestHelper.getCurrencyDecimalsLocal); + const optimisticReportData = Report.createNewReport({ + ownerPersonalDetails: {accountID}, + hasViolationsParam: true, + isASAPSubmitBetaEnabled: false, + policy, + betas: [CONST.BETAS.ALL], + isTrackIntentUser: false, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + shouldNotifyNewAction: false, + formatPhoneNumber: TestHelper.formatPhoneNumber, + options: {}, + }); await waitForBatchedUpdates(); // Then the report's status should be draft. @@ -2993,7 +3050,18 @@ describe('actions/Report', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); - const {reportID} = Report.createNewReport({accountID}, true, false, policy, [CONST.BETAS.ALL], false, TestHelper.getCurrencyDecimalsLocal); + const {reportID} = Report.createNewReport({ + ownerPersonalDetails: {accountID}, + hasViolationsParam: true, + isASAPSubmitBetaEnabled: false, + policy, + betas: [CONST.BETAS.ALL], + isTrackIntentUser: false, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + shouldNotifyNewAction: false, + formatPhoneNumber: TestHelper.formatPhoneNumber, + options: {}, + }); const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); await waitForBatchedUpdates(); @@ -3652,6 +3720,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: targetPolicy, currentUserAccountID: 1, @@ -3688,6 +3757,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: newPolicy, currentUserAccountID: 1, @@ -3750,6 +3820,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport, policy: newPolicy, currentUserAccountID: 1, @@ -3822,6 +3893,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: newPolicy, currentUserAccountID: 1, @@ -3920,6 +3992,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: newPolicy, currentUserAccountID: 1, @@ -4006,6 +4079,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: newPolicy, currentUserAccountID: 1, @@ -4060,6 +4134,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4153,6 +4228,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: newPolicy, currentUser: {accountID: 1}, @@ -4199,6 +4275,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4231,6 +4308,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: targetPolicy, currentUser: {accountID: 1}, @@ -4262,6 +4340,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4293,6 +4372,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4326,6 +4406,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4380,6 +4461,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy: targetPolicy, currentUser: {accountID: 1, email: 'current-user@expensifail.com'}, @@ -4829,6 +4911,7 @@ describe('actions/Report', () => { Report.buildOptimisticChangePolicyData({ report, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy, currentUserAccountID: 1, @@ -4884,6 +4967,7 @@ describe('actions/Report', () => { const {optimisticData, successData, failureData} = Report.buildOptimisticChangePolicyData({ report, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy, currentUserAccountID: 1, @@ -4949,6 +5033,7 @@ describe('actions/Report', () => { const {optimisticData} = Report.buildOptimisticChangePolicyData({ report, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy, currentUserAccountID: 1, @@ -4998,6 +5083,7 @@ describe('actions/Report', () => { const {optimisticData} = Report.buildOptimisticChangePolicyData({ report, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy, currentUserAccountID: 1, @@ -5060,6 +5146,7 @@ describe('actions/Report', () => { const {optimisticData} = Report.buildOptimisticChangePolicyData({ report, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport: undefined, policy, currentUserAccountID: 1, @@ -5125,6 +5212,7 @@ describe('actions/Report', () => { const {optimisticData, failureData} = Report.buildOptimisticChangePolicyData({ report, getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, + formatPhoneNumber: TestHelper.formatPhoneNumber, parentReport, policy, currentUserAccountID: 1, @@ -9716,14 +9804,34 @@ describe('actions/Report', () => { it('sets delegateAccountID when delegateAccountIDParam is provided', () => { const chatReport = createMock({reportID: 'chat1'}); const iouReport = createMock({reportID: 'iou1', ownerAccountID: 1, managerID: 2}); - const result = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, TestHelper.getCurrencyDecimalsLocal, '', null, undefined, undefined, DELEGATE_ACCOUNT_ID); + const result = ReportUtils.buildOptimisticReportPreview( + chatReport, + iouReport, + TestHelper.formatPhoneNumber, + TestHelper.getCurrencyDecimalsLocal, + '', + null, + undefined, + undefined, + DELEGATE_ACCOUNT_ID, + ); expect(result.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('does not set delegateAccountID when delegateAccountIDParam is undefined', () => { const chatReport = createMock({reportID: 'chat2'}); const iouReport = createMock({reportID: 'iou2', ownerAccountID: 1, managerID: 2}); - const result = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, TestHelper.getCurrencyDecimalsLocal, '', null, undefined, undefined, undefined); + const result = ReportUtils.buildOptimisticReportPreview( + chatReport, + iouReport, + TestHelper.formatPhoneNumber, + TestHelper.getCurrencyDecimalsLocal, + '', + null, + undefined, + undefined, + undefined, + ); expect(result.delegateAccountID).toBeUndefined(); }); }); diff --git a/tests/actions/TransactionTest.ts b/tests/actions/TransactionTest.ts index 3a2343c5e92a..d25c08160ef2 100644 --- a/tests/actions/TransactionTest.ts +++ b/tests/actions/TransactionTest.ts @@ -215,7 +215,18 @@ describe('actions/Transaction', () => { await waitForBatchedUpdates(); - createNewReport(creatorPersonalDetails, true, false, mockPolicy, [CONST.BETAS.ALL], false, getCurrencyDecimalsLocal); + createNewReport({ + ownerPersonalDetails: creatorPersonalDetails, + hasViolationsParam: true, + isASAPSubmitBetaEnabled: false, + policy: mockPolicy, + betas: [CONST.BETAS.ALL], + isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, + shouldNotifyNewAction: false, + formatPhoneNumber, + options: {}, + }); // Create a tracked expense const selfDMReport: Report = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), @@ -256,6 +267,7 @@ describe('actions/Transaction', () => { delegateAccountID: undefined, reportActionsList: undefined, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); await getOnyxData({ key: ONYXKEYS.COLLECTION.TRANSACTION, diff --git a/tests/perf-test/ReportUtils.perf-test.ts b/tests/perf-test/ReportUtils.perf-test.ts index de3f7bb46056..5b8afdf4a4aa 100644 --- a/tests/perf-test/ReportUtils.perf-test.ts +++ b/tests/perf-test/ReportUtils.perf-test.ts @@ -158,6 +158,7 @@ describe('ReportUtils', () => { shouldConsiderScanningReceiptOrPendingRoute: shouldConsiderReceiptBeingScanned, isPreviewMessageForParentChatReport, policy, + formatPhoneNumber, }, getCurrencyDecimalsLocal, ), diff --git a/tests/ui/ReportActionComposeTest.tsx b/tests/ui/ReportActionComposeTest.tsx index 465424818175..0801df7de48c 100644 --- a/tests/ui/ReportActionComposeTest.tsx +++ b/tests/ui/ReportActionComposeTest.tsx @@ -40,6 +40,7 @@ jest.mock('@hooks/useLocalize', () => jest.fn(() => ({ translate: jest.fn((key: string) => key), numberFormat: jest.fn((num: number) => num.toString()), + formatPhoneNumber: jest.fn((phone: string) => phone), })), ); diff --git a/tests/ui/ReportActionMessageEditLayoutTest.tsx b/tests/ui/ReportActionMessageEditLayoutTest.tsx index 24d8f6bf536f..2804470a55be 100644 --- a/tests/ui/ReportActionMessageEditLayoutTest.tsx +++ b/tests/ui/ReportActionMessageEditLayoutTest.tsx @@ -75,6 +75,7 @@ jest.mock('@hooks/useLocalize', () => jest.fn(() => ({ translate: jest.fn((key: string) => key), numberFormat: jest.fn((num: number) => num.toString()), + formatPhoneNumber: jest.fn((phone: string) => phone), })), ); diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index b44d8a7871c6..be4569884d80 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -34,6 +34,7 @@ import {createRandomReport} from '../utils/collections/reports'; import createRandomTransaction from '../utils/collections/transaction'; import createMock from '../utils/createMock'; import PusherHelper from '../utils/PusherHelper'; +import {formatPhoneNumber} from '../utils/TestHelper'; import * as TestHelper from '../utils/TestHelper'; import {isObject} from '../utils/typeGuards'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -879,6 +880,7 @@ describe('Unread Indicators', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdates(); diff --git a/tests/unit/GoogleTagManagerTest.tsx b/tests/unit/GoogleTagManagerTest.tsx index 38d70c800e5d..1116c614eb9d 100644 --- a/tests/unit/GoogleTagManagerTest.tsx +++ b/tests/unit/GoogleTagManagerTest.tsx @@ -18,7 +18,7 @@ import {NavigationContainer} from '@react-navigation/native'; import Onyx from 'react-native-onyx'; import getOnyxValue from '../utils/getOnyxValue'; -import {getCurrencyDecimalsLocal} from '../utils/TestHelper'; +import {getCurrencyDecimalsLocal, formatPhoneNumber} from '../utils/TestHelper'; import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; jest.mock('@libs/GoogleTagManager'); @@ -300,6 +300,7 @@ describe('GoogleTagManagerTest', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + formatPhoneNumber, }); await waitForBatchedUpdatesWithAct(); diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index bc28373566ae..cfa648049dce 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -5830,6 +5830,7 @@ describe('OptionsListUtils', () => { policy: null, isForListPreview: true, originalReportAction: reportPreviewAction, + formatPhoneNumber, }, getCurrencyDecimalsLocal, ); diff --git a/tests/unit/PaymentUtilsTest.ts b/tests/unit/PaymentUtilsTest.ts index 99fc16b22a86..36c512fcee12 100644 --- a/tests/unit/PaymentUtilsTest.ts +++ b/tests/unit/PaymentUtilsTest.ts @@ -16,7 +16,7 @@ import type PaymentMethod from '@src/types/onyx/PaymentMethod'; import createMockPaymentMethod from '../utils/collections/paymentMethods'; import createRandomPolicy from '../utils/collections/policies'; import createMock from '../utils/createMock'; -import {getCurrencyDecimalsLocal} from '../utils/TestHelper'; +import {getCurrencyDecimalsLocal, formatPhoneNumber} from '../utils/TestHelper'; jest.mock('@libs/Navigation/Navigation', () => ({ navigate: jest.fn(), @@ -156,6 +156,7 @@ describe('PaymentUtils', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }; beforeEach(() => { @@ -260,6 +261,7 @@ describe('PaymentUtils', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); }); @@ -290,6 +292,7 @@ describe('PaymentUtils', () => { delegateAccountID: undefined, isTrackIntentUser: false, ownerLogin: undefined, + formatPhoneNumber, }); }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index a582e94676a6..ec1ec0a14dc4 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3463,13 +3463,13 @@ describe('ReportUtils', () => { }); it('should return the correct parent navigation subtitle for the archived invoice report', () => { - const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, undefined, true); + const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, formatPhoneNumber, undefined, true); const normalizedActual = {...actual, reportName: actual.reportName?.replaceAll('\u00A0', ' ')}; expect(normalizedActual).toEqual({reportName: 'A workspace & Ragnar Lothbrok (archived)'}); }); it('should return the correct parent navigation subtitle for the non archived invoice report', () => { - const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, undefined, false); + const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, formatPhoneNumber, undefined, false); const normalizedActual = {...actual, reportName: actual.reportName?.replaceAll('\u00A0', ' ')}; expect(normalizedActual).toEqual({reportName: 'A workspace & Ragnar Lothbrok'}); }); @@ -3488,7 +3488,7 @@ describe('ReportUtils', () => { role: CONST.POLICY.ROLE.ADMIN, }); - const actual = getParentNavigationSubtitle(expenseReport, testPolicy, undefined, translateLocal, undefined); + const actual = getParentNavigationSubtitle(expenseReport, testPolicy, undefined, translateLocal, formatPhoneNumber, undefined); expect(actual.workspaceName).toBe('Direct Policy Name'); }); @@ -3516,14 +3516,14 @@ describe('ReportUtils', () => { }; return Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}200`, parentInvoiceRoom).then(() => { - const actual = getParentNavigationSubtitle(invoiceReport, testPolicy, undefined, translateLocal, undefined); + const actual = getParentNavigationSubtitle(invoiceReport, testPolicy, undefined, translateLocal, formatPhoneNumber, undefined); const normalizedActual = {...actual, reportName: actual.reportName?.replaceAll('\u00A0', ' ')}; expect(normalizedActual.reportName).toContain('Invoice Policy'); }); }); it('should fall back to allPolicies when policy parameter is undefined', () => { - const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, undefined); + const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, formatPhoneNumber, undefined); const normalizedActual = {...actual, reportName: actual.reportName?.replaceAll('\u00A0', ' ')}; // Should still resolve via Onyx-connected allPolicies or report.policyName expect(normalizedActual.reportName).toContain('A workspace'); @@ -3536,7 +3536,7 @@ describe('ReportUtils', () => { reportName: 'Chat Report', type: CONST.REPORT.TYPE.CHAT, }; - const actual = getParentNavigationSubtitle(chatReport, undefined, undefined, translateLocal, undefined); + const actual = getParentNavigationSubtitle(chatReport, undefined, undefined, translateLocal, formatPhoneNumber, undefined); expect(actual).toEqual({}); }); @@ -3563,13 +3563,13 @@ describe('ReportUtils', () => { }) .then(waitForBatchedUpdates) .then(() => { - const actual = getParentNavigationSubtitle(childReport, undefined, conciergeReportID, translateLocal, 'Concierge'); + const actual = getParentNavigationSubtitle(childReport, undefined, conciergeReportID, translateLocal, formatPhoneNumber, 'Concierge'); expect(actual.reportName).toBe('Concierge'); }); }); it('should return reportName and workspaceName when parent report exists and conciergeReportID is undefined', () => { - const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, undefined); + const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, formatPhoneNumber, undefined); expect(actual).toHaveProperty('reportName'); }); @@ -3581,7 +3581,7 @@ describe('ReportUtils', () => { const expenseReport = {reportID: '780051', type: CONST.REPORT.TYPE.EXPENSE, ownerAccountID: hiddenOwnerAccountID}; const translateWithHiddenMarker: LocalizedTranslate = (path, ...parameters) => (path === 'common.hidden' ? 'HiddenMarker' : translateLocal(path, ...parameters)); - const actual = getParentNavigationSubtitle(expenseReport, undefined, undefined, translateWithHiddenMarker, undefined); + const actual = getParentNavigationSubtitle(expenseReport, undefined, undefined, translateWithHiddenMarker, formatPhoneNumber, undefined); expect(actual.reportName).toContain('HiddenMarker'); }); }); @@ -3645,7 +3645,7 @@ describe('ReportUtils', () => { originalMessage: {amount: 1000, currency: CONST.CURRENCY.USD}, }); - const result = getReimbursementDeQueuedOrCanceledActionMessage(translateWithHiddenMarker, reportAction, hiddenAccountID, convertToDisplayString); + const result = getReimbursementDeQueuedOrCanceledActionMessage(translateWithHiddenMarker, formatPhoneNumber, reportAction, hiddenAccountID, convertToDisplayString); expect(result).toContain('HiddenMarker'); }); @@ -3658,7 +3658,7 @@ describe('ReportUtils', () => { originalMessage: {amount: 1000, currency: CONST.CURRENCY.USD, cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN}, }); - const result = getReimbursementDeQueuedOrCanceledActionMessage(translateWithAdminMarker, reportAction, 780020, convertToDisplayString); + const result = getReimbursementDeQueuedOrCanceledActionMessage(translateWithAdminMarker, formatPhoneNumber, reportAction, 780020, convertToDisplayString); expect(result).toBe('AdminCanceledMarker'); }); }); @@ -5384,6 +5384,7 @@ describe('ReportUtils', () => { const reportPreview = buildOptimisticReportPreview( chatReport, expenseReport, + formatPhoneNumber, getCurrencyDecimalsLocal, '', expenseTransaction, @@ -13451,7 +13452,7 @@ describe('ReportUtils', () => { managerID: 2, }; - const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimalsLocal); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, formatPhoneNumber, getCurrencyDecimalsLocal); expect(reportPreviewAction.childOwnerAccountID).toBe(iouReport.ownerAccountID); expect(reportPreviewAction.childManagerAccountID).toBe(iouReport.managerID); @@ -13473,10 +13474,11 @@ describe('ReportUtils', () => { managerID: 2, }; - const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimalsLocal); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, formatPhoneNumber, getCurrencyDecimalsLocal); const updatedPreviewAction = updateReportPreview( iouReport, reportPreviewAction, + formatPhoneNumber, getCurrencyDecimalsLocal, false, '', @@ -17273,7 +17275,10 @@ describe('ReportUtils', () => { }; // When we call getReportPreviewReportActionMessage - const result = getReportPreviewReportActionMessage({reportOrID: report, iouReportAction: reportAction, originalReportAction: reportAction}, getCurrencyDecimalsLocal); + const result = getReportPreviewReportActionMessage( + {reportOrID: report, iouReportAction: reportAction, originalReportAction: reportAction, formatPhoneNumber}, + getCurrencyDecimalsLocal, + ); // Then it should return the childReportName instead of "payer owes $0" expect(result).toBe('Expense Report 2025-01-15'); @@ -17293,7 +17298,10 @@ describe('ReportUtils', () => { }; // When we call getReportPreviewReportActionMessage - const result = getReportPreviewReportActionMessage({reportOrID: report, iouReportAction: reportAction, originalReportAction: reportAction}, getCurrencyDecimalsLocal); + const result = getReportPreviewReportActionMessage( + {reportOrID: report, iouReportAction: reportAction, originalReportAction: reportAction, formatPhoneNumber}, + getCurrencyDecimalsLocal, + ); // Then it should return the message from the report action (not the childReportName) expect(result).toBe('payer owes $100'); @@ -17386,7 +17394,7 @@ describe('ReportUtils', () => { }; const result = getReportPreviewReportActionMessage( - {reportOrID: settledReport, iouReportAction: actionWithAccountNumber, originalReportAction: actionWithAccountNumber}, + {reportOrID: settledReport, iouReportAction: actionWithAccountNumber, originalReportAction: actionWithAccountNumber, formatPhoneNumber}, getCurrencyDecimalsLocal, ); @@ -17396,7 +17404,7 @@ describe('ReportUtils', () => { it('falls back to the policy default bank account when the action has no accountNumber', () => { const result = getReportPreviewReportActionMessage( - {reportOrID: settledReport, iouReportAction: payReportAction, originalReportAction: payReportAction}, + {reportOrID: settledReport, iouReportAction: payReportAction, originalReportAction: payReportAction, formatPhoneNumber}, getCurrencyDecimalsLocal, ); @@ -17405,10 +17413,12 @@ describe('ReportUtils', () => { it('matches the localized getReportPreviewMessage output when translated to English', () => { const englishTranslate: LocalizedTranslate = (path, ...parameters) => translate(CONST.LOCALES.EN, path, ...parameters); - const params = {reportOrID: settledReport, iouReportAction: payReportAction, originalReportAction: payReportAction}; + const params = {reportOrID: settledReport, iouReportAction: payReportAction, originalReportAction: payReportAction, formatPhoneNumber}; // The hardcoded English copy must not drift from the localized function - expect(getReportPreviewReportActionMessage(params, getCurrencyDecimalsLocal)).toBe(getReportPreviewMessage(englishTranslate, convertToDisplayString, params)); + expect(getReportPreviewReportActionMessage(params, getCurrencyDecimalsLocal)).toBe( + getReportPreviewMessage(englishTranslate, formatPhoneNumber, convertToDisplayString, params), + ); }); describe('cross-border payment', () => { @@ -17417,11 +17427,11 @@ describe('ReportUtils', () => { ...payReportAction, originalMessage: {...payOriginalMessage, creditedAmount: 1340, creditedCurrency: 'GBP', creditBankAccountLast4: '3335'}, }; - const crossBorderParams = {reportOrID: settledReport, iouReportAction: crossBorderAction, originalReportAction: crossBorderAction}; + const crossBorderParams = {reportOrID: settledReport, iouReportAction: crossBorderAction, originalReportAction: crossBorderAction, formatPhoneNumber}; it('names the credited amount, falling back to the policy default for the debited account', () => { // Given a converted payment that recorded the employee's account but not the account it was paid from - const result = getReportPreviewMessage(englishTranslate, convertToDisplayString, crossBorderParams); + const result = getReportPreviewMessage(englishTranslate, formatPhoneNumber, convertToDisplayString, crossBorderParams); // Then the debited account comes from the policy default, the same fallback the non-converted wording uses expect(result).toBe( @@ -17436,22 +17446,23 @@ describe('ReportUtils', () => { it('stores the same wording on the report action as the localized preview shows', () => { // The hardcoded English copy must not drift from the localized function expect(getReportPreviewReportActionMessage(crossBorderParams, getCurrencyDecimalsLocal)).toBe( - getReportPreviewMessage(englishTranslate, convertToDisplayString, crossBorderParams), + getReportPreviewMessage(englishTranslate, formatPhoneNumber, convertToDisplayString, crossBorderParams), ); }); it('still names the report total in the parent chat preview', () => { // Given the parent chat preview, which summarizes the report rather than describing the payment const params = {...crossBorderParams, isPreviewMessageForParentChatReport: true}; - const paymentWithoutConversion = getReportPreviewMessage(englishTranslate, convertToDisplayString, { + const paymentWithoutConversion = getReportPreviewMessage(englishTranslate, formatPhoneNumber, convertToDisplayString, { reportOrID: settledReport, iouReportAction: payReportAction, originalReportAction: payReportAction, isPreviewMessageForParentChatReport: true, + formatPhoneNumber, }); // Then the credited amount does not replace the report total, which is what the report is denominated in - expect(getReportPreviewMessage(englishTranslate, convertToDisplayString, params)).toBe(paymentWithoutConversion); + expect(getReportPreviewMessage(englishTranslate, formatPhoneNumber, convertToDisplayString, params)).toBe(paymentWithoutConversion); }); }); }); @@ -17471,14 +17482,16 @@ describe('ReportUtils', () => { }); it('uses the injected translate function (not translateLocal) so output follows the passed locale, while getReportPreviewReportActionMessage stays English', async () => { - const params = {reportOrID: expenseReport}; + const params = {reportOrID: expenseReport, formatPhoneNumber}; const englishTranslate: LocalizedTranslate = (path, ...parameters) => translate(CONST.LOCALES.EN, path, ...parameters); const spanishTranslate: LocalizedTranslate = (path, ...parameters) => translate(CONST.LOCALES.ES, path, ...parameters); await IntlStore.load(CONST.LOCALES.ES).then(waitForBatchedUpdates); // The localized preview differs between English and Spanish... - expect(getReportPreviewMessage(spanishTranslate, convertToDisplayString, params)).not.toBe(getReportPreviewMessage(englishTranslate, convertToDisplayString, params)); + expect(getReportPreviewMessage(spanishTranslate, formatPhoneNumber, convertToDisplayString, params)).not.toBe( + getReportPreviewMessage(englishTranslate, formatPhoneNumber, convertToDisplayString, params), + ); // ...but the report-action-message variant is always the English text, regardless of the loaded locale // TODO: Re-enable this assertion once getReportPreviewReportActionMessage is refactored @@ -17508,7 +17521,7 @@ describe('ReportUtils', () => { const translateWithMarker: LocalizedTranslate = (path, ...parameters) => path === 'common.hidden' ? 'HiddenParticipantMarker' : translate(CONST.LOCALES.EN, path, ...parameters); - const result = getReportPreviewMessage(translateWithMarker, convertToDisplayString, {reportOrID: iouReport}); + const result = getReportPreviewMessage(translateWithMarker, formatPhoneNumber, convertToDisplayString, {reportOrID: iouReport, formatPhoneNumber}); // The manager's name resolves to the marker, proving getDisplayNameForParticipant received the injected translate expect(result).toContain('HiddenParticipantMarker'); @@ -17528,10 +17541,10 @@ describe('ReportUtils', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); const englishTranslate: LocalizedTranslate = (path, ...parameters) => translate(CONST.LOCALES.EN, path, ...parameters); - const result = getReportPreviewReportActionMessage({reportOrID: report}, getCurrencyDecimalsLocal); + const result = getReportPreviewReportActionMessage({reportOrID: report, formatPhoneNumber}, getCurrencyDecimalsLocal); // The hardcoded English string must match the en.ts translation produced by the localized function - expect(result).toBe(getReportPreviewMessage(englishTranslate, convertToDisplayString, {reportOrID: report})); + expect(result).toBe(getReportPreviewMessage(englishTranslate, formatPhoneNumber, convertToDisplayString, {reportOrID: report, formatPhoneNumber})); expect(result).toContain('owes'); }); }); @@ -17577,7 +17590,7 @@ describe('ReportUtils', () => { const translateWithMarker: LocalizedTranslate = (path, ...parameters) => (path === 'common.hidden' ? 'HiddenPayeeMarker' : translate(CONST.LOCALES.EN, path, ...parameters)); // The nameless payee resolves to the marker, proving getDisplayNameForParticipant received the injected translate - expect(getPayeeName(report, translateWithMarker, currentUserAccountID)).toBe('HiddenPayeeMarker'); + expect(getPayeeName(report, translateWithMarker, formatPhoneNumber, currentUserAccountID)).toBe('HiddenPayeeMarker'); }); it('excludes the passed current user from the payee candidates', async () => { @@ -17597,10 +17610,10 @@ describe('ReportUtils', () => { }; // With the payer treated as the current user, the remaining participant is the payee - expect(getPayeeName(report, translateLocal, payerAccountID)).toBe('Payee'); + expect(getPayeeName(report, translateLocal, formatPhoneNumber, payerAccountID)).toBe('Payee'); // Swapping which account is the current user swaps the resolved payee - expect(getPayeeName(report, translateLocal, payeeAccountID)).toBe('Payer'); + expect(getPayeeName(report, translateLocal, formatPhoneNumber, payeeAccountID)).toBe('Payer'); }); it('returns undefined when the only participant is the passed current user', () => { @@ -17610,7 +17623,7 @@ describe('ReportUtils', () => { participants: buildParticipantsFromAccountIDs([currentUserAccountID]), }; - expect(getPayeeName(report, translateLocal, currentUserAccountID)).toBeUndefined(); + expect(getPayeeName(report, translateLocal, formatPhoneNumber, currentUserAccountID)).toBeUndefined(); }); }); @@ -21646,7 +21659,7 @@ describe('ReportUtils', () => { }; // REPORT_PREVIEW action that sits in the chat report and links to the expense report - const reportPreviewAction = buildOptimisticReportPreview(chatReport, expenseReport, getCurrencyDecimalsLocal, '', transaction); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, expenseReport, formatPhoneNumber, getCurrencyDecimalsLocal, '', transaction); beforeAll(async () => { await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID}); diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index 0376b64bd7fd..961b611c7bb7 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -17,7 +17,7 @@ import Onyx from 'react-native-onyx'; import createRandomPolicy from '../../utils/collections/policies'; import createMock from '../../utils/createMock'; -import {getCurrencyDecimalsLocal} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, formatPhoneNumber} from '../../utils/TestHelper'; jest.mock('@src/components/ConfirmedRoute.tsx'); jest.mock('@libs/deferModalPresentationAfterPopoverDismiss', () => ({ @@ -362,6 +362,7 @@ describe('handleActionButtonPress', () => { currentUserAccountID: 1206, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, allViolations: undefined, }); expect(goToItem).not.toHaveBeenCalled(); @@ -389,6 +390,7 @@ describe('handleActionButtonPress', () => { currentUserAccountID: 1206, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, allViolations: undefined, }); @@ -416,6 +418,7 @@ describe('handleActionButtonPress', () => { currentUserAccountID: 1206, delegateAccountID: undefined, isTrackIntentUser: false, + formatPhoneNumber, allViolations: undefined, }); expect(goToItem).toHaveBeenCalledTimes(0); @@ -452,6 +455,7 @@ describe('handleActionButtonPress', () => { allViolations, conciergeChat: undefined, getCurrencyDecimals: getCurrencyDecimalsLocal, + formatPhoneNumber, }); // Then: hasViolations is evaluated against the passed collection, proving the deprecated global getter is no longer used, diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index e337b1894ff5..08d1e432aafd 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -930,7 +930,7 @@ describe('SidebarUtils', () => { participantAccountIDs: [actorAccountID], }, }; - const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimalsLocal, '', transaction); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, formatPhoneNumber, getCurrencyDecimalsLocal, '', transaction); await act(async () => { await Onyx.set(ONYXKEYS.SESSION, {accountID: 55555}); @@ -4330,6 +4330,7 @@ describe('SidebarUtils', () => { policy: null, isForListPreview: true, originalReportAction: lastReportPreviewAction, + formatPhoneNumber, }, getCurrencyDecimalsLocal, ); @@ -4446,6 +4447,7 @@ describe('SidebarUtils', () => { policy: null, isForListPreview: true, originalReportAction: lastReportPreviewAction, + formatPhoneNumber, }, getCurrencyDecimalsLocal, ); diff --git a/tests/unit/useCreateNavigationSuggestionsTest.ts b/tests/unit/useCreateNavigationSuggestionsTest.ts index 204e012799a8..d824aab8180b 100644 --- a/tests/unit/useCreateNavigationSuggestionsTest.ts +++ b/tests/unit/useCreateNavigationSuggestionsTest.ts @@ -338,7 +338,24 @@ describe('useCreateNavigationSuggestions', () => { const onCreateReport = mockUseCreateReport.mock.calls.at(0)?.at(0)?.onCreateReport; act(() => onCreateReport?.(true)); - expect(createNewReport).toHaveBeenCalledWith(expect.anything(), false, true, submitPolicy, [], false, mockGetCurrencyDecimals, false, true); + expect(createNewReport).toHaveBeenCalledWith( + expect.objectContaining({ + ownerPersonalDetails: expect.objectContaining({ + accountID: 1, + login: 'test@example.com', + }), + hasViolationsParam: false, + isASAPSubmitBetaEnabled: true, + policy: submitPolicy, + betas: [], + isTrackIntentUser: false, + getCurrencyDecimals: mockGetCurrencyDecimals, + formatPhoneNumber: undefined, + shouldNotifyNewAction: false, + shouldDismissEmptyReportsConfirmation: true, + options: {}, + }), + ); expect(clearLastSearchParams).not.toHaveBeenCalled(); expect(Navigation.navigate).toHaveBeenNthCalledWith(1, 'reports', {forceReplace: false}); expect(Navigation.navigate).toHaveBeenNthCalledWith(2, 'report/created-report', {forceReplace: false});