Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libs/API/parameters/DeleteWorkspaceParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type DeleteWorkspaceParams = {
policyID: string;
reportIDToOptimisticClosedReportActionID: Record<string, string>;
};

export default DeleteWorkspaceParams;
31 changes: 17 additions & 14 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import type {
PolicyCategory,
ReimbursementAccount,
Report,
ReportAction,
Request,
TaxRatesWithDefault,
Transaction,
Expand Down Expand Up @@ -329,8 +328,12 @@ function deleteWorkspace(policyID: string, policyName: string) {
);
const finallyData: OnyxUpdate[] = [];
const currentTime = DateUtils.getDBTime();
const reportIDToOptimisticClosedReportActionID: Record<string, string> = {};
reportsToArchive.forEach((report) => {
const {reportID, ownerAccountID} = report ?? {};
if (!report) {
return;
}
const {reportID, ownerAccountID} = report;
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
Expand Down Expand Up @@ -361,19 +364,10 @@ function deleteWorkspace(policyID: string, policyName: string) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
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,
[optimisticClosedReportAction.reportActionID]: optimisticClosedReportAction,
},
});
reportIDToOptimisticClosedReportActionID[reportID] = optimisticClosedReportAction.reportActionID;
});

const policy = getPolicy(policyID);
Expand All @@ -394,6 +388,15 @@ function deleteWorkspace(policyID: string, policyName: string) {
},
},
];
Object.entries(reportIDToOptimisticClosedReportActionID).forEach(([reportID, optimisticReportActionID]) => {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[optimisticReportActionID]: null,
},
});
});

reportsToArchive.forEach((report) => {
const {reportID, stateNum, statusNum, oldPolicyName} = report ?? {};
Expand All @@ -411,7 +414,7 @@ function deleteWorkspace(policyID: string, policyName: string) {
});
});

const params: DeleteWorkspaceParams = {policyID};
const params: DeleteWorkspaceParams = {policyID, reportIDToOptimisticClosedReportActionID};

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

Expand Down