import { makeStyles } from "@material-ui/core/styles"; import TextField from "@material-ui/core/TextField"; import React from "react"; import { useIntl, IntlShape } from "react-intl"; import FormSpacer from "@saleor/components/FormSpacer"; import Grid from "@saleor/components/Grid"; import SingleAutocompleteSelectField, { SingleAutocompleteChoiceType } from "@saleor/components/SingleAutocompleteSelectField"; import { AddressTypeInput } from "@saleor/customers/types"; import { ChangeEvent } from "@saleor/hooks/useForm"; import getShopErrorMessage from "@saleor/utils/errors/shop"; import { getFormErrors } from "@saleor/utils/errors"; import { ShopErrorFragment } from "@saleor/siteSettings/types/ShopErrorFragment"; import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment"; import getAccountErrorMessage from "@saleor/utils/errors/account"; export interface CompanyAddressFormProps { countries: SingleAutocompleteChoiceType[]; data: AddressTypeInput; displayCountry: string; errors: Array; disabled: boolean; onChange: (event: ChangeEvent) => void; onCountryChange: (event: ChangeEvent) => void; } const useStyles = makeStyles( { root: {} }, { name: "CompanyAddressForm" } ); function getErrorMessage( err: AccountErrorFragment | ShopErrorFragment, intl: IntlShape ): string { if (err?.__typename === "AccountError") { return getAccountErrorMessage(err, intl); } return getShopErrorMessage(err, intl); } const CompanyAddressForm: React.FC = props => { const { countries, data, disabled, displayCountry, errors, onChange, onCountryChange } = props; const classes = useStyles(props); const intl = useIntl(); const formFields = [ "companyName", "streetAddress1", "streetAddress2", "city", "postalCode", "country", "companyArea", "phone" ]; const formErrors = getFormErrors(formFields, errors); return (
); }; CompanyAddressForm.displayName = "CompanyAddressForm"; export default CompanyAddressForm;