diff --git a/src/customers/components/CustomerCreatePage/CustomerCreatePage.tsx b/src/customers/components/CustomerCreatePage/CustomerCreatePage.tsx index 1ce4a9397..d6572883c 100644 --- a/src/customers/components/CustomerCreatePage/CustomerCreatePage.tsx +++ b/src/customers/components/CustomerCreatePage/CustomerCreatePage.tsx @@ -9,6 +9,7 @@ import Form from "@saleor/components/Form"; import Grid from "@saleor/components/Grid"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; +import useAddressValidation from "@saleor/hooks/useAddressValidation"; import { sectionNames } from "@saleor/intl"; import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler"; import { UserError } from "../../../types"; @@ -67,12 +68,16 @@ const CustomerCreatePage: React.FC = ({ label: country.country, value: country.code })); + const { + errors: validationErrors, + submit: handleSubmit + } = useAddressValidation(onSubmit); return (
{({ change, data, errors: formErrors, hasChanged, submit }) => { diff --git a/src/hooks/useAddressValidation.ts b/src/hooks/useAddressValidation.ts index 9bd1e401d..ef7ad365a 100644 --- a/src/hooks/useAddressValidation.ts +++ b/src/hooks/useAddressValidation.ts @@ -8,14 +8,14 @@ import { UserError } from "@saleor/types"; import { AddressInput } from "@saleor/types/globalTypes"; import { add, remove } from "@saleor/utils/lists"; -interface UseAddressValidation { +interface UseAddressValidation { errors: UserError[]; - submit: (data: AddressTypeInput) => void; + submit: (data: T & AddressTypeInput) => void; } -function useAddressValidation( - onSubmit: (address: AddressInput) => void -): UseAddressValidation { +function useAddressValidation( + onSubmit: (address: T & AddressInput) => void +): UseAddressValidation { const intl = useIntl(); const [validationErrors, setValidationErrors] = useState([]); @@ -26,7 +26,7 @@ function useAddressValidation( return { errors: validationErrors, - submit: (data: AddressTypeInput) => { + submit: (data: T & AddressTypeInput) => { try { setValidationErrors( remove( diff --git a/src/misc.ts b/src/misc.ts index ff80d36a2..b6f3f958e 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -339,9 +339,9 @@ export function capitalize(s: string) { return s.charAt(0).toLocaleUpperCase() + s.slice(1); } -export function transformFormToAddress( - address: AddressTypeInput -): AddressInput { +export function transformFormToAddress( + address: T & AddressTypeInput +): T & AddressInput { return { ...address, country: findInEnum(address.country, CountryCode)