diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 0f4582fae1dd..388beee18b70 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -90,7 +90,6 @@ import * as PhoneNumber from '@libs/PhoneNumber'; import { getDefaultApprover, getMemberAccountIDsForWorkspace, - getPolicy, isInstantSubmitEnabled, isPaidGroupPolicy, isPolicyAdmin as isPolicyAdminPolicyUtils, @@ -3037,13 +3036,10 @@ function createNewReport( creatorPersonalDetails: CurrentUserPersonalDetails, hasViolationsParam: boolean, isASAPSubmitBetaEnabled: boolean, - policyID?: string, + policy: OnyxEntry, shouldNotifyNewAction = false, shouldDismissEmptyReportsConfirmation?: boolean, ) { - // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 - // eslint-disable-next-line @typescript-eslint/no-deprecated - const policy = getPolicy(policyID); const optimisticReportID = generateReportID(); const reportActionID = rand64(); const reportPreviewReportActionID = rand64(); @@ -3067,7 +3063,7 @@ function createNewReport( { reportName: optimisticReportName, type: CONST.REPORT.TYPE.EXPENSE, - policyID, + policyID: policy?.id, reportID: optimisticReportID, reportActionID, reportPreviewReportActionID, diff --git a/src/pages/NewReportWorkspaceSelectionPage.tsx b/src/pages/NewReportWorkspaceSelectionPage.tsx index 32b36476304e..2e8f19a85afd 100644 --- a/src/pages/NewReportWorkspaceSelectionPage.tsx +++ b/src/pages/NewReportWorkspaceSelectionPage.tsx @@ -116,7 +116,14 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag const createReport = useCallback( (policyID: string, shouldDismissEmptyReportsConfirmation?: boolean) => { - const optimisticReport = createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policyID, false, shouldDismissEmptyReportsConfirmation); + const optimisticReport = createNewReport( + currentUserPersonalDetails, + isASAPSubmitBetaEnabled, + hasViolations, + policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`], + false, + shouldDismissEmptyReportsConfirmation, + ); const selectedTransactionsKeys = Object.keys(selectedTransactions); if (isMovingExpenses && (!!selectedTransactionsKeys.length || !!selectedTransactionIDs.length)) { diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index a15a16bec888..d32751266e55 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -212,7 +212,7 @@ function EmptySearchViewContent({ const handleCreateWorkspaceReport = useCallback( (shouldDismissEmptyReportsConfirmation?: boolean) => { - if (!defaultChatEnabledPolicyID) { + if (!defaultChatEnabledPolicy?.id) { return; } @@ -220,7 +220,7 @@ function EmptySearchViewContent({ currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, - defaultChatEnabledPolicyID, + defaultChatEnabledPolicy, false, shouldDismissEmptyReportsConfirmation, ); @@ -228,7 +228,7 @@ function EmptySearchViewContent({ Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: createdReportID, backTo: Navigation.getActiveRoute()})); }); }, - [currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicyID, isASAPSubmitBetaEnabled], + [currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled], ); const {openCreateReportConfirmation: openCreateReportFromSearch, CreateReportConfirmationModal} = useCreateEmptyReportConfirmation({ diff --git a/src/pages/Search/SearchTransactionsChangeReport.tsx b/src/pages/Search/SearchTransactionsChangeReport.tsx index e4b7d587deff..a5bf591fb6ad 100644 --- a/src/pages/Search/SearchTransactionsChangeReport.tsx +++ b/src/pages/Search/SearchTransactionsChangeReport.tsx @@ -73,7 +73,7 @@ function SearchTransactionsChangeReport() { }, [selectedTransactions, selectedTransactionsKeys]); const createReportForPolicy = (shouldDismissEmptyReportsConfirmation?: boolean) => { - const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForMovingExpensesID, false, shouldDismissEmptyReportsConfirmation); + const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForMovingExpenses, false, shouldDismissEmptyReportsConfirmation); const reportNextStep = allReportNextSteps?.[`${ONYXKEYS.COLLECTION.NEXT_STEP}${optimisticReport.reportID}`]; setNavigationActionToMicrotaskQueue(() => { changeTransactionsReport( @@ -82,7 +82,7 @@ function SearchTransactionsChangeReport() { session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '', optimisticReport, - policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined, + policyForMovingExpenses, reportNextStep, allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyForMovingExpensesID}`], ); diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index ed0ae4d10bf9..b14bb3d54844 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -198,7 +198,7 @@ function AttachmentPickerWithMenuItems({ policyID: report?.policyID, policyName: policy?.name ?? '', onConfirm: (shouldDismissEmptyReportsConfirmation) => - selectOption(() => createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, report?.policyID, true, shouldDismissEmptyReportsConfirmation), true), + selectOption(() => createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, true, shouldDismissEmptyReportsConfirmation), true), }); const openCreateReportConfirmationRef = useRef(openCreateReportConfirmation); @@ -208,9 +208,9 @@ function AttachmentPickerWithMenuItems({ if (shouldShowEmptyReportConfirmation) { openCreateReportConfirmationRef.current(); } else { - createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, report?.policyID, true, false); + createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, true, false); } - }, [currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, report?.policyID, shouldShowEmptyReportConfirmation]); + }, [currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, shouldShowEmptyReportConfirmation]); const teacherUnitePolicyID = isProduction ? CONST.TEACHERS_UNITE.PROD_POLICY_ID : CONST.TEACHERS_UNITE.TEST_POLICY_ID; const isTeachersUniteReport = report?.policyID === teacherUnitePolicyID; diff --git a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx index 2b76b5ce3c77..acda36fe0523 100644 --- a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx @@ -224,7 +224,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref const handleCreateWorkspaceReport = useCallback( (shouldDismissEmptyReportsConfirmation?: boolean) => { - if (!defaultChatEnabledPolicyID) { + if (!defaultChatEnabledPolicy?.id) { return; } @@ -236,7 +236,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, - defaultChatEnabledPolicyID, + defaultChatEnabledPolicy, false, shouldDismissEmptyReportsConfirmation, ); @@ -249,7 +249,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref ); }); }, - [currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicyID, isASAPSubmitBetaEnabled, isReportInSearch], + [currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, isReportInSearch], ); const {openCreateReportConfirmation: openFabCreateReportConfirmation, CreateReportConfirmationModal: FabCreateReportConfirmationModal} = useCreateEmptyReportConfirmation({ diff --git a/src/pages/iou/request/step/IOURequestEditReport.tsx b/src/pages/iou/request/step/IOURequestEditReport.tsx index 80adc50d2331..c59a549d2e93 100644 --- a/src/pages/iou/request/step/IOURequestEditReport.tsx +++ b/src/pages/iou/request/step/IOURequestEditReport.tsx @@ -45,6 +45,8 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) { const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); const [allPolicyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}`, {canBeMissing: true}); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); + const selectedReportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${selectedReport?.policyID}`]; + const hasPerDiemTransactions = useHasPerDiemTransactions(selectedTransactionIDs); const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(hasPerDiemTransactions); @@ -91,12 +93,12 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) { }; const createReportForPolicy = (shouldDismissEmptyReportsConfirmation?: boolean) => { - if (!hasPerDiemTransactions && !policyForMovingExpensesID) { + if (!hasPerDiemTransactions && !policyForMovingExpenses?.id) { return; } - const policyForNewReportID = hasPerDiemTransactions ? selectedReport?.policyID : policyForMovingExpensesID; - const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForNewReportID, false, shouldDismissEmptyReportsConfirmation); + const policyForNewReport = hasPerDiemTransactions ? selectedReportPolicy : policyForMovingExpenses; + const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForNewReport, false, shouldDismissEmptyReportsConfirmation); selectReport({value: optimisticReport.reportID}, optimisticReport); }; diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 84bb5b6b0883..f944a12d0248 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -178,11 +178,11 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { const shouldShowNotFoundPage = useShowNotFoundPageInIOUStep(action, iouType, reportActionID, reportOrDraftReport, transaction); const createReportForPolicy = (shouldDismissEmptyReportsConfirmation?: boolean) => { - if (!isPerDiemTransaction && !policyForMovingExpensesID) { + if (!isPerDiemTransaction && !policyForMovingExpenses?.id) { return; } - const policyForNewReport = isPerDiemTransaction && perDiemOriginalPolicy ? perDiemOriginalPolicy.id : policyForMovingExpensesID; + const policyForNewReport = isPerDiemTransaction && perDiemOriginalPolicy ? perDiemOriginalPolicy : policyForMovingExpenses; const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForNewReport, false, shouldDismissEmptyReportsConfirmation); handleRegularReportSelection({value: optimisticReport.reportID}, optimisticReport); }; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index ecfd374df0ff..9a787e378554 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -8314,17 +8314,18 @@ describe('actions/IOU', () => { const creatorPersonalDetails = personalDetailsList?.[CARLOS_ACCOUNT_ID] ?? {accountID: CARLOS_ACCOUNT_ID}; const policyID = generatePolicyID(); - createWorkspace({ - policyOwnerEmail: CARLOS_EMAIL, - makeMeAdmin: true, - policyName: "Carlos's Workspace", - policyID, - currency: CONST.CURRENCY.USD, - }); + const mockPolicy: Policy = { + ...createRandomPolicy(1, CONST.POLICY.TYPE.TEAM, "Carlos's Workspace"), + id: policyID, + outputCurrency: CONST.CURRENCY.USD, + owner: CARLOS_EMAIL, + ownerAccountID: CARLOS_ACCOUNT_ID, + pendingAction: undefined, + }; await waitForBatchedUpdates(); - createNewReport(creatorPersonalDetails, true, false, policyID); + createNewReport(creatorPersonalDetails, true, false, mockPolicy); // Create a tracked expense const selfDMReport: Report = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 2e8f0aae252f..a7b377214ba7 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -1761,7 +1761,7 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); mockFetchData.pause(); - const {reportID} = Report.createNewReport({accountID}, true, false, policyID); + const {reportID} = Report.createNewReport({accountID}, true, false, policy); const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); const reportPreviewAction = await new Promise>>((resolve) => { @@ -1834,7 +1834,7 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); mockFetchData.pause(); - Report.createNewReport({accountID}, true, false, policyID); + Report.createNewReport({accountID}, true, false, policy); const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); await new Promise((resolve) => { @@ -1872,7 +1872,7 @@ describe('actions/Report', () => { } // When create new report - Report.createNewReport({accountID}, true, false, policyID); + Report.createNewReport({accountID}, true, false, policy); // Then the parent report's hasOutstandingChildRequest property should remain unchanged await new Promise((resolve) => {