saleor-dashboard/src/customers/components/CustomerAddress/CustomerAddress.tsx
Tomasz Szymański c30429f7f4
Implement inclusion feature of postal codes (#983)
* Temporary merged schema and types update

* Update typing for zipCodeRules -> postalCodeRules

* Refactor zipCodes to postalCodes

* Fix new schema webhooks

* Delete postal code unassign dialog

* Query inclusion type from backend

* Clean up schema from old mutations

* Proper new mutations structure, all postal code related changes

* Linter changes

* Fix bug with save not being refreshed after codes are added / deleted / inclusion change

* Tests and translations

* Fix warnings across app, minor variables refactor

* Linting

* Trigger deployment

* CR changes, cleanups and refactors

* Update snapshots

* Resolve bug with radio not shows correct value on page refresh

* Fix price and weight creation of codes

* Reducer

* Revert "Reducer"

This reverts commit 07a3aed9c88332bde7d9be61b6dbc29e34e4edba.
2021-02-23 09:58:25 +01:00

135 lines
3.7 KiB
TypeScript

import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import { makeStyles } from "@material-ui/core/styles";
import AddressFormatter from "@saleor/components/AddressFormatter";
import CardMenu from "@saleor/components/CardMenu";
import CardTitle from "@saleor/components/CardTitle";
import Skeleton from "@saleor/components/Skeleton";
import React from "react";
import { defineMessages, useIntl } from "react-intl";
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 messages = defineMessages({
defaultAddress: {
defaultMessage: "Default Address"
},
defaultBillingAddress: {
defaultMessage: "Default Billing Address"
},
defaultShippingAddress: {
defaultMessage: "Default Shipping Address"
},
deleteAddress: {
defaultMessage: "Delete Address",
description: "button"
},
editAddress: {
defaultMessage: "Edit Address",
description: "button"
},
setDefaultBilling: {
defaultMessage: "Set as default billing address",
description: "button"
},
setDefaultShipping: {
defaultMessage: "Set as default shipping address",
description: "button"
}
});
const useStyles = makeStyles(
{
actions: {
flexDirection: "row"
},
actionsContainer: {
display: "flex",
flexDirection: "column",
height: "100%",
justifyContent: "flex-end"
},
card: {
display: "flex",
flexDirection: "column"
}
},
{ name: "CustomerAddress" }
);
const CustomerAddress: React.FC<CustomerAddressProps> = props => {
const {
address,
disabled,
isDefaultBillingAddress,
isDefaultShippingAddress,
onEdit,
onRemove,
onSetAsDefault
} = props;
const classes = useStyles(props);
const intl = useIntl();
return (
<Card className={classes.card}>
<CardTitle
title={
address ? (
<>
{isDefaultBillingAddress && isDefaultShippingAddress
? intl.formatMessage(messages.defaultAddress)
: isDefaultShippingAddress
? intl.formatMessage(messages.defaultShippingAddress)
: isDefaultBillingAddress
? intl.formatMessage(messages.defaultBillingAddress)
: null}
</>
) : (
<Skeleton />
)
}
height="const"
toolbar={
<CardMenu
disabled={disabled}
menuItems={[
{
label: intl.formatMessage(messages.setDefaultShipping),
onSelect: () => onSetAsDefault(AddressTypeEnum.SHIPPING)
},
{
label: intl.formatMessage(messages.setDefaultBilling),
onSelect: () => onSetAsDefault(AddressTypeEnum.BILLING)
},
{
label: intl.formatMessage(messages.editAddress),
onSelect: () => onEdit()
},
{
label: intl.formatMessage(messages.deleteAddress),
onSelect: () => onRemove()
}
]}
/>
}
/>
<CardContent>
<AddressFormatter address={address} />
</CardContent>
</Card>
);
};
CustomerAddress.displayName = "CustomerAddress";
export default CustomerAddress;