Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/libs/API/parameters/DeleteWorkspaceParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
type DeleteWorkspaceParams = {
policyID: string;
/**
* Stringified JSON object with type of following structure:
* {
* [reportID]: optimisticReportActionID;
* }>
*/
reportIDToOptimisticCloseReportActionID: string;
};

export default DeleteWorkspaceParams;
11 changes: 5 additions & 6 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
PolicyCategories,
PolicyCategory,
Report,
ReportAction,
ReportActions,
Request,
TaxRatesWithDefault,
Expand Down Expand Up @@ -215,7 +214,7 @@
};

const deprecatedAllPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 217 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (val, key) => {
if (!key) {
Expand All @@ -231,7 +230,7 @@
});

let deprecatedAllReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 233 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -241,7 +240,7 @@

let deprecatedSessionEmail = '';
let deprecatedSessionAccountID = 0;
Onyx.connect({

Check warning on line 243 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
deprecatedSessionEmail = val?.email ?? '';
Expand All @@ -250,25 +249,25 @@
});

let deprecatedAllPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 252 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => (deprecatedAllPersonalDetails = val),
});

let deprecatedAllRecentlyUsedCurrencies: string[];
Onyx.connect({

Check warning on line 258 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.RECENTLY_USED_CURRENCIES,
callback: (val) => (deprecatedAllRecentlyUsedCurrencies = val ?? []),
});

let deprecatedActivePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 264 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (deprecatedActivePolicyID = value),
});

let deprecatedIntroSelected: OnyxEntry<IntroSelected>;
Onyx.connect({

Check warning on line 270 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (value) => (deprecatedIntroSelected = value),
});
Expand Down Expand Up @@ -487,6 +486,7 @@

const finallyData: OnyxUpdate[] = [];
const currentTime = DateUtils.getDBTime();
const reportIDToOptimisticCloseReportActionID: Record<string, string> = {};
for (const report of reportsToArchive) {
const {reportID, ownerAccountID, oldPolicyName} = report ?? {};
const isInvoiceReceiverReport = report?.invoiceReceiver && 'policyID' in report.invoiceReceiver && report.invoiceReceiver.policyID === policyID;
Expand Down Expand Up @@ -527,7 +527,7 @@
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[optimisticClosedReportAction.reportActionID]: optimisticClosedReportAction as ReportAction,
[optimisticClosedReportAction.reportActionID]: optimisticClosedReportAction,
},
});

Expand All @@ -549,15 +549,14 @@
},
});

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

for (const transactionViolationKey of Object.keys(transactionViolations ?? {})) {
const transactionViolation = transactionViolations?.[transactionViolationKey];
Expand Down Expand Up @@ -617,7 +616,7 @@
});
}
}
const apiParams: DeleteWorkspaceParams = {policyID};
const apiParams: DeleteWorkspaceParams = {policyID, reportIDToOptimisticCloseReportActionID: JSON.stringify(reportIDToOptimisticCloseReportActionID)};

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

Expand Down
Loading