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

implement offline behaviour for updateGroupChatMemberRole #40700

Merged
merged 10 commits into from
May 6, 2024
29 changes: 27 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2703,12 +2703,37 @@ function updateGroupChatMemberRoles(reportID: string, accountIDList: number[], r
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participants,
participants: Object.keys(participants).reduce((acc, accountID) => {
acc[Number(accountID)] = {
...participants[Number(accountID)],
nexarvo marked this conversation as resolved.
Show resolved Hide resolved
pendingFields: {
role: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
};
return acc;
}, {} as Participants),
nexarvo marked this conversation as resolved.
Show resolved Hide resolved
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participants: Object.keys(participants).reduce((acc, accountID) => {
acc[Number(accountID)] = {
pendingFields: {
role: null,
},
};
return acc;
}, {} as Participants),
},
},
];
const parameters: UpdateGroupChatMemberRolesParams = {reportID, memberRoles: JSON.stringify(memberRoles)};
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_MEMBER_ROLES, parameters, {optimisticData});
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_MEMBER_ROLES, parameters, {optimisticData, successData});
}

/** Invites people to a group chat */
Expand Down
17 changes: 16 additions & 1 deletion src/pages/ReportParticipantsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ function ReportParticipantsPage({report, personalDetails, session}: ReportPartic
);
}

const participantsPendingFields = report.participants?.[accountID]?.pendingFields;
let pendingAction;

if (pendingChatMember?.pendingAction) {
pendingAction = pendingChatMember.pendingAction;
} else if (participantsPendingFields) {
// We can have multiple Pending Fields in participant
for (const key in participantsPendingFields) {
if (key in participantsPendingFields) {
pendingAction = participantsPendingFields[key];
break;
}
}
}
nexarvo marked this conversation as resolved.
Show resolved Hide resolved

result.push({
keyForList: `${accountID}`,
accountID,
Expand All @@ -101,7 +116,7 @@ function ReportParticipantsPage({report, personalDetails, session}: ReportPartic
text: formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)),
alternateText: formatPhoneNumber(details?.login ?? ''),
rightElement: roleBadge,
pendingAction: pendingChatMember?.pendingAction,
pendingAction,
icons: [
{
source: UserUtils.getAvatar(details?.avatar, accountID),
Expand Down
1 change: 1 addition & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type PendingChatMember = {
type Participant = {
hidden?: boolean;
role?: 'admin' | 'member';
pendingFields?: Record<string, OnyxCommon.PendingAction>;
};
nexarvo marked this conversation as resolved.
Show resolved Hide resolved

type Participants = Record<number, Participant>;
Expand Down
Loading