Skip to content

Commit

Permalink
Merge pull request Expensify#40884 from nexarvo/feat/39983
Browse files Browse the repository at this point in the history
implement offline behaviour for updateGroupChatAvatar
  • Loading branch information
marcaaron authored May 3, 2024
2 parents a6299a1 + 0c0ec70 commit ee8f9c6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
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,
},
},
},
];
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 @@ -3709,4 +3753,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

0 comments on commit ee8f9c6

Please sign in to comment.