saleor-dashboard/src/customers/components/CustomerInfo/CustomerInfo.tsx

110 lines
3.2 KiB
TypeScript
Raw Normal View History

2019-11-12 12:21:37 +00:00
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import { makeStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle";
import Grid from "@saleor/components/Grid";
import Hr from "@saleor/components/Hr";
import { commonMessages } from "@saleor/intl";
2020-02-24 14:14:48 +00:00
import { UserError } from "@saleor/types";
import { getFieldError } from "@saleor/utils/errors";
2019-11-12 12:21:37 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
content: {
paddingTop: theme.spacing(2)
},
hr: {
margin: theme.spacing(3, 0)
},
sectionHeader: {
marginBottom: theme.spacing()
}
}),
{ name: "CustomerInfo" }
);
2019-11-12 12:21:37 +00:00
2019-11-12 12:27:40 +00:00
export interface CustomerInfoProps {
2019-11-12 12:21:37 +00:00
data: {
firstName: string;
lastName: string;
email: string;
};
disabled: boolean;
2020-02-24 14:14:48 +00:00
errors: UserError[];
2019-11-12 12:21:37 +00:00
onChange: (event: React.ChangeEvent<any>) => void;
}
2019-11-12 12:27:40 +00:00
const CustomerInfo: React.FC<CustomerInfoProps> = props => {
const { data, disabled, errors, onChange } = props;
2019-11-12 12:21:37 +00:00
const classes = useStyles(props);
const intl = useIntl();
return (
<Card>
<CardTitle
title={
2019-11-12 12:27:40 +00:00
<FormattedMessage
defaultMessage="Personal Informations"
description="customer informations, header"
/>
2019-11-12 12:21:37 +00:00
}
/>
<CardContent className={classes.content}>
<Typography className={classes.sectionHeader}>
<FormattedMessage {...commonMessages.generalInformations} />
</Typography>
<Grid variant="uniform">
<TextField
disabled={disabled}
2020-02-24 14:14:48 +00:00
error={!!getFieldError(errors, "firstName")}
2019-11-12 12:21:37 +00:00
fullWidth
2020-02-24 14:14:48 +00:00
helperText={getFieldError(errors, "firstName")?.message}
2019-11-12 12:21:37 +00:00
name="firstName"
type="text"
label={intl.formatMessage(commonMessages.firstName)}
value={data.firstName}
onChange={onChange}
/>
<TextField
disabled={disabled}
2020-02-24 14:14:48 +00:00
error={!!getFieldError(errors, "lastName")}
2019-11-12 12:21:37 +00:00
fullWidth
2020-02-24 14:14:48 +00:00
helperText={getFieldError(errors, "lastName")?.message}
2019-11-12 12:21:37 +00:00
name="lastName"
type="text"
label={intl.formatMessage(commonMessages.lastName)}
value={data.lastName}
onChange={onChange}
/>
</Grid>
<Hr className={classes.hr} />
<Typography className={classes.sectionHeader}>
<FormattedMessage
defaultMessage="Contact Informations"
description="customer contact section, header"
/>
</Typography>
<TextField
disabled={disabled}
2020-02-24 14:14:48 +00:00
error={!!getFieldError(errors, "email")}
2019-11-12 12:21:37 +00:00
fullWidth
2020-02-24 14:14:48 +00:00
helperText={getFieldError(errors, "email")?.message}
2019-11-12 12:21:37 +00:00
name="email"
type="email"
label={intl.formatMessage(commonMessages.email)}
value={data.email}
onChange={onChange}
/>
</CardContent>
</Card>
);
};
2019-11-12 12:27:40 +00:00
CustomerInfo.displayName = "CustomerInfo";
export default CustomerInfo;