Skip to content

Commit

Permalink
Clear the logic in leaveRoom util
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Dec 7, 2023
1 parent 7f6c168 commit 41471e9
Showing 1 changed file with 36 additions and 40 deletions.
76 changes: 36 additions & 40 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2034,54 +2034,50 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal

// If a workspace member is leaving a workspace room, they don't actually lose the room from Onyx.
// Instead, their notification preference just gets set to "hidden".
const optimisticData: OnyxUpdate[] = [];
const successData: OnyxUpdate[] = [];
const failureData: OnyxUpdate[] = [
const optimisticData: OnyxUpdate[] = [
isWorkspaceMemberLeavingWorkspaceRoom
? {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
}
: {
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
reportID,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.CLOSED,
chatType: report.chatType,
parentReportID: report.parentReportID,
parentReportActionID: report.parentReportActionID,
policyID: report.policyID,
type: report.type,
},
},
];
const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: report,
value: isWorkspaceMemberLeavingWorkspaceRoom
? {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}
: Object.keys(report).reduce<Record<string, null>>((acc, key) => {
acc[key] = null;
return acc;
}, {}),
},
];

if (isWorkspaceMemberLeavingWorkspaceRoom) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
});

successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
});
} else {
optimisticData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
reportID,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.CLOSED,
chatType: report.chatType,
parentReportID: report.parentReportID,
parentReportActionID: report.parentReportActionID,
policyID: report.policyID,
type: report.type,
},
});
successData.push({
const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: Object.keys(report).reduce<Record<string, null>>((acc, key) => {
acc[key] = null;
return acc;
}, {}),
});
}
value: report,
},
];

type LeaveRoomParameters = {
reportID: string;
Expand Down

0 comments on commit 41471e9

Please sign in to comment.