import { TextField } from "@material-ui/core"; 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 { AccountErrorFragment } from "@saleor/fragments/types/AccountErrorFragment"; import { ShopErrorFragment } from "@saleor/fragments/types/ShopErrorFragment"; import { WarehouseErrorFragment } from "@saleor/fragments/types/WarehouseErrorFragment"; import { ChangeEvent } from "@saleor/hooks/useForm"; import { makeStyles } from "@saleor/theme"; import { getFormErrors } from "@saleor/utils/errors"; import getAccountErrorMessage from "@saleor/utils/errors/account"; import getShopErrorMessage from "@saleor/utils/errors/shop"; import getWarehouseErrorMessage from "@saleor/utils/errors/warehouse"; import React from "react"; import { IntlShape, useIntl } from "react-intl"; export interface CompanyAddressFormProps { countries: SingleAutocompleteChoiceType[]; data: AddressTypeInput; displayCountry: string; errors: Array< AccountErrorFragment | ShopErrorFragment | WarehouseErrorFragment >; disabled: boolean; onChange: (event: ChangeEvent) => void; onCountryChange: (event: ChangeEvent) => void; } const useStyles = makeStyles( { root: {} }, { name: "CompanyAddressForm" } ); function getErrorMessage( err: AccountErrorFragment | ShopErrorFragment | WarehouseErrorFragment, intl: IntlShape ): string { switch (err?.__typename) { case "AccountError": return getAccountErrorMessage(err, intl); case "WarehouseError": return getWarehouseErrorMessage(err, intl); default: 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", "countryArea", "companyArea", "phone" ]; const formErrors = getFormErrors(formFields, errors); return (
); }; CompanyAddressForm.displayName = "CompanyAddressForm"; export default CompanyAddressForm;