From cbcee0fa9c0a9bf1d1d38efd3d2cff8c9093494d Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 26 Mar 2024 16:37:30 +0530 Subject: [PATCH 1/3] hide approve button post submit for submit and close policy --- src/libs/actions/IOU.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 85ab98bb78191..7b2bc6e6e4036 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4526,8 +4526,9 @@ function canApproveIOU(iouReport: OnyxEntry | EmptyObject, cha const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport); const isApproved = ReportUtils.isReportApproved(iouReport); const iouSettled = ReportUtils.isSettled(iouReport?.reportID); + const isArchivedReport = ReportUtils.isArchivedRoom(iouReport); - return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled; + return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled && !isArchivedReport; } function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chatReport: OnyxEntry | EmptyObject, policy: OnyxEntry | EmptyObject) { @@ -4666,6 +4667,7 @@ function submitReport(expenseReport: OnyxTypes.Report) { const policy = ReportUtils.getPolicy(expenseReport.policyID); const isCurrentUserManager = currentUserPersonalDetails.accountID === expenseReport.managerID; const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED); + const isSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); const optimisticData: OnyxUpdate[] = [ { @@ -4685,8 +4687,8 @@ function submitReport(expenseReport: OnyxTypes.Report) { ...expenseReport, lastMessageText: optimisticSubmittedReportAction.message?.[0].text ?? '', lastMessageHtml: optimisticSubmittedReportAction.message?.[0].html ?? '', - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + stateNum: isSubmitAndClosePolicy ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: isSubmitAndClosePolicy ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.SUBMITTED, }, }, { From b1bedb4443362a770302812d3cf6019f59f57b3f Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 26 Mar 2024 21:24:16 +0530 Subject: [PATCH 2/3] do not show submitted action --- src/libs/actions/IOU.ts | 109 +++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 46 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 7b2bc6e6e4036..843e664306393 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4669,34 +4669,46 @@ function submitReport(expenseReport: OnyxTypes.Report) { const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED); const isSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, - value: { - [optimisticSubmittedReportAction.reportActionID]: { - ...(optimisticSubmittedReportAction as OnyxTypes.ReportAction), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, - value: { - ...expenseReport, - lastMessageText: optimisticSubmittedReportAction.message?.[0].text ?? '', - lastMessageHtml: optimisticSubmittedReportAction.message?.[0].html ?? '', - stateNum: isSubmitAndClosePolicy ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: isSubmitAndClosePolicy ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.SUBMITTED, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, - value: optimisticNextStep, - }, - ]; + const optimisticData: OnyxUpdate[] = !isSubmitAndClosePolicy + ? [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, + value: { + [optimisticSubmittedReportAction.reportActionID]: { + ...(optimisticSubmittedReportAction as OnyxTypes.ReportAction), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, + value: { + ...expenseReport, + lastMessageText: optimisticSubmittedReportAction.message?.[0].text ?? '', + lastMessageHtml: optimisticSubmittedReportAction.message?.[0].html ?? '', + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, + value: optimisticNextStep, + }, + ] + : [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, + value: { + ...expenseReport, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.CLOSED, + }, + }, + ]; if (parentReport?.reportID) { optimisticData.push({ @@ -4711,8 +4723,9 @@ function submitReport(expenseReport: OnyxTypes.Report) { }); } - const successData: OnyxUpdate[] = [ - { + const successData: OnyxUpdate[] = []; + if (!isSubmitAndClosePolicy) { + successData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, value: { @@ -4720,19 +4733,10 @@ function submitReport(expenseReport: OnyxTypes.Report) { pendingAction: null, }, }, - }, - ]; + }); + } const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, - value: { - [optimisticSubmittedReportAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError('iou.error.other'), - }, - }, - }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, @@ -4741,12 +4745,25 @@ function submitReport(expenseReport: OnyxTypes.Report) { stateNum: CONST.REPORT.STATE_NUM.OPEN, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, - value: currentNextStep, - }, ]; + if (!isSubmitAndClosePolicy) { + failureData.push( + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, + value: { + [optimisticSubmittedReportAction.reportActionID]: { + pendingAction: null, + }, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, + value: currentNextStep, + }, + ); + } if (parentReport?.reportID) { failureData.push({ From 247b02e3bf97727d70a35a2b4443d8a85cd5514b Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 1 Apr 2024 17:57:17 +0530 Subject: [PATCH 3/3] failureData fix --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 6542cd51d3307..61957434c2504 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4806,7 +4806,7 @@ function submitReport(expenseReport: OnyxTypes.Report) { key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, value: { [optimisticSubmittedReportAction.reportActionID]: { - pendingAction: null, + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.other'), }, }, },