From 0cabc49b11a58dc90f0a52ef0be4b351b181bc04 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 31 Oct 2023 18:31:28 +0700 Subject: [PATCH 1/6] fix: invite and remove member when offline in workspace --- src/libs/ReportUtils.js | 12 +++++++ src/libs/actions/Policy.js | 70 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 21c29a07ebae..de7f30e1a376 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4124,6 +4124,17 @@ function shouldUseFullTitleToDisplay(report) { return isMoneyRequestReport(report) || isPolicyExpenseChat(report) || isChatRoom(report) || isChatThread(report) || isTaskReport(report); } +/** + * + * @param {String} type + * @param {String} policyID + * @returns {Object} + */ +function getRoom(type, policyID) { + const room = _.find(allReports, (report) => report && report.policyID === policyID && report.chatType === type && !isThread(report)); + return room; +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -4281,4 +4292,5 @@ export { shouldUseFullTitleToDisplay, parseReportRouteParams, getReimbursementQueuedActionMessage, + getRoom, }; diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 8060e737bd22..d25365201621 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -213,6 +213,69 @@ function hasActiveFreePolicy(policies) { return true; } +/** + * + * @param {String} policyID + * @param {Object} invitedEmailsToAccountIDs + * @returns {Object} + */ +function createOptimisticAnnounceRoomMembers(policyID, invitedEmailsToAccountIDs) { + const announceReport = ReportUtils.getRoom(CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, policyID); + const announceRoomMembers = { + onyxOptimisticData: [], + onyxFailureData: [], + }; + + announceRoomMembers.onyxOptimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, + value: { + participantAccountIDs: [...announceReport.participantAccountIDs, ..._.values(invitedEmailsToAccountIDs)], + }, + }); + + announceRoomMembers.onyxFailureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, + value: { + participantAccountIDs: announceReport.participantAccountIDs, + }, + }); + return announceRoomMembers; +} + +/** + * + * @param {String} policyID + * @param {Array} accountIDs + * @returns {Object} + */ +function removeOptimisticAnnounceRoomMembers(policyID, accountIDs) { + const announceReport = ReportUtils.getRoom(CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, policyID); + const announceRoomMembers = { + onyxOptimisticData: [], + onyxFailureData: [], + }; + + const remainUsers = _.difference(announceReport.participantAccountIDs, accountIDs); + announceRoomMembers.onyxOptimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, + value: { + participantAccountIDs: [...remainUsers], + }, + }); + + announceRoomMembers.onyxFailureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, + value: { + participantAccountIDs: announceReport.participantAccountIDs, + }, + }); + return announceRoomMembers; +} + /** * Remove the passed members from the policy employeeList * @@ -233,6 +296,8 @@ function removeMembers(accountIDs, policyID) { ReportUtils.buildOptimisticClosedReportAction(sessionEmail, policy.name, CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY), ); + const announceRoomMembers = removeOptimisticAnnounceRoomMembers(policyID, accountIDs); + const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -254,6 +319,7 @@ function removeMembers(accountIDs, policyID) { key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChats[index].reportID}`, value: {[reportAction.reportActionID]: reportAction}, })), + ...announceRoomMembers.onyxOptimisticData, ]; // If the policy has primaryLoginsInvited, then it displays informative messages on the members page about which primary logins were added by secondary logins. @@ -305,6 +371,7 @@ function removeMembers(accountIDs, policyID) { key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChats[index].reportID}`, value: {[reportAction.reportActionID]: null}, })), + ...announceRoomMembers.onyxFailureData, ]; API.write( 'DeleteMembersFromWorkspace', @@ -420,6 +487,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID) const accountIDs = _.values(invitedEmailsToAccountIDs); const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, accountIDs); + const announceRoomMembers = createOptimisticAnnounceRoomMembers(policyID, invitedEmailsToAccountIDs); // create onyx data for policy expense chats for each new member const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs); @@ -433,6 +501,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID) }, ...newPersonalDetailsOnyxData.optimisticData, ...membersChats.onyxOptimisticData, + ...announceRoomMembers.onyxOptimisticData, ]; const successData = [ @@ -480,6 +549,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID) }, ...newPersonalDetailsOnyxData.failureData, ...membersChats.onyxFailureData, + ...announceRoomMembers.onyxFailureData, ]; const params = { From 227ce6f78b7695749b16af526cd64dc699f90dc6 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 31 Oct 2023 18:34:30 +0700 Subject: [PATCH 2/6] fix: add comments for functions in policy --- src/libs/actions/Policy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index d25365201621..6f8e3912b499 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -214,7 +214,7 @@ function hasActiveFreePolicy(policies) { } /** - * + * Build optimistic data for adding users from announce room * @param {String} policyID * @param {Object} invitedEmailsToAccountIDs * @returns {Object} @@ -245,7 +245,7 @@ function createOptimisticAnnounceRoomMembers(policyID, invitedEmailsToAccountIDs } /** - * + * Build optimistic data for removing users from announce room * @param {String} policyID * @param {Array} accountIDs * @returns {Object} From 920f00200b4dee2c585f5cd4bc302028ac568318 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 1 Nov 2023 14:15:16 +0700 Subject: [PATCH 3/6] fix: comments --- src/libs/actions/Policy.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 6f8e3912b499..d14d6142402e 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -214,12 +214,12 @@ function hasActiveFreePolicy(policies) { } /** - * Build optimistic data for adding users from announce room + * Build optimistic data to the announce room * @param {String} policyID - * @param {Object} invitedEmailsToAccountIDs + * @param {Array} accountIDs * @returns {Object} */ -function createOptimisticAnnounceRoomMembers(policyID, invitedEmailsToAccountIDs) { +function buildAnnounceRoomMembersOnyxData(policyID, accountIDs) { const announceReport = ReportUtils.getRoom(CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, policyID); const announceRoomMembers = { onyxOptimisticData: [], @@ -230,7 +230,7 @@ function createOptimisticAnnounceRoomMembers(policyID, invitedEmailsToAccountIDs onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { - participantAccountIDs: [...announceReport.participantAccountIDs, ..._.values(invitedEmailsToAccountIDs)], + participantAccountIDs: [...announceReport.participantAccountIDs, ...accountIDs], }, }); @@ -245,7 +245,7 @@ function createOptimisticAnnounceRoomMembers(policyID, invitedEmailsToAccountIDs } /** - * Build optimistic data for removing users from announce room + * Build optimistic data for removing users to the announce room * @param {String} policyID * @param {Array} accountIDs * @returns {Object} @@ -487,7 +487,8 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID) const accountIDs = _.values(invitedEmailsToAccountIDs); const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, accountIDs); - const announceRoomMembers = createOptimisticAnnounceRoomMembers(policyID, invitedEmailsToAccountIDs); + const announceRoomMembers = buildAnnounceRoomMembersOnyxData(policyID, accountIDs); + // create onyx data for policy expense chats for each new member const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs); From 20ca6e9736fb8e14fae9b7f103e3ee99c3f8140a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 2 Nov 2023 09:14:43 +0700 Subject: [PATCH 4/6] update comments --- src/libs/actions/Policy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index d14d6142402e..795441d4060a 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -214,7 +214,7 @@ function hasActiveFreePolicy(policies) { } /** - * Build optimistic data to the announce room + * Build optimistic data for adding users from announce room * @param {String} policyID * @param {Array} accountIDs * @returns {Object} @@ -245,7 +245,7 @@ function buildAnnounceRoomMembersOnyxData(policyID, accountIDs) { } /** - * Build optimistic data for removing users to the announce room + * Build optimistic data for removing users from the announce room * @param {String} policyID * @param {Array} accountIDs * @returns {Object} From a27d594025b5bc1d0a5bdd895e4e24d6acb5a23f Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 2 Nov 2023 09:19:29 +0700 Subject: [PATCH 5/6] update comments for policy function --- src/libs/actions/Policy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 795441d4060a..36ea52446906 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -214,7 +214,7 @@ function hasActiveFreePolicy(policies) { } /** - * Build optimistic data for adding users from announce room + * Build optimistic data for adding members to the announce room * @param {String} policyID * @param {Array} accountIDs * @returns {Object} From 8d5241d9b0ff19e4f739b12307b46122bd58d42f Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 6 Nov 2023 10:43:12 +0700 Subject: [PATCH 6/6] fix lint issue --- src/styles/fontFamily/multiFontFamily.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/styles/fontFamily/multiFontFamily.ts b/src/styles/fontFamily/multiFontFamily.ts index 14f64d406954..5bd89e0d4bcb 100644 --- a/src/styles/fontFamily/multiFontFamily.ts +++ b/src/styles/fontFamily/multiFontFamily.ts @@ -1,7 +1,7 @@ +import getOperatingSystem from '@libs/getOperatingSystem'; +import CONST from '@src/CONST'; import {multiBold} from './bold'; import FontFamilyStyles from './types'; -import CONST from '../../CONST'; -import getOperatingSystem from '../../libs/getOperatingSystem'; // In windows and ubuntu, we need some extra system fonts for emojis to work properly // otherwise few of them will appear as black and white