diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index 3613fff73cdb..83d001c3cc4a 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -27,6 +27,7 @@ import {setKYCWallSource} from '@userActions/Wallet'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails'; import {lastWorkspaceNumberSelector} from '@src/selectors/Policy'; import type {BankAccountList, Policy} from '@src/types/onyx'; import {getEmptyObject} from '@src/types/utils/EmptyObject'; @@ -68,6 +69,7 @@ function KYCWall({ const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); const [betas] = useOnyx(ONYXKEYS.BETAS); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); + const [employeeLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(iouReport?.ownerAccountID)}); const {formatPhoneNumber, translate} = useLocalize(); const currentUserDetails = useCurrentUserPersonalDetails(); @@ -75,8 +77,6 @@ function KYCWall({ const currentUserEmail = currentUserDetails.email ?? ''; const localCurrency = currentUserDetails.localCurrencyCode ?? CONST.CURRENCY.USD; const reportPreviewAction = useParentReportAction(iouReport); - const personalDetails = usePersonalDetails(); - const employeeEmail = personalDetails?.[iouReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID]?.login ?? ''; const reportTransactions = useReportTransactions(iouReport?.reportID); const filteredReportActions = useAllPolicyExpenseChatReportActions(); const anchorRef = useRef(null); @@ -150,6 +150,7 @@ function KYCWall({ formatPhoneNumber, filteredReportActions, currentUserAccountID, + employeeLogin, reportTransactions, ); if (inviteResult?.policyExpenseChatReportID) { @@ -184,7 +185,7 @@ function KYCWall({ reportPreviewAction, currentUserAccountID, currentUserEmail, - employeeEmail, + employeeLogin ?? '', conciergeReportID, localCurrency, lastWorkspaceNumber, @@ -234,7 +235,7 @@ function KYCWall({ reportPreviewAction, currentUserAccountID, currentUserEmail, - employeeEmail, + employeeLogin, introSelected, formatPhoneNumber, translate, diff --git a/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx b/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx index cc7f922ecc54..7379c1467d6f 100644 --- a/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx +++ b/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx @@ -64,6 +64,7 @@ import {canApproveIOU, canIOUBePaid as canIOUBePaidAction} from '@userActions/IO import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; +import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; type MoneyReportHeaderSecondaryActionsProps = { @@ -84,6 +85,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(moneyRequestReport?.policyID)}`); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(moneyRequestReport?.chatReportID)}`); + const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(moneyRequestReport?.ownerAccountID)}); const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${moneyRequestReport?.reportID}`); @@ -317,6 +319,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo ? getSecondaryReportActions({ currentUserLogin: currentUserLogin ?? '', currentUserAccountID: accountID, + submitterLogin, report: moneyRequestReport, chatReport, reportTransactions: nonPendingDeleteTransactions, diff --git a/src/components/MoneyReportHeaderActions/MoneyReportHeaderSelectionDropdown.tsx b/src/components/MoneyReportHeaderActions/MoneyReportHeaderSelectionDropdown.tsx index f68593fcaeab..b5b9b20ca5cd 100644 --- a/src/components/MoneyReportHeaderActions/MoneyReportHeaderSelectionDropdown.tsx +++ b/src/components/MoneyReportHeaderActions/MoneyReportHeaderSelectionDropdown.tsx @@ -62,6 +62,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Route} from '@src/ROUTES'; +import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; const PAYMENT_ICONS = ['Send', 'ThumbsUp', 'Cash', 'ArrowRight', 'Building'] as const; @@ -96,6 +97,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportID)}`); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(moneyRequestReport?.chatReportID)}`); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(moneyRequestReport?.policyID)}`); + const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(moneyRequestReport?.ownerAccountID)}); const [session] = useOnyx(ONYXKEYS.SESSION); const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector}); const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector}); @@ -194,6 +196,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn ? getSecondaryReportActions({ currentUserLogin: currentUserLogin ?? '', currentUserAccountID: accountID, + submitterLogin, report: moneyRequestReport, chatReport, reportTransactions: nonPendingDeleteTransactions, diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 82cd43bd6319..104d9fbd0105 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -35,6 +35,7 @@ import initSplitExpense from '@libs/actions/SplitExpenses'; import {setNameValuePair} from '@libs/actions/User'; import {getTransactionsAndReportsFromSearch} from '@libs/MergeTransactionUtils'; import Navigation from '@libs/Navigation/Navigation'; +import {getLoginByAccountID} from '@libs/PersonalDetailsUtils'; import {getConnectedIntegration} from '@libs/PolicyUtils'; import {getSecondaryExportReportActions, isMergeActionForSelectedTransactions} from '@libs/ReportSecondaryActionUtils'; import { @@ -229,6 +230,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED); const {isBetaEnabled} = usePermissions(); const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END); + const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const defaultExpensePolicy = useDefaultExpensePolicy(); const undeleteTransactions = useUndeleteTransactions(); @@ -751,7 +753,15 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { ); return; } - const invite = moveIOUReportToPolicyAndInviteSubmitter(itemReport, adminPolicy, formatPhoneNumber, policyExpenseChatReportActions, accountID, reportTransactions); + const invite = moveIOUReportToPolicyAndInviteSubmitter( + itemReport, + adminPolicy, + formatPhoneNumber, + policyExpenseChatReportActions, + accountID, + getLoginByAccountID(itemReport?.ownerAccountID, personalDetails), + reportTransactions, + ); if (!invite?.policyExpenseChatReportID) { moveIOUReportToPolicy(itemReport, adminPolicy, false, reportTransactions); } @@ -818,6 +828,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { formatPhoneNumber, clearSelectedTransactions, accountID, + personalDetails, ], ); diff --git a/src/hooks/useSelectionModeReportActions.ts b/src/hooks/useSelectionModeReportActions.ts index 9b5817b4f3a9..026ab63fd047 100644 --- a/src/hooks/useSelectionModeReportActions.ts +++ b/src/hooks/useSelectionModeReportActions.ts @@ -43,6 +43,7 @@ import {hasAnyPendingRTERViolation as hasAnyPendingRTERViolationTransactionUtils import {markPendingRTERTransactionsAsCash} from '@userActions/Transaction'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails'; import type * as OnyxTypes from '@src/types/onyx'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import useActiveAdminPolicies from './useActiveAdminPolicies'; @@ -111,6 +112,7 @@ function useSelectionModeReportActions({ const [betas] = useOnyx(ONYXKEYS.BETAS); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); + const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(report?.ownerAccountID)}); const {isOffline} = useNetwork(); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); @@ -235,6 +237,7 @@ function useSelectionModeReportActions({ return getSecondaryReportActions({ currentUserLogin: currentUserEmail ?? '', currentUserAccountID, + submitterLogin, report, chatReport, reportTransactions: transactions, diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 81ed9e4a5909..c822713ac0f6 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -162,14 +162,8 @@ function getAccountIDsByLogins(logins: string[]): number[] { }, []); } -/** - * Given an accountID, find the associated personal detail and return related login. - * - * @param accountID User accountID - * @returns Login according to passed accountID - */ -function getLoginByAccountID(accountID: number): string | undefined { - return allPersonalDetails?.[accountID]?.login; +function getLoginByAccountID(accountID: number | undefined, personalDetails: OnyxEntry = allPersonalDetails): string | undefined { + return accountID ? personalDetails?.[accountID]?.login : undefined; } /** diff --git a/src/libs/ReportSecondaryActionUtils.ts b/src/libs/ReportSecondaryActionUtils.ts index faddec958bce..0a177c7a22a0 100644 --- a/src/libs/ReportSecondaryActionUtils.ts +++ b/src/libs/ReportSecondaryActionUtils.ts @@ -15,7 +15,6 @@ import type { TransactionViolation, } from '@src/types/onyx'; import {areTransactionsEligibleForMerge} from './MergeTransactionUtils'; -import {getLoginByAccountID} from './PersonalDetailsUtils'; import { arePaymentsEnabled as arePaymentsEnabledUtils, getConnectedIntegration, @@ -602,7 +601,7 @@ function isHoldActionForTransaction( return true; } -function isChangeWorkspaceAction(report: Report, policies: OnyxCollection, currentUserLogin: string, reportActions?: ReportAction[]): boolean { +function isChangeWorkspaceAction(report: Report, policies: OnyxCollection, currentUserLogin: string, submitterLogin: string | undefined, reportActions?: ReportAction[]): boolean { // We can't move the iou report to the workspace if both users from the iou report create the expense if (isIOUReportUtils(report) && doesReportContainRequestsFromMultipleUsers(report)) { return false; @@ -615,14 +614,13 @@ function isChangeWorkspaceAction(report: Report, policies: OnyxCollection; reportTransactions: Transaction[]; @@ -1014,7 +1014,7 @@ function getSecondaryReportActions({ options.push(CONST.REPORT.SECONDARY_ACTIONS.PRINT); - if (isChangeWorkspaceAction(report, policies, currentUserLogin, reportActions)) { + if (isChangeWorkspaceAction(report, policies, currentUserLogin, submitterLogin, reportActions)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.CHANGE_WORKSPACE); } diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 142a9a3c61d8..131f4fec9b37 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -6504,6 +6504,7 @@ function moveIOUReportToPolicyAndInviteSubmitter( formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], reportActions: OnyxCollection, currentUserAccountID: number, + submitterLogin: string | undefined, reportTransactions: Transaction[] = [], ): {policyExpenseChatReportID?: string} | undefined { if (!policy || !iouReport) { @@ -6513,12 +6514,18 @@ function moveIOUReportToPolicyAndInviteSubmitter( const reportID = iouReport.reportID; const isPolicyAdmin = isPolicyAdminPolicyUtils(policy); const submitterAccountID = iouReport.ownerAccountID; - const submitterEmail = PersonalDetailsUtils.getLoginByAccountID(submitterAccountID ?? CONST.DEFAULT_NUMBER_ID); - const submitterLogin = PhoneNumber.addSMSDomainIfPhoneNumber(submitterEmail); + const submitterLoginWithSMSDomain = PhoneNumber.addSMSDomainIfPhoneNumber(submitterLogin); const policyID = policy.id; // This flow only works for admins moving an IOU report to a policy where the submitter is NOT yet a member of the policy - if (!isPolicyAdmin || !isIOUReportUsingReport(iouReport) || !submitterAccountID || !submitterEmail || isPolicyMember(policy, submitterLogin)) { + if ( + !isPolicyAdmin || + !isIOUReportUsingReport(iouReport) || + !submitterAccountID || + !submitterLogin || + !submitterLoginWithSMSDomain || + isPolicyMember(policy, submitterLoginWithSMSDomain) + ) { return; } @@ -6564,14 +6571,14 @@ function moveIOUReportToPolicyAndInviteSubmitter( // Optimistically add the submitter to the workspace and create a expense chat for them const policyKey = `${ONYXKEYS.COLLECTION.POLICY}${policyID}` as const; const invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs = { - [submitterEmail]: submitterAccountID, + [submitterLogin]: submitterAccountID, }; // Set up new member optimistic data const role = CONST.POLICY.ROLE.USER; // Get personal details onyx data (similar to addMembersToWorkspace) - const {newAccountIDs, newLogins} = PersonalDetailsUtils.getNewAccountIDsAndLogins([submitterLogin], [submitterAccountID]); + const {newAccountIDs, newLogins} = PersonalDetailsUtils.getNewAccountIDsAndLogins([submitterLoginWithSMSDomain], [submitterAccountID]); const newPersonalDetailsOnyxData = PersonalDetailsUtils.getPersonalDetailsOnyxDataForOptimisticUsers(newLogins, newAccountIDs, formatPhoneNumber); // Build announce room members data for the new member @@ -6579,12 +6586,12 @@ function moveIOUReportToPolicyAndInviteSubmitter( // Create policy expense chat for the submitter const policyExpenseChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs, currentUserAccountID, reportActions); - const optimisticPolicyExpenseChatReportID = policyExpenseChats.reportCreationData[submitterEmail].reportID; - const optimisticPolicyExpenseChatCreatedReportActionID = policyExpenseChats.reportCreationData[submitterEmail].reportActionID; + const optimisticPolicyExpenseChatReportID = policyExpenseChats.reportCreationData[submitterLoginWithSMSDomain].reportID; + const optimisticPolicyExpenseChatCreatedReportActionID = policyExpenseChats.reportCreationData[submitterLoginWithSMSDomain].reportActionID; // Set up optimistic member state const optimisticMembersState: OnyxCollectionInputValue = { - [submitterLogin]: { + [submitterLoginWithSMSDomain]: { role, email: submitterLogin, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, @@ -6593,11 +6600,11 @@ function moveIOUReportToPolicyAndInviteSubmitter( }; const successMembersState: OnyxCollectionInputValue = { - [submitterLogin]: {pendingAction: null}, + [submitterLoginWithSMSDomain]: {pendingAction: null}, }; const failureMembersState: OnyxCollectionInputValue = { - [submitterLogin]: { + [submitterLoginWithSMSDomain]: { errors: getMicroSecondOnyxErrorWithTranslationKey('workspace.people.error.genericAdd'), }, }; @@ -6920,18 +6927,31 @@ function navigateToTrainingModal(isChangePolicyTrainingModalDismissed: boolean) }); } -function buildOptimisticChangePolicyData( - report: Report, - parentReport: OnyxEntry, - policy: Policy, - currentUserAccountID: number, - email: string, - hasViolationsParam: boolean, - isASAPSubmitBetaEnabled: boolean, - isReportLastVisibleArchived: boolean | undefined, - reportNextStep?: ReportNextStepDeprecated, - optimisticPolicyExpenseChatReport?: Report, -) { +function buildOptimisticChangePolicyData({ + report, + parentReport, + policy, + currentUserAccountID, + email, + managerLogin, + hasViolationsParam, + isASAPSubmitBetaEnabled, + isReportLastVisibleArchived, + reportNextStep, + optimisticPolicyExpenseChatReport, +}: { + report: Report; + parentReport: OnyxEntry; + policy: Policy; + currentUserAccountID: number; + email: string; + managerLogin: string | undefined; + hasViolationsParam: boolean; + isASAPSubmitBetaEnabled: boolean; + isReportLastVisibleArchived: boolean | undefined; + reportNextStep?: ReportNextStepDeprecated; + optimisticPolicyExpenseChatReport?: Report; +}) { const optimisticData: Array< OnyxUpdate< | typeof ONYXKEYS.COLLECTION.REPORT @@ -6960,9 +6980,8 @@ function buildOptimisticChangePolicyData( const reportIDToThreadsReportIDsMap = buildReportIDToThreadsReportIDsMap(); updatePolicyIdForReportAndThreads(reportID, policy.id, reportIDToThreadsReportIDsMap, optimisticData, failureData); - const managerLogin = PersonalDetailsUtils.getLoginByAccountID(report.managerID ?? CONST.DEFAULT_NUMBER_ID); const newManagerAccountID = getSubmitToAccountID(policy, report); - const shouldResetApprovalChain = isProcessingReport(report) && newManagerAccountID !== report.managerID && isPolicyMember(policy, managerLogin); + const shouldResetApprovalChain = isProcessingReport(report) && newManagerAccountID !== report.managerID && managerLogin && isPolicyMember(policy, managerLogin); if (shouldResetApprovalChain) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -7405,33 +7424,47 @@ function buildOptimisticChangePolicyData( /** * Changes the policy of a report and all its child reports, and moves the report to the new policy's expense chat. */ -function changeReportPolicy( - report: Report, - parentReport: OnyxEntry, - policy: Policy, - accountID: number, - email: string, - hasViolationsParam: boolean, - isChangePolicyTrainingModalDismissed: boolean, - isASAPSubmitBetaEnabled: boolean, - reportNextStep?: ReportNextStepDeprecated, +function changeReportPolicy({ + report, + parentReport, + policy, + currentUserAccountID, + email, + managerLogin, + hasViolationsParam, + isChangePolicyTrainingModalDismissed, + isASAPSubmitBetaEnabled, + reportNextStep, isReportLastVisibleArchived = false, -) { +}: { + report: Report; + parentReport: OnyxEntry; + policy: Policy; + currentUserAccountID: number; + email: string; + managerLogin: string | undefined; + hasViolationsParam: boolean; + isChangePolicyTrainingModalDismissed: boolean; + isASAPSubmitBetaEnabled: boolean; + reportNextStep?: ReportNextStepDeprecated; + isReportLastVisibleArchived?: boolean; +}) { if (!report || !policy || report.policyID === policy.id || !isExpenseReport(report)) { return; } - const {optimisticData, successData, failureData, optimisticReportPreviewAction, optimisticMovedReportAction} = buildOptimisticChangePolicyData( + const {optimisticData, successData, failureData, optimisticReportPreviewAction, optimisticMovedReportAction} = buildOptimisticChangePolicyData({ report, parentReport, policy, - accountID, + currentUserAccountID, email, + managerLogin, hasViolationsParam, isASAPSubmitBetaEnabled, isReportLastVisibleArchived, reportNextStep, - ); + }); const params = { reportID: report.reportID, @@ -7455,6 +7488,8 @@ function changeReportPolicyAndInviteSubmitter({ policy, currentUserAccountID, email, + submitterLogin, + managerLogin, hasViolationsParam, isChangePolicyTrainingModalDismissed, isASAPSubmitBetaEnabled, @@ -7469,6 +7504,8 @@ function changeReportPolicyAndInviteSubmitter({ policy: Policy; currentUserAccountID: number; email: string; + submitterLogin: string | undefined; + managerLogin: string | undefined; hasViolationsParam: boolean; isChangePolicyTrainingModalDismissed: boolean; isASAPSubmitBetaEnabled: boolean; @@ -7479,15 +7516,10 @@ function changeReportPolicyAndInviteSubmitter({ // TODO: Remove optional (?) once all callers are updated in follow-up PRs of https://github.com/Expensify/App/issues/66578 reportActionsList?: OnyxCollection; }) { - if (!report.reportID || !policy?.id || report.policyID === policy.id || !isExpenseReport(report) || !report.ownerAccountID) { + if (!report.reportID || !policy?.id || report.policyID === policy.id || !isExpenseReport(report) || !report.ownerAccountID || !submitterLogin) { return; } - const submitterEmail = PersonalDetailsUtils.getLoginByAccountID(report.ownerAccountID); - - if (!submitterEmail) { - return; - } const policyMemberAccountIDs = Object.values(getMemberAccountIDsForWorkspace(employeeList, false, false)); const { optimisticData: optimisticAddMembersData, @@ -7495,7 +7527,7 @@ function changeReportPolicyAndInviteSubmitter({ failureData: failureAddMembersData, membersChats, } = buildAddMembersToWorkspaceOnyxData( - {[submitterEmail]: report.ownerAccountID}, + {[submitterLogin]: report.ownerAccountID}, policy, policyMemberAccountIDs, CONST.POLICY.ROLE.USER, @@ -7505,8 +7537,8 @@ function changeReportPolicyAndInviteSubmitter({ CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, reportActionsList, ); - const optimisticPolicyExpenseChatReportID = membersChats.reportCreationData[submitterEmail].reportID; - const optimisticPolicyExpenseChatCreatedReportActionID = membersChats.reportCreationData[submitterEmail].reportActionID; + const optimisticPolicyExpenseChatReportID = membersChats.reportCreationData[submitterLogin].reportID; + const optimisticPolicyExpenseChatCreatedReportActionID = membersChats.reportCreationData[submitterLogin].reportActionID; if (!optimisticPolicyExpenseChatReportID) { return; @@ -7518,18 +7550,19 @@ function changeReportPolicyAndInviteSubmitter({ failureData: failureChangePolicyData, optimisticReportPreviewAction, optimisticMovedReportAction, - } = buildOptimisticChangePolicyData( + } = buildOptimisticChangePolicyData({ report, parentReport, policy, currentUserAccountID, email, + managerLogin, hasViolationsParam, isASAPSubmitBetaEnabled, isReportLastVisibleArchived, reportNextStep, - membersChats.reportCreationData[submitterEmail], - ); + optimisticPolicyExpenseChatReport: membersChats.reportCreationData[submitterLogin], + }); const optimisticData = [...optimisticAddMembersData, ...optimisticChangePolicyData]; const successData = [...successAddMembersData, ...successChangePolicyData]; diff --git a/src/pages/ReportChangeWorkspacePage.tsx b/src/pages/ReportChangeWorkspacePage.tsx index 6be5c79fa54b..f560ec688c25 100644 --- a/src/pages/ReportChangeWorkspacePage.tsx +++ b/src/pages/ReportChangeWorkspacePage.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useMemo} from 'react'; +import React from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import ActivityIndicator from '@components/ActivityIndicator'; @@ -22,7 +22,6 @@ import {changeReportPolicy, changeReportPolicyAndInviteSubmitter, moveIOUReportT import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportChangeWorkspaceNavigatorParamList} from '@libs/Navigation/types'; -import {getLoginByAccountID} from '@libs/PersonalDetailsUtils'; import {isPolicyAdmin, isPolicyMember} from '@libs/PolicyUtils'; import { hasViolations as hasViolationsReportUtils, @@ -38,7 +37,8 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {DismissedProductTraining, PersonalDetailsList} from '@src/types/onyx'; +import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails'; +import type {DismissedProductTraining} from '@src/types/onyx'; import NotFoundPage from './ErrorPage/NotFoundPage'; import type {WithReportOrNotFoundProps} from './inbox/report/withReportOrNotFound'; import withReportOrNotFound from './inbox/report/withReportOrNotFound'; @@ -63,12 +63,8 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); const isReportLastVisibleArchived = useReportIsArchived(report?.parentReportID); - const reportOwnerAccountID = report?.ownerAccountID; - const submitterEmailSelector = useCallback( - (personalDetailsList: OnyxEntry) => personalDetailsList?.[reportOwnerAccountID ?? CONST.DEFAULT_NUMBER_ID]?.login, - [reportOwnerAccountID], - ); - const [submitterEmail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: submitterEmailSelector}, [submitterEmailSelector]); + const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(report?.ownerAccountID)}); + const [managerLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(report?.managerID)}); const shouldShowLoadingIndicator = isLoadingApp && !isOffline; const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); @@ -79,84 +75,70 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED); const filteredReportActions = useAllPolicyExpenseChatReportActions(); - const selectPolicy = useCallback( - (policyID?: string) => { - const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; - if (!policyID || !policy) { - return; - } - if (shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriods, amountOwed)) { - Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); - return; - } - const {backTo} = route.params; - Navigation.goBack(backTo); - if (isIOUReport(reportID)) { - const invite = moveIOUReportToPolicyAndInviteSubmitter( - report, - policy, - formatPhoneNumber, - filteredReportActions, - session?.accountID ?? CONST.DEFAULT_NUMBER_ID, - reportTransactions, - ); - if (!invite?.policyExpenseChatReportID) { - moveIOUReportToPolicy(report, policy, false, reportTransactions); - } - // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 - } else if (isExpenseReport(report) && isPolicyAdmin(policy) && report.ownerAccountID && !isPolicyMember(policy, getLoginByAccountID(report.ownerAccountID))) { - const employeeList = policy?.employeeList; - changeReportPolicyAndInviteSubmitter({ - report, - parentReport, - policy, - currentUserAccountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID, - email: session?.email ?? '', - hasViolationsParam: hasViolations, - isChangePolicyTrainingModalDismissed, - isASAPSubmitBetaEnabled, - employeeList, - formatPhoneNumber, - isReportLastVisibleArchived, - reportNextStep, - reportActionsList: filteredReportActions, - }); - } else { - changeReportPolicy( - report, - parentReport, - policy, - session?.accountID ?? CONST.DEFAULT_NUMBER_ID, - session?.email ?? '', - hasViolations, - isChangePolicyTrainingModalDismissed, - isASAPSubmitBetaEnabled, - reportNextStep, - isReportLastVisibleArchived, - ); + const selectPolicy = (policyID?: string) => { + const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; + if (!policyID || !policy) { + return; + } + if (shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriods, amountOwed)) { + Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); + return; + } + const {backTo} = route.params; + Navigation.goBack(backTo); + if (isIOUReport(reportID)) { + const invite = moveIOUReportToPolicyAndInviteSubmitter( + report, + policy, + formatPhoneNumber, + filteredReportActions, + session?.accountID ?? CONST.DEFAULT_NUMBER_ID, + submitterLogin, + reportTransactions, + ); + if (!invite?.policyExpenseChatReportID) { + moveIOUReportToPolicy(report, policy, false, reportTransactions); } - }, - [ - policies, - userBillingGracePeriods, - ownerBillingGracePeriodEnd, - amountOwed, - route.params, - reportID, + return; + } + + // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 + if (isExpenseReport(report) && isPolicyAdmin(policy) && submitterLogin && !isPolicyMember(policy, submitterLogin)) { + const employeeList = policy?.employeeList; + changeReportPolicyAndInviteSubmitter({ + report, + parentReport, + policy, + currentUserAccountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID, + email: session?.email ?? '', + submitterLogin, + managerLogin, + hasViolationsParam: hasViolations, + isChangePolicyTrainingModalDismissed, + isASAPSubmitBetaEnabled, + employeeList, + formatPhoneNumber, + isReportLastVisibleArchived, + reportNextStep, + reportActionsList: filteredReportActions, + }); + return; + } + + changeReportPolicy({ report, parentReport, - formatPhoneNumber, - reportTransactions, - filteredReportActions, - isReportLastVisibleArchived, - session?.accountID, - session?.email, - hasViolations, + policy, + currentUserAccountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID, + email: session?.email ?? '', + managerLogin, + hasViolationsParam: hasViolations, + isChangePolicyTrainingModalDismissed, isASAPSubmitBetaEnabled, reportNextStep, - isChangePolicyTrainingModalDismissed, - ], - ); + isReportLastVisibleArchived, + }); + }; const {data, shouldShowNoResultsFoundMessage, shouldShowSearchInput} = useWorkspaceList({ policies, @@ -167,7 +149,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro localeCompare, additionalFilter: (newPolicy) => { const isReportSettled = isSettled(report); - const isEligible = isWorkspaceEligibleForReportChange(submitterEmail, newPolicy, report); + const isEligible = isWorkspaceEligibleForReportChange(submitterLogin, newPolicy, report); if (isReportSettled) { return isEligible && isPolicyAdmin(newPolicy, session?.email); } @@ -175,15 +157,12 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro }, }); - const textInputOptions = useMemo( - () => ({ - label: shouldShowSearchInput ? translate('common.search') : undefined, - value: searchTerm, - onChangeText: setSearchTerm, - headerMessage: shouldShowNoResultsFoundMessage ? translate('common.noResultsFound') : '', - }), - [searchTerm, setSearchTerm, shouldShowNoResultsFoundMessage, shouldShowSearchInput, translate], - ); + const textInputOptions = { + label: shouldShowSearchInput ? translate('common.search') : undefined, + value: searchTerm, + onChangeText: setSearchTerm, + headerMessage: shouldShowNoResultsFoundMessage ? translate('common.noResultsFound') : '', + }; if (!isMoneyRequestReport(report) || isMoneyRequestReportPendingDeletion(report)) { return ; diff --git a/src/pages/domain/Members/MoveUsersBetweenGroupsPage.tsx b/src/pages/domain/Members/MoveUsersBetweenGroupsPage.tsx index b463e29f8e6e..892b621a6673 100644 --- a/src/pages/domain/Members/MoveUsersBetweenGroupsPage.tsx +++ b/src/pages/domain/Members/MoveUsersBetweenGroupsPage.tsx @@ -37,6 +37,7 @@ function MoveUsersBetweenGroupsPage({route}: MoveUsersBetweenGroupsPageProps) { const [domainName] = useOnyx(`${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`, {selector: domainNameSelector}); const [securityGroups] = useOnyx(`${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`, {selector: groupsSelector}); const [selectedMemberAccountIDs] = useOnyx(ONYXKEYS.DOMAIN_MEMBERS_SELECTED_FOR_MOVE); + const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const memberCount = selectedMemberAccountIDs?.length ?? 0; @@ -58,7 +59,7 @@ function MoveUsersBetweenGroupsPage({route}: MoveUsersBetweenGroupsPageProps) { for (const accountIDString of selectedMemberAccountIDs) { const accountID = Number(accountIDString); - const memberLogin = getLoginByAccountID(accountID); + const memberLogin = getLoginByAccountID(accountID, personalDetails); const currentGroup = securityGroups?.find((g) => !!g.details.shared?.[accountIDString]); const currentGroupData = currentGroup ? {key: `${CONST.DOMAIN.DOMAIN_SECURITY_GROUP_PREFIX}${currentGroup.id}` as const, securityGroup: currentGroup.details} : undefined; const newSecurityGroupKey: `${typeof CONST.DOMAIN.DOMAIN_SECURITY_GROUP_PREFIX}${string}` = `${CONST.DOMAIN.DOMAIN_SECURITY_GROUP_PREFIX}${selectedGroupId}`; diff --git a/src/selectors/PersonalDetails.ts b/src/selectors/PersonalDetails.ts index 4d1713da063e..d04dae414513 100644 --- a/src/selectors/PersonalDetails.ts +++ b/src/selectors/PersonalDetails.ts @@ -1,10 +1,11 @@ import type {OnyxEntry} from 'react-native-onyx'; +import {getLoginByAccountID} from '@libs/PersonalDetailsUtils'; import CONST from '@src/CONST'; import type {PersonalDetailsList, Report} from '@src/types/onyx'; const personalDetailsSelector = (accountID: number) => (personalDetailsList: OnyxEntry) => personalDetailsList?.[accountID]; -const personalDetailsLoginSelector = (accountID: number) => (personalDetailsList: OnyxEntry) => personalDetailsList?.[accountID]?.login; +const personalDetailsLoginSelector = (accountID: number | undefined) => (personalDetailsList: OnyxEntry) => getLoginByAccountID(accountID, personalDetailsList); const accountIDToLoginSelector = (reportsToArchive: Report[]) => (personalDetailsList: OnyxEntry) => { const map: Record = {}; diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 6b7cb2cb4a05..9e79b6544671 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -3061,7 +3061,17 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy); // When moving to another workspace - Report.changeReportPolicy(expenseReport, undefined, newPolicy, 1, '', true, false, false); + Report.changeReportPolicy({ + report: expenseReport, + parentReport: undefined, + policy: newPolicy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: true, + isChangePolicyTrainingModalDismissed: false, + isASAPSubmitBetaEnabled: false, + }); await waitForBatchedUpdates(); // Then the expense report should not be archived anymore @@ -3108,7 +3118,17 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy); // When moving to another workspace - Report.changeReportPolicy(expenseReport, parentReport, newPolicy, 1, '', false, false, false); + Report.changeReportPolicy({ + report: expenseReport, + parentReport, + policy: newPolicy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isChangePolicyTrainingModalDismissed: false, + isASAPSubmitBetaEnabled: false, + }); await waitForBatchedUpdates(); // Then the expense report chatReportID and parentReportID should be updated to the new expense chat reportID @@ -3165,7 +3185,17 @@ describe('actions/Report', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy); - Report.changeReportPolicy(expenseReport, undefined, newPolicy, 1, '', false, false, false); + Report.changeReportPolicy({ + report: expenseReport, + parentReport: undefined, + policy: newPolicy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isChangePolicyTrainingModalDismissed: false, + isASAPSubmitBetaEnabled: false, + }); await waitForBatchedUpdates(); const updatedReport = await new Promise>((resolve) => { @@ -3248,7 +3278,17 @@ describe('actions/Report', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy); - Report.changeReportPolicy(expenseReport, undefined, newPolicy, 1, '', false, false, false); + Report.changeReportPolicy({ + report: expenseReport, + parentReport: undefined, + policy: newPolicy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isChangePolicyTrainingModalDismissed: false, + isASAPSubmitBetaEnabled: false, + }); await waitForBatchedUpdates(); // Then the report total should correctly include expense (-1000) and refund (+500) = -500 @@ -3319,7 +3359,17 @@ describe('actions/Report', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy); - Report.changeReportPolicy(expenseReport, undefined, newPolicy, 1, '', false, false, false); + Report.changeReportPolicy({ + report: expenseReport, + parentReport: undefined, + policy: newPolicy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isChangePolicyTrainingModalDismissed: false, + isASAPSubmitBetaEnabled: false, + }); await waitForBatchedUpdates(); // Then only AUD transaction should contribute to total (-1000), USD is excluded @@ -3364,6 +3414,8 @@ describe('actions/Report', () => { policy: createRandomPolicy(Number(2)), currentUserAccountID: 1, email: '', + submitterLogin: ownerEmail, + managerLogin: '', hasViolationsParam: true, isChangePolicyTrainingModalDismissed: false, isASAPSubmitBetaEnabled: false, @@ -3453,6 +3505,8 @@ describe('actions/Report', () => { policy: newPolicy, currentUserAccountID: 1, email: '', + submitterLogin: ownerEmail, + managerLogin: '', hasViolationsParam: true, isChangePolicyTrainingModalDismissed: false, isASAPSubmitBetaEnabled: false, @@ -3495,6 +3549,8 @@ describe('actions/Report', () => { policy: createRandomPolicy(Number(2)), currentUserAccountID: 1, email: '', + submitterLogin: '', + managerLogin: '', hasViolationsParam: false, isChangePolicyTrainingModalDismissed: false, isASAPSubmitBetaEnabled: false, @@ -3523,6 +3579,8 @@ describe('actions/Report', () => { policy: targetPolicy, currentUserAccountID: 1, email: '', + submitterLogin: '', + managerLogin: '', hasViolationsParam: false, isChangePolicyTrainingModalDismissed: false, isASAPSubmitBetaEnabled: false, @@ -3550,6 +3608,8 @@ describe('actions/Report', () => { policy: createRandomPolicy(Number(2)), currentUserAccountID: 1, email: '', + submitterLogin: '', + managerLogin: '', hasViolationsParam: false, isChangePolicyTrainingModalDismissed: false, isASAPSubmitBetaEnabled: false, @@ -3577,6 +3637,8 @@ describe('actions/Report', () => { policy: createRandomPolicy(Number(2)), currentUserAccountID: 1, email: '', + submitterLogin: '', + managerLogin: '', hasViolationsParam: false, isChangePolicyTrainingModalDismissed: false, isASAPSubmitBetaEnabled: false, @@ -3606,6 +3668,8 @@ describe('actions/Report', () => { policy: createRandomPolicy(Number(2)), currentUserAccountID: 1, email: '', + submitterLogin: '', + managerLogin: '', hasViolationsParam: false, isChangePolicyTrainingModalDismissed: false, isASAPSubmitBetaEnabled: false, @@ -3656,6 +3720,8 @@ describe('actions/Report', () => { policy: targetPolicy, currentUserAccountID: 1, email: 'current-user@expensifail.com', + submitterLogin: ownerEmail, + managerLogin: '', hasViolationsParam: false, isChangePolicyTrainingModalDismissed: false, isASAPSubmitBetaEnabled: false, @@ -3888,7 +3954,7 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`, policy); // When moving iou to a workspace and invite the submitter - Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID); + Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID, ownerEmail); await waitForBatchedUpdates(); // Then MOVED report action should be added to the expense report @@ -3955,7 +4021,7 @@ describe('actions/Report', () => { // Call moveIOUReportToPolicyAndInviteSubmitter const formatPhoneNumber = (phoneNumber: string) => phoneNumber; - Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, policy, formatPhoneNumber, {}, TEST_USER_ACCOUNT_ID); + Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, policy, formatPhoneNumber, {}, TEST_USER_ACCOUNT_ID, ownerEmail); await waitForBatchedUpdates(); // Simulate network failure @@ -4012,7 +4078,7 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, transaction); // When moving IOU to a workspace with reportTransactions - Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID, [transaction]); + Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID, ownerEmail, [transaction]); await waitForBatchedUpdates(); // Then the transaction amounts should be negated optimistically @@ -4057,7 +4123,7 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, transaction); // When moving IOU to a workspace with transactions - Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID, [transaction]); + Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID, ownerEmail, [transaction]); await waitForBatchedUpdates(); // Then the report should be converted to an expense report with the new policyID @@ -4080,13 +4146,13 @@ describe('actions/Report', () => { ...createRandomReport(1, undefined), type: CONST.REPORT.TYPE.IOU, }; - const result = Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, undefined as unknown as OnyxTypes.Policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID); + const result = Report.moveIOUReportToPolicyAndInviteSubmitter(iouReport, undefined as unknown as OnyxTypes.Policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID, ''); expect(result).toBeUndefined(); }); it('should return undefined when iouReport is missing', () => { const policy: OnyxTypes.Policy = {...createRandomPolicy(1), role: CONST.POLICY.ROLE.ADMIN}; - const result = Report.moveIOUReportToPolicyAndInviteSubmitter(undefined, policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID); + const result = Report.moveIOUReportToPolicyAndInviteSubmitter(undefined, policy, (phone: string) => phone, {}, TEST_USER_ACCOUNT_ID, ''); expect(result).toBeUndefined(); }); }); @@ -4099,7 +4165,17 @@ describe('actions/Report', () => { type: CONST.REPORT.TYPE.EXPENSE, }; const policy = createRandomPolicy(Number(1)); - Report.buildOptimisticChangePolicyData(report, undefined, policy, 1, '', false, true, undefined); + Report.buildOptimisticChangePolicyData({ + report, + parentReport: undefined, + policy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isASAPSubmitBetaEnabled: true, + isReportLastVisibleArchived: undefined, + }); expect(buildNextStepNew).toHaveBeenCalledWith({ report, policy, @@ -4139,7 +4215,17 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, transaction); await waitForBatchedUpdates(); - const {optimisticData, successData, failureData} = Report.buildOptimisticChangePolicyData(report, undefined, policy, 1, '', false, true, undefined); + const {optimisticData, successData, failureData} = Report.buildOptimisticChangePolicyData({ + report, + parentReport: undefined, + policy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isASAPSubmitBetaEnabled: true, + isReportLastVisibleArchived: undefined, + }); // Find the transaction optimistic data const transactionOptimisticData = optimisticData.find((data) => data.key === `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); @@ -4187,7 +4273,17 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, transaction); await waitForBatchedUpdates(); - const {optimisticData} = Report.buildOptimisticChangePolicyData(report, undefined, policy, 1, '', false, true, undefined); + const {optimisticData} = Report.buildOptimisticChangePolicyData({ + report, + parentReport: undefined, + policy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isASAPSubmitBetaEnabled: true, + isReportLastVisibleArchived: undefined, + }); // Should NOT find transaction optimistic data when currencies are the same const transactionOptimisticData = optimisticData.find((data) => data.key === `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); @@ -4222,7 +4318,17 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, transaction); await waitForBatchedUpdates(); - const {optimisticData} = Report.buildOptimisticChangePolicyData(report, undefined, policy, 1, '', false, true, undefined); + const {optimisticData} = Report.buildOptimisticChangePolicyData({ + report, + parentReport: undefined, + policy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isASAPSubmitBetaEnabled: true, + isReportLastVisibleArchived: undefined, + }); // Should NOT find transaction optimistic data when transaction matches destination currency const transactionOptimisticData = optimisticData.find((data) => data.key === `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); @@ -4270,7 +4376,17 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${nonMatchingTransactionID}`, nonMatchingTransaction); await waitForBatchedUpdates(); - const {optimisticData} = Report.buildOptimisticChangePolicyData(report, undefined, policy, 1, '', false, true, undefined); + const {optimisticData} = Report.buildOptimisticChangePolicyData({ + report, + parentReport: undefined, + policy, + currentUserAccountID: 1, + email: '', + managerLogin: '', + hasViolationsParam: false, + isASAPSubmitBetaEnabled: true, + isReportLastVisibleArchived: undefined, + }); // Should NOT find optimistic data for the matching transaction (USD matches USD destination) const matchingOptimisticData = optimisticData.find((data) => data.key === `${ONYXKEYS.COLLECTION.TRANSACTION}${matchingTransactionID}`); diff --git a/tests/unit/ReportSecondaryActionUtilsTest.ts b/tests/unit/ReportSecondaryActionUtilsTest.ts index 554c68fca242..873af72aa2ad 100644 --- a/tests/unit/ReportSecondaryActionUtilsTest.ts +++ b/tests/unit/ReportSecondaryActionUtilsTest.ts @@ -79,6 +79,7 @@ describe('getSecondaryAction', () => { getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -115,6 +116,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -147,6 +149,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -182,6 +185,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -217,6 +221,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -249,6 +254,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -288,6 +294,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -334,6 +341,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction1, transaction2], @@ -365,6 +373,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -413,6 +422,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -447,6 +457,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -486,6 +497,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -531,6 +543,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -571,6 +584,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -610,6 +624,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -648,6 +663,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -690,6 +706,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -734,6 +751,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -777,6 +795,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -817,6 +836,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -854,6 +874,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -891,6 +912,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -925,6 +947,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -950,6 +973,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -978,6 +1002,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1005,6 +1030,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1032,6 +1058,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1060,6 +1087,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1088,6 +1116,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1117,6 +1146,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1147,6 +1177,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1180,6 +1211,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1211,6 +1243,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1258,6 +1291,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [ @@ -1309,6 +1343,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [ @@ -1360,6 +1395,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [ @@ -1411,6 +1447,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [ @@ -1443,6 +1480,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1472,6 +1510,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1501,6 +1540,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1537,6 +1577,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1573,6 +1614,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1606,6 +1648,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -1639,6 +1682,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -1683,6 +1727,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -1728,6 +1773,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], @@ -1788,6 +1834,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], @@ -1848,6 +1895,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], @@ -1908,6 +1956,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], @@ -1934,6 +1983,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [{} as Transaction], @@ -1998,6 +2048,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2043,6 +2094,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2103,6 +2155,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction1, transaction2], @@ -2148,6 +2201,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2198,6 +2252,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction1, transaction2], @@ -2239,6 +2294,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2276,6 +2332,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2328,6 +2385,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2371,6 +2429,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2401,6 +2460,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions, @@ -2435,6 +2495,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions, @@ -2479,6 +2540,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction1], @@ -2510,6 +2572,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -2569,6 +2632,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction1, transaction2], @@ -2610,6 +2674,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2654,6 +2719,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction1], @@ -2687,6 +2753,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2718,6 +2785,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [transaction], @@ -2984,6 +3052,7 @@ describe('getSecondaryExportReportActions', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions, @@ -3116,6 +3185,7 @@ describe('getSecondaryTransactionThreadActions', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport, reportTransactions: [], @@ -3387,6 +3457,7 @@ describe('getSecondaryTransactionThreadActions', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport: undefined, reportTransactions: [transaction], @@ -3441,6 +3512,7 @@ describe('getSecondaryTransactionThreadActions', () => { const result = getSecondaryReportActions({ currentUserLogin: EMPLOYEE_EMAIL, currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + submitterLogin: '', report, chatReport: undefined, reportTransactions: [transaction], @@ -3856,7 +3928,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({type: CONST.REPORT.TYPE.IOU}); const policies = createPolicies(POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(false); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(false); }); it('should return false when IOU report and user is neither submitter nor manager', () => { @@ -3864,7 +3936,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({type: CONST.REPORT.TYPE.IOU}); const policies = createPolicies(POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(false); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(false); }); it('should return false when there are no available policies', () => { @@ -3872,7 +3944,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport(); const policies = createPolicies(POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(false); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(false); }); it('should return false when only one available policy and it is the same as current report policy', () => { @@ -3880,7 +3952,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({policyID: POLICY_ID}); const policies = createPolicies(POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(false); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(false); }); it('should return true when only one available policy but report has no policy', () => { @@ -3888,7 +3960,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({policyID: undefined}); const policies = createPolicies(POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(true); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(true); }); it('should return true when only one available policy and it is different from current report policy', () => { @@ -3896,7 +3968,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({policyID: OLD_POLICY_ID}); const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(true); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(true); }); it('should return false when cannot edit report policy', () => { @@ -3904,7 +3976,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({policyID: OLD_POLICY_ID}); const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(false); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(false); }); it('should return false when report is exported', () => { @@ -3912,7 +3984,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({policyID: OLD_POLICY_ID}); const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, [])).toBe(false); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '', [])).toBe(false); }); it('should return true when multiple available policies exist', () => { @@ -3920,7 +3992,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({policyID: OLD_POLICY_ID}); const policies = createPolicies(POLICY_ID, OLD_POLICY_ID, 'another_policy'); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(true); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(true); }); it('should return true when IOU report with single user and user is submitter', () => { @@ -3928,7 +4000,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({type: CONST.REPORT.TYPE.IOU, policyID: OLD_POLICY_ID}); const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(true); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(true); }); it('should return true when IOU report with single user and user is manager', () => { @@ -3936,7 +4008,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({type: CONST.REPORT.TYPE.IOU, policyID: OLD_POLICY_ID}); const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(true); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(true); }); it('should return true when report is settled and currentUserLogin is admin of available policies', () => { @@ -3947,7 +4019,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({policyID: OLD_POLICY_ID}); const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, ADMIN_EMAIL)).toBe(true); + expect(isChangeWorkspaceAction(report, policies, ADMIN_EMAIL, '')).toBe(true); }); it('should return false when report is settled and currentUserLogin is not admin of any policy', () => { @@ -3958,7 +4030,7 @@ describe('getSecondaryTransactionThreadActions', () => { const report = createReport({policyID: OLD_POLICY_ID}); const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(false); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(false); }); it('should filter policies by admin role using currentUserLogin when report is settled', () => { @@ -3972,9 +4044,9 @@ describe('getSecondaryTransactionThreadActions', () => { const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); // Admin user sees the one eligible policy (POLICY_ID) which differs from report's OLD_POLICY_ID - expect(isChangeWorkspaceAction(report, policies, ADMIN_EMAIL)).toBe(true); + expect(isChangeWorkspaceAction(report, policies, ADMIN_EMAIL, '')).toBe(true); // Non-admin user has all policies filtered out - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(false); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(false); }); it('should not filter policies by admin role when report is not settled', () => { @@ -3986,7 +4058,7 @@ describe('getSecondaryTransactionThreadActions', () => { const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); // Even though isPolicyAdmin returns false, non-settled reports skip the admin check - expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL)).toBe(true); + expect(isChangeWorkspaceAction(report, policies, EMPLOYEE_EMAIL, '')).toBe(true); }); it('should pass currentUserLogin to isPolicyAdmin for each candidate policy when settled', () => { @@ -3998,7 +4070,7 @@ describe('getSecondaryTransactionThreadActions', () => { const policies = createPolicies(POLICY_ID, OLD_POLICY_ID); const testLogin = 'specific-user@mail.com'; - isChangeWorkspaceAction(report, policies, testLogin); + isChangeWorkspaceAction(report, policies, testLogin, ''); const callsWithLogin = mockedIsPolicyAdmin.mock.calls.filter((call: unknown[]) => call.at(1) === testLogin); expect(callsWithLogin.length).toBeGreaterThan(0);