2021-12-03 11:59:29 +00:00
|
|
|
import { Card, CardContent, Typography } from "@material-ui/core";
|
2021-05-06 11:38:15 +00:00
|
|
|
import AddressFormatter from "@saleor/components/AddressFormatter";
|
2021-12-03 11:59:29 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
|
|
|
import { EditIcon } from "@saleor/macaw-ui";
|
2021-05-06 11:38:15 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
import React from "react";
|
2021-12-03 11:59:29 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2021-05-06 11:38:15 +00:00
|
|
|
|
|
|
|
import { CustomerAddresses_user_addresses } from "../../types/CustomerAddresses";
|
|
|
|
import { useStyles } from "./styles";
|
|
|
|
|
|
|
|
export interface CustomerAddressChoiceCardProps {
|
|
|
|
address: CustomerAddresses_user_addresses;
|
2021-12-03 11:59:29 +00:00
|
|
|
selected?: boolean;
|
|
|
|
editable?: boolean;
|
|
|
|
onSelect?: () => void;
|
|
|
|
onEditClick?: () => void;
|
2021-05-06 11:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const CustomerAddressChoiceCard: React.FC<CustomerAddressChoiceCardProps> = props => {
|
2021-12-03 11:59:29 +00:00
|
|
|
const { address, selected, editable, onSelect, onEditClick } = props;
|
2021-05-06 11:38:15 +00:00
|
|
|
const classes = useStyles(props);
|
|
|
|
|
2021-12-03 11:59:29 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
|
2021-05-06 11:38:15 +00:00
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
className={classNames(classes.card, {
|
2021-12-03 11:59:29 +00:00
|
|
|
[classes.cardSelected]: selected,
|
2022-02-02 11:22:39 +00:00
|
|
|
[classes.selectableCard]: !editable && !selected
|
2021-05-06 11:38:15 +00:00
|
|
|
})}
|
|
|
|
onClick={onSelect}
|
|
|
|
>
|
2021-12-03 11:59:29 +00:00
|
|
|
<CardContent className={classes.cardContent}>
|
2021-05-06 11:38:15 +00:00
|
|
|
<AddressFormatter address={address} />
|
2021-12-03 11:59:29 +00:00
|
|
|
{editable && (
|
|
|
|
<div onClick={onEditClick}>
|
|
|
|
<EditIcon className={classes.editIcon} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{selected && (
|
|
|
|
<Typography color="primary" className={classes.selectedLabel}>
|
|
|
|
{intl.formatMessage(commonMessages.selected)}
|
|
|
|
</Typography>
|
|
|
|
)}
|
2021-05-06 11:38:15 +00:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
CustomerAddressChoiceCard.displayName = "CustomerAddressChoiceCard";
|
|
|
|
export default CustomerAddressChoiceCard;
|