Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/34671: Grey out pending member in report #35883

Merged
merged 31 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a2eb3fc
add pending action member for report
DylanDylann Feb 6, 2024
ae2f26b
merge main
DylanDylann Feb 6, 2024
cdc42c5
optional
DylanDylann Feb 6, 2024
45aa3c5
fix type check
DylanDylann Feb 6, 2024
26b612f
fix type check
DylanDylann Feb 6, 2024
f61c018
fix type check
DylanDylann Feb 6, 2024
952005b
fix lint
DylanDylann Feb 6, 2024
21c0c56
update pending member for workspace expense chat
DylanDylann Feb 8, 2024
c7bc82d
update
DylanDylann Feb 8, 2024
22199b7
fix lint
DylanDylann Feb 8, 2024
69eab0c
dry code
DylanDylann Feb 10, 2024
58a58e4
lint fix
DylanDylann Feb 10, 2024
7356236
add comment
DylanDylann Feb 12, 2024
e071cc2
merge main
DylanDylann Feb 19, 2024
55c837d
fix lint
DylanDylann Feb 19, 2024
93091e7
fix lint
DylanDylann Feb 19, 2024
5dc8855
fix lint
DylanDylann Feb 19, 2024
52d2ec8
merge main
DylanDylann Feb 22, 2024
03b855c
merge main
DylanDylann Feb 24, 2024
be08d31
merge main
DylanDylann Feb 26, 2024
7114db3
merge main
DylanDylann Feb 27, 2024
738900f
merge main
DylanDylann Feb 28, 2024
e084c97
merge main
DylanDylann Mar 4, 2024
1614428
Update src/pages/RoomMembersPage.tsx
DylanDylann Mar 4, 2024
14fb50d
Update src/pages/ReportParticipantsPage.tsx
DylanDylann Mar 4, 2024
d7a8b75
clean code
DylanDylann Mar 4, 2024
bc18fe7
merge main
DylanDylann Mar 7, 2024
6581dc7
change the variable name
DylanDylann Mar 7, 2024
cd6a3a1
change variable name
DylanDylann Mar 7, 2024
bf7a894
add pending member for admin room
DylanDylann Mar 8, 2024
8904bfb
lint fix
DylanDylann Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import type {
ReimbursementDeQueuedMessage,
} 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';
Expand Down Expand Up @@ -2642,6 +2642,14 @@ function getChatRoomSubtitle(report: OnyxEntry<Report>): 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
*/
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -5288,6 +5299,7 @@ export {
getAvailableReportFields,
reportFieldsEnabled,
getAllAncestorReportActionIDs,
getPendingChatMembers,
canEditRoomVisibility,
canEditPolicyDescription,
getPolicyDescriptionText,
Expand Down
85 changes: 68 additions & 17 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';

type AnnounceRoomMembersOnyxData = {
onyxOptimisticData: OnyxUpdate[];
onyxSuccessData: OnyxUpdate[];
onyxFailureData: OnyxUpdate[];
};

Expand Down Expand Up @@ -372,6 +373,7 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[]
const announceRoomMembers: AnnounceRoomMembersOnyxData = {
onyxOptimisticData: [],
onyxFailureData: [],
onyxSuccessData: [],
};

if (!announceReport) {
Expand All @@ -381,13 +383,15 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[]
if (announceReport?.participantAccountIDs) {
// Everyone in special policy rooms is visible
const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs];
const pendingChatMembers = ReportUtils.getPendingChatMembers(accountIDs, announceReport?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);

announceRoomMembers.onyxOptimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport?.reportID}`,
value: {
participantAccountIDs,
visibleChatMemberAccountIDs: participantAccountIDs,
pendingChatMembers,
},
});
}
Expand All @@ -398,6 +402,14 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[]
value: {
participantAccountIDs: announceReport?.participantAccountIDs,
visibleChatMemberAccountIDs: announceReport?.visibleChatMemberAccountIDs,
pendingChatMembers: announceReport?.pendingChatMembers ?? null,
},
});
announceRoomMembers.onyxSuccessData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport?.reportID}`,
value: {
pendingChatMembers: announceReport?.pendingChatMembers ?? null,
},
});
return announceRoomMembers;
Expand Down Expand Up @@ -571,6 +583,7 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe
const announceRoomMembers: AnnounceRoomMembersOnyxData = {
onyxOptimisticData: [],
onyxFailureData: [],
onyxSuccessData: [],
};

if (!announceReport) {
Expand All @@ -579,12 +592,15 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe

if (announceReport?.participantAccountIDs) {
const remainUsers = announceReport.participantAccountIDs.filter((e) => !accountIDs.includes(e));
const pendingChatMembers = ReportUtils.getPendingChatMembers(accountIDs, announceReport?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

announceRoomMembers.onyxOptimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: [...remainUsers],
visibleChatMemberAccountIDs: [...remainUsers],
pendingChatMembers,
},
});

Expand All @@ -594,6 +610,14 @@ function removeOptimisticAnnounceRoomMembers(policyID: string, accountIDs: numbe
value: {
participantAccountIDs: announceReport.participantAccountIDs,
visibleChatMemberAccountIDs: announceReport.visibleChatMemberAccountIDs,
pendingChatMembers: announceReport?.pendingChatMembers ?? null,
},
});
announceRoomMembers.onyxSuccessData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
pendingChatMembers: announceReport?.pendingChatMembers ?? null,
},
});
}
Expand Down Expand Up @@ -637,6 +661,26 @@ function removeMembers(accountIDs: number[], policyID: string) {
...announceRoomMembers.onyxOptimisticData,
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: membersListKey,
value: successMembersState,
},
...announceRoomMembers.onyxSuccessData,
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: membersListKey,
value: failureMembersState,
},
...announceRoomMembers.onyxFailureData,
];

