diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 57505543b88e7..533db8c679e0b 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -762,7 +762,7 @@ function MoneyReportHeader({ const primaryAction = useMemo(() => { return getReportPrimaryAction({ - currentUserEmail: currentUserLogin ?? '', + currentUserLogin: currentUserLogin ?? '', currentUserAccountID: accountID, report: moneyRequestReport, chatReport, @@ -1073,7 +1073,7 @@ function MoneyReportHeader({ return []; } return getSecondaryReportActions({ - currentUserEmail: currentUserLogin ?? '', + currentUserLogin: currentUserLogin ?? '', currentUserAccountID: accountID, report: moneyRequestReport, chatReport, @@ -1517,9 +1517,9 @@ function MoneyReportHeader({ if (!hasFinishedPDFDownload || !canTriggerAutomaticPDFDownload.current) { return; } - downloadReportPDF(reportPDFFilename, moneyRequestReport?.reportName ?? '', translate); + downloadReportPDF(reportPDFFilename, moneyRequestReport?.reportName ?? '', translate, currentUserLogin ?? ''); canTriggerAutomaticPDFDownload.current = false; - }, [hasFinishedPDFDownload, reportPDFFilename, moneyRequestReport?.reportName, translate]); + }, [hasFinishedPDFDownload, reportPDFFilename, moneyRequestReport?.reportName, translate, currentUserLogin]); const shouldShowBackButton = shouldDisplayBackButton || shouldUseNarrowLayout; @@ -1828,7 +1828,7 @@ function MoneyReportHeader({ if (!hasFinishedPDFDownload) { setIsPDFModalVisible(false); } else { - downloadReportPDF(reportPDFFilename, moneyRequestReport?.reportName ?? '', translate); + downloadReportPDF(reportPDFFilename, moneyRequestReport?.reportName ?? '', translate, currentUserLogin ?? ''); } }} text={hasFinishedPDFDownload ? translate('common.download') : translate('common.cancel')} diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index dede65f847e7c..c2819921fd91c 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -527,7 +527,7 @@ function MoneyRequestReportPreviewContent({ return getReportPreviewAction({ isReportArchived: isIouReportArchived || isChatReportArchived, currentUserAccountID: currentUserDetails.accountID, - currentUserEmail: currentUserDetails.email ?? '', + currentUserLogin: currentUserDetails.login ?? '', report: iouReport, policy, transactions, @@ -544,7 +544,7 @@ function MoneyRequestReportPreviewContent({ isIouReportArchived, isChatReportArchived, currentUserDetails.accountID, - currentUserDetails.email, + currentUserDetails.login, iouReport, policy, transactions, diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index c3b3e386fead3..80c70136f9bea 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -321,7 +321,7 @@ function MoneyRequestView({ const companyCardPageURL = `${environmentURL}/${ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(transactionThreadReport?.policyID)}`; const [originalTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transaction?.comment?.originalTransactionID)}`, {canBeMissing: true}); const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction); - const isSplitAvailable = moneyRequestReport && transaction && isSplitAction(moneyRequestReport, [transaction], originalTransaction, policy); + const isSplitAvailable = moneyRequestReport && transaction && isSplitAction(moneyRequestReport, [transaction], originalTransaction, currentUserPersonalDetails.login ?? '', policy); const canEditTaxFields = canEdit && !isDistanceRequest; const canEditAmount = diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index afc59d1d637bf..ed7d2e29ecfe6 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -100,7 +100,6 @@ function mapTransactionItemToSelectedEntry( ): [string, SelectedTransactionInfo] { const {canHoldRequest, canUnholdRequest} = canHoldUnholdReportAction(item.report, item.reportAction, item.holdReportAction, item, item.policy); const canRejectRequest = item.report ? canRejectReportAction(currentUserLogin, item.report, item.policy) : false; - return [ item.keyForList, { @@ -109,7 +108,7 @@ function mapTransactionItemToSelectedEntry( canHold: canHoldRequest, isHeld: isOnHold(item), canUnhold: canUnholdRequest, - canSplit: isSplitAction(item.report, [itemTransaction], originalItemTransaction, item.policy), + canSplit: isSplitAction(item.report, [itemTransaction], originalItemTransaction, currentUserLogin, item.policy), hasBeenSplit: getOriginalTransactionWithSplitInfo(itemTransaction, originalItemTransaction).isExpenseSplit, canChangeReport: canEditFieldOfMoneyRequest( item.reportAction, @@ -161,7 +160,7 @@ function prepareTransactionsList( canHold: canHoldRequest, isHeld: isOnHold(item), canUnhold: canUnholdRequest, - canSplit: isSplitAction(item.report, [itemTransaction], originalItemTransaction, item.policy), + canSplit: isSplitAction(item.report, [itemTransaction], originalItemTransaction, currentUserLogin, item.policy), hasBeenSplit: getOriginalTransactionWithSplitInfo(itemTransaction, originalItemTransaction).isExpenseSplit, canChangeReport: canEditFieldOfMoneyRequest( item.reportAction, @@ -245,7 +244,7 @@ function Search({ const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: true}); const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID, {canBeMissing: true}); const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); - const {accountID, email} = useCurrentUserPersonalDetails(); + const {accountID, email, login} = useCurrentUserPersonalDetails(); const [isActionLoadingSet = new Set()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}`, {canBeMissing: true, selector: isActionLoadingSetSelector}); const [visibleColumns] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true, selector: columnsSelector}); const [customCardNames] = useOnyx(ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES, {canBeMissing: true}); @@ -520,7 +519,7 @@ function Search({ canHold: canHoldRequest, isHeld: isOnHold(transactionItem), canUnhold: canUnholdRequest, - canSplit: isSplitAction(transactionItem.report, [itemTransaction], originalItemTransaction, transactionItem.policy), + canSplit: isSplitAction(transactionItem.report, [itemTransaction], originalItemTransaction, login ?? '', transactionItem.policy), hasBeenSplit: getOriginalTransactionWithSplitInfo(itemTransaction, originalItemTransaction).isExpenseSplit, canChangeReport: canEditFieldOfMoneyRequest( transactionItem.reportAction, @@ -573,7 +572,7 @@ function Search({ canHold: canHoldRequest, isHeld: isOnHold(transactionItem), canUnhold: canUnholdRequest, - canSplit: isSplitAction(transactionItem.report, [itemTransaction], originalItemTransaction, transactionItem.policy), + canSplit: isSplitAction(transactionItem.report, [itemTransaction], originalItemTransaction, login ?? '', transactionItem.policy), hasBeenSplit: getOriginalTransactionWithSplitInfo(itemTransaction, originalItemTransaction).isExpenseSplit, canChangeReport: canEditFieldOfMoneyRequest( transactionItem.reportAction, diff --git a/src/hooks/useSelectedTransactionsActions.ts b/src/hooks/useSelectedTransactionsActions.ts index 73a0b6aa3b8bf..0291873e3e24a 100644 --- a/src/hooks/useSelectedTransactionsActions.ts +++ b/src/hooks/useSelectedTransactionsActions.ts @@ -27,6 +27,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Policy, Report, ReportAction, Session, Transaction} from '@src/types/onyx'; import useAllTransactions from './useAllTransactions'; +import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDeleteTransactions from './useDeleteTransactions'; import useDuplicateTransactionsAndViolations from './useDuplicateTransactionsAndViolations'; import {useMemoizedLazyExpensifyIcons} from './useLazyAsset'; @@ -77,6 +78,7 @@ function useSelectedTransactionsActions({ const {duplicateTransactions, duplicateTransactionViolations} = useDuplicateTransactionsAndViolations(selectedTransactionIDs); const isReportArchived = useReportIsArchived(report?.reportID); const {deleteTransactions} = useDeleteTransactions({report, reportActions, policy}); + const {login} = useCurrentUserPersonalDetails(); const selectedTransactionsList = useMemo( () => selectedTransactionIDs.reduce((acc, transactionID) => { @@ -330,7 +332,7 @@ function useSelectedTransactionsActions({ const originalTransaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${firstTransaction?.comment?.originalTransactionID}`]; const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(firstTransaction, originalTransaction); - const canSplitTransaction = selectedTransactionsList.length === 1 && report && !isExpenseSplit && isSplitAction(report, [firstTransaction], originalTransaction, policy); + const canSplitTransaction = selectedTransactionsList.length === 1 && report && !isExpenseSplit && isSplitAction(report, [firstTransaction], originalTransaction, login ?? '', policy); if (canSplitTransaction) { options.push({ @@ -400,6 +402,7 @@ function useSelectedTransactionsActions({ expensifyIcons.Trashcan, localeCompare, isOnSearch, + login, ]); return { diff --git a/src/hooks/useTodos.ts b/src/hooks/useTodos.ts index d710e653056e8..485bea8bbf2c5 100644 --- a/src/hooks/useTodos.ts +++ b/src/hooks/useTodos.ts @@ -13,7 +13,7 @@ export default function useTodos() { const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: false}); const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: false}); const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); - const {email = '', accountID} = useCurrentUserPersonalDetails(); + const {login = '', accountID} = useCurrentUserPersonalDetails(); return useMemo(() => { const reportsToSubmit: Report[] = []; @@ -51,14 +51,14 @@ export default function useTodos() { if (isApproveAction(report, reportTransactions, policy)) { reportsToApprove.push(report); } - if (isPrimaryPayAction(report, accountID, email, bankAccountList, policy, reportNameValuePair)) { + if (isPrimaryPayAction(report, accountID, login, bankAccountList, policy, reportNameValuePair)) { reportsToPay.push(report); } - if (isExportAction(report, policy, reportActions)) { + if (isExportAction(report, login, policy, reportActions)) { reportsToExport.push(report); } } return {reportsToSubmit, reportsToApprove, reportsToPay, reportsToExport}; - }, [allReports, allTransactions, allPolicies, allReportNameValuePairs, allReportActions, accountID, email, bankAccountList]); + }, [allReports, allTransactions, allPolicies, allReportNameValuePairs, allReportActions, accountID, login, bankAccountList]); } diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 361bb2a906f72..5ecae25ab27b8 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -34,7 +34,6 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {getBankAccountFromID} from './actions/BankAccounts'; import {hasSynchronizationErrorMessage, isConnectionUnverified} from './actions/connections'; import {shouldShowQBOReimbursableExportDestinationAccountError} from './actions/connections/QuickbooksOnline'; -import {getCurrentUserEmail} from './actions/Report'; import {getCategoryApproverRule} from './CategoryUtils'; import Navigation from './Navigation/Navigation'; import {isOffline as isOfflineNetworkStore} from './Network/NetworkStore'; @@ -1610,8 +1609,7 @@ const getDescriptionForPolicyDomainCard = (domainName: string): string => { return domainName; }; -function isPreferredExporter(policy: Policy) { - const user = getCurrentUserEmail(); +function isPreferredExporter(policy: Policy, currentUserLogin: string) { const exporters = [ policy.connections?.intacct?.config?.export?.exporter, policy.connections?.netsuite?.options?.config?.exporter, @@ -1620,7 +1618,7 @@ function isPreferredExporter(policy: Policy) { policy.connections?.xero?.config?.export?.exporter, ]; - return exporters.some((exporter) => exporter && exporter === user); + return exporters.some((exporter) => exporter && exporter === currentUserLogin); } /** diff --git a/src/libs/ReportPreviewActionUtils.ts b/src/libs/ReportPreviewActionUtils.ts index cef96ec750101..75bd7dd8e16f4 100644 --- a/src/libs/ReportPreviewActionUtils.ts +++ b/src/libs/ReportPreviewActionUtils.ts @@ -90,7 +90,7 @@ function canPay( report: Report, isReportArchived: boolean, currentUserAccountID: number, - currentUserEmail: string, + currentUserLogin: string, bankAccountList: OnyxEntry, policy?: Policy, invoiceReceiverPolicy?: Policy, @@ -99,7 +99,7 @@ function canPay( return false; } - const isReportPayer = isPayer(currentUserAccountID, currentUserEmail, report, bankAccountList, policy, false); + const isReportPayer = isPayer(currentUserAccountID, currentUserLogin, report, bankAccountList, policy, false); const isExpense = isExpenseReport(report); const isPaymentsEnabled = arePaymentsEnabled(policy); const isProcessing = isProcessingReport(report); @@ -143,9 +143,9 @@ function canPay( return invoiceReceiverPolicy?.role === CONST.POLICY.ROLE.ADMIN && reimbursableSpend > 0; } -function canExport(report: Report, policy?: Policy) { +function canExport(report: Report, currentUserLogin: string, policy?: Policy) { const isExpense = isExpenseReport(report); - const isExporter = policy ? isPreferredExporter(policy) : false; + const isExporter = policy ? isPreferredExporter(policy, currentUserLogin) : false; const isReimbursed = isSettled(report); const isClosed = isClosedReport(report); const isApproved = isReportApproved({report}); @@ -176,7 +176,7 @@ function canExport(report: Report, policy?: Policy) { function getReportPreviewAction({ isReportArchived, currentUserAccountID, - currentUserEmail, + currentUserLogin, report, policy, transactions, @@ -190,7 +190,7 @@ function getReportPreviewAction({ }: { isReportArchived: boolean; currentUserAccountID: number; - currentUserEmail: string; + currentUserLogin: string; report: Report | undefined; policy: Policy | undefined; transactions: Transaction[]; @@ -223,16 +223,16 @@ function getReportPreviewAction({ return CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW; } - if (canSubmit(report, isReportArchived, currentUserAccountID, currentUserEmail, violationsData, policy, transactions)) { + if (canSubmit(report, isReportArchived, currentUserAccountID, currentUserLogin, violationsData, policy, transactions)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT; } if (canApprove(report, currentUserAccountID, policy, transactions)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE; } - if (canPay(report, isReportArchived, currentUserAccountID, currentUserEmail, bankAccountList, policy, invoiceReceiverPolicy)) { + if (canPay(report, isReportArchived, currentUserAccountID, currentUserLogin, bankAccountList, policy, invoiceReceiverPolicy)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY; } - if (canExport(report, policy)) { + if (canExport(report, currentUserLogin, policy)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.EXPORT_TO_ACCOUNTING; } diff --git a/src/libs/ReportPrimaryActionUtils.ts b/src/libs/ReportPrimaryActionUtils.ts index 1d1d91356acf6..4722e735515d5 100644 --- a/src/libs/ReportPrimaryActionUtils.ts +++ b/src/libs/ReportPrimaryActionUtils.ts @@ -52,7 +52,7 @@ import { } from './TransactionUtils'; type GetReportPrimaryActionParams = { - currentUserEmail: string; + currentUserLogin: string; currentUserAccountID: number; report: Report | undefined; chatReport: OnyxEntry; @@ -159,7 +159,7 @@ function isApproveAction(report: Report, reportTransactions: Transaction[], poli function isPrimaryPayAction( report: Report, currentUserAccountID: number, - currentUserEmail: string, + currentUserLogin: string, bankAccountList: OnyxEntry, policy?: Policy, reportNameValuePairs?: ReportNameValuePairs, @@ -172,7 +172,7 @@ function isPrimaryPayAction( return false; } const isExpenseReport = isExpenseReportUtils(report); - const isReportPayer = isPayer(currentUserAccountID, currentUserEmail, report, bankAccountList, policy, false); + const isReportPayer = isPayer(currentUserAccountID, currentUserLogin, report, bankAccountList, policy, false); const arePaymentsEnabled = arePaymentsEnabledUtils(policy); const isReportApproved = isReportApprovedUtils({report}); const isReportClosed = isClosedReportUtils(report); @@ -215,7 +215,7 @@ function isPrimaryPayAction( return invoiceReceiverPolicy?.role === CONST.POLICY.ROLE.ADMIN && reimbursableSpend > 0; } -function isExportAction(report: Report, policy?: Policy, reportActions?: ReportAction[]) { +function isExportAction(report: Report, currentUserLogin: string, policy?: Policy, reportActions?: ReportAction[]) { if (!policy) { return false; } @@ -229,7 +229,7 @@ function isExportAction(report: Report, policy?: Policy, reportActions?: ReportA const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; - const isReportExporter = isPreferredExporter(policy); + const isReportExporter = isPreferredExporter(policy, currentUserLogin); if (!isReportExporter && !isAdmin) { return false; } @@ -401,7 +401,7 @@ function getAllExpensesToHoldIfApplicable(report: Report | undefined, reportActi function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf | '' { const { - currentUserEmail, + currentUserLogin, currentUserAccountID, report, reportTransactions, @@ -437,15 +437,15 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf, reportTransactions: Array>, originalTransaction: OnyxEntry, policy?: OnyxEntry): boolean { +function isSplitAction( + report: OnyxEntry, + reportTransactions: Array>, + originalTransaction: OnyxEntry, + currentUserLogin: string, + policy?: OnyxEntry, +): boolean { if (Number(reportTransactions?.length) !== 1 || !report) { return false; } @@ -129,8 +135,7 @@ function isSplitAction(report: OnyxEntry, reportTransactions: Array | ''; violations?: OnyxCollection; - currentUserEmail?: string; + currentUserLogin?: string; currentUserAccountID?: number; }): boolean { if (isArchivedReport(reportNameValuePairs) || isChatReportArchived) { @@ -189,8 +194,8 @@ function isSubmitAction({ return false; } - if (violations && currentUserEmail && currentUserAccountID !== undefined) { - if (reportTransactions.some((transaction) => hasSmartScanFailedViolation(transaction, violations, currentUserEmail, currentUserAccountID, report, policy))) { + if (violations && currentUserLogin && currentUserAccountID !== undefined) { + if (reportTransactions.some((transaction) => hasSmartScanFailedViolation(transaction, violations, currentUserLogin, currentUserAccountID, report, policy))) { return false; } } @@ -388,7 +393,7 @@ function isCancelPaymentAction( return isPaymentProcessing && !hasDailyNachaCutoffPassed; } -function isExportAction(currentAccountID: number, currentUserEmail: string, report: Report, bankAccountList: OnyxEntry, policy?: Policy): boolean { +function isExportAction(currentAccountID: number, currentUserLogin: string, report: Report, bankAccountList: OnyxEntry, policy?: Policy): boolean { if (!policy) { return false; } @@ -412,7 +417,7 @@ function isExportAction(currentAccountID: number, currentUserEmail: string, repo } const isReportApproved = isReportApprovedUtils({report}); - const isReportPayer = isPayerUtils(currentAccountID, currentUserEmail, report, bankAccountList, policy, false); + const isReportPayer = isPayerUtils(currentAccountID, currentUserLogin, report, bankAccountList, policy, false); const arePaymentsEnabled = arePaymentsEnabledUtils(policy); const isReportClosed = isClosedReportUtils(report); @@ -430,7 +435,7 @@ function isExportAction(currentAccountID: number, currentUserEmail: string, repo return isAdmin && isReportFinished && syncEnabled; } -function isMarkAsExportedAction(currentAccountID: number, currentUserEmail: string, report: Report, bankAccountList: OnyxEntry, policy?: Policy): boolean { +function isMarkAsExportedAction(currentAccountID: number, currentUserLogin: string, report: Report, bankAccountList: OnyxEntry, policy?: Policy): boolean { if (!policy) { return false; } @@ -453,7 +458,7 @@ function isMarkAsExportedAction(currentAccountID: number, currentUserEmail: stri return false; } - const isReportPayer = isPayerUtils(currentAccountID, currentUserEmail, report, bankAccountList, policy, false); + const isReportPayer = isPayerUtils(currentAccountID, currentUserLogin, report, bankAccountList, policy, false); const arePaymentsEnabled = arePaymentsEnabledUtils(policy); const isReportApproved = isReportApprovedUtils({report}); const isReportClosed = isClosedReportUtils(report); @@ -474,7 +479,7 @@ function isMarkAsExportedAction(currentAccountID: number, currentUserEmail: stri const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; - const isExporter = isPreferredExporter(policy); + const isExporter = isPreferredExporter(policy, currentUserLogin); return (isAdmin && syncEnabled) || (isExporter && !syncEnabled); } @@ -766,7 +771,7 @@ function isDuplicateAction(report: Report, reportTransactions: Transaction[]): b } function getSecondaryReportActions({ - currentUserEmail, + currentUserLogin, currentUserAccountID, report, chatReport, @@ -781,7 +786,7 @@ function getSecondaryReportActions({ policies, isChatReportArchived = false, }: { - currentUserEmail: string; + currentUserLogin: string; currentUserAccountID: number; report: Report; chatReport: OnyxEntry; @@ -804,7 +809,7 @@ function getSecondaryReportActions({ const didExportFail = !isExported && hasExportError; if ( - isPrimaryPayAction(report, currentUserAccountID, currentUserEmail, bankAccountList, policy, reportNameValuePairs, isChatReportArchived, undefined, reportActions, true) && + isPrimaryPayAction(report, currentUserAccountID, currentUserLogin, bankAccountList, policy, reportNameValuePairs, isChatReportArchived, undefined, reportActions, true) && (hasOnlyHeldExpenses(report?.reportID) || didExportFail) ) { options.push(CONST.REPORT.SECONDARY_ACTIONS.PAY); @@ -815,7 +820,7 @@ function getSecondaryReportActions({ } const primaryAction = getReportPrimaryAction({ - currentUserEmail, + currentUserLogin, currentUserAccountID, report, chatReport, @@ -840,22 +845,22 @@ function getSecondaryReportActions({ isChatReportArchived, primaryAction, violations, - currentUserEmail, + currentUserLogin, currentUserAccountID, }) ) { options.push(CONST.REPORT.SECONDARY_ACTIONS.SUBMIT); } - if (isApproveAction(currentUserEmail, report, reportTransactions, violations, policy)) { + if (isApproveAction(currentUserLogin, report, reportTransactions, violations, policy)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.APPROVE); } - if (isUnapproveAction(currentUserEmail, report, policy)) { + if (isUnapproveAction(currentUserLogin, report, policy)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE); } - if (isCancelPaymentAction(currentUserAccountID, currentUserEmail, report, reportTransactions, bankAccountList, policy)) { + if (isCancelPaymentAction(currentUserAccountID, currentUserLogin, report, reportTransactions, bankAccountList, policy)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.CANCEL_PAYMENT); } @@ -875,11 +880,11 @@ function getSecondaryReportActions({ options.push(CONST.REPORT.SECONDARY_ACTIONS.REMOVE_HOLD); } - if (canRejectReportAction(currentUserEmail, report, policy)) { + if (canRejectReportAction(currentUserLogin, report, policy)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.REJECT); } - if (isSplitAction(report, reportTransactions, originalTransaction, policy)) { + if (isSplitAction(report, reportTransactions, originalTransaction, currentUserLogin, policy)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.SPLIT); } @@ -919,18 +924,18 @@ function getSecondaryReportActions({ function getSecondaryExportReportActions( currentUserAccountID: number, - currentUserEmail: string, + currentUserLogin: string, report: Report, bankAccountList: OnyxEntry, policy?: Policy, exportTemplates: ExportTemplate[] = [], ): Array> { const options: Array> = []; - if (isExportAction(currentUserAccountID, currentUserEmail, report, bankAccountList, policy)) { + if (isExportAction(currentUserAccountID, currentUserLogin, report, bankAccountList, policy)) { options.push(CONST.REPORT.EXPORT_OPTIONS.EXPORT_TO_INTEGRATION); } - if (isMarkAsExportedAction(currentUserAccountID, currentUserEmail, report, bankAccountList, policy)) { + if (isMarkAsExportedAction(currentUserAccountID, currentUserLogin, report, bankAccountList, policy)) { options.push(CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED); } @@ -945,7 +950,7 @@ function getSecondaryExportReportActions( } function getSecondaryTransactionThreadActions( - currentUserEmail: string, + currentUserLogin: string, parentReport: Report, reportTransaction: Transaction, reportAction: ReportAction | undefined, @@ -963,11 +968,11 @@ function getSecondaryTransactionThreadActions( options.push(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REMOVE_HOLD); } - if (canRejectReportAction(currentUserEmail, parentReport, policy)) { + if (canRejectReportAction(currentUserLogin, parentReport, policy)) { options.push(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT); } - if (isSplitAction(parentReport, [reportTransaction], originalTransaction, policy)) { + if (isSplitAction(parentReport, [reportTransaction], originalTransaction, currentUserLogin, policy)) { options.push(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.SPLIT); } diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 6b720742e51fb..a2c174be043f9 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1415,7 +1415,7 @@ function getActions( allViolations: OnyxCollection, key: string, currentSearch: SearchKey, - currentUserEmail: string, + currentUserLogin: string, bankAccountList: OnyxEntry, reportActions: OnyxTypes.ReportAction[] = [], ): SearchTransactionAction[] { @@ -1437,7 +1437,7 @@ function getActions( } const policy = getPolicyFromKey(data, report); - const isExportAvailable = isExportAction(report, policy, reportActions) && !isTransaction; + const isExportAvailable = isExportAction(report, currentUserLogin, policy, reportActions) && !isTransaction; if (isSettled(report) && !isExportAvailable) { return [CONST.SEARCH.ACTION_TYPES.PAID]; @@ -1512,7 +1512,7 @@ function getActions( } // We check for isAllowedToApproveExpenseReport because if the policy has preventSelfApprovals enabled, we disable the Submit action and in that case we want to show the View action instead - if (canSubmitReport(report, policy, allReportTransactions, allViolations, isIOUReportArchived || isChatReportArchived, currentUserEmail) && isAllowedToApproveExpenseReport) { + if (canSubmitReport(report, policy, allReportTransactions, allViolations, isIOUReportArchived || isChatReportArchived, currentUserLogin) && isAllowedToApproveExpenseReport) { allActions.push(CONST.SEARCH.ACTION_TYPES.SUBMIT); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index e76a6c445a303..469cf74c80da3 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -276,8 +276,9 @@ type ReportError = { const addNewMessageWithText = new Set([WRITE_COMMANDS.ADD_COMMENT, WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT]); let conciergeReportID: string | undefined; -let currentUserAccountID = -1; -let currentUserEmail: string | undefined; +let deprecatedCurrentUserAccountID = -1; +/** @deprecated This value is deprecated and will be removed soon after migration. Use the email from useCurrentUserPersonalDetails hook instead. */ +let deprecatedCurrentUserLogin: string | undefined; Onyx.connect({ key: ONYXKEYS.SESSION, @@ -287,8 +288,9 @@ Onyx.connect({ conciergeReportID = undefined; return; } - currentUserEmail = value.email; - currentUserAccountID = value.accountID; + // eslint-disable-next-line @typescript-eslint/no-deprecated + deprecatedCurrentUserLogin = value.email; + deprecatedCurrentUserAccountID = value.accountID; }, }); @@ -427,7 +429,7 @@ function subscribeToReportTypingEvents(reportID: string) { } // Don't show the typing indicator if the user is typing on another platform - if (Number(accountIDOrLogin) === currentUserAccountID) { + if (Number(accountIDOrLogin) === deprecatedCurrentUserAccountID) { return; } @@ -476,7 +478,7 @@ function subscribeToReportLeavingEvents(reportID: string | undefined) { return; } - if (Number(accountIDOrLogin) !== currentUserAccountID) { + if (Number(accountIDOrLogin) !== deprecatedCurrentUserAccountID) { return; } @@ -533,7 +535,7 @@ function notifyNewAction(reportID: string | undefined, accountID: number | undef if (!actionSubscriber) { return; } - const isFromCurrentUser = accountID === currentUserAccountID; + const isFromCurrentUser = accountID === deprecatedCurrentUserAccountID; actionSubscriber.callback(isFromCurrentUser, reportAction); } @@ -590,14 +592,14 @@ function addActions(report: OnyxEntry, notifyReportID: string, ancestors lastVisibleActionCreated: lastAction?.created, lastMessageText: lastCommentText, lastMessageHtml: lastCommentText, - lastActorAccountID: currentUserAccountID, + lastActorAccountID: deprecatedCurrentUserAccountID, lastReadTime: currentTime, }; const shouldUpdateNotificationPreference = !isEmptyObject(report) && isHiddenForCurrentUser(report); if (shouldUpdateNotificationPreference) { optimisticReport.participants = { - [currentUserAccountID]: {notificationPreference: getDefaultNotificationPreferenceForReport(report)}, + [deprecatedCurrentUserAccountID]: {notificationPreference: getDefaultNotificationPreferenceForReport(report)}, }; } @@ -701,13 +703,13 @@ function addActions(report: OnyxEntry, notifyReportID: string, ancestors ]; // Update the timezone if it's been 5 minutes from the last time the user added a comment - if (DateUtils.canUpdateTimezone() && currentUserAccountID) { + if (DateUtils.canUpdateTimezone() && deprecatedCurrentUserAccountID) { const timezone = DateUtils.getCurrentTimezone(timezoneParam); parameters.timezone = JSON.stringify(timezone); optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: {[currentUserAccountID]: {timezone}}, + value: {[deprecatedCurrentUserAccountID]: {timezone}}, }); DateUtils.setTimezoneUpdated(); } @@ -903,7 +905,7 @@ function updatePolicyRoomAvatar(reportID: string, file?: File | CustomRNImageMan onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { - lastActorAccountID: currentUserAccountID, + lastActorAccountID: deprecatedCurrentUserAccountID, lastVisibleActionCreated: optimisticAction.created, lastMessageText: (optimisticAction.message as Message[]).at(0)?.text, }, @@ -1083,8 +1085,9 @@ function openReport( // Use optimisticSelfDMReport if provided (when selfDM exists but wasn't in allReports) const parentReport = transactionParentReportID === optimisticSelfDMReport?.reportID ? optimisticSelfDMReport : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionParentReportID}`]; - const submitterAccountID = parentReport?.ownerAccountID ?? currentUserAccountID; - const submitterEmail = PersonalDetailsUtils.getLoginsByAccountIDs([submitterAccountID]).at(0) ?? currentUserEmail ?? ''; + const submitterAccountID = parentReport?.ownerAccountID ?? deprecatedCurrentUserAccountID; + // eslint-disable-next-line @typescript-eslint/no-deprecated + const submitterEmail = PersonalDetailsUtils.getLoginsByAccountIDs([submitterAccountID]).at(0) ?? deprecatedCurrentUserLogin ?? ''; const submitterPersonalDetails = PersonalDetailsUtils.getPersonalDetailByEmail(submitterEmail); const optimisticIOUAction = buildOptimisticIOUReportAction({ @@ -1211,7 +1214,8 @@ function openReport( const isGroupChat = isGroupChatReportUtils(newReportObject); if (isGroupChat) { parameters.chatType = CONST.REPORT.CHAT_TYPE.GROUP; - parameters.groupChatAdminLogins = currentUserEmail; + // eslint-disable-next-line @typescript-eslint/no-deprecated + parameters.groupChatAdminLogins = deprecatedCurrentUserLogin; parameters.optimisticAccountIDList = Object.keys(newReportObject?.participants ?? {}).join(','); parameters.reportName = newReportObject?.reportName ?? ''; @@ -1406,7 +1410,7 @@ function prepareOnyxDataForCleanUpOptimisticParticipants( */ function getOptimisticChatReport(accountID: number): OptimisticChatReport { return buildOptimisticChatReport({ - participantList: [accountID, currentUserAccountID], + participantList: [accountID, deprecatedCurrentUserAccountID], notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, }); } @@ -1453,7 +1457,8 @@ function createTransactionThreadReport( openReport( optimisticTransactionThreadReportID, undefined, - currentUserEmail ? [currentUserEmail] : [], + // eslint-disable-next-line @typescript-eslint/no-deprecated + deprecatedCurrentUserLogin ? [deprecatedCurrentUserLogin] : [], optimisticTransactionThread, iouReportAction?.reportActionID, false, @@ -1490,16 +1495,16 @@ function navigateToAndOpenReport( // If we are not creating a new Group Chat then we are creating a 1:1 DM and will look for an existing chat if (!isGroupChat) { - chat = getChatByParticipants([...participantAccountIDs, currentUserAccountID]); + chat = getChatByParticipants([...participantAccountIDs, deprecatedCurrentUserAccountID]); } if (isEmptyObject(chat)) { if (isGroupChat) { - // If we are creating a group chat then participantAccountIDs is expected to contain currentUserAccountID + // If we are creating a group chat then participantAccountIDs is expected to contain deprecatedCurrentUserAccountID newChat = buildOptimisticGroupChatReport(participantAccountIDs, reportName ?? '', avatarUri ?? '', optimisticReportID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); } else { newChat = buildOptimisticChatReport({ - participantList: [...participantAccountIDs, currentUserAccountID], + participantList: [...participantAccountIDs, deprecatedCurrentUserAccountID], notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, }); } @@ -1534,10 +1539,10 @@ function navigateToAndOpenReport( */ function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[]) { let newChat: OptimisticChatReport | undefined; - const chat = getChatByParticipants([...participantAccountIDs, currentUserAccountID]); + const chat = getChatByParticipants([...participantAccountIDs, deprecatedCurrentUserAccountID]); if (!chat) { newChat = buildOptimisticChatReport({ - participantList: [...participantAccountIDs, currentUserAccountID], + participantList: [...participantAccountIDs, deprecatedCurrentUserAccountID], }); // We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server openReport(newChat?.reportID, '', [], newChat, '0', false, participantAccountIDs); @@ -1559,7 +1564,7 @@ function navigateToAndOpenChildReport(childReportID: string | undefined, parentR if (childReport?.reportID) { Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(childReportID, undefined, undefined, Navigation.getActiveRoute())); } else { - const participantAccountIDs = [...new Set([currentUserAccountID, Number(parentReportAction.actorAccountID)])]; + const participantAccountIDs = [...new Set([deprecatedCurrentUserAccountID, Number(parentReportAction.actorAccountID)])]; const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`]; // Threads from DMs and selfDMs don't have a chatType. All other threads inherit the chatType from their parent const childReportChatType = parentReport && isSelfDM(parentReport) ? undefined : parentReport?.chatType; @@ -1831,7 +1836,7 @@ function markCommentAsUnread(reportID: string | undefined, reportAction: ReportA const latestReportActionFromOtherUsers = Object.values(reportActions ?? {}).reduce((latest: ReportAction | null, current: ReportAction) => { if ( !ReportActionsUtils.isDeletedAction(current) && - current.actorAccountID !== currentUserAccountID && + current.actorAccountID !== deprecatedCurrentUserAccountID && (!latest || current.created > latest.created) && // Whisper action doesn't affect lastVisibleActionCreated, so skip whisper action except actionable mention whisper (!ReportActionsUtils.isWhisperAction(current) || current.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER) @@ -1919,7 +1924,7 @@ function saveReportDraftComment(reportID: string, comment: string | null, callba function broadcastUserIsTyping(reportID: string) { const privateReportChannelName = getReportChannelName(reportID); const typingStatus: UserIsTypingEvent = { - [currentUserAccountID]: true, + [deprecatedCurrentUserAccountID]: true, }; Pusher.sendEvent(privateReportChannelName, Pusher.TYPE.USER_IS_TYPING, typingStatus); } @@ -1928,7 +1933,7 @@ function broadcastUserIsTyping(reportID: string) { function broadcastUserIsLeavingRoom(reportID: string) { const privateReportChannelName = getReportChannelName(reportID); const leavingStatus: UserIsLeavingRoomEvent = { - [currentUserAccountID]: true, + [deprecatedCurrentUserAccountID]: true, }; Pusher.sendEvent(privateReportChannelName, Pusher.TYPE.USER_IS_LEAVING_ROOM, leavingStatus); } @@ -2176,12 +2181,12 @@ function removeLinksFromHtml(html: string, links: string[]): string { * @param originalCommentMarkdown original markdown of the comment before editing. * @param videoAttributeCache cache of video attributes ([videoSource]: videoAttributes) */ -function handleUserDeletedLinksInHtml(newCommentText: string, originalCommentMarkdown: string, videoAttributeCache?: Record): string { +function handleUserDeletedLinksInHtml(newCommentText: string, originalCommentMarkdown: string, currentUserLogin: string, videoAttributeCache?: Record): string { if (newCommentText.length > CONST.MAX_MARKUP_LENGTH) { return newCommentText; } - const userEmailDomain = isEmailPublicDomain(currentUserEmail ?? '') ? '' : Str.extractEmailDomain(currentUserEmail ?? ''); + const userEmailDomain = isEmailPublicDomain(currentUserLogin) ? '' : Str.extractEmailDomain(currentUserLogin); const allPersonalDetailLogins = Object.values(allPersonalDetails ?? {}).map((personalDetail) => personalDetail?.login ?? ''); const htmlForNewComment = getParsedMessageWithShortMentions({ @@ -2205,7 +2210,7 @@ function editReportComment( textForNewComment: string, isOriginalReportArchived: boolean | undefined, isOriginalParentReportArchived: boolean | undefined, - currentEmail: string, + currentUserLogin: string, videoAttributeCache?: Record, ) { const originalReportID = originalReport?.reportID; @@ -2225,7 +2230,7 @@ function editReportComment( if (originalCommentMarkdown === textForNewComment) { return; } - const htmlForNewComment = handleUserDeletedLinksInHtml(textForNewComment, originalCommentMarkdown, videoAttributeCache); + const htmlForNewComment = handleUserDeletedLinksInHtml(textForNewComment, originalCommentMarkdown, currentUserLogin, videoAttributeCache); const reportComment = Parser.htmlToText(htmlForNewComment); @@ -2239,7 +2244,7 @@ function editReportComment( // Delete the comment if it's empty if (!htmlForNewComment) { - deleteReportComment(originalReportID, originalReportAction, ancestors, isOriginalReportArchived, isOriginalParentReportArchived, currentEmail); + deleteReportComment(originalReportID, originalReportAction, ancestors, isOriginalReportArchived, isOriginalParentReportArchived, currentUserLogin); return; } @@ -2365,7 +2370,7 @@ function updateNotificationPreference( key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { participants: { - [currentUserAccountID]: { + [deprecatedCurrentUserAccountID]: { notificationPreference: newValue, }, }, @@ -2379,7 +2384,7 @@ function updateNotificationPreference( key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { participants: { - [currentUserAccountID]: { + [deprecatedCurrentUserAccountID]: { notificationPreference: previousValue, }, }, @@ -2454,7 +2459,7 @@ function toggleSubscribeToChildReport( updateNotificationPreference(childReportID, prevNotificationPreference, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, parentReportID, parentReportActionID); } } else { - const participantAccountIDs = [...new Set([currentUserAccountID, Number(parentReportAction?.actorAccountID)])]; + const participantAccountIDs = [...new Set([deprecatedCurrentUserAccountID, Number(parentReportAction?.actorAccountID)])]; const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`]; const newChat = buildOptimisticChatReport({ participantList: participantAccountIDs, @@ -2789,7 +2794,7 @@ function updateDescription(reportID: string, currentDescription: string, newMark value: { description: parsedDescription, pendingFields: {description: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, - lastActorAccountID: currentUserAccountID, + lastActorAccountID: deprecatedCurrentUserAccountID, lastVisibleActionCreated: optimisticDescriptionUpdatedReportAction.created, lastMessageText: (optimisticDescriptionUpdatedReportAction?.message as Message[])?.at(0)?.text, }, @@ -3468,7 +3473,7 @@ function shouldShowReportActionNotification(reportID: string, action: ReportActi } // If this comment is from the current user we don't want to parrot whatever they wrote back to them. - if (action && action.actorAccountID === currentUserAccountID) { + if (action && action.actorAccountID === deprecatedCurrentUserAccountID) { Log.info(`${tag} No notification because comment is from the currently logged in user`); return false; } @@ -3556,7 +3561,7 @@ function addEmojiReaction(reportID: string, reportActionID: string, emoji: Emoji createdAt, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, users: { - [currentUserAccountID]: { + [deprecatedCurrentUserAccountID]: { skinTones: { [skinTone]: createdAt, }, @@ -3614,7 +3619,7 @@ function removeEmojiReaction(reportID: string, reportActionID: string, emoji: Em value: { [emoji.name]: { users: { - [currentUserAccountID]: null, + [deprecatedCurrentUserAccountID]: null, }, }, }, @@ -3662,7 +3667,7 @@ function toggleEmojiReaction( // Only use skin tone if emoji supports it const skinTone = emoji.types === undefined ? CONST.EMOJI_DEFAULT_SKIN_TONE : paramSkinTone; - if (existingReactionObject && EmojiUtils.hasAccountIDEmojiReacted(currentUserAccountID, existingReactionObject.users, ignoreSkinToneOnCompare ? undefined : skinTone)) { + if (existingReactionObject && EmojiUtils.hasAccountIDEmojiReacted(deprecatedCurrentUserAccountID, existingReactionObject.users, ignoreSkinToneOnCompare ? undefined : skinTone)) { removeEmojiReaction(originalReportID, reportAction.reportActionID, emoji); return; } @@ -3675,11 +3680,7 @@ function doneCheckingPublicRoom() { } function getCurrentUserAccountID(): number { - return currentUserAccountID; -} - -function getCurrentUserEmail(): string | undefined { - return currentUserEmail; + return deprecatedCurrentUserAccountID; } function navigateToMostRecentReport(currentReport: OnyxEntry) { @@ -3736,7 +3737,7 @@ function leaveGroupChat(reportID: string, shouldClearQuickAction: boolean) { stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, participants: { - [currentUserAccountID]: { + [deprecatedCurrentUserAccountID]: { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, }, }, @@ -3799,7 +3800,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal isWorkspaceMemberLeavingWorkspaceRoom || isChatThread ? { participants: { - [currentUserAccountID]: { + [deprecatedCurrentUserAccountID]: { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, }, }, @@ -3809,7 +3810,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, participants: { - [currentUserAccountID]: { + [deprecatedCurrentUserAccountID]: { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, }, }, @@ -3824,7 +3825,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { participants: { - [currentUserAccountID]: { + [deprecatedCurrentUserAccountID]: { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, }, }, @@ -3864,7 +3865,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, value: { [report.parentReportActionID]: { - childReportNotificationPreference: report?.participants?.[currentUserAccountID]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report), + childReportNotificationPreference: report?.participants?.[deprecatedCurrentUserAccountID]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report), }, }, }); @@ -4946,12 +4947,12 @@ function exportReportToPDF({reportID}: ExportReportPDFParams) { API.write(WRITE_COMMANDS.EXPORT_REPORT_TO_PDF, params, {optimisticData, failureData}); } -function downloadReportPDF(fileName: string, reportName: string, translate: LocalizedTranslate) { +function downloadReportPDF(fileName: string, reportName: string, translate: LocalizedTranslate, currentUserLogin: string) { const baseURL = addTrailingForwardSlash(getOldDotURLFromEnvironment(environment)); const downloadFileName = `${reportName}.pdf`; setDownload(fileName, true); const pdfURL = `${baseURL}secure?secureType=pdfreport&filename=${encodeURIComponent(fileName)}&downloadName=${encodeURIComponent(downloadFileName)}&email=${encodeURIComponent( - currentUserEmail ?? '', + currentUserLogin, )}`; fileDownload(translate, addEncryptedAuthTokenToURL(pdfURL, true), downloadFileName, '', Browser.isMobileSafari()).then(() => setDownload(fileName, false)); } @@ -5900,7 +5901,7 @@ function buildOptimisticChangePolicyData( if (newStatusNum === CONST.REPORT.STATUS_NUM.OPEN) { shouldSetOutstandingChildRequest = isCurrentUserSubmitter(report); } else if (isProcessingReport(report)) { - shouldSetOutstandingChildRequest = report.managerID === currentUserAccountID; + shouldSetOutstandingChildRequest = report.managerID === deprecatedCurrentUserAccountID; } } @@ -6455,7 +6456,6 @@ export { exportToIntegration, flagComment, getCurrentUserAccountID, - getCurrentUserEmail, getMostRecentReportID, getNewerActions, getOlderActions, diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx index e8fdc82312168..5d56e89db59ce 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx @@ -12,6 +12,7 @@ import type {AnimatedTextInputRef} from '@components/RNTextInput'; import ScreenWrapper from '@components/ScreenWrapper'; import Text from '@components/Text'; import TextInput from '@components/TextInput'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -51,6 +52,7 @@ function PrivateNotesEditPageInternal({route, report, accountID, privateNoteDraf const styles = useThemeStyles(); const {translate} = useLocalize(); const personalDetailsList = usePersonalDetails(); + const {login} = useCurrentUserPersonalDetails(); // We need to edit the note in markdown format, but display it in HTML format const [privateNote, setPrivateNote] = useState(() => privateNoteDraft || Parser.htmlToMarkdown(report?.privateNotes?.[Number(route.params.accountID)]?.note ?? '').trim()); @@ -91,7 +93,7 @@ function PrivateNotesEditPageInternal({route, report, accountID, privateNoteDraf const originalNote = report?.privateNotes?.[Number(route.params.accountID)]?.note ?? ''; let editedNote = ''; if (privateNote.trim() !== originalNote.trim()) { - editedNote = handleUserDeletedLinksInHtml(privateNote.trim(), Parser.htmlToMarkdown(originalNote).trim()); + editedNote = handleUserDeletedLinksInHtml(privateNote.trim(), Parser.htmlToMarkdown(originalNote).trim(), login ?? '', undefined); updatePrivateNotes(report.reportID, Number(route.params.accountID), editedNote); } diff --git a/src/pages/iou/SplitExpenseCreateDateRagePage.tsx b/src/pages/iou/SplitExpenseCreateDateRagePage.tsx index 7cb001e41d9ab..8697340f705f2 100644 --- a/src/pages/iou/SplitExpenseCreateDateRagePage.tsx +++ b/src/pages/iou/SplitExpenseCreateDateRagePage.tsx @@ -9,6 +9,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import {useSearchContext} from '@components/Search/SearchContext'; import useAllTransactions from '@hooks/useAllTransactions'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import usePolicy from '@hooks/usePolicy'; @@ -51,13 +52,14 @@ function SplitExpenseCreateDateRagePage({route}: SplitExpenseCreateDateRagePageP const currentPolicy = Object.keys(policy?.employeeList ?? {}).length ? policy : currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(currentReport?.policyID)}`]; + const {login} = useCurrentUserPersonalDetails(); const updateDate = (value: FormOnyxValues) => { resetSplitExpensesByDateRange(transaction, value[INPUT_IDS.START_DATE], value[INPUT_IDS.END_DATE]); Navigation.goBack(backTo); }; - const isSplitAvailable = report && transaction && isSplitAction(currentReport, [transaction], originalTransaction, currentPolicy); + const isSplitAvailable = report && transaction && isSplitAction(currentReport, [transaction], originalTransaction, login ?? '', currentPolicy); const validate = (values: FormOnyxValues) => { const errors: FormInputErrors = {}; diff --git a/src/pages/iou/SplitExpenseEditPage.tsx b/src/pages/iou/SplitExpenseEditPage.tsx index 5aadc2d486980..aa9ecb5e02a81 100644 --- a/src/pages/iou/SplitExpenseEditPage.tsx +++ b/src/pages/iou/SplitExpenseEditPage.tsx @@ -9,6 +9,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import {useSearchContext} from '@components/Search/SearchContext'; import useAllTransactions from '@hooks/useAllTransactions'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import usePolicy from '@hooks/usePolicy'; @@ -71,6 +72,7 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) { const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${currentReport?.policyID}`, {canBeMissing: false}); const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${currentReport?.policyID}`, {canBeMissing: false}); + const {login} = useCurrentUserPersonalDetails(); const fetchData = useCallback(() => { if (!policyCategories) { @@ -103,7 +105,7 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) { const transactionTag = getTag(splitExpenseDraftTransaction); const policyTagLists = useMemo(() => getTagLists(policyTags), [policyTags]); - const isSplitAvailable = report && transaction && isSplitAction(currentReport, [transaction], originalTransaction, currentPolicy); + const isSplitAvailable = report && transaction && isSplitAction(currentReport, [transaction], originalTransaction, login ?? '', currentPolicy); const isCategoryRequired = !!currentPolicy?.requiresCategory; const reportName = computeReportName(currentReport); diff --git a/src/pages/iou/SplitExpensePage.tsx b/src/pages/iou/SplitExpensePage.tsx index f32896f5011f2..89752db14a385 100644 --- a/src/pages/iou/SplitExpensePage.tsx +++ b/src/pages/iou/SplitExpensePage.tsx @@ -81,6 +81,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) { const searchHash = searchContext?.currentSearchHash ?? CONST.DEFAULT_NUMBER_ID; const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${searchHash}`, {canBeMissing: true}); const allTransactions = useAllTransactions(); + const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`]; const originalTransaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transaction?.comment?.originalTransactionID)}`]; @@ -97,7 +98,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) { ? policy : currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(currentReport?.policyID)}`]; - const isSplitAvailable = report && transaction && isSplitAction(currentReport, [transaction], originalTransaction, currentPolicy); + const isSplitAvailable = report && transaction && isSplitAction(currentReport, [transaction], originalTransaction, currentUserPersonalDetails.login ?? '', currentPolicy); const transactionDetails = useMemo>(() => getTransactionDetails(transaction) ?? {}, [transaction]); const transactionDetailsAmount = transactionDetails?.amount ?? 0; @@ -117,7 +118,6 @@ function SplitExpensePage({route}: SplitExpensePageProps) { const childTransactions = useMemo(() => getChildTransactions(allTransactions, allReports, transactionID), [allReports, allTransactions, transactionID]); const splitFieldDataFromChildTransactions = useMemo(() => childTransactions.map((currentTransaction) => initSplitExpenseItemData(currentTransaction)), [childTransactions]); const splitFieldDataFromOriginalTransaction = useMemo(() => initSplitExpenseItemData(transaction), [transaction]); - const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true}); const icons = useMemoizedLazyExpensifyIcons(['ArrowsLeftRight', 'Plus'] as const); diff --git a/tests/actions/ReportPreviewActionUtilsTest.ts b/tests/actions/ReportPreviewActionUtilsTest.ts index f98ee426c669f..67692adf734d4 100644 --- a/tests/actions/ReportPreviewActionUtilsTest.ts +++ b/tests/actions/ReportPreviewActionUtilsTest.ts @@ -76,7 +76,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: false, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [], @@ -115,7 +115,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -155,7 +155,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -198,7 +198,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -250,7 +250,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -294,7 +294,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -332,7 +332,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: false, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -371,7 +371,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: false, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -409,7 +409,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -444,7 +444,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -480,7 +480,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: false, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -519,7 +519,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -575,7 +575,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -619,7 +619,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -658,7 +658,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isChatReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -692,7 +692,7 @@ describe('getReportPreviewAction', () => { getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, report, policy, transactions: [transaction], @@ -727,7 +727,7 @@ describe('getReportPreviewAction', () => { const result = getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: '', + currentUserLogin: '', report, policy, transactions: [transaction], @@ -772,7 +772,7 @@ describe('getReportPreviewAction', () => { const result = getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: '', + currentUserLogin: '', report, policy, transactions: [transaction], @@ -817,7 +817,7 @@ describe('getReportPreviewAction', () => { const result = getReportPreviewAction({ isReportArchived: isReportArchived.current, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, - currentUserEmail: '', + currentUserLogin: '', report, policy, transactions: [transaction], diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index c829b6d06c52c..7f5435ea39b8d 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -542,7 +542,7 @@ describe('actions/Report', () => { return setPromise; }); - it('Should properly update comment with links', () => { + it('Should properly update comment with links', async () => { /* This tests a variety of scenarios when a user edits a comment. * We should generate a link when editing a message unless the link was * already in the comment and the user deleted it on purpose. @@ -550,11 +550,13 @@ describe('actions/Report', () => { global.fetch = TestHelper.getGlobalFetchMock(); + const TEST_USER_LOGIN = 'test@expensify.com'; + // User edits comment to add link // We should generate link let originalCommentMarkdown = 'Original Comment'; let afterEditCommentText = 'Original Comment www.google.com'; - let newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + let newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); let expectedOutput = 'Original Comment www.google.com'; expect(newCommentHTML).toBe(expectedOutput); @@ -562,7 +564,7 @@ describe('actions/Report', () => { // We should not generate link originalCommentMarkdown = 'Comment [www.google.com](https://www.google.com)'; afterEditCommentText = 'Comment www.google.com'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); expectedOutput = 'Comment www.google.com'; expect(newCommentHTML).toBe(expectedOutput); @@ -570,7 +572,7 @@ describe('actions/Report', () => { // We should not generate link originalCommentMarkdown = 'Comment [www.google.com](https://www.google.com)'; afterEditCommentText = 'Comment [www.google.com]'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); expectedOutput = 'Comment [www.google.com]'; expect(newCommentHTML).toBe(expectedOutput); @@ -578,7 +580,7 @@ describe('actions/Report', () => { // We should generate both links originalCommentMarkdown = 'Comment'; afterEditCommentText = 'Comment www.google.com www.facebook.com'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); expectedOutput = 'Comment www.google.com ' + 'www.facebook.com'; @@ -588,7 +590,7 @@ describe('actions/Report', () => { // Should not generate link again for the deleted one originalCommentMarkdown = 'Comment [www.google.com](https://www.google.com) [www.facebook.com](https://www.facebook.com)'; afterEditCommentText = 'Comment www.google.com [www.facebook.com](https://www.facebook.com)'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); expectedOutput = 'Comment www.google.com www.facebook.com'; expect(newCommentHTML).toBe(expectedOutput); @@ -596,7 +598,7 @@ describe('actions/Report', () => { // We should generate link originalCommentMarkdown = 'Comment'; afterEditCommentText = 'https://www.facebook.com/hashtag/__main/?__eep__=6'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); expectedOutput = 'https://www.facebook.com/hashtag/__main/?__eep__=6'; expect(newCommentHTML).toBe(expectedOutput); @@ -604,7 +606,7 @@ describe('actions/Report', () => { // We should not generate link originalCommentMarkdown = '[https://www.facebook.com/hashtag/__main/?__eep__=6](https://www.facebook.com/hashtag/__main/?__eep__=6)'; afterEditCommentText = 'https://www.facebook.com/hashtag/__main/?__eep__=6'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); expectedOutput = 'https://www.facebook.com/hashtag/__main/?__eep__=6'; expect(newCommentHTML).toBe(expectedOutput); @@ -612,7 +614,7 @@ describe('actions/Report', () => { // We should generate link originalCommentMarkdown = 'Comment'; afterEditCommentText = 'http://example.com/foo/*/bar/*/test.txt'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); expectedOutput = 'http://example.com/foo/*/bar/*/test.txt'; expect(newCommentHTML).toBe(expectedOutput); @@ -620,9 +622,25 @@ describe('actions/Report', () => { // We should not generate link originalCommentMarkdown = '[http://example.com/foo/*/bar/*/test.txt](http://example.com/foo/*/bar/*/test.txt)'; afterEditCommentText = 'http://example.com/foo/*/bar/*/test.txt'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); expectedOutput = 'http://example.com/foo/*/bar/*/test.txt'; expect(newCommentHTML).toBe(expectedOutput); + + // User edits comment to add mention + // We should generate mention-user tag + const privateDomainAccount = { + accountID: 2, + login: 'user@expensify.com', + email: 'user@expensify.com', + }; + await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { + [privateDomainAccount.accountID]: privateDomainAccount, + }); + originalCommentMarkdown = 'Comment'; + afterEditCommentText = 'Comment @user'; + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + expectedOutput = 'Comment @user@expensify.com'; + expect(newCommentHTML).toBe(expectedOutput); }); it('should show a notification for report action updates with shouldNotify', () => { @@ -1747,7 +1765,70 @@ describe('actions/Report', () => { TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 1); }); - it('it should only send the last sequential UpdateComment request to BE with currentUserEmail', async () => { + it('should convert short mentions to full format when editing comments', async () => { + global.fetch = TestHelper.getGlobalFetchMock(); + + const TEST_USER_LOGIN = 'alice@expensify.com'; + const TEST_USER_ACCOUNT_ID = 1; + const MENTIONED_USER_ACCOUNT_ID = 2; + const MENTIONED_USER_LOGIN = 'bob@expensify.com'; + const REPORT_ID = '1'; + const REPORT: OnyxTypes.Report = createRandomReport(1, undefined); + + const TEN_MINUTES_AGO = subMinutes(new Date(), 10); + const created = format(addSeconds(TEN_MINUTES_AGO, 10), CONST.DATE.FNS_DB_FORMAT_STRING); + + // Set up personal details with private domain users + await TestHelper.setPersonalDetails(TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID); + await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { + [MENTIONED_USER_ACCOUNT_ID]: { + accountID: MENTIONED_USER_ACCOUNT_ID, + login: MENTIONED_USER_LOGIN, + displayName: 'Bob', + }, + }); + + await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}); + + Report.addComment(REPORT, REPORT.reportID, [], 'Initial comment', CONST.DEFAULT_TIME_ZONE); + + // Get the reportActionID to edit and delete the comment + const newComment = PersistedRequests.getAll().at(0); + const reportActionID = newComment?.data?.reportActionID as string | undefined; + const newReportAction = TestHelper.buildTestReportComment(created, TEST_USER_ACCOUNT_ID, reportActionID); + const originalReport = { + reportID: REPORT_ID, + }; + + const {result: ancestors} = renderHook(() => useAncestors(originalReport)); + + // Edit the comment to add a short mention + Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Initial comment with @bob', undefined, undefined, TEST_USER_LOGIN); + + await waitForBatchedUpdates(); + + // Verify the mention was converted in the edited comment + await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, + callback: (reportActions) => { + Onyx.disconnect(connection); + + const reportAction = reportActionID ? reportActions?.[reportActionID] : null; + const message = reportAction?.message; + const editedMessage = Array.isArray(message) && message.length > 0 ? message.at(0)?.html : undefined; + // Verify the mention was converted to full mention with domain + expect(editedMessage).toContain('@bob@expensify.com'); + expect(editedMessage).toBe('Initial comment with @bob@expensify.com'); + resolve(); + }, + }); + }); + await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}); + await waitForBatchedUpdates(); + }); + + it('it should only send the last sequential UpdateComment request to BE with currentUserLogin', async () => { global.fetch = TestHelper.getGlobalFetchMock(); await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}); diff --git a/tests/unit/ReportPrimaryActionUtilsTest.ts b/tests/unit/ReportPrimaryActionUtilsTest.ts index 6ef75bff775b5..ec1bc80dffbba 100644 --- a/tests/unit/ReportPrimaryActionUtilsTest.ts +++ b/tests/unit/ReportPrimaryActionUtilsTest.ts @@ -66,7 +66,7 @@ describe('getPrimaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -97,7 +97,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -132,7 +132,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -167,7 +167,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -203,7 +203,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -242,7 +242,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -279,7 +279,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -321,7 +321,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -364,7 +364,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -396,7 +396,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -436,7 +436,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -474,7 +474,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -512,7 +512,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -578,7 +578,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -637,7 +637,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -697,7 +697,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -738,7 +738,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -776,7 +776,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -815,7 +815,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -854,7 +854,7 @@ describe('getPrimaryAction', () => { // Then the getReportPrimaryAction should return the empty string expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport: invoiceChatReport, @@ -1114,7 +1114,7 @@ describe('getTransactionThreadPrimaryAction', () => { expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -1154,7 +1154,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction; expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, @@ -1195,7 +1195,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction; expect( getReportPrimaryAction({ - currentUserEmail: CURRENT_USER_EMAIL, + currentUserLogin: CURRENT_USER_EMAIL, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, diff --git a/tests/unit/ReportSecondaryActionUtilsTest.ts b/tests/unit/ReportSecondaryActionUtilsTest.ts index 2875cb176a53b..8fa30c96f4d6a 100644 --- a/tests/unit/ReportSecondaryActionUtilsTest.ts +++ b/tests/unit/ReportSecondaryActionUtilsTest.ts @@ -63,7 +63,7 @@ describe('getSecondaryAction', () => { const result = [CONST.REPORT.SECONDARY_ACTIONS.EXPORT, CONST.REPORT.SECONDARY_ACTIONS.DOWNLOAD_PDF, CONST.REPORT.SECONDARY_ACTIONS.VIEW_DETAILS]; expect( getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -99,7 +99,7 @@ describe('getSecondaryAction', () => { } as unknown as Transaction; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -131,7 +131,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -163,7 +163,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -209,7 +209,7 @@ describe('getSecondaryAction', () => { } as unknown as Transaction; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -240,7 +240,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -288,7 +288,7 @@ describe('getSecondaryAction', () => { jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(true); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -322,7 +322,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -361,7 +361,7 @@ describe('getSecondaryAction', () => { } as unknown as Transaction; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -406,7 +406,7 @@ describe('getSecondaryAction', () => { } as TransactionViolation; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -445,7 +445,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -483,7 +483,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -523,7 +523,7 @@ describe('getSecondaryAction', () => { } as unknown as TransactionViolation; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -563,7 +563,7 @@ describe('getSecondaryAction', () => { } as unknown as TransactionViolation; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -600,7 +600,7 @@ describe('getSecondaryAction', () => { } as unknown as TransactionViolation; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -637,7 +637,7 @@ describe('getSecondaryAction', () => { } as unknown as TransactionViolation; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -671,7 +671,7 @@ describe('getSecondaryAction', () => { } as unknown as Transaction; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -696,7 +696,7 @@ describe('getSecondaryAction', () => { const policy = {approver: EMPLOYEE_EMAIL} as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -724,7 +724,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -751,7 +751,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -778,7 +778,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -806,7 +806,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -834,7 +834,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -863,7 +863,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -892,7 +892,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -936,7 +936,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[ACTION_ID]: reportAction}); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -984,7 +984,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[ACTION_ID]: reportAction}); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1032,7 +1032,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[ACTION_ID]: reportAction}); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1080,7 +1080,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[ACTION_ID]: reportAction}); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1115,7 +1115,7 @@ describe('getSecondaryAction', () => { jest.spyOn(ReportUtils, 'canHoldUnholdReportAction').mockReturnValueOnce({canHoldRequest: true, canUnholdRequest: true}); jest.spyOn(ReportActionsUtils, 'getOneTransactionThreadReportID').mockReturnValueOnce(originalMessageR14932.IOUTransactionID); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1159,7 +1159,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1204,7 +1204,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1264,7 +1264,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1324,7 +1324,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1384,7 +1384,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1410,7 +1410,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1474,7 +1474,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1519,7 +1519,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1579,7 +1579,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1624,7 +1624,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1674,7 +1674,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1715,7 +1715,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1752,7 +1752,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1804,7 +1804,7 @@ describe('getSecondaryAction', () => { // Then it should return false since the unreported card expense is imported with deleting disabled const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1847,7 +1847,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1877,7 +1877,7 @@ describe('getSecondaryAction', () => { jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(false); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1911,7 +1911,7 @@ describe('getSecondaryAction', () => { jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(false); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1955,7 +1955,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -1986,7 +1986,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2045,7 +2045,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2086,7 +2086,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2130,7 +2130,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2396,7 +2396,7 @@ describe('getSecondaryExportReportActions', () => { jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(false); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2527,7 +2527,7 @@ describe('getSecondaryTransactionThreadActions', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2696,7 +2696,7 @@ describe('getSecondaryTransactionThreadActions', () => { jest.spyOn(ReportUtils, 'isMoneyRequestReportEligibleForMerge').mockReturnValue(true); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport: undefined, @@ -2749,7 +2749,7 @@ describe('getSecondaryTransactionThreadActions', () => { jest.spyOn(ReportUtils, 'isMoneyRequestReportEligibleForMerge').mockReturnValue(true); const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport: undefined, @@ -2773,7 +2773,7 @@ describe('getSecondaryTransactionThreadActions', () => { const transactions = [{transactionID: '1'} as unknown as Transaction, {transactionID: '2'} as unknown as Transaction]; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2794,7 +2794,7 @@ describe('getSecondaryTransactionThreadActions', () => { const transactions = [{transactionID: '1'} as unknown as Transaction, {transactionID: '2'} as unknown as Transaction]; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2815,7 +2815,7 @@ describe('getSecondaryTransactionThreadActions', () => { const transactions = [{transactionID: '1'} as unknown as Transaction]; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2835,7 +2835,7 @@ describe('getSecondaryTransactionThreadActions', () => { } as unknown as Report; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2856,7 +2856,7 @@ describe('getSecondaryTransactionThreadActions', () => { const transactions = [{transactionID: '1'} as unknown as Transaction, {transactionID: '2'} as unknown as Transaction]; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, @@ -2877,7 +2877,7 @@ describe('getSecondaryTransactionThreadActions', () => { const transactions = [{transactionID: '1'} as unknown as Transaction, {transactionID: '2'} as unknown as Transaction, {transactionID: '3'} as unknown as Transaction]; const result = getSecondaryReportActions({ - currentUserEmail: EMPLOYEE_EMAIL, + currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 1ed7c8c5b9de1..dee7b31e7c281 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1811,6 +1811,42 @@ describe('SearchUIUtils', () => { expect(action).toEqual(CONST.SEARCH.ACTION_TYPES.PAY); }); + test('Should return EXPORT_TO_ACCOUNTING action when report is approved and policy has verified accounting integration', () => { + const exportReportID = 'report_export'; + const localSearchResults = { + ...searchResults.data, + [`policy_${policyID}`]: { + ...searchResults.data[`policy_${policyID}`], + role: CONST.POLICY.ROLE.ADMIN, + exporter: adminEmail, + connections: { + [CONST.POLICY.CONNECTIONS.NAME.NETSUITE]: { + verified: true, + lastSync: { + errorDate: '', + errorMessage: '', + isAuthenticationError: false, + isConnected: true, + isSuccessful: true, + source: 'NEWEXPENSIFY', + successfulDate: '', + }, + }, + } as Connections, + }, + [`report_${exportReportID}`]: { + ...searchResults.data[`report_${reportID2}`], + reportID: exportReportID, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + }, + }; + + const actions = SearchUIUtils.getActions(localSearchResults, {}, `report_${exportReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminEmail, {}); + + expect(actions).toContain(CONST.SEARCH.ACTION_TYPES.EXPORT_TO_ACCOUNTING); + }); + test('Should return `Submit` action when report has DEW_SUBMIT_FAILED action and is still OPEN', async () => { const dewReportID = '999'; const dewTransactionID = '9999';