Skip to content

Commit

Permalink
Merge pull request Expensify#36225 from mkhutornyi/fix-35174
Browse files Browse the repository at this point in the history
fix workspace chats and rooms not archived when delete policy offline
  • Loading branch information
cristipaval authored Feb 12, 2024
2 parents 96e4614 + b7ea5b3 commit 6c5bbbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ Onyx.connect({
},
});

let allReports: OnyxCollection<Report> = null;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => (allReports = value),
});

let allPolicyMembers: OnyxCollection<PolicyMember>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY_MEMBERS,
Expand Down Expand Up @@ -218,7 +225,7 @@ function hasActiveFreePolicy(policies: Array<OnyxEntry<Policy>> | PoliciesRecord
/**
* Delete the workspace
*/
function deleteWorkspace(policyID: string, reports: Report[], policyName: string) {
function deleteWorkspace(policyID: string, policyName: string) {
if (!allPolicies) {
return;
}
Expand Down Expand Up @@ -247,7 +254,9 @@ function deleteWorkspace(policyID: string, reports: Report[], policyName: string
: []),
];

reports.forEach(({reportID, ownerAccountID}) => {
const reportsToArchive = Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID && (ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)));
reportsToArchive.forEach((report) => {
const {reportID, ownerAccountID} = report ?? {};
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
Expand Down Expand Up @@ -292,7 +301,8 @@ function deleteWorkspace(policyID: string, reports: Report[], policyName: string
},
];

reports.forEach(({reportID, stateNum, statusNum, hasDraft, oldPolicyName}) => {
reportsToArchive.forEach((report) => {
const {reportID, stateNum, statusNum, hasDraft, oldPolicyName} = report ?? {};
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r
return;
}

Policy.deleteWorkspace(policyIDToDelete, [], policyNameToDelete);
Policy.deleteWorkspace(policyIDToDelete, policyNameToDelete);
setIsDeleteModalOpen(false);
};

Expand Down

0 comments on commit 6c5bbbd

Please sign in to comment.