diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 15ba2d8bbb8b..43a991b56c06 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -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>((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>((acc, key) => { - acc[key] = null; - return acc; - }, {}), - }); - } + value: report, + }, + ]; type LeaveRoomParameters = { reportID: string;