
* Create user addresses select modal * Prepare user addresses select modal form * Add user addresses select modal to order draft details page * Update draft order validation of adresses in edit modal * Add Customer Change modal * Update snapshots and messages * Indication of address form errors by address type * Refactor addresses submiting * Refactor address transform functions * Add data-testids to addresses change dialog * Update customer address choice style * Trigger CI * Update customer addresses edit flow * Move styles outside of component files * Refactor after review * Refactor after review * Do not update customer if the same selected * Handle setting adress after edit customer with no addresses * Trigger CI
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
import { transformAddressToForm } from "@saleor/misc";
|
|
import OrderAddressEditDialog from "@saleor/orders/components/OrderAddressEditDialog";
|
|
import { OrderDetails } from "@saleor/orders/types/OrderDetails";
|
|
import {
|
|
OrderDraftUpdate,
|
|
OrderDraftUpdateVariables
|
|
} from "@saleor/orders/types/OrderDraftUpdate";
|
|
import {
|
|
OrderUpdate,
|
|
OrderUpdateVariables
|
|
} from "@saleor/orders/types/OrderUpdate";
|
|
import { PartialMutationProviderOutput } from "@saleor/types";
|
|
import { AddressInput } from "@saleor/types/globalTypes";
|
|
import React from "react";
|
|
|
|
enum FieldType {
|
|
shipping = "shippingAddress",
|
|
billing = "billingAddress"
|
|
}
|
|
|
|
interface Props {
|
|
action: string;
|
|
id: string;
|
|
isDraft: boolean;
|
|
data: OrderDetails;
|
|
onClose: () => void;
|
|
orderUpdate: PartialMutationProviderOutput<OrderUpdate, OrderUpdateVariables>;
|
|
orderDraftUpdate: PartialMutationProviderOutput<
|
|
OrderDraftUpdate,
|
|
OrderDraftUpdateVariables
|
|
>;
|
|
}
|
|
|
|
const OrderAddressFields = ({
|
|
action,
|
|
isDraft,
|
|
id,
|
|
onClose,
|
|
orderUpdate,
|
|
orderDraftUpdate,
|
|
data
|
|
}: Props) => {
|
|
const order = data?.order;
|
|
|
|
const handleConfirm = (type: FieldType) => (value: AddressInput) => {
|
|
const updateMutation = isDraft ? orderDraftUpdate : orderUpdate;
|
|
|
|
updateMutation.mutate({
|
|
id,
|
|
input: {
|
|
[type]: value
|
|
}
|
|
});
|
|
};
|
|
|
|
const addressFieldCommonProps = {
|
|
confirmButtonState: isDraft
|
|
? orderDraftUpdate.opts.status
|
|
: orderUpdate.opts.status,
|
|
countries: data?.shop?.countries,
|
|
errors: isDraft
|
|
? orderDraftUpdate.opts.data?.draftOrderUpdate.errors
|
|
: orderUpdate.opts.data?.orderUpdate.errors,
|
|
onClose
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<OrderAddressEditDialog
|
|
{...addressFieldCommonProps}
|
|
address={transformAddressToForm(order?.shippingAddress)}
|
|
open={action === "edit-shipping-address"}
|
|
variant="shipping"
|
|
onConfirm={handleConfirm(FieldType.shipping)}
|
|
/>
|
|
<OrderAddressEditDialog
|
|
{...addressFieldCommonProps}
|
|
address={transformAddressToForm(order?.billingAddress)}
|
|
open={action === "edit-billing-address"}
|
|
variant="billing"
|
|
onConfirm={handleConfirm(FieldType.billing)}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default OrderAddressFields;
|