2019-06-19 14:40:52 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
|
|
|
import {
|
|
|
|
createStyles,
|
|
|
|
Theme,
|
|
|
|
withStyles,
|
|
|
|
WithStyles
|
|
|
|
} from "@material-ui/core/styles";
|
|
|
|
import TextField from "@material-ui/core/TextField";
|
|
|
|
import Typography from "@material-ui/core/Typography";
|
2019-08-09 11:14:35 +00:00
|
|
|
import moment from "moment-timezone";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-23 12:23:59 +00:00
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import { ControlledCheckbox } from "@saleor/components/ControlledCheckbox";
|
|
|
|
import { FormSpacer } from "@saleor/components/FormSpacer";
|
|
|
|
import Skeleton from "@saleor/components/Skeleton";
|
2019-08-23 12:23:59 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { CustomerDetails_user } from "../../types/CustomerDetails";
|
|
|
|
|
2019-10-28 16:16:49 +00:00
|
|
|
const styles = theme =>
|
2019-06-19 14:40:52 +00:00
|
|
|
createStyles({
|
|
|
|
cardTitle: {
|
|
|
|
height: 64
|
|
|
|
},
|
|
|
|
root: {
|
|
|
|
display: "grid" as "grid",
|
2019-10-28 16:16:49 +00:00
|
|
|
gridColumnGap: theme.spacing(2),
|
|
|
|
gridRowGap: theme.spacing(3),
|
2019-06-19 14:40:52 +00:00
|
|
|
gridTemplateColumns: "1fr 1fr"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export interface CustomerDetailsProps extends WithStyles<typeof styles> {
|
|
|
|
customer: CustomerDetails_user;
|
|
|
|
data: {
|
|
|
|
firstName: string;
|
|
|
|
lastName: string;
|
|
|
|
email: string;
|
|
|
|
isActive: boolean;
|
|
|
|
note: string;
|
|
|
|
};
|
|
|
|
disabled: boolean;
|
|
|
|
errors: {
|
|
|
|
firstName?: string;
|
|
|
|
lastName?: string;
|
|
|
|
email?: string;
|
|
|
|
note?: string;
|
|
|
|
};
|
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CustomerDetails = withStyles(styles, { name: "CustomerDetails" })(
|
|
|
|
({
|
|
|
|
classes,
|
|
|
|
customer,
|
|
|
|
data,
|
|
|
|
disabled,
|
|
|
|
errors,
|
|
|
|
onChange
|
2019-08-23 12:23:59 +00:00
|
|
|
}: CustomerDetailsProps) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardTitle
|
|
|
|
className={classes.cardTitle}
|
|
|
|
title={
|
|
|
|
<>
|
|
|
|
<FormattedMessage {...commonMessages.generalInformations} />
|
|
|
|
{customer && customer.dateJoined ? (
|
2019-10-28 16:16:49 +00:00
|
|
|
<Typography variant="caption" component="div">
|
2019-08-23 12:23:59 +00:00
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Customer since: {date}"
|
|
|
|
description="section subheader"
|
|
|
|
values={{
|
|
|
|
date: moment(customer.dateJoined).format("MMM YYYY")
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Typography>
|
|
|
|
) : (
|
|
|
|
<Skeleton style={{ width: "10rem" }} />
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
/>
|
2019-08-23 12:23:59 +00:00
|
|
|
<CardContent>
|
|
|
|
<ControlledCheckbox
|
|
|
|
checked={data.isActive}
|
|
|
|
disabled={disabled}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "User account active",
|
|
|
|
description: "check to mark this account as active"
|
|
|
|
})}
|
|
|
|
name="isActive"
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<div className={classes.root}>
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.firstName}
|
|
|
|
fullWidth
|
|
|
|
helperText={errors.firstName}
|
|
|
|
name="firstName"
|
|
|
|
type="text"
|
|
|
|
label={intl.formatMessage(commonMessages.firstName)}
|
|
|
|
value={data.firstName}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.lastName}
|
|
|
|
fullWidth
|
|
|
|
helperText={errors.lastName}
|
|
|
|
name="lastName"
|
|
|
|
type="text"
|
|
|
|
label={intl.formatMessage(commonMessages.lastName)}
|
|
|
|
value={data.lastName}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<FormSpacer />
|
2019-06-19 14:40:52 +00:00
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2019-08-23 12:23:59 +00:00
|
|
|
error={!!errors.email}
|
2019-06-19 14:40:52 +00:00
|
|
|
fullWidth
|
2019-08-23 12:23:59 +00:00
|
|
|
helperText={errors.email}
|
|
|
|
name="email"
|
|
|
|
type="email"
|
|
|
|
label={intl.formatMessage(commonMessages.email)}
|
|
|
|
value={data.email}
|
2019-06-19 14:40:52 +00:00
|
|
|
onChange={onChange}
|
|
|
|
/>
|
2019-08-23 12:23:59 +00:00
|
|
|
<FormSpacer />
|
2019-06-19 14:40:52 +00:00
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2019-08-23 12:23:59 +00:00
|
|
|
error={!!errors.note}
|
2019-06-19 14:40:52 +00:00
|
|
|
fullWidth
|
2019-08-23 12:23:59 +00:00
|
|
|
multiline
|
|
|
|
helperText={errors.note}
|
|
|
|
name="note"
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Note",
|
|
|
|
description: "note about customer"
|
|
|
|
})}
|
|
|
|
value={data.note}
|
2019-06-19 14:40:52 +00:00
|
|
|
onChange={onChange}
|
|
|
|
/>
|
2019-08-23 12:23:59 +00:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
);
|
|
|
|
CustomerDetails.displayName = "CustomerDetails";
|
|
|
|
export default CustomerDetails;
|