2019-06-19 14:40:52 +00:00
|
|
|
import Button from "@material-ui/core/Button";
|
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardActions from "@material-ui/core/CardActions";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
|
|
|
import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
|
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 AddressFormatter from "@saleor/components/AddressFormatter";
|
|
|
|
import CardMenu from "@saleor/components/CardMenu";
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import Skeleton from "@saleor/components/Skeleton";
|
2019-08-23 12:23:59 +00:00
|
|
|
import { buttonMessages } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { AddressTypeEnum } from "../../../types/globalTypes";
|
|
|
|
import { CustomerAddresses_user_addresses } from "../../types/CustomerAddresses";
|
|
|
|
|
|
|
|
export interface CustomerAddressProps {
|
|
|
|
address: CustomerAddresses_user_addresses;
|
|
|
|
disabled: boolean;
|
|
|
|
isDefaultBillingAddress: boolean;
|
|
|
|
isDefaultShippingAddress: boolean;
|
|
|
|
addressNumber: number;
|
|
|
|
onEdit: () => void;
|
|
|
|
onRemove: () => void;
|
|
|
|
onSetAsDefault: (type: AddressTypeEnum) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = createStyles({
|
|
|
|
actions: {
|
|
|
|
flexDirection: "row"
|
|
|
|
},
|
|
|
|
actionsContainer: {
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
height: "100%",
|
|
|
|
justifyContent: "flex-end"
|
|
|
|
},
|
|
|
|
card: {
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const CustomerAddress = withStyles(styles, { name: "CustomerAddress" })(
|
|
|
|
({
|
|
|
|
address,
|
|
|
|
classes,
|
|
|
|
disabled,
|
|
|
|
isDefaultBillingAddress,
|
|
|
|
isDefaultShippingAddress,
|
|
|
|
onEdit,
|
|
|
|
onRemove,
|
|
|
|
onSetAsDefault
|
2019-08-23 12:23:59 +00:00
|
|
|
}: CustomerAddressProps & WithStyles<typeof styles>) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card className={classes.card}>
|
|
|
|
<CardTitle
|
|
|
|
title={
|
|
|
|
address ? (
|
|
|
|
<>
|
2019-09-05 10:54:31 +00:00
|
|
|
{isDefaultBillingAddress && isDefaultShippingAddress
|
|
|
|
? intl.formatMessage({
|
|
|
|
defaultMessage: "Default Address"
|
|
|
|
})
|
|
|
|
: isDefaultShippingAddress
|
|
|
|
? intl.formatMessage({
|
|
|
|
defaultMessage: "Default Shipping Address"
|
|
|
|
})
|
|
|
|
: isDefaultBillingAddress
|
|
|
|
? intl.formatMessage({
|
|
|
|
defaultMessage: "Default Billing Address"
|
|
|
|
})
|
|
|
|
: null}
|
2019-08-23 12:23:59 +00:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<Skeleton />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
height="const"
|
|
|
|
toolbar={
|
|
|
|
<CardMenu
|
|
|
|
disabled={disabled}
|
|
|
|
menuItems={[
|
|
|
|
{
|
|
|
|
label: intl.formatMessage({
|
|
|
|
defaultMessage: "Set as default shipping address",
|
|
|
|
description: "button"
|
|
|
|
}),
|
|
|
|
onSelect: () => onSetAsDefault(AddressTypeEnum.SHIPPING)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: intl.formatMessage({
|
|
|
|
defaultMessage: "Set as default billing address",
|
|
|
|
description: "button"
|
|
|
|
}),
|
|
|
|
onSelect: () => onSetAsDefault(AddressTypeEnum.BILLING)
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<CardContent>
|
|
|
|
<AddressFormatter address={address} />
|
|
|
|
</CardContent>
|
|
|
|
<div className={classes.actionsContainer}>
|
|
|
|
<CardActions className={classes.actions}>
|
|
|
|
<Button color="primary" disabled={disabled} onClick={onEdit}>
|
|
|
|
<FormattedMessage {...buttonMessages.edit} />
|
|
|
|
</Button>
|
|
|
|
<Button color="primary" disabled={disabled} onClick={onRemove}>
|
2019-09-05 10:44:10 +00:00
|
|
|
<FormattedMessage {...buttonMessages.delete} />
|
2019-08-23 12:23:59 +00:00
|
|
|
</Button>
|
|
|
|
</CardActions>
|
|
|
|
</div>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
);
|
|
|
|
CustomerAddress.displayName = "CustomerAddress";
|
|
|
|
export default CustomerAddress;
|