saleor-dashboard/src/customers/components/CustomerAddressChoiceCard/CustomerAddressChoiceCard.tsx
Michał Droń 394c33c0b5
Refactor changing address in order details directly (#1697) (#1818)
* Refactor changing address in order details directly (#1697)

* wip change address edit buttons behaviour in order draft

* wip modify dialog view when customer is not changed

* wip remove old address edit modal

* wip rm old address modal storybook

* wip async search state change

* wip disable edit in draft when no customer is selected

* wip fix submitting issues

* wip allow single address mutation

* wip fix billing change & manual address change

* wip fix covered country dropdown

* wip add address clone checkbox

* wip normal order details & unconfirmed views

* wip messages minor fixes

* wip clone address checkbox on new address input option

* Storybook update

* cleanup

* billing same as shipping fixes

* improve stories titles & move to component folder

* improve continueToAddressSearchState readibility

* improve dialog title/description message descriptors

* change .then() to await

* Remove redundant onClick arrow function

Co-authored-by: Dominik Żegleń <flesz3@o2.pl>

* Improve OrderAddressFields component

* move shipping & billing address edit props outside file

* Update snapshots

* fix mutation output types in order views

* Fix confirm button state type

* fix skipping query when modal is refreshed

* fix cancel button to match designs

* update dialog headers

* fix customer address choice card styling for blue theme

* change hidecard to showcard

* export types to local file

* improve isAnyAddressEditModalOpen function

* fix cut hover effect on inputs

* fix submitting modal when modal is closed with x button

* fix validation & initial form data

* update messages

* Update partial mutation return type

* Add vertical spacer component

* Revert CardSpacer changes

* Change some of Form & Card spacers to Vertical Spacers

* Fix makeStyles import in VerticalSpacer

* Fix border color for AddressCards

* Add type to addressFieldsCommonProps object

* Change stories subtitles to lowercase

* Fix country choices type

* Fix setState react type

* Improve address change handlers

* Update snapshots

* Fix default country not showing up in address edit single autocomplete field

Co-authored-by: Dominik Żegleń <flesz3@o2.pl>
Co-authored-by: Magdalena Markusik <magdalena.markusik@mirumee.com>

* Fix linter issue

Co-authored-by: Dominik Żegleń <flesz3@o2.pl>
Co-authored-by: Magdalena Markusik <magdalena.markusik@mirumee.com>
2022-02-02 12:22:39 +01:00

51 lines
1.6 KiB
TypeScript

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