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 AddressFormatter from "@saleor/components/AddressFormatter";
|
|
|
|
import CardMenu from "@saleor/components/CardMenu";
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import Skeleton from "@saleor/components/Skeleton";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
2021-01-07 10:17:40 +00:00
|
|
|
import { defineMessages, useIntl } from "react-intl";
|
2020-05-14 09:30:32 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-01-07 10:17:40 +00:00
|
|
|
const messages = defineMessages({
|
|
|
|
defaultAddress: {
|
|
|
|
defaultMessage: "Default Address"
|
|
|
|
},
|
|
|
|
defaultShippingAddress: {
|
|
|
|
defaultMessage: "Default Shipping Address"
|
|
|
|
},
|
|
|
|
defaultBillingAddress: {
|
|
|
|
defaultMessage: "Default Billing Address"
|
|
|
|
},
|
|
|
|
setDefaultShipping: {
|
|
|
|
defaultMessage: "Set as default shipping address",
|
|
|
|
description: "button"
|
|
|
|
},
|
|
|
|
setDefaultBilling: {
|
|
|
|
defaultMessage: "Set as default billing address",
|
|
|
|
description: "button"
|
|
|
|
},
|
|
|
|
editAddress: {
|
|
|
|
defaultMessage: "Edit Address",
|
|
|
|
description: "button"
|
|
|
|
},
|
|
|
|
deleteAddress: {
|
|
|
|
defaultMessage: "Delete Address",
|
|
|
|
description: "button"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-03 15:28:40 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
{
|
|
|
|
actions: {
|
|
|
|
flexDirection: "row"
|
|
|
|
},
|
|
|
|
actionsContainer: {
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
height: "100%",
|
|
|
|
justifyContent: "flex-end"
|
|
|
|
},
|
|
|
|
card: {
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column"
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
{ name: "CustomerAddress" }
|
|
|
|
);
|
2019-10-30 14:34:24 +00:00
|
|
|
const CustomerAddress: React.FC<CustomerAddressProps> = props => {
|
|
|
|
const {
|
2019-06-19 14:40:52 +00:00
|
|
|
address,
|
|
|
|
disabled,
|
|
|
|
isDefaultBillingAddress,
|
|
|
|
isDefaultShippingAddress,
|
|
|
|
onEdit,
|
|
|
|
onRemove,
|
|
|
|
onSetAsDefault
|
2019-10-30 14:34:24 +00:00
|
|
|
} = props;
|
|
|
|
const classes = useStyles(props);
|
2019-08-23 12:23:59 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card className={classes.card}>
|
|
|
|
<CardTitle
|
|
|
|
title={
|
|
|
|
address ? (
|
|
|
|
<>
|
|
|
|
{isDefaultBillingAddress && isDefaultShippingAddress
|
2021-01-07 10:17:40 +00:00
|
|
|
? intl.formatMessage(messages.defaultAddress)
|
2019-10-30 14:34:24 +00:00
|
|
|
: isDefaultShippingAddress
|
2021-01-07 10:17:40 +00:00
|
|
|
? intl.formatMessage(messages.defaultShippingAddress)
|
2019-10-30 14:34:24 +00:00
|
|
|
: isDefaultBillingAddress
|
2021-01-07 10:17:40 +00:00
|
|
|
? intl.formatMessage(messages.defaultBillingAddress)
|
2019-10-30 14:34:24 +00:00
|
|
|
: null}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<Skeleton />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
height="const"
|
|
|
|
toolbar={
|
|
|
|
<CardMenu
|
|
|
|
disabled={disabled}
|
|
|
|
menuItems={[
|
|
|
|
{
|
2021-01-07 10:17:40 +00:00
|
|
|
label: intl.formatMessage(messages.setDefaultShipping),
|
2019-10-30 14:34:24 +00:00
|
|
|
onSelect: () => onSetAsDefault(AddressTypeEnum.SHIPPING)
|
|
|
|
},
|
|
|
|
{
|
2021-01-07 10:17:40 +00:00
|
|
|
label: intl.formatMessage(messages.setDefaultBilling),
|
2019-10-30 14:34:24 +00:00
|
|
|
onSelect: () => onSetAsDefault(AddressTypeEnum.BILLING)
|
2021-01-07 10:17:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: intl.formatMessage(messages.editAddress),
|
|
|
|
onSelect: () => onEdit()
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: intl.formatMessage(messages.deleteAddress),
|
|
|
|
onSelect: () => onRemove()
|
2019-10-30 14:34:24 +00:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<CardContent>
|
|
|
|
<AddressFormatter address={address} />
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
CustomerAddress.displayName = "CustomerAddress";
|
|
|
|
export default CustomerAddress;
|