From a2eb3fcda12cad432e91e0c3f6b53b45f6e73334 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 6 Feb 2024 16:03:49 +0700 Subject: [PATCH 01/22] add pending action member for report --- src/libs/actions/Policy.ts | 36 +++++++++++++++++++++++++++++ src/libs/actions/Report.ts | 33 +++++++++++++++++++++++--- src/pages/ReportParticipantsPage.js | 2 ++ src/pages/RoomMembersPage.js | 2 ++ src/types/onyx/Report.ts | 10 +++++++- 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index b47891e64350..5ae4e320d95b 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -26,6 +26,7 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject'; type AnnounceRoomMembersOnyxData = { onyxOptimisticData: OnyxUpdate[]; + onyxSuccessData: OnyxUpdate[]; onyxFailureData: OnyxUpdate[]; }; @@ -305,6 +306,7 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] const announceRoomMembers: AnnounceRoomMembersOnyxData = { onyxOptimisticData: [], onyxFailureData: [], + onyxSuccessData: [], }; if (!announceReport) { @@ -314,6 +316,13 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] if (announceReport?.participantAccountIDs) { // Everyone in special policy rooms is visible const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs]; + const pendingAccountIDs = accountIDs.map((accountID) => { + return { + accountID: accountID.toString(), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }; + }); + const pendingVisibleChatMembers = [...(announceReport?.pendingVisibleChatMembers || []), ...pendingAccountIDs]; announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -321,6 +330,7 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] value: { participantAccountIDs, visibleChatMemberAccountIDs: participantAccountIDs, + pendingVisibleChatMembers, }, }); } @@ -331,6 +341,14 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] value: { participantAccountIDs: announceReport?.participantAccountIDs, visibleChatMemberAccountIDs: announceReport?.visibleChatMemberAccountIDs, + pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers, + }, + }); + announceRoomMembers.onyxSuccessData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport?.reportID}`, + value: { + pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers, }, }); return announceRoomMembers; @@ -344,6 +362,7 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe const announceRoomMembers: AnnounceRoomMembersOnyxData = { onyxOptimisticData: [], onyxFailureData: [], + onyxSuccessData: [], }; if (!announceReport) { @@ -352,12 +371,21 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe if (announceReport?.participantAccountIDs) { const remainUsers = announceReport.participantAccountIDs.filter((e) => !accountIDs.includes(e)); + const pendingAccountIDs = accountIDs.map((accountID) => { + return { + accountID: accountID.toString(), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + }; + }); + const pendingVisibleChatMembers = [...(announceReport?.pendingVisibleChatMembers || []), ...pendingAccountIDs]; + announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { participantAccountIDs: [...remainUsers], visibleChatMemberAccountIDs: [...remainUsers], + pendingVisibleChatMembers, }, }); @@ -367,6 +395,14 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe value: { participantAccountIDs: announceReport.participantAccountIDs, visibleChatMemberAccountIDs: announceReport.visibleChatMemberAccountIDs, + pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers, + }, + }); + announceRoomMembers.onyxSuccessData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, + value: { + pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers, }, }); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 36ac445a78d4..bd302e4be446 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -34,7 +34,7 @@ import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import type {PersonalDetails, PersonalDetailsList, ReportActionReactions, ReportUserIsTyping} from '@src/types/onyx'; import type {Decision, OriginalMessageIOU} from '@src/types/onyx/OriginalMessage'; -import type {NotificationPreference, WriteCapability} from '@src/types/onyx/Report'; +import type {NotificationPreference, PendingChatMember, WriteCapability} from '@src/types/onyx/Report'; import type Report from '@src/types/onyx/Report'; import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction'; import type ReportAction from '@src/types/onyx/ReportAction'; @@ -2202,6 +2202,13 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin)); const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, inviteeAccountIDs); + const pendingAccountIDs = inviteeAccountIDs.map((accountID) => { + return { + accountID: accountID.toString(), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }; + }); + const pendingVisibleChatMembers = [...(report?.pendingVisibleChatMembers || []), ...pendingAccountIDs]; const optimisticData: OnyxUpdate[] = [ { @@ -2210,13 +2217,22 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record !targetAccountIDs.includes(id)); const visibleChatMemberAccountIDsAfterRemoval = report?.visibleChatMemberAccountIDs?.filter((id: number) => !targetAccountIDs.includes(id)); + const pendingAccountIDs = targetAccountIDs.map((accountID) => { + return { + accountID: accountID.toString(), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + }; + }); + const pendingVisibleChatMembers = [...(report?.pendingVisibleChatMembers || []), ...pendingAccountIDs]; const optimisticData: OnyxUpdate[] = [ { @@ -2256,6 +2280,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) { value: { participantAccountIDs: participantAccountIDsAfterRemoval, visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval, + pendingVisibleChatMembers, }, }, ]; @@ -2267,6 +2292,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) { value: { participantAccountIDs: report?.participantAccountIDs, visibleChatMemberAccountIDs: report?.visibleChatMemberAccountIDs, + pendingVisibleChatMembers: report?.pendingVisibleChatMembers, }, }, ]; @@ -2280,6 +2306,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) { value: { participantAccountIDs: participantAccountIDsAfterRemoval, visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval, + pendingVisibleChatMembers: report?.pendingVisibleChatMembers, }, }, ]; diff --git a/src/pages/ReportParticipantsPage.js b/src/pages/ReportParticipantsPage.js index 7dbc1c7036c4..e4239fe422a0 100755 --- a/src/pages/ReportParticipantsPage.js +++ b/src/pages/ReportParticipantsPage.js @@ -62,8 +62,10 @@ const getAllParticipants = (report, personalDetails, translate) => const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login || '') || translate('common.hidden'); const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); + const pendingVisibleChatMember = _.find(report.pendingVisibleChatMemberAccountIDs, (member) => member.accountID === accountID); return { alternateText: userLogin, + pendingAction: pendingVisibleChatMember.pendingAction || null, displayName, accountID: userPersonalDetail.accountID, icons: [ diff --git a/src/pages/RoomMembersPage.js b/src/pages/RoomMembersPage.js index 30ffd60aa4ac..f4a89fd0fa79 100644 --- a/src/pages/RoomMembersPage.js +++ b/src/pages/RoomMembersPage.js @@ -205,6 +205,7 @@ function RoomMembersPage(props) { return; } } + const pendingVisibleChatMember = _.find(props.report.pendingVisibleChatMemberAccountIDs, (member) => member.accountID === accountID); result.push({ keyForList: String(accountID), @@ -220,6 +221,7 @@ function RoomMembersPage(props) { type: CONST.ICON_TYPE_AVATAR, }, ], + pendingAction: pendingVisibleChatMember.pendingAction || null, }); }); diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 5a22313a3f48..a8b8bf0f4a76 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -13,6 +13,11 @@ type Note = { pendingAction?: OnyxCommon.PendingAction; }; +type PendingChatMember = { + accountID: string; + pendingAction: OnyxCommon.PendingAction; +}; + type Report = { /** The specific type of chat */ chatType?: ValueOf; @@ -161,8 +166,11 @@ type Report = { /** If the report contains reportFields, save the field id and its value */ reportFields?: Record; + + /** Pending member of the report */ + pendingVisibleChatMembers: PendingChatMember[]; }; export default Report; -export type {NotificationPreference, WriteCapability, Note}; +export type {NotificationPreference, WriteCapability, Note, PendingChatMember}; From cdc42c52973f46cedb943bd77753998eadb22697 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 6 Feb 2024 16:19:18 +0700 Subject: [PATCH 02/22] optional --- src/types/onyx/Report.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 36c39d52f28f..bd7a517226d0 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -181,7 +181,7 @@ type Report = { reportFields?: Record; /** Pending member of the report */ - pendingVisibleChatMembers: PendingChatMember[]; + pendingVisibleChatMembers?: PendingChatMember[]; }; export default Report; From 45aa3c57c8c9199e392740de949d28e5e695944e Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 6 Feb 2024 16:30:27 +0700 Subject: [PATCH 03/22] fix type check --- src/pages/ReportParticipantsPage.tsx | 5 +++-- src/pages/RoomMembersPage.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 56dc3e1204b2..37c21423a5f2 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -2,6 +2,7 @@ import React from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; +import lodashFind from 'lodash/find'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import OptionsList from '@components/OptionsList'; @@ -48,10 +49,10 @@ const getAllParticipants = ( const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail?.login ?? '') ?? translate('common.hidden'); const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); - const pendingVisibleChatMember = _.find(report.pendingVisibleChatMemberAccountIDs, (member) => member.accountID === accountID); + const pendingVisibleChatMember = lodashFind(report?.pendingVisibleChatMembers, (member) => member.accountID === accountID.toString()); return { alternateText: userLogin, - pendingAction: pendingVisibleChatMember.pendingAction || null, + pendingAction: pendingVisibleChatMember?.pendingAction || undefined, displayName, accountID: userPersonalDetail?.accountID ?? accountID, icons: [ diff --git a/src/pages/RoomMembersPage.js b/src/pages/RoomMembersPage.js index f4a89fd0fa79..14df38dc0410 100644 --- a/src/pages/RoomMembersPage.js +++ b/src/pages/RoomMembersPage.js @@ -205,7 +205,7 @@ function RoomMembersPage(props) { return; } } - const pendingVisibleChatMember = _.find(props.report.pendingVisibleChatMemberAccountIDs, (member) => member.accountID === accountID); + const pendingVisibleChatMember = _.find(props.report.pendingVisibleChatMembers, (member) => member.accountID === accountID); result.push({ keyForList: String(accountID), @@ -221,7 +221,7 @@ function RoomMembersPage(props) { type: CONST.ICON_TYPE_AVATAR, }, ], - pendingAction: pendingVisibleChatMember.pendingAction || null, + pendingAction: pendingVisibleChatMember.pendingAction || undefined, }); }); From 26b612fe5a79a7298093f1b17d47fd2d0b741399 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 6 Feb 2024 17:00:55 +0700 Subject: [PATCH 04/22] fix type check --- src/libs/actions/Policy.ts | 21 +++++++-------------- src/libs/actions/Report.ts | 20 +++++--------------- src/pages/ReportParticipantsPage.tsx | 6 +++--- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 6d8e729d7825..f4b198711759 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -329,13 +329,8 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] if (announceReport?.participantAccountIDs) { // Everyone in special policy rooms is visible const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs]; - const pendingAccountIDs = accountIDs.map((accountID) => { - return { - accountID: accountID.toString(), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }; - }); - const pendingVisibleChatMembers = [...(announceReport?.pendingVisibleChatMembers || []), ...pendingAccountIDs]; + const pendingAccountIDs = accountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})); + const pendingVisibleChatMembers = [...(announceReport?.pendingVisibleChatMembers ?? []), ...pendingAccountIDs]; announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -384,13 +379,11 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe if (announceReport?.participantAccountIDs) { const remainUsers = announceReport.participantAccountIDs.filter((e) => !accountIDs.includes(e)); - const pendingAccountIDs = accountIDs.map((accountID) => { - return { - accountID: accountID.toString(), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, - }; - }); - const pendingVisibleChatMembers = [...(announceReport?.pendingVisibleChatMembers || []), ...pendingAccountIDs]; + const pendingAccountIDs = accountIDs.map((accountID) => ({ + accountID: accountID.toString(), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + })); + const pendingVisibleChatMembers = [...(announceReport?.pendingVisibleChatMembers ?? []), ...pendingAccountIDs]; announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index a44fe1e81a84..f1c7e13bcd07 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -68,7 +68,7 @@ import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import type {PersonalDetails, PersonalDetailsList, PolicyReportField, RecentlyUsedReportFields, ReportActionReactions, ReportMetadata, ReportUserIsTyping} from '@src/types/onyx'; import type {Decision, OriginalMessageIOU} from '@src/types/onyx/OriginalMessage'; -import type {NotificationPreference, PendingChatMember, WriteCapability} from '@src/types/onyx/Report'; +import type {NotificationPreference, WriteCapability} from '@src/types/onyx/Report'; import type Report from '@src/types/onyx/Report'; import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction'; import type ReportAction from '@src/types/onyx/ReportAction'; @@ -2308,13 +2308,8 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin)); const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, inviteeAccountIDs); - const pendingAccountIDs = inviteeAccountIDs.map((accountID) => { - return { - accountID: accountID.toString(), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }; - }); - const pendingVisibleChatMembers = [...(report?.pendingVisibleChatMembers || []), ...pendingAccountIDs]; + const pendingAccountIDs = inviteeAccountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})); + const pendingVisibleChatMembers = [...(report?.pendingVisibleChatMembers ?? []), ...pendingAccountIDs]; const optimisticData: OnyxUpdate[] = [ { @@ -2366,13 +2361,8 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) { const participantAccountIDsAfterRemoval = report?.participantAccountIDs?.filter((id: number) => !targetAccountIDs.includes(id)); const visibleChatMemberAccountIDsAfterRemoval = report?.visibleChatMemberAccountIDs?.filter((id: number) => !targetAccountIDs.includes(id)); - const pendingAccountIDs = targetAccountIDs.map((accountID) => { - return { - accountID: accountID.toString(), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, - }; - }); - const pendingVisibleChatMembers = [...(report?.pendingVisibleChatMembers || []), ...pendingAccountIDs]; + const pendingAccountIDs = targetAccountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE})); + const pendingVisibleChatMembers = [...(report?.pendingVisibleChatMembers ?? []), ...pendingAccountIDs]; const optimisticData: OnyxUpdate[] = [ { diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 37c21423a5f2..87e658694cdf 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -1,8 +1,8 @@ +import lodashFind from 'lodash/find'; import React from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; -import lodashFind from 'lodash/find'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import OptionsList from '@components/OptionsList'; @@ -49,10 +49,10 @@ const getAllParticipants = ( const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail?.login ?? '') ?? translate('common.hidden'); const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); - const pendingVisibleChatMember = lodashFind(report?.pendingVisibleChatMembers, (member) => member.accountID === accountID.toString()); + const pendingVisibleChatMember = (report?.pendingVisibleChatMembers ?? []).find((member) => member.accountID === accountID.toString()); return { alternateText: userLogin, - pendingAction: pendingVisibleChatMember?.pendingAction || undefined, + pendingAction: pendingVisibleChatMember?.pendingAction, displayName, accountID: userPersonalDetail?.accountID ?? accountID, icons: [ From f61c018c08c455a0e59e0de82164808077737681 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 6 Feb 2024 17:06:01 +0700 Subject: [PATCH 05/22] fix type check --- src/pages/ReportParticipantsPage.tsx | 1 - src/pages/RoomMembersPage.js | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 87e658694cdf..434757d00da4 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -1,4 +1,3 @@ -import lodashFind from 'lodash/find'; import React from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; diff --git a/src/pages/RoomMembersPage.js b/src/pages/RoomMembersPage.js index 14df38dc0410..26407cf6e9fc 100644 --- a/src/pages/RoomMembersPage.js +++ b/src/pages/RoomMembersPage.js @@ -3,6 +3,7 @@ import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; +import lodashGet from 'lodash/get'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import Button from '@components/Button'; import ConfirmModal from '@components/ConfirmModal'; @@ -221,7 +222,7 @@ function RoomMembersPage(props) { type: CONST.ICON_TYPE_AVATAR, }, ], - pendingAction: pendingVisibleChatMember.pendingAction || undefined, + pendingAction: lodashGet(pendingVisibleChatMember, 'pendingAction', undefined) }); }); From 952005b7249ab81c140beb88da872839f3b7b695 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 6 Feb 2024 17:23:33 +0700 Subject: [PATCH 06/22] fix lint --- src/pages/RoomMembersPage.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/RoomMembersPage.js b/src/pages/RoomMembersPage.js index 26407cf6e9fc..6dec2b410001 100644 --- a/src/pages/RoomMembersPage.js +++ b/src/pages/RoomMembersPage.js @@ -1,9 +1,9 @@ +import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; -import lodashGet from 'lodash/get'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import Button from '@components/Button'; import ConfirmModal from '@components/ConfirmModal'; @@ -206,7 +206,7 @@ function RoomMembersPage(props) { return; } } - const pendingVisibleChatMember = _.find(props.report.pendingVisibleChatMembers, (member) => member.accountID === accountID); + const pendingVisibleChatMember = _.find(props.report.pendingVisibleChatMembers, (member) => member.accountID === accountID.toString()); result.push({ keyForList: String(accountID), @@ -222,7 +222,7 @@ function RoomMembersPage(props) { type: CONST.ICON_TYPE_AVATAR, }, ], - pendingAction: lodashGet(pendingVisibleChatMember, 'pendingAction', undefined) + pendingAction: lodashGet(pendingVisibleChatMember, 'pendingAction', undefined), }); }); From 21c0c56ec6f6eda7c4111e3af1d19d688807e82b Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 9 Feb 2024 02:03:21 +0700 Subject: [PATCH 07/22] update pending member for workspace expense chat --- src/libs/actions/Policy.ts | 57 ++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index f4b198711759..4d0575c40ad8 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -451,6 +451,25 @@ function removeMembers(accountIDs: number[], policyID: string) { ...announceRoomMembers.onyxOptimisticData, ]; + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: membersListKey, + value: successMembersState, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: membersListKey, + value: failureMembersState, + }, + ...announceRoomMembers.onyxFailureData, + ]; + + const pendingVisibleChatMembers = accountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})); + workspaceChats.forEach((report) => { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -460,6 +479,21 @@ function removeMembers(accountIDs: number[], policyID: string) { stateNum: CONST.REPORT.STATE_NUM.APPROVED, oldPolicyName: policy.name, hasDraft: false, + pendingVisibleChatMembers, + }, + }); + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`, + value: { + pendingVisibleChatMembers: null, + }, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`, + value: { + pendingVisibleChatMembers: null, }, }); }); @@ -496,23 +530,7 @@ function removeMembers(accountIDs: number[], policyID: string) { } } - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: membersListKey, - value: successMembersState, - }, - ]; - const filteredWorkspaceChats = workspaceChats.filter((report): report is Report => report !== null); - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: membersListKey, - value: failureMembersState, - }, - ...announceRoomMembers.onyxFailureData, - ]; filteredWorkspaceChats.forEach(({reportID, stateNum, statusNum, hasDraft, oldPolicyName = null}) => { failureData.push({ @@ -579,7 +597,10 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: R } const optimisticReport = ReportUtils.buildOptimisticChatReport([sessionAccountID, cleanAccountID], undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID, cleanAccountID); const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(login); - + const pendingVisibleChatMembers = Object.values(invitedEmailsToAccountIDs).map((accountID) => ({ + accountID: accountID.toString(), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + })); workspaceMembersChats.reportCreationData[login] = { reportID: optimisticReport.reportID, reportActionID: optimisticCreatedAction.reportActionID, @@ -595,6 +616,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: R }, isOptimisticReport: true, hasOutstandingChildRequest, + pendingVisibleChatMembers, }, }); workspaceMembersChats.onyxOptimisticData.push({ @@ -614,6 +636,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: R createChat: null, }, isOptimisticReport: false, + pendingVisibleChatMembers: null, }, }); workspaceMembersChats.onyxSuccessData.push({ From c7bc82de25b3ff5cbd434223e23fd5c8dcce9287 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 9 Feb 2024 02:12:57 +0700 Subject: [PATCH 08/22] update --- src/libs/actions/Policy.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 4d0575c40ad8..8f0db9fbc9ac 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -597,10 +597,6 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: R } const optimisticReport = ReportUtils.buildOptimisticChatReport([sessionAccountID, cleanAccountID], undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID, cleanAccountID); const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(login); - const pendingVisibleChatMembers = Object.values(invitedEmailsToAccountIDs).map((accountID) => ({ - accountID: accountID.toString(), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - })); workspaceMembersChats.reportCreationData[login] = { reportID: optimisticReport.reportID, reportActionID: optimisticCreatedAction.reportActionID, @@ -616,7 +612,10 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: R }, isOptimisticReport: true, hasOutstandingChildRequest, - pendingVisibleChatMembers, + pendingVisibleChatMembers: [{ + accountID: accountID.toString(), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }] }, }); workspaceMembersChats.onyxOptimisticData.push({ From 22199b731bfbb11d0171f089d0bd909ffe65c72c Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 9 Feb 2024 02:56:41 +0700 Subject: [PATCH 09/22] fix lint --- src/libs/actions/Policy.ts | 21 ++++++++++++--------- src/libs/actions/Report.ts | 8 ++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 8f0db9fbc9ac..74311cc1b6fa 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -349,14 +349,14 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] value: { participantAccountIDs: announceReport?.participantAccountIDs, visibleChatMemberAccountIDs: announceReport?.visibleChatMemberAccountIDs, - pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers, + pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers ?? null, }, }); announceRoomMembers.onyxSuccessData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport?.reportID}`, value: { - pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers, + pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers ?? null, }, }); return announceRoomMembers; @@ -401,14 +401,14 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe value: { participantAccountIDs: announceReport.participantAccountIDs, visibleChatMemberAccountIDs: announceReport.visibleChatMemberAccountIDs, - pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers, + pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers ?? null, }, }); announceRoomMembers.onyxSuccessData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { - pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers, + pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers ?? null, }, }); } @@ -457,6 +457,7 @@ function removeMembers(accountIDs: number[], policyID: string) { key: membersListKey, value: successMembersState, }, + ...announceRoomMembers.onyxSuccessData, ]; const failureData: OnyxUpdate[] = [ @@ -612,10 +613,12 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: R }, isOptimisticReport: true, hasOutstandingChildRequest, - pendingVisibleChatMembers: [{ - accountID: accountID.toString(), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }] + pendingVisibleChatMembers: [ + { + accountID: accountID.toString(), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + ], }, }); workspaceMembersChats.onyxOptimisticData.push({ @@ -666,7 +669,6 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: Record const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, accountIDs); const announceRoomMembers = buildAnnounceRoomMembersOnyxData(policyID, accountIDs); - // create onyx data for policy expense chats for each new member const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs); @@ -712,6 +714,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: Record }, ...newPersonalDetailsOnyxData.finallyData, ...membersChats.onyxSuccessData, + ...announceRoomMembers.onyxSuccessData, ]; const failureData: OnyxUpdate[] = [ diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index f1c7e13bcd07..dd9b9b99894a 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2329,7 +2329,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record Date: Sat, 10 Feb 2024 19:37:38 +0700 Subject: [PATCH 10/22] dry code --- src/libs/ReportUtils.ts | 8 +++++++- src/libs/actions/Policy.ts | 11 +++-------- src/libs/actions/Report.ts | 6 ++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 965ee5d8433b..9324ca75c3a8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -33,7 +33,7 @@ import type {Participant} from '@src/types/onyx/IOU'; import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; import type {ChangeLog, IOUMessage, OriginalMessageActionName, OriginalMessageCreated, PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type {Status} from '@src/types/onyx/PersonalDetails'; -import type {NotificationPreference} from '@src/types/onyx/Report'; +import type {NotificationPreference, PendingChatMember} from '@src/types/onyx/Report'; import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction'; import type {Receipt, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; @@ -4768,6 +4768,11 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry ({accountID: accountID.toString(), pendingAction})); + return [...previousPendingVisibleChatMembers, ...pendingVisibleChatMembers]; +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -4959,6 +4964,7 @@ export { isReportFieldDisabled, getAvailableReportFields, getAllAncestorReportActionIDs, + getPendingVisibleChatMembers }; export type { diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 74311cc1b6fa..91e9ef436e5b 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -329,8 +329,7 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] if (announceReport?.participantAccountIDs) { // Everyone in special policy rooms is visible const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs]; - const pendingAccountIDs = accountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})); - const pendingVisibleChatMembers = [...(announceReport?.pendingVisibleChatMembers ?? []), ...pendingAccountIDs]; + const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(accountIDs, announceReport?.pendingVisibleChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -379,11 +378,7 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe if (announceReport?.participantAccountIDs) { const remainUsers = announceReport.participantAccountIDs.filter((e) => !accountIDs.includes(e)); - const pendingAccountIDs = accountIDs.map((accountID) => ({ - accountID: accountID.toString(), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, - })); - const pendingVisibleChatMembers = [...(announceReport?.pendingVisibleChatMembers ?? []), ...pendingAccountIDs]; + const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(accountIDs, announceReport?.pendingVisibleChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -469,7 +464,7 @@ function removeMembers(accountIDs: number[], policyID: string) { ...announceRoomMembers.onyxFailureData, ]; - const pendingVisibleChatMembers = accountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})); + const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(accountIDs, [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); workspaceChats.forEach((report) => { optimisticData.push({ diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index dd9b9b99894a..da0f89408f47 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2308,8 +2308,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin)); const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, inviteeAccountIDs); - const pendingAccountIDs = inviteeAccountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})); - const pendingVisibleChatMembers = [...(report?.pendingVisibleChatMembers ?? []), ...pendingAccountIDs]; + const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(inviteeAccountIDs, report?.pendingVisibleChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); const optimisticData: OnyxUpdate[] = [ { @@ -2361,8 +2360,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) { const participantAccountIDsAfterRemoval = report?.participantAccountIDs?.filter((id: number) => !targetAccountIDs.includes(id)); const visibleChatMemberAccountIDsAfterRemoval = report?.visibleChatMemberAccountIDs?.filter((id: number) => !targetAccountIDs.includes(id)); - const pendingAccountIDs = targetAccountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE})); - const pendingVisibleChatMembers = [...(report?.pendingVisibleChatMembers ?? []), ...pendingAccountIDs]; + const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(targetAccountIDs, report?.pendingVisibleChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); const optimisticData: OnyxUpdate[] = [ { From 58a58e452524945973d6d9c5f5b2481f8b632d6d Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 10 Feb 2024 20:04:22 +0700 Subject: [PATCH 11/22] lint fix --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9324ca75c3a8..7508a2641fc3 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4964,7 +4964,7 @@ export { isReportFieldDisabled, getAvailableReportFields, getAllAncestorReportActionIDs, - getPendingVisibleChatMembers + getPendingVisibleChatMembers, }; export type { From 7356236c4c40468f3c677c8dae81d1fcd3e0f374 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 12 Feb 2024 09:05:31 +0700 Subject: [PATCH 12/22] add comment --- src/libs/ReportUtils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7508a2641fc3..64e1eb9bbbd9 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4768,6 +4768,9 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry ({accountID: accountID.toString(), pendingAction})); return [...previousPendingVisibleChatMembers, ...pendingVisibleChatMembers]; From 55c837daaac8d6d09b6b196fe0ae7ece06dcd03a Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 19 Feb 2024 10:44:29 +0700 Subject: [PATCH 13/22] fix lint --- src/pages/RoomMembersPage.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index 2376d66a6e1c..070c10a35253 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -1,5 +1,3 @@ -import lodashGet from 'lodash/get'; -import PropTypes from 'prop-types'; import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; @@ -183,7 +181,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { return; } } - const pendingVisibleChatMember = _.find(props.report.pendingVisibleChatMembers, (member) => member.accountID === accountID.toString()); + const pendingVisibleChatMember = report?.pendingVisibleChatMembers ? report?.pendingVisibleChatMembers.find((member) => member.accountID === accountID.toString()) : undefined; result.push({ keyForList: String(accountID), @@ -200,7 +198,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { id: Number(accountID), }, ], - pendingAction: lodashGet(pendingVisibleChatMember, 'pendingAction', undefined), + pendingAction: pendingVisibleChatMember?.pendingAction ?? undefined }); }); From 93091e712f1781fd53172b544d3c03c161e6cff0 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 19 Feb 2024 10:58:51 +0700 Subject: [PATCH 14/22] fix lint --- src/pages/ReportParticipantsPage.tsx | 4 ++-- src/pages/RoomMembersPage.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index c3bd9d762170..2904e4e550d0 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -49,10 +49,10 @@ const getAllParticipants = ( !!userPersonalDetail?.login && !CONST.RESTRICTED_ACCOUNT_IDS.includes(accountID) ? LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login) : translate('common.hidden'); const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); - const pendingVisibleChatMember = (report?.pendingVisibleChatMembers ?? []).find((member) => member.accountID === accountID.toString()); + const pendingVisibleChatMember = report?.pendingVisibleChatMembers ? report?.pendingVisibleChatMembers.find((member) => member.accountID === accountID.toString()) : undefined return { alternateText: userLogin, - pendingAction: pendingVisibleChatMember?.pendingAction, + pendingAction: pendingVisibleChatMember?.pendingAction ?? undefined, displayName, accountID: userPersonalDetail?.accountID ?? accountID, icons: [ diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index 070c10a35253..c697100e7d2e 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -198,7 +198,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { id: Number(accountID), }, ], - pendingAction: pendingVisibleChatMember?.pendingAction ?? undefined + pendingAction: pendingVisibleChatMember?.pendingAction ?? undefined, }); }); From 5dc88556870b881b58a3d7bf402897ecf974d326 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 19 Feb 2024 11:13:00 +0700 Subject: [PATCH 15/22] fix lint --- src/pages/ReportParticipantsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 2904e4e550d0..2988677f6be8 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -49,7 +49,7 @@ const getAllParticipants = ( !!userPersonalDetail?.login && !CONST.RESTRICTED_ACCOUNT_IDS.includes(accountID) ? LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login) : translate('common.hidden'); const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); - const pendingVisibleChatMember = report?.pendingVisibleChatMembers ? report?.pendingVisibleChatMembers.find((member) => member.accountID === accountID.toString()) : undefined + const pendingVisibleChatMember = report?.pendingVisibleChatMembers ? report?.pendingVisibleChatMembers.find((member) => member.accountID === accountID.toString()) : undefined; return { alternateText: userLogin, pendingAction: pendingVisibleChatMember?.pendingAction ?? undefined, From 1614428cf4110c29748fe23cb848988235b6faf6 Mon Sep 17 00:00:00 2001 From: DylanDylann <141406735+DylanDylann@users.noreply.github.com> Date: Tue, 5 Mar 2024 00:21:06 +0700 Subject: [PATCH 16/22] Update src/pages/RoomMembersPage.tsx Co-authored-by: Getabalew Tesfaye <75031127+getusha@users.noreply.github.com> --- src/pages/RoomMembersPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index c78e3a02cb87..dd0feaec9473 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -183,7 +183,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { return; } } - const pendingVisibleChatMember = report?.pendingVisibleChatMembers ? report?.pendingVisibleChatMembers.find((member) => member.accountID === accountID.toString()) : undefined; + const pendingVisibleChatMember = report?.pendingVisibleChatMembers?.find((member) => member.accountID === accountID.toString()); result.push({ keyForList: String(accountID), From 14fb50d6e7900f0419b0a81a7355ef04135e2289 Mon Sep 17 00:00:00 2001 From: DylanDylann <141406735+DylanDylann@users.noreply.github.com> Date: Tue, 5 Mar 2024 00:21:27 +0700 Subject: [PATCH 17/22] Update src/pages/ReportParticipantsPage.tsx Co-authored-by: Getabalew Tesfaye <75031127+getusha@users.noreply.github.com> --- src/pages/ReportParticipantsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 8d8b276067ae..3ed16dd5707e 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -50,7 +50,7 @@ const getAllParticipants = ( !!userPersonalDetail?.login && !CONST.RESTRICTED_ACCOUNT_IDS.includes(accountID) ? LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login) : translate('common.hidden'); const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); - const pendingVisibleChatMember = report?.pendingVisibleChatMembers ? report?.pendingVisibleChatMembers.find((member) => member.accountID === accountID.toString()) : undefined; + const pendingVisibleChatMember = report?.pendingVisibleChatMembers?.find((member) => member.accountID === accountID.toString()); return { alternateText: userLogin, pendingAction: pendingVisibleChatMember?.pendingAction ?? undefined, From d7a8b752c9dc8549ce277026ef3eb38148a673b5 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 5 Mar 2024 00:29:55 +0700 Subject: [PATCH 18/22] clean code --- src/pages/ReportParticipantsPage.tsx | 2 +- src/pages/RoomMembersPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 3ed16dd5707e..315dcd9faa09 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -53,7 +53,7 @@ const getAllParticipants = ( const pendingVisibleChatMember = report?.pendingVisibleChatMembers?.find((member) => member.accountID === accountID.toString()); return { alternateText: userLogin, - pendingAction: pendingVisibleChatMember?.pendingAction ?? undefined, + pendingAction: pendingVisibleChatMember?.pendingAction, displayName, accountID: userPersonalDetail?.accountID ?? accountID, icons: [ diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index dd0feaec9473..b50d568c73f1 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -200,7 +200,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { id: Number(accountID), }, ], - pendingAction: pendingVisibleChatMember?.pendingAction ?? undefined, + pendingAction: pendingVisibleChatMember?.pendingAction, }); }); From 6581dc75a9a6b52859718eaadb92dd8e2a9e900e Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 7 Mar 2024 13:14:46 +0700 Subject: [PATCH 19/22] change the variable name --- src/libs/ReportUtils.ts | 8 ++++---- src/libs/actions/Policy.ts | 28 ++++++++++++++-------------- src/libs/actions/Report.ts | 16 ++++++++-------- src/pages/ReportParticipantsPage.tsx | 2 +- src/pages/RoomMembersPage.tsx | 2 +- src/types/onyx/Report.ts | 5 +++-- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a1369a011bfa..b9cd024f4888 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5091,9 +5091,9 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry ({accountID: accountID.toString(), pendingAction})); - return [...previousPendingVisibleChatMembers, ...pendingVisibleChatMembers]; +function getPendingChatMembers(accountIDs: number[], previousPendingChatMembers: PendingChatMember[], pendingAction: PendingAction): PendingChatMember[] { + const pendingChatMembers = accountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction})); + return [...previousPendingChatMembers, ...pendingChatMembers]; } export { @@ -5296,7 +5296,7 @@ export { getAvailableReportFields, reportFieldsEnabled, getAllAncestorReportActionIDs, - getPendingVisibleChatMembers, + getPendingChatMembers, canEditRoomVisibility, canEditPolicyDescription, getPolicyDescriptionText, diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index a2d253979a43..02580c718985 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -383,7 +383,7 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] if (announceReport?.participantAccountIDs) { // Everyone in special policy rooms is visible const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs]; - const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(accountIDs, announceReport?.pendingVisibleChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + const pendingChatMembers = ReportUtils.getPendingChatMembers(accountIDs, announceReport?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -391,7 +391,7 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] value: { participantAccountIDs, visibleChatMemberAccountIDs: participantAccountIDs, - pendingVisibleChatMembers, + pendingChatMembers, }, }); } @@ -402,14 +402,14 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] value: { participantAccountIDs: announceReport?.participantAccountIDs, visibleChatMemberAccountIDs: announceReport?.visibleChatMemberAccountIDs, - pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers ?? null, + pendingChatMembers: announceReport?.pendingChatMembers ?? null, }, }); announceRoomMembers.onyxSuccessData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport?.reportID}`, value: { - pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers ?? null, + pendingChatMembers: announceReport?.pendingChatMembers ?? null, }, }); return announceRoomMembers; @@ -592,7 +592,7 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe if (announceReport?.participantAccountIDs) { const remainUsers = announceReport.participantAccountIDs.filter((e) => !accountIDs.includes(e)); - const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(accountIDs, announceReport?.pendingVisibleChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); + const pendingChatMembers = ReportUtils.getPendingChatMembers(accountIDs, announceReport?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -600,7 +600,7 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe value: { participantAccountIDs: [...remainUsers], visibleChatMemberAccountIDs: [...remainUsers], - pendingVisibleChatMembers, + pendingChatMembers, }, }); @@ -610,14 +610,14 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe value: { participantAccountIDs: announceReport.participantAccountIDs, visibleChatMemberAccountIDs: announceReport.visibleChatMemberAccountIDs, - pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers ?? null, + pendingChatMembers: announceReport?.pendingChatMembers ?? null, }, }); announceRoomMembers.onyxSuccessData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { - pendingVisibleChatMembers: announceReport?.pendingVisibleChatMembers ?? null, + pendingChatMembers: announceReport?.pendingChatMembers ?? null, }, }); } @@ -679,7 +679,7 @@ function removeMembers(accountIDs: number[], policyID: string) { ...announceRoomMembers.onyxFailureData, ]; - const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(accountIDs, [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); + const pendingChatMembers = ReportUtils.getPendingChatMembers(accountIDs, [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); workspaceChats.forEach((report) => { optimisticData.push({ @@ -690,21 +690,21 @@ function removeMembers(accountIDs: number[], policyID: string) { stateNum: CONST.REPORT.STATE_NUM.APPROVED, oldPolicyName: policy.name, hasDraft: false, - pendingVisibleChatMembers, + pendingChatMembers, }, }); successData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`, value: { - pendingVisibleChatMembers: null, + pendingChatMembers: null, }, }); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`, value: { - pendingVisibleChatMembers: null, + pendingChatMembers: null, }, }); }); @@ -883,7 +883,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I }, isOptimisticReport: true, hasOutstandingChildRequest, - pendingVisibleChatMembers: [ + pendingChatMembers: [ { accountID: accountID.toString(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, @@ -908,7 +908,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I createChat: null, }, isOptimisticReport: false, - pendingVisibleChatMembers: null, + pendingChatMembers: null, }, }); workspaceMembersChats.onyxSuccessData.push({ diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1b2d3184825f..425d15f81ace 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2416,7 +2416,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record PhoneNumber.addSMSDomainIfPhoneNumber(memberLogin)); const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, inviteeAccountIDs); - const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(inviteeAccountIDs, report?.pendingVisibleChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + const pendingChatMembers = ReportUtils.getPendingChatMembers(inviteeAccountIDs, report?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); const optimisticData: OnyxUpdate[] = [ { @@ -2425,7 +2425,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record !targetAccountIDs.includes(id)); const visibleChatMemberAccountIDsAfterRemoval = report?.visibleChatMemberAccountIDs?.filter((id: number) => !targetAccountIDs.includes(id)); - const pendingVisibleChatMembers = ReportUtils.getPendingVisibleChatMembers(targetAccountIDs, report?.pendingVisibleChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); + const pendingChatMembers = ReportUtils.getPendingChatMembers(targetAccountIDs, report?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); const optimisticData: OnyxUpdate[] = [ { @@ -2479,7 +2479,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) { value: { participantAccountIDs: participantAccountIDsAfterRemoval, visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval, - pendingVisibleChatMembers, + pendingChatMembers, }, }, ]; @@ -2491,7 +2491,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) { value: { participantAccountIDs: report?.participantAccountIDs, visibleChatMemberAccountIDs: report?.visibleChatMemberAccountIDs, - pendingVisibleChatMembers: report?.pendingVisibleChatMembers ?? null, + pendingChatMembers: report?.pendingChatMembers ?? null, }, }, ]; @@ -2505,7 +2505,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) { value: { participantAccountIDs: participantAccountIDsAfterRemoval, visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval, - pendingVisibleChatMembers: report?.pendingVisibleChatMembers ?? null, + pendingChatMembers: report?.pendingChatMembers ?? null, }, }, ]; diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 315dcd9faa09..8c2bca100abc 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -50,7 +50,7 @@ const getAllParticipants = ( !!userPersonalDetail?.login && !CONST.RESTRICTED_ACCOUNT_IDS.includes(accountID) ? LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login) : translate('common.hidden'); const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); - const pendingVisibleChatMember = report?.pendingVisibleChatMembers?.find((member) => member.accountID === accountID.toString()); + const pendingVisibleChatMember = report?.pendingChatMembers?.find((member) => member.accountID === accountID.toString()); return { alternateText: userLogin, pendingAction: pendingVisibleChatMember?.pendingAction, diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index b50d568c73f1..2dc7ab48c31b 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -183,7 +183,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { return; } } - const pendingVisibleChatMember = report?.pendingVisibleChatMembers?.find((member) => member.accountID === accountID.toString()); + const pendingVisibleChatMember = report?.pendingChatMembers?.find((member) => member.accountID === accountID.toString()); result.push({ keyForList: String(accountID), diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index bf0b66f2fce4..1f3b49ff77b0 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -17,6 +17,7 @@ type Note = OnyxCommon.OnyxValueWithOfflineFeedback<{ errors?: OnyxCommon.Errors; }>; +/** The pending member of report */ type PendingChatMember = { accountID: string; pendingAction: OnyxCommon.PendingAction; @@ -175,8 +176,8 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< isLoadingPrivateNotes?: boolean; selected?: boolean; - /** Pending member of the report */ - pendingVisibleChatMembers?: PendingChatMember[]; + /** Pending members of the report */ + pendingChatMembers?: PendingChatMember[]; /** If the report contains reportFields, save the field id and its value */ reportFields?: Record; From cd6a3a1649e6a713b2106ad1fb144548eefddd1f Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 7 Mar 2024 13:29:30 +0700 Subject: [PATCH 20/22] change variable name --- src/libs/ReportUtils.ts | 2 +- src/libs/actions/Policy.ts | 2 ++ src/pages/ReportParticipantsPage.tsx | 4 ++-- src/pages/RoomMembersPage.tsx | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b9cd024f4888..9c8a57c19b75 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5089,7 +5089,7 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry ({accountID: accountID.toString(), pendingAction})); diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 02580c718985..0d70fc1d03e9 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -868,6 +868,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I } const optimisticReport = ReportUtils.buildOptimisticChatReport([sessionAccountID, cleanAccountID], undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID, cleanAccountID); const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(login); + workspaceMembersChats.reportCreationData[login] = { reportID: optimisticReport.reportID, reportActionID: optimisticCreatedAction.reportActionID, @@ -940,6 +941,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, accountIDs); const announceRoomMembers = buildAnnounceRoomMembersOnyxData(policyID, accountIDs); + // create onyx data for policy expense chats for each new member const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs); diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 8c2bca100abc..a2b2f094ac26 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -50,10 +50,10 @@ const getAllParticipants = ( !!userPersonalDetail?.login && !CONST.RESTRICTED_ACCOUNT_IDS.includes(accountID) ? LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login) : translate('common.hidden'); const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); - const pendingVisibleChatMember = report?.pendingChatMembers?.find((member) => member.accountID === accountID.toString()); + const pendingChatMember = report?.pendingChatMembers?.find((member) => member.accountID === accountID.toString()); return { alternateText: userLogin, - pendingAction: pendingVisibleChatMember?.pendingAction, + pendingAction: pendingChatMember?.pendingAction, displayName, accountID: userPersonalDetail?.accountID ?? accountID, icons: [ diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index 2dc7ab48c31b..47ba5174e4b0 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -183,7 +183,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { return; } } - const pendingVisibleChatMember = report?.pendingChatMembers?.find((member) => member.accountID === accountID.toString()); + const pendingChatMember = report?.pendingChatMembers?.find((member) => member.accountID === accountID.toString()); result.push({ keyForList: String(accountID), @@ -200,7 +200,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { id: Number(accountID), }, ], - pendingAction: pendingVisibleChatMember?.pendingAction, + pendingAction: pendingChatMember?.pendingAction, }); }); From bf7a894bd6c98157b6a12a1127cb1a27ad5406dc Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 8 Mar 2024 14:12:42 +0700 Subject: [PATCH 21/22] add pending member for admin room --- src/libs/ReportUtils.ts | 39 ++++++++++++++++++++------------------ src/libs/actions/Policy.ts | 3 ++- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9c8a57c19b75..ce1882550b84 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2642,6 +2642,14 @@ function getChatRoomSubtitle(report: OnyxEntry): string | undefined { return getPolicyName(report); } +/** + * Get pending members for reports + */ +function getPendingChatMembers(accountIDs: number[], previousPendingChatMembers: PendingChatMember[], pendingAction: PendingAction): PendingChatMember[] { + const pendingChatMembers = accountIDs.map((accountID) => ({accountID: accountID.toString(), pendingAction})); + return [...previousPendingChatMembers, ...pendingChatMembers]; +} + /** * Gets the parent navigation subtitle for the report */ @@ -3742,16 +3750,19 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string): Op const announceReportActionData = { [announceCreatedAction.reportActionID]: announceCreatedAction, }; - - const adminsChatData = buildOptimisticChatReport( - [currentUserAccountID ?? -1], - CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS, - CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, - policyID, - CONST.POLICY.OWNER_ACCOUNT_ID_FAKE, - false, - policyName, - ); + const pendingChatMembers = getPendingChatMembers(currentUserAccountID ? [currentUserAccountID] : [], [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + const adminsChatData = { + ...buildOptimisticChatReport( + [currentUserAccountID ?? -1], + CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS, + CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, + policyID, + CONST.POLICY.OWNER_ACCOUNT_ID_FAKE, + false, + policyName, + ), + pendingChatMembers, + }; const adminsChatReportID = adminsChatData.reportID; const adminsCreatedAction = buildOptimisticCreatedReportAction(CONST.POLICY.OWNER_EMAIL_FAKE); const adminsReportActionData = { @@ -5088,14 +5099,6 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry ({accountID: accountID.toString(), pendingAction})); - return [...previousPendingChatMembers, ...pendingChatMembers]; -} - export { getReportParticipantsTitle, isReportMessageAttachment, diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 0d70fc1d03e9..9bb313316e54 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1591,7 +1591,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName expenseReportActionData, expenseCreatedReportActionID, } = ReportUtils.buildOptimisticWorkspaceChats(policyID, workspaceName); - + console.log('adminsChatData', adminsChatData); const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.SET, @@ -1715,6 +1715,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName addWorkspaceRoom: null, }, pendingAction: null, + pendingChatMembers: [], }, }, { From 8904bfbf82000efc0585f54a5087b2dbeda9f064 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 8 Mar 2024 14:17:47 +0700 Subject: [PATCH 22/22] lint fix --- src/libs/actions/Policy.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 9bb313316e54..f3526cf45887 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1591,7 +1591,6 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName expenseReportActionData, expenseCreatedReportActionID, } = ReportUtils.buildOptimisticWorkspaceChats(policyID, workspaceName); - console.log('adminsChatData', adminsChatData); const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.SET,