From f9e1bb0569a337fce51525d41e9132c49679075e Mon Sep 17 00:00:00 2001 From: Wojciech Mista Date: Tue, 1 Feb 2022 15:41:31 +0100 Subject: [PATCH] Don't render delete button if user doesn't have an avatar (#1803) * Make "delete" button appear only when user has an avatar * Remove unused import * Update tests * Refetch user on avatar update --- locale/defaultMessages.json | 14 ++++---- .../StaffProperties/StaffProperties.tsx | 34 +++++++++++-------- src/staff/views/StaffDetails.tsx | 4 ++- .../__snapshots__/Stories.test.ts.snap | 4 +-- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index 2f6714e25..6adfb8d29 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -7639,17 +7639,17 @@ "context": "section header", "string": "Preferences" }, + "src_dot_staff_dot_components_dot_StaffProperties_dot_1473195966": { + "context": "avatar change button", + "string": "Change" + }, "src_dot_staff_dot_components_dot_StaffProperties_dot_2650522200": { "context": "section header", "string": "Staff Member Information" }, - "src_dot_staff_dot_components_dot_StaffProperties_dot_2771097267": { - "context": "button", - "string": "Change photo" - }, - "src_dot_staff_dot_components_dot_StaffProperties_dot_457748370": { - "context": "button", - "string": "Delete photo" + "src_dot_staff_dot_components_dot_StaffProperties_dot_3645414921": { + "context": "avatar delete button", + "string": "Delete" }, "src_dot_staff_dot_components_dot_UserStatus_dot_userDisableInstruction": { "string": "If you want to disable this User please uncheck the box below." diff --git a/src/staff/components/StaffProperties/StaffProperties.tsx b/src/staff/components/StaffProperties/StaffProperties.tsx index 788f90010..4016ff398 100644 --- a/src/staff/components/StaffProperties/StaffProperties.tsx +++ b/src/staff/components/StaffProperties/StaffProperties.tsx @@ -10,7 +10,7 @@ import React from "react"; import SVG from "react-inlinesvg"; import { FormattedMessage, useIntl } from "react-intl"; -import { getUserInitials, maybe } from "../../../misc"; +import { getUserInitials } from "../../../misc"; import { StaffMemberDetails_user } from "../../types/StaffMemberDetails"; const useStyles = makeStyles( @@ -128,6 +128,8 @@ const StaffProperties: React.FC = props => { const clickImgInput = () => imgInputAnchor.current.click(); const formErrors = getFormErrors(["id"], errors || []); + const hasAvatar = !!staffMember?.avatar?.url; + return ( = props => {
- {maybe(() => staffMember.avatar.url) ? ( + {hasAvatar ? ( staffMember.avatar.url)} + src={staffMember.avatar.url} /> ) : (
@@ -158,19 +160,23 @@ const StaffProperties: React.FC = props => { className={classes.avatarActionText} > - - - + {hasAvatar && ( + <> + + + + + )} = ({ id, params }) => { return ( - {({ data, loading }) => { + {({ data, loading, refetch }) => { const staffMember = data?.user; if (staffMember === null) { @@ -123,6 +123,7 @@ export const StaffDetails: React.FC = ({ id, params }) => { status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); + refetch(); } else { notify({ status: "error", @@ -138,6 +139,7 @@ export const StaffDetails: React.FC = ({ id, params }) => { text: intl.formatMessage(commonMessages.savedChanges) }); navigate(staffMemberDetailsUrl(id)); + refetch(); } }; diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index a4fc76dee..1abeadb7c 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -240749,12 +240749,12 @@ exports[`Storyshots Views / Staff / Staff member details himself 1`] = `
- Change photo + Change
- Delete photo + Delete