Skip to content

Commit

Permalink
Merge pull request Expensify#39008 from Expensify/aldo_remove-optimis…
Browse files Browse the repository at this point in the history
…tic-closed-reportactions

Remove optimistic CLOSED actions on success
  • Loading branch information
yuwenmemon authored Mar 26, 2024
2 parents 20f083f + 704e854 commit 29fd425
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ function deleteWorkspace(policyID: string, policyName: string) {
const reportsToArchive = Object.values(allReports ?? {}).filter(
(report) => report?.policyID === policyID && (ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isTaskReport(report)),
);
const finallyData: OnyxUpdate[] = [];
reportsToArchive.forEach((report) => {
const {reportID, ownerAccountID} = report ?? {};
optimisticData.push({
Expand Down Expand Up @@ -369,12 +370,22 @@ function deleteWorkspace(policyID: string, policyName: string) {
emailClosingReport = allPersonalDetails?.[ownerAccountID]?.login ?? '';
}
const optimisticClosedReportAction = ReportUtils.buildOptimisticClosedReportAction(emailClosingReport, policyName, CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED);
const optimisticReportActions: Record<string, ReportAction> = {};
optimisticReportActions[optimisticClosedReportAction.reportActionID] = optimisticClosedReportAction as ReportAction;
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: optimisticReportActions,
value: {
[optimisticClosedReportAction.reportActionID]: optimisticClosedReportAction as ReportAction,
},
});

// We are temporarily adding this workaround because 'DeleteWorkspace' doesn't
// support receiving the optimistic reportActions' ids for the moment.
finallyData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[optimisticClosedReportAction.reportActionID]: null,
},
});
});

Expand Down Expand Up @@ -406,7 +417,7 @@ function deleteWorkspace(policyID: string, policyName: string) {

const params: DeleteWorkspaceParams = {policyID};

API.write(WRITE_COMMANDS.DELETE_WORKSPACE, params, {optimisticData, failureData});
API.write(WRITE_COMMANDS.DELETE_WORKSPACE, params, {optimisticData, finallyData, failureData});

// Reset the lastAccessedWorkspacePolicyID
if (policyID === lastAccessedWorkspacePolicyID) {
Expand Down

0 comments on commit 29fd425

Please sign in to comment.