Fix "Add Staff Member" form errors on inputs (#2186)
* Fix input errors in staff member forms * Remove unused import
This commit is contained in:
parent
2c97b2da41
commit
b0d7342e1f
3 changed files with 39 additions and 41 deletions
|
@ -19,7 +19,6 @@ import { commonMessages } from "@saleor/intl";
|
||||||
import { ConfirmButtonTransitionState, makeStyles } from "@saleor/macaw-ui";
|
import { ConfirmButtonTransitionState, makeStyles } from "@saleor/macaw-ui";
|
||||||
import { FetchMoreProps, RelayToFlat, SearchPageProps } from "@saleor/types";
|
import { FetchMoreProps, RelayToFlat, SearchPageProps } from "@saleor/types";
|
||||||
import { getFormErrors } from "@saleor/utils/errors";
|
import { getFormErrors } from "@saleor/utils/errors";
|
||||||
import getStaffErrorMessage from "@saleor/utils/errors/staff";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
|
@ -81,6 +80,14 @@ const StaffAddMemberDialog: React.FC<StaffAddMemberDialogProps> = props => {
|
||||||
dialogErrors,
|
dialogErrors,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getFieldProps = (name: string) => ({
|
||||||
|
disabled: props.disabled,
|
||||||
|
error: !!formErrors[name],
|
||||||
|
helperText: formErrors[name]?.message,
|
||||||
|
label: intl.formatMessage(commonMessages[name]),
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog onClose={onClose} open={open}>
|
<Dialog onClose={onClose} open={open}>
|
||||||
<Form initial={initialForm} onSubmit={onConfirm}>
|
<Form initial={initialForm} onSubmit={onConfirm}>
|
||||||
|
@ -96,25 +103,13 @@ const StaffAddMemberDialog: React.FC<StaffAddMemberDialogProps> = props => {
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<div className={classes.textFieldGrid}>
|
<div className={classes.textFieldGrid}>
|
||||||
<TextField
|
<TextField
|
||||||
error={!!formErrors.firstName}
|
{...getFieldProps("firstName")}
|
||||||
helperText={
|
|
||||||
!!formErrors.firstName &&
|
|
||||||
getStaffErrorMessage(formErrors.firstName, intl)
|
|
||||||
}
|
|
||||||
label={intl.formatMessage(commonMessages.firstName)}
|
|
||||||
name="firstName"
|
|
||||||
type="text"
|
type="text"
|
||||||
value={formData.firstName}
|
value={formData.firstName}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
error={!!formErrors.lastName}
|
{...getFieldProps("lastName")}
|
||||||
helperText={
|
|
||||||
!!formErrors.lastName &&
|
|
||||||
getStaffErrorMessage(formErrors.lastName, intl)
|
|
||||||
}
|
|
||||||
label={intl.formatMessage(commonMessages.lastName)}
|
|
||||||
name="lastName"
|
|
||||||
type="text"
|
type="text"
|
||||||
value={formData.lastName}
|
value={formData.lastName}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
|
@ -122,14 +117,8 @@ const StaffAddMemberDialog: React.FC<StaffAddMemberDialogProps> = props => {
|
||||||
</div>
|
</div>
|
||||||
<FormSpacer />
|
<FormSpacer />
|
||||||
<TextField
|
<TextField
|
||||||
error={!!formErrors.email}
|
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
{...getFieldProps("email")}
|
||||||
!!formErrors.email &&
|
|
||||||
getStaffErrorMessage(formErrors.email, intl)
|
|
||||||
}
|
|
||||||
label={intl.formatMessage(commonMessages.email)}
|
|
||||||
name="email"
|
|
||||||
type="email"
|
type="email"
|
||||||
value={formData.email}
|
value={formData.email}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
|
|
|
@ -128,10 +128,22 @@ const StaffProperties: React.FC<StaffPropertiesProps> = props => {
|
||||||
const imgInputAnchor = React.createRef<HTMLInputElement>();
|
const imgInputAnchor = React.createRef<HTMLInputElement>();
|
||||||
|
|
||||||
const clickImgInput = () => imgInputAnchor.current.click();
|
const clickImgInput = () => imgInputAnchor.current.click();
|
||||||
const formErrors = getFormErrors(["id"], errors || []);
|
const formErrors = getFormErrors(
|
||||||
|
["id", "firstName", "lastName", "email"],
|
||||||
|
errors || [],
|
||||||
|
);
|
||||||
|
|
||||||
const hasAvatar = !!staffMember?.avatar?.url;
|
const hasAvatar = !!staffMember?.avatar?.url;
|
||||||
|
|
||||||
|
const getFieldProps = (name: string) => ({
|
||||||
|
disabled: props.disabled,
|
||||||
|
error: !!formErrors[name],
|
||||||
|
helperText: formErrors[name]?.message,
|
||||||
|
label: intl.formatMessage(commonMessages[name]),
|
||||||
|
name,
|
||||||
|
value: data[name],
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className={className}>
|
<Card className={className}>
|
||||||
<CardTitle
|
<CardTitle
|
||||||
|
@ -197,27 +209,21 @@ const StaffProperties: React.FC<StaffPropertiesProps> = props => {
|
||||||
<div className={classes.propGrid}>
|
<div className={classes.propGrid}>
|
||||||
<div className={classes.prop}>
|
<div className={classes.prop}>
|
||||||
<TextField
|
<TextField
|
||||||
label={intl.formatMessage(commonMessages.firstName)}
|
{...getFieldProps("firstName")}
|
||||||
value={data.firstName}
|
|
||||||
name="firstName"
|
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.prop}>
|
<div className={classes.prop}>
|
||||||
<TextField
|
<TextField
|
||||||
label={intl.formatMessage(commonMessages.lastName)}
|
{...getFieldProps("lastName")}
|
||||||
value={data.lastName}
|
|
||||||
name="lastName"
|
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.prop}>
|
<div className={classes.prop}>
|
||||||
<TextField
|
<TextField
|
||||||
label={intl.formatMessage(commonMessages.email)}
|
{...getFieldProps("email")}
|
||||||
value={data.email}
|
|
||||||
name="email"
|
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -248304,17 +248304,18 @@ exports[`Storyshots Views / Staff / Staff member details loading 1`] = `
|
||||||
class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id"
|
class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id"
|
||||||
>
|
>
|
||||||
<label
|
<label
|
||||||
class="MuiFormLabel-root-id MuiInputLabel-root-id MuiInputLabel-formControl-id MuiInputLabel-animated-id MuiInputLabel-outlined-id"
|
class="MuiFormLabel-root-id MuiInputLabel-root-id MuiInputLabel-formControl-id MuiInputLabel-animated-id MuiInputLabel-outlined-id MuiFormLabel-disabled-id MuiInputLabel-disabled-id"
|
||||||
data-shrink="false"
|
data-shrink="false"
|
||||||
>
|
>
|
||||||
First Name
|
First Name
|
||||||
</label>
|
</label>
|
||||||
<div
|
<div
|
||||||
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id"
|
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id"
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id"
|
||||||
|
disabled=""
|
||||||
name="firstName"
|
name="firstName"
|
||||||
type="text"
|
type="text"
|
||||||
value=""
|
value=""
|
||||||
|
@ -248341,17 +248342,18 @@ exports[`Storyshots Views / Staff / Staff member details loading 1`] = `
|
||||||
class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id"
|
class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id"
|
||||||
>
|
>
|
||||||
<label
|
<label
|
||||||
class="MuiFormLabel-root-id MuiInputLabel-root-id MuiInputLabel-formControl-id MuiInputLabel-animated-id MuiInputLabel-outlined-id"
|
class="MuiFormLabel-root-id MuiInputLabel-root-id MuiInputLabel-formControl-id MuiInputLabel-animated-id MuiInputLabel-outlined-id MuiFormLabel-disabled-id MuiInputLabel-disabled-id"
|
||||||
data-shrink="false"
|
data-shrink="false"
|
||||||
>
|
>
|
||||||
Last Name
|
Last Name
|
||||||
</label>
|
</label>
|
||||||
<div
|
<div
|
||||||
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id"
|
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id"
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id"
|
||||||
|
disabled=""
|
||||||
name="lastName"
|
name="lastName"
|
||||||
type="text"
|
type="text"
|
||||||
value=""
|
value=""
|
||||||
|
@ -248378,17 +248380,18 @@ exports[`Storyshots Views / Staff / Staff member details loading 1`] = `
|
||||||
class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id"
|
class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id"
|
||||||
>
|
>
|
||||||
<label
|
<label
|
||||||
class="MuiFormLabel-root-id MuiInputLabel-root-id MuiInputLabel-formControl-id MuiInputLabel-animated-id MuiInputLabel-outlined-id"
|
class="MuiFormLabel-root-id MuiInputLabel-root-id MuiInputLabel-formControl-id MuiInputLabel-animated-id MuiInputLabel-outlined-id MuiFormLabel-disabled-id MuiInputLabel-disabled-id"
|
||||||
data-shrink="false"
|
data-shrink="false"
|
||||||
>
|
>
|
||||||
Email address
|
Email address
|
||||||
</label>
|
</label>
|
||||||
<div
|
<div
|
||||||
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id"
|
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id"
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
aria-invalid="false"
|
aria-invalid="false"
|
||||||
class="MuiInputBase-input-id MuiOutlinedInput-input-id"
|
class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id"
|
||||||
|
disabled=""
|
||||||
name="email"
|
name="email"
|
||||||
type="text"
|
type="text"
|
||||||
value=""
|
value=""
|
||||||
|
|
Loading…
Reference in a new issue