2019-06-19 14:40:52 +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-06-19 14:40:52 +00:00
|
|
|
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 Skeleton from "@saleor/components/Skeleton";
|
2019-11-12 12:21:37 +00:00
|
|
|
import { maybe } from "@saleor/misc";
|
|
|
|
import { FormErrors } from "@saleor/types";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { CustomerDetails_user } from "../../types/CustomerDetails";
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const useStyles = makeStyles(theme => ({
|
|
|
|
cardTitle: {
|
2019-11-12 12:21:37 +00:00
|
|
|
height: 72
|
2019-10-30 14:34:24 +00:00
|
|
|
},
|
2019-11-12 12:21:37 +00:00
|
|
|
checkbox: {
|
|
|
|
marginBottom: theme.spacing()
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
paddingTop: theme.spacing()
|
|
|
|
},
|
|
|
|
subtitle: {
|
|
|
|
marginTop: theme.spacing()
|
2019-10-30 14:34:24 +00:00
|
|
|
}
|
|
|
|
}));
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
export interface CustomerDetailsProps {
|
2019-06-19 14:40:52 +00:00
|
|
|
customer: CustomerDetails_user;
|
|
|
|
data: {
|
|
|
|
isActive: boolean;
|
|
|
|
note: string;
|
|
|
|
};
|
|
|
|
disabled: boolean;
|
2019-11-12 12:21:37 +00:00
|
|
|
errors: FormErrors<"isActive" | "note">;
|
2019-06-19 14:40:52 +00:00
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const CustomerDetails: React.FC<CustomerDetailsProps> = props => {
|
|
|
|
const { customer, data, disabled, errors, onChange } = props;
|
|
|
|
const classes = useStyles(props);
|
|
|
|
|
|
|
|
const intl = useIntl();
|
2019-08-23 12:23:59 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardTitle
|
|
|
|
className={classes.cardTitle}
|
|
|
|
title={
|
|
|
|
<>
|
2019-11-12 12:21:37 +00:00
|
|
|
{maybe<React.ReactNode>(() => customer.email, <Skeleton />)}
|
2019-10-30 14:34:24 +00:00
|
|
|
{customer && customer.dateJoined ? (
|
2019-11-12 12:21:37 +00:00
|
|
|
<Typography
|
|
|
|
className={classes.subtitle}
|
|
|
|
variant="caption"
|
|
|
|
component="div"
|
|
|
|
>
|
2019-10-30 14:34:24 +00:00
|
|
|
<FormattedMessage
|
2019-11-12 12:21:37 +00:00
|
|
|
defaultMessage="Active member since {date}"
|
2019-10-30 14:34:24 +00:00
|
|
|
description="section subheader"
|
|
|
|
values={{
|
|
|
|
date: moment(customer.dateJoined).format("MMM YYYY")
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Typography>
|
|
|
|
) : (
|
|
|
|
<Skeleton style={{ width: "10rem" }} />
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
2019-11-12 12:21:37 +00:00
|
|
|
<CardContent className={classes.content}>
|
2019-10-30 14:34:24 +00:00
|
|
|
<ControlledCheckbox
|
|
|
|
checked={data.isActive}
|
2019-11-12 12:21:37 +00:00
|
|
|
className={classes.checkbox}
|
2019-10-30 14:34:24 +00:00
|
|
|
disabled={disabled}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "User account active",
|
|
|
|
description: "check to mark this account as active"
|
|
|
|
})}
|
|
|
|
name="isActive"
|
|
|
|
onChange={onChange}
|
2019-06-19 14:40:52 +00:00
|
|
|
/>
|
2019-10-30 14:34:24 +00:00
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.note}
|
|
|
|
fullWidth
|
|
|
|
multiline
|
|
|
|
helperText={errors.note}
|
|
|
|
name="note"
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Note",
|
|
|
|
description: "note about customer"
|
|
|
|
})}
|
|
|
|
value={data.note}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
CustomerDetails.displayName = "CustomerDetails";
|
|
|
|
export default CustomerDetails;
|