const pendingChatMembers = ReportUtils.getPendingChatMembers(accountIDs, [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

workspaceChats.forEach((report) => {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -646,6 +690,21 @@ function removeMembers(accountIDs: number[], policyID: string) {
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
oldPolicyName: policy.name,
hasDraft: false,
pendingChatMembers,
},
});
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`,
value: {
pendingChatMembers: null,
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`,
value: {
pendingChatMembers: null,
},
});
});
Expand Down Expand Up @@ -682,23 +741,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({
Expand Down Expand Up @@ -841,6 +884,12 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I
},
isOptimisticReport: true,
hasOutstandingChildRequest,
pendingChatMembers: [
{
accountID: accountID.toString(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
],
},
});
workspaceMembersChats.onyxOptimisticData.push({
Expand All @@ -860,6 +909,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I
createChat: null,
},
isOptimisticReport: false,
pendingChatMembers: null,
},
});
workspaceMembersChats.onyxSuccessData.push({
Expand Down Expand Up @@ -937,6 +987,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount
},
...newPersonalDetailsOnyxData.finallyData,
...membersChats.onyxSuccessData,
...announceRoomMembers.onyxSuccessData,
];

const failureData: OnyxUpdate[] = [
Expand Down Expand Up @@ -1540,7 +1591,6 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName
expenseReportActionData,
expenseCreatedReportActionID,
} = ReportUtils.buildOptimisticWorkspaceChats(policyID, workspaceName);

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.SET,
Expand Down Expand Up @@ -1664,6 +1714,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName
addWorkspaceRoom: null,
},
pendingAction: null,
pendingChatMembers: [],
},
},
{
Expand Down
19 changes: 17 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string

const logins = inviteeEmails.map((memberLogin) => PhoneNumber.addSMSDomainIfPhoneNumber(memberLogin));
const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, inviteeAccountIDs);
const pendingChatMembers = ReportUtils.getPendingChatMembers(inviteeAccountIDs, report?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);

const optimisticData: OnyxUpdate[] = [
{
Expand All @@ -2424,20 +2425,30 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string
value: {
participantAccountIDs: participantAccountIDsAfterInvitation,
visibleChatMemberAccountIDs: visibleMemberAccountIDsAfterInvitation,
pendingChatMembers,
},
},
...newPersonalDetailsOnyxData.optimisticData,
];

const successData: OnyxUpdate[] = newPersonalDetailsOnyxData.finallyData;

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
pendingChatMembers: report?.pendingChatMembers ?? null,
},
},
...newPersonalDetailsOnyxData.finallyData,
];
const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participantAccountIDs: report.participantAccountIDs,
visibleChatMemberAccountIDs: report.visibleChatMemberAccountIDs,
pendingChatMembers: report?.pendingChatMembers ?? null,
},
},
...newPersonalDetailsOnyxData.finallyData,
Expand All @@ -2459,6 +2470,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 pendingChatMembers = ReportUtils.getPendingChatMembers(targetAccountIDs, report?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

const optimisticData: OnyxUpdate[] = [
{
Expand All @@ -2467,6 +2479,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) {
value: {
participantAccountIDs: participantAccountIDsAfterRemoval,
visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval,
pendingChatMembers,
},
},
];
Expand All @@ -2478,6 +2491,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) {
value: {
participantAccountIDs: report?.participantAccountIDs,
visibleChatMemberAccountIDs: report?.visibleChatMemberAccountIDs,
pendingChatMembers: report?.pendingChatMembers ?? null,
},
},
];
Expand All @@ -2491,6 +2505,7 @@ function removeFromRoom(reportID: string, targetAccountIDs: number[]) {
value: {
participantAccountIDs: participantAccountIDsAfterRemoval,
visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval,
pendingChatMembers: report?.pendingChatMembers ?? null,
},
},
];
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ReportParticipantsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +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 pendingChatMember = report?.pendingChatMembers?.find((member) => member.accountID === accountID.toString());
return {
alternateText: userLogin,
pendingAction: pendingChatMember?.pendingAction,
displayName,
accountID: userPersonalDetail?.accountID ?? accountID,
icons: [
Expand Down
2 changes: 2 additions & 0 deletions src/pages/RoomMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) {
return;
}
}
const pendingChatMember = report?.pendingChatMembers?.find((member) => member.accountID === accountID.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi coming from #38821

The issue is the deleted member offline didn't get strikethrough because we didn't get the last pendingChatMembers.


result.push({
keyForList: String(accountID),
Expand All @@ -199,6 +200,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) {
id: Number(accountID),
},
],
pendingAction: pendingChatMember?.pendingAction,
});
});

Expand Down
11 changes: 10 additions & 1 deletion src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ type Note = OnyxCommon.OnyxValueWithOfflineFeedback<{
errors?: OnyxCommon.Errors;
}>;

/** The pending member of report */
type PendingChatMember = {
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
accountID: string;
pendingAction: OnyxCommon.PendingAction;
};

type Participant = {
hidden: boolean;
role?: 'admin' | 'member';
Expand Down Expand Up @@ -170,6 +176,9 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback<
isLoadingPrivateNotes?: boolean;
selected?: boolean;

/** Pending members of the report */
pendingChatMembers?: PendingChatMember[];

/** If the report contains reportFields, save the field id and its value */
reportFields?: Record<string, PolicyReportField>;
},
Expand All @@ -180,4 +189,4 @@ type ReportCollectionDataSet = CollectionDataSet<typeof ONYXKEYS.COLLECTION.REPO

export default Report;

export type {NotificationPreference, RoomVisibility, WriteCapability, Note, ReportCollectionDataSet};
export type {NotificationPreference, RoomVisibility, WriteCapability, Note, PendingChatMember, ReportCollectionDataSet};
Loading