2019-08-09 10:17:04 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
2019-10-30 14:34:24 +00:00
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
2019-08-09 10:17:04 +00:00
|
|
|
import TextField from "@material-ui/core/TextField";
|
|
|
|
import React from "react";
|
2019-08-26 21:39:21 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
|
|
|
import Grid from "@saleor/components/Grid";
|
|
|
|
import SingleAutocompleteSelectField, {
|
|
|
|
SingleAutocompleteChoiceType
|
|
|
|
} from "@saleor/components/SingleAutocompleteSelectField";
|
|
|
|
import { ChangeEvent } from "@saleor/hooks/useForm";
|
2020-02-24 14:14:48 +00:00
|
|
|
import { UserError } from "@saleor/types";
|
|
|
|
import { getFieldError } from "@saleor/utils/errors";
|
2019-08-09 10:17:04 +00:00
|
|
|
import { SiteSettingsPageFormData } from "../SiteSettingsPage";
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
interface SiteSettingsAddressProps {
|
2019-08-09 10:17:04 +00:00
|
|
|
countries: SingleAutocompleteChoiceType[];
|
|
|
|
data: SiteSettingsPageFormData;
|
|
|
|
displayCountry: string;
|
2020-02-24 14:14:48 +00:00
|
|
|
errors: UserError[];
|
2019-08-09 10:17:04 +00:00
|
|
|
disabled: boolean;
|
|
|
|
onChange: (event: ChangeEvent) => void;
|
|
|
|
onCountryChange: (event: ChangeEvent) => void;
|
|
|
|
}
|
|
|
|
|
2019-12-03 15:28:40 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
{
|
|
|
|
root: {
|
|
|
|
overflow: "visible"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ name: "SiteSettingsAddress" }
|
|
|
|
);
|
2019-08-09 10:17:04 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const SiteSettingsAddress: React.FC<SiteSettingsAddressProps> = props => {
|
|
|
|
const {
|
2019-08-09 10:17:04 +00:00
|
|
|
countries,
|
|
|
|
data,
|
|
|
|
disabled,
|
|
|
|
displayCountry,
|
|
|
|
errors,
|
|
|
|
onChange,
|
|
|
|
onCountryChange
|
2019-10-30 14:34:24 +00:00
|
|
|
} = props;
|
|
|
|
const classes = useStyles(props);
|
2019-08-26 21:39:21 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card className={classes.root}>
|
|
|
|
<CardTitle
|
|
|
|
title={intl.formatMessage({
|
|
|
|
defaultMessage: "Store Information",
|
|
|
|
description: "section header"
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<CardContent>
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-02-24 14:14:48 +00:00
|
|
|
error={!!getFieldError(errors, "companyName")}
|
|
|
|
helperText={getFieldError(errors, "companyName")?.message}
|
2019-10-30 14:34:24 +00:00
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Company"
|
|
|
|
})}
|
|
|
|
name={"companyName" as keyof SiteSettingsPageFormData}
|
|
|
|
onChange={onChange}
|
|
|
|
value={data.companyName}
|
|
|
|
fullWidth
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-02-24 14:14:48 +00:00
|
|
|
error={!!getFieldError(errors, "streetAddress1")}
|
|
|
|
helperText={getFieldError(errors, "streetAddress1")?.message}
|
2019-10-30 14:34:24 +00:00
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Address line 1"
|
2019-08-26 21:39:21 +00:00
|
|
|
})}
|
2019-10-30 14:34:24 +00:00
|
|
|
name={"streetAddress1" as keyof SiteSettingsPageFormData}
|
|
|
|
onChange={onChange}
|
|
|
|
value={data.streetAddress1}
|
|
|
|
fullWidth
|
2019-08-09 10:17:04 +00:00
|
|
|
/>
|
2019-10-30 14:34:24 +00:00
|
|
|
<FormSpacer />
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-02-24 14:14:48 +00:00
|
|
|
error={!!getFieldError(errors, "streetAddress2")}
|
|
|
|
helperText={getFieldError(errors, "streetAddress2")?.message}
|
2019-10-30 14:34:24 +00:00
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Address line 2"
|
|
|
|
})}
|
|
|
|
name={"streetAddress2" as keyof SiteSettingsPageFormData}
|
|
|
|
onChange={onChange}
|
|
|
|
value={data.streetAddress2}
|
|
|
|
fullWidth
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<Grid>
|
2019-08-09 10:17:04 +00:00
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-02-24 14:14:48 +00:00
|
|
|
error={!!getFieldError(errors, "city")}
|
|
|
|
helperText={getFieldError(errors, "city")?.message}
|
2019-08-26 21:39:21 +00:00
|
|
|
label={intl.formatMessage({
|
2019-10-30 14:34:24 +00:00
|
|
|
defaultMessage: "City"
|
2019-08-26 21:39:21 +00:00
|
|
|
})}
|
2019-10-30 14:34:24 +00:00
|
|
|
name={"city" as keyof SiteSettingsPageFormData}
|
2019-08-09 10:17:04 +00:00
|
|
|
onChange={onChange}
|
2019-10-30 14:34:24 +00:00
|
|
|
value={data.city}
|
2019-08-09 10:17:04 +00:00
|
|
|
fullWidth
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-02-24 14:14:48 +00:00
|
|
|
error={!!getFieldError(errors, "postalCode")}
|
|
|
|
helperText={getFieldError(errors, "postalCode")?.message}
|
2019-08-26 21:39:21 +00:00
|
|
|
label={intl.formatMessage({
|
2019-10-30 14:34:24 +00:00
|
|
|
defaultMessage: "ZIP / Postal code"
|
2019-08-26 21:39:21 +00:00
|
|
|
})}
|
2019-10-30 14:34:24 +00:00
|
|
|
name={"postalCode" as keyof SiteSettingsPageFormData}
|
2019-08-09 10:17:04 +00:00
|
|
|
onChange={onChange}
|
2019-10-30 14:34:24 +00:00
|
|
|
value={data.postalCode}
|
2019-08-09 10:17:04 +00:00
|
|
|
fullWidth
|
|
|
|
/>
|
2019-10-30 14:34:24 +00:00
|
|
|
</Grid>
|
|
|
|
<FormSpacer />
|
|
|
|
<Grid>
|
|
|
|
<SingleAutocompleteSelectField
|
2019-08-09 10:17:04 +00:00
|
|
|
disabled={disabled}
|
2019-10-30 14:34:24 +00:00
|
|
|
displayValue={displayCountry}
|
2020-02-24 14:14:48 +00:00
|
|
|
error={!!getFieldError(errors, "country")}
|
|
|
|
helperText={getFieldError(errors, "country")?.message}
|
2019-08-26 21:39:21 +00:00
|
|
|
label={intl.formatMessage({
|
2019-10-30 14:34:24 +00:00
|
|
|
defaultMessage: "Country"
|
2019-08-26 21:39:21 +00:00
|
|
|
})}
|
2019-10-30 14:34:24 +00:00
|
|
|
name={"country" as keyof SiteSettingsPageFormData}
|
|
|
|
onChange={onCountryChange}
|
|
|
|
value={data.country}
|
|
|
|
choices={countries}
|
|
|
|
InputProps={{
|
|
|
|
autoComplete: "off"
|
|
|
|
}}
|
2019-08-09 10:17:04 +00:00
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-02-24 14:14:48 +00:00
|
|
|
error={!!getFieldError(errors, "companyArea")}
|
|
|
|
helperText={getFieldError(errors, "companyArea")?.message}
|
2019-08-26 21:39:21 +00:00
|
|
|
label={intl.formatMessage({
|
2019-10-30 14:34:24 +00:00
|
|
|
defaultMessage: "Country area"
|
2019-08-26 21:39:21 +00:00
|
|
|
})}
|
2019-10-30 14:34:24 +00:00
|
|
|
name={"countryArea" as keyof SiteSettingsPageFormData}
|
2019-08-26 21:39:21 +00:00
|
|
|
onChange={onChange}
|
2019-10-30 14:34:24 +00:00
|
|
|
value={data.countryArea}
|
|
|
|
fullWidth
|
2019-08-09 10:17:04 +00:00
|
|
|
/>
|
2019-10-30 14:34:24 +00:00
|
|
|
</Grid>
|
|
|
|
<FormSpacer />
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-02-24 14:14:48 +00:00
|
|
|
error={!!getFieldError(errors, "phone")}
|
2019-10-30 14:34:24 +00:00
|
|
|
fullWidth
|
2020-02-24 14:14:48 +00:00
|
|
|
helperText={getFieldError(errors, "phone")?.message}
|
2019-10-30 14:34:24 +00:00
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Phone"
|
|
|
|
})}
|
|
|
|
name={"phone" as keyof SiteSettingsPageFormData}
|
|
|
|
value={data.phone}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-08-09 10:17:04 +00:00
|
|
|
SiteSettingsAddress.displayName = "SiteSettingsAddress";
|
|
|
|
export default SiteSettingsAddress;
|