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
This commit is contained in:
parent
3bfed3216e
commit
f9e1bb0569
4 changed files with 32 additions and 24 deletions
|
@ -7639,17 +7639,17 @@
|
||||||
"context": "section header",
|
"context": "section header",
|
||||||
"string": "Preferences"
|
"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": {
|
"src_dot_staff_dot_components_dot_StaffProperties_dot_2650522200": {
|
||||||
"context": "section header",
|
"context": "section header",
|
||||||
"string": "Staff Member Information"
|
"string": "Staff Member Information"
|
||||||
},
|
},
|
||||||
"src_dot_staff_dot_components_dot_StaffProperties_dot_2771097267": {
|
"src_dot_staff_dot_components_dot_StaffProperties_dot_3645414921": {
|
||||||
"context": "button",
|
"context": "avatar delete button",
|
||||||
"string": "Change photo"
|
"string": "Delete"
|
||||||
},
|
|
||||||
"src_dot_staff_dot_components_dot_StaffProperties_dot_457748370": {
|
|
||||||
"context": "button",
|
|
||||||
"string": "Delete photo"
|
|
||||||
},
|
},
|
||||||
"src_dot_staff_dot_components_dot_UserStatus_dot_userDisableInstruction": {
|
"src_dot_staff_dot_components_dot_UserStatus_dot_userDisableInstruction": {
|
||||||
"string": "If you want to disable this User please uncheck the box below."
|
"string": "If you want to disable this User please uncheck the box below."
|
||||||
|
|
|
@ -10,7 +10,7 @@ import React from "react";
|
||||||
import SVG from "react-inlinesvg";
|
import SVG from "react-inlinesvg";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
import { getUserInitials, maybe } from "../../../misc";
|
import { getUserInitials } from "../../../misc";
|
||||||
import { StaffMemberDetails_user } from "../../types/StaffMemberDetails";
|
import { StaffMemberDetails_user } from "../../types/StaffMemberDetails";
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
|
@ -128,6 +128,8 @@ const StaffProperties: React.FC<StaffPropertiesProps> = props => {
|
||||||
const clickImgInput = () => imgInputAnchor.current.click();
|
const clickImgInput = () => imgInputAnchor.current.click();
|
||||||
const formErrors = getFormErrors(["id"], errors || []);
|
const formErrors = getFormErrors(["id"], errors || []);
|
||||||
|
|
||||||
|
const hasAvatar = !!staffMember?.avatar?.url;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className={className}>
|
<Card className={className}>
|
||||||
<CardTitle
|
<CardTitle
|
||||||
|
@ -140,10 +142,10 @@ const StaffProperties: React.FC<StaffPropertiesProps> = props => {
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<div>
|
<div>
|
||||||
<div className={classes.avatar}>
|
<div className={classes.avatar}>
|
||||||
{maybe(() => staffMember.avatar.url) ? (
|
{hasAvatar ? (
|
||||||
<img
|
<img
|
||||||
className={classes.avatarImage}
|
className={classes.avatarImage}
|
||||||
src={maybe(() => staffMember.avatar.url)}
|
src={staffMember.avatar.url}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className={classes.avatarDefault}>
|
<div className={classes.avatarDefault}>
|
||||||
|
@ -158,19 +160,23 @@ const StaffProperties: React.FC<StaffPropertiesProps> = props => {
|
||||||
className={classes.avatarActionText}
|
className={classes.avatarActionText}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Change photo"
|
defaultMessage="Change"
|
||||||
description="button"
|
description="avatar change button"
|
||||||
/>
|
/>
|
||||||
</Typography>
|
</Typography>
|
||||||
|
{hasAvatar && (
|
||||||
|
<>
|
||||||
<Typography
|
<Typography
|
||||||
onClick={onImageDelete}
|
onClick={onImageDelete}
|
||||||
className={classes.avatarActionText}
|
className={classes.avatarActionText}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Delete photo"
|
defaultMessage="Delete"
|
||||||
description="button"
|
description="avatar delete button"
|
||||||
/>
|
/>
|
||||||
</Typography>
|
</Typography>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<input
|
<input
|
||||||
className={classes.fileField}
|
className={classes.fileField}
|
||||||
id="fileUpload"
|
id="fileUpload"
|
||||||
|
|
|
@ -101,7 +101,7 @@ export const StaffDetails: React.FC<OrderListProps> = ({ id, params }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TypedStaffMemberDetailsQuery displayLoader variables={{ id }}>
|
<TypedStaffMemberDetailsQuery displayLoader variables={{ id }}>
|
||||||
{({ data, loading }) => {
|
{({ data, loading, refetch }) => {
|
||||||
const staffMember = data?.user;
|
const staffMember = data?.user;
|
||||||
|
|
||||||
if (staffMember === null) {
|
if (staffMember === null) {
|
||||||
|
@ -123,6 +123,7 @@ export const StaffDetails: React.FC<OrderListProps> = ({ id, params }) => {
|
||||||
status: "success",
|
status: "success",
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
});
|
});
|
||||||
|
refetch();
|
||||||
} else {
|
} else {
|
||||||
notify({
|
notify({
|
||||||
status: "error",
|
status: "error",
|
||||||
|
@ -138,6 +139,7 @@ export const StaffDetails: React.FC<OrderListProps> = ({ id, params }) => {
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
});
|
});
|
||||||
navigate(staffMemberDetailsUrl(id));
|
navigate(staffMemberDetailsUrl(id));
|
||||||
|
refetch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -240749,12 +240749,12 @@ exports[`Storyshots Views / Staff / Staff member details himself 1`] = `
|
||||||
<div
|
<div
|
||||||
class="MuiTypography-root-id StaffProperties-avatarActionText-id MuiTypography-body1-id"
|
class="MuiTypography-root-id StaffProperties-avatarActionText-id MuiTypography-body1-id"
|
||||||
>
|
>
|
||||||
Change photo
|
Change
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="MuiTypography-root-id StaffProperties-avatarActionText-id MuiTypography-body1-id"
|
class="MuiTypography-root-id StaffProperties-avatarActionText-id MuiTypography-body1-id"
|
||||||
>
|
>
|
||||||
Delete photo
|
Delete
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
class="StaffProperties-fileField-id"
|
class="StaffProperties-fileField-id"
|
||||||
|
|
Loading…
Reference in a new issue