import TextField from "@material-ui/core/TextField"; import { AddressTypeInput } from "@saleor/customers/types"; import { AccountErrorFragment } from "@saleor/fragments/types/AccountErrorFragment"; import { OrderErrorFragment } from "@saleor/fragments/types/OrderErrorFragment"; import { commonMessages } from "@saleor/intl"; import { makeStyles } from "@saleor/theme"; import { getFormErrors } from "@saleor/utils/errors"; import getAccountErrorMessage from "@saleor/utils/errors/account"; import getOrderErrorMessage from "@saleor/utils/errors/order"; import React from "react"; import { IntlShape, useIntl } from "react-intl"; import FormSpacer from "../FormSpacer"; import SingleAutocompleteSelectField, { SingleAutocompleteChoiceType } from "../SingleAutocompleteSelectField"; const useStyles = makeStyles( theme => ({ root: { display: "grid", gridColumnGap: theme.spacing(2), gridTemplateColumns: "1fr 1fr" } }), { name: "AddressEdit" } ); interface AddressEditProps { countries: SingleAutocompleteChoiceType[]; countryDisplayValue: string; data: AddressTypeInput; disabled?: boolean; errors: Array; onChange(event: React.ChangeEvent); onCountryChange(event: React.ChangeEvent); } function getErrorMessage( err: AccountErrorFragment | OrderErrorFragment, intl: IntlShape ): string { if (err?.__typename === "AccountError") { return getAccountErrorMessage(err, intl); } return getOrderErrorMessage(err, intl); } const AddressEdit: React.FC = props => { const { countries, countryDisplayValue, data, disabled, errors, onChange, onCountryChange } = props; const classes = useStyles(props); const intl = useIntl(); const formFields: Array = [ "city", "cityArea", "country", "countryArea", "firstName", "lastName", "companyName", "phone", "postalCode", "streetAddress1", "streetAddress2" ]; const formErrors = getFormErrors< keyof AddressTypeInput, AccountErrorFragment | OrderErrorFragment >(formFields, errors); return ( <>
); }; AddressEdit.displayName = "AddressEdit"; export default AddressEdit;