From b0d7342e1f524e4b21e23ed68456edca77c9fb61 Mon Sep 17 00:00:00 2001 From: Wojciech Mista Date: Thu, 4 Aug 2022 08:40:14 +0200 Subject: [PATCH] Fix "Add Staff Member" form errors on inputs (#2186) * Fix input errors in staff member forms * Remove unused import --- .../StaffAddMemberDialog.tsx | 33 +++++++------------ .../StaffProperties/StaffProperties.tsx | 26 +++++++++------ .../__snapshots__/Stories.test.ts.snap | 21 +++++++----- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsx b/src/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsx index d54364f9a..ad1968139 100644 --- a/src/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsx +++ b/src/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsx @@ -19,7 +19,6 @@ import { commonMessages } from "@saleor/intl"; import { ConfirmButtonTransitionState, makeStyles } from "@saleor/macaw-ui"; import { FetchMoreProps, RelayToFlat, SearchPageProps } from "@saleor/types"; import { getFormErrors } from "@saleor/utils/errors"; -import getStaffErrorMessage from "@saleor/utils/errors/staff"; import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; @@ -81,6 +80,14 @@ const StaffAddMemberDialog: React.FC = props => { dialogErrors, ); + const getFieldProps = (name: string) => ({ + disabled: props.disabled, + error: !!formErrors[name], + helperText: formErrors[name]?.message, + label: intl.formatMessage(commonMessages[name]), + name, + }); + return (
@@ -96,25 +103,13 @@ const StaffAddMemberDialog: React.FC = props => {
= props => {
= props => { const imgInputAnchor = React.createRef(); const clickImgInput = () => imgInputAnchor.current.click(); - const formErrors = getFormErrors(["id"], errors || []); + const formErrors = getFormErrors( + ["id", "firstName", "lastName", "email"], + errors || [], + ); 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 ( = props => {
diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index ba826ca8a..eec3cfbf9 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -248304,17 +248304,18 @@ exports[`Storyshots Views / Staff / Staff member details loading 1`] = ` class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id" >