Skip to content

Commit

Permalink
Use finallyData instead of optimisticData
Browse files Browse the repository at this point in the history
  • Loading branch information
aldo-expensify committed Mar 26, 2024
1 parent 2618a35 commit 7ecd3fe
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ function deleteWorkspace(policyID: string, policyName: string) {
}

const filteredPolicies = Object.values(allPolicies).filter((policy): policy is Policy => policy?.id !== policyID);
const successData: OnyxUpdate[] = [];
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -343,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 @@ -370,17 +370,19 @@ 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,
},
});
successData.push({
finallyData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: Object.fromEntries(Object.entries(optimisticReportActions).map(([reportActionID]) => [reportActionID, null])),
value: {
[optimisticClosedReportAction.reportActionID]: null,
},
})
});

Expand Down

0 comments on commit 7ecd3fe

Please sign in to comment.