saleor-dashboard/src/orders/components/OrderAddressFields/OrderAddressFields.tsx

90 lines
2.7 KiB
TypeScript
Raw Normal View History

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 11:22:39 +00:00
import { CustomerAddresses_user } from "@saleor/customers/types/CustomerAddresses";
import { OrderErrorFragment } from "@saleor/fragments/types/OrderErrorFragment";
import { SubmitPromise } from "@saleor/hooks/useForm";
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
import { transformAddressToForm } from "@saleor/misc";
import {
OrderDetails_order_billingAddress,
OrderDetails_order_shippingAddress,
OrderDetails_shop_countries
} from "@saleor/orders/types/OrderDetails";
import React from "react";
import OrderCustomerAddressesEditDialog, {
OrderCustomerAddressesEditDialogProps
} from "../OrderCustomerAddressesEditDialog";
import {
AddressEditDialogVariant,
OrderCustomerAddressesEditDialogOutput
} from "../OrderCustomerAddressesEditDialog/types";
interface OrderAddressFieldsProps {
action: string;
isDraft: boolean;
customerAddressesLoading: boolean;
customer: CustomerAddresses_user;
countries: OrderDetails_shop_countries[];
onClose: () => void;
onConfirm: (data: OrderCustomerAddressesEditDialogOutput) => SubmitPromise;
confirmButtonState: ConfirmButtonTransitionState;
errors: OrderErrorFragment[];
orderShippingAddress: OrderDetails_order_shippingAddress;
orderBillingAddress: OrderDetails_order_billingAddress;
}
const OrderAddressFields: React.FC<OrderAddressFieldsProps> = ({
action,
isDraft,
customerAddressesLoading,
customer,
countries,
onClose,
onConfirm,
confirmButtonState,
errors,
orderShippingAddress,
orderBillingAddress
}) => {
const addressFieldCommonProps: Omit<
OrderCustomerAddressesEditDialogProps,
"open" | "variant"
> = {
loading: customerAddressesLoading,
confirmButtonState,
countries,
errors,
orderShippingAddress: transformAddressToForm(orderShippingAddress),
orderBillingAddress: transformAddressToForm(orderBillingAddress),
customerAddresses: customer?.addresses,
defaultShippingAddress: customer?.defaultShippingAddress,
defaultBillingAddress: customer?.defaultBillingAddress,
onClose,
onConfirm
};
return (
<>
{isDraft && (
<OrderCustomerAddressesEditDialog
open={action === "edit-customer-addresses"}
variant={AddressEditDialogVariant.CHANGE_CUSTOMER}
{...addressFieldCommonProps}
/>
)}
<OrderCustomerAddressesEditDialog
open={action === "edit-shipping-address"}
variant={AddressEditDialogVariant.CHANGE_SHIPPING_ADDRESS}
{...addressFieldCommonProps}
/>
<OrderCustomerAddressesEditDialog
open={action === "edit-billing-address"}
variant={AddressEditDialogVariant.CHANGE_BILLING_ADDRESS}
{...addressFieldCommonProps}
/>
</>
);
};
export default OrderAddressFields;