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 updateGroupChatAvatar #40884

Merged
merged 6 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 47 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,55 @@ function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageMani
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {avatarUrl: file?.uri ?? ''},
value: {
avatarUrl: file?.uri ?? '',
pendingFields: {
avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
avatar: null,
},
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
avatarUrl: currentReportData?.[reportID]?.avatarUrl ?? null,
pendingFields: {
avatar: null,
},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
pendingFields: {
avatar: null,
},
},
},
];
nexarvo marked this conversation as resolved.
Show resolved Hide resolved
const parameters: UpdateGroupChatAvatarParams = {file, reportID};
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_AVATAR, parameters, {optimisticData});
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_AVATAR, parameters, {optimisticData, failureData, successData});
}

/**
* Clear error and pending fields for the report avatar
*/
function clearAvatarErrors(reportID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
errorFields: {
avatar: null,
},
});
}

/**
Expand Down Expand Up @@ -3772,4 +3816,5 @@ export {
leaveGroupChat,
removeFromGroupChat,
updateGroupChatMemberRoles,
clearAvatarErrors,
};
4 changes: 4 additions & 0 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
onImageSelected={(file) => Report.updateGroupChatAvatar(report.reportID ?? '', file)}
editIcon={Expensicons.Camera}
editIconStyle={styles.smallEditIconAccount}
pendingAction={report.pendingFields?.avatar ?? undefined}
errors={report.errorFields?.avatar ?? null}
errorRowStyles={styles.mt6}
onErrorClose={() => Report.clearAvatarErrors(report.reportID ?? '')}
/>
) : (
<RoomHeaderAvatars
Expand Down
Loading