Call proper mutation on address change for draft / non draft order

This commit is contained in:
Tomasz Szymanski 2020-10-28 14:11:22 +01:00
parent e4fc4489df
commit 66f435bba0
2 changed files with 37 additions and 12 deletions

View file

@ -173,6 +173,7 @@ export const OrderDetailsMessages: React.FC<OrderDetailsMessages> = ({
}) })
}); });
} }
closeModal();
}; };
const handleShippingMethodUpdate = (data: OrderShippingMethodUpdate) => { const handleShippingMethodUpdate = (data: OrderShippingMethodUpdate) => {
const errs = data.orderUpdateShipping?.errors; const errs = data.orderUpdateShipping?.errors;

View file

@ -580,7 +580,11 @@ export const OrderDetails: React.FC<OrderDetailsProps> = ({ id, params }) => {
</> </>
)} )}
<OrderAddressEditDialog <OrderAddressEditDialog
confirmButtonState={orderUpdate.opts.status} confirmButtonState={
order?.status === OrderStatus.DRAFT
? orderDraftUpdate.opts.status
: orderUpdate.opts.status
}
address={transformAddressToForm(order?.shippingAddress)} address={transformAddressToForm(order?.shippingAddress)}
countries={ countries={
data?.shop?.countries.map(country => ({ data?.shop?.countries.map(country => ({
@ -588,21 +592,33 @@ export const OrderDetails: React.FC<OrderDetailsProps> = ({ id, params }) => {
label: country.country label: country.country
})) || [] })) || []
} }
errors={orderUpdate.opts.data?.orderUpdate.errors || []} errors={
(order?.status === OrderStatus.DRAFT
? orderDraftUpdate.opts.data?.draftOrderUpdate.errors
: orderUpdate.opts.data?.orderUpdate.errors) || []
}
open={params.action === "edit-shipping-address"} open={params.action === "edit-shipping-address"}
variant="shipping" variant="shipping"
onClose={closeModal} onClose={closeModal}
onConfirm={shippingAddress => onConfirm={shippingAddress => {
orderUpdate.mutate({ const updateMutation =
order?.status === OrderStatus.DRAFT
? orderDraftUpdate
: orderUpdate;
updateMutation.mutate({
id, id,
input: { input: {
shippingAddress shippingAddress
} }
}) });
} }}
/> />
<OrderAddressEditDialog <OrderAddressEditDialog
confirmButtonState={orderUpdate.opts.status} confirmButtonState={
order?.status === OrderStatus.DRAFT
? orderDraftUpdate.opts.status
: orderUpdate.opts.status
}
address={transformAddressToForm(order?.billingAddress)} address={transformAddressToForm(order?.billingAddress)}
countries={ countries={
data?.shop?.countries.map(country => ({ data?.shop?.countries.map(country => ({
@ -610,18 +626,26 @@ export const OrderDetails: React.FC<OrderDetailsProps> = ({ id, params }) => {
label: country.country label: country.country
})) || [] })) || []
} }
errors={orderUpdate.opts.data?.orderUpdate.errors || []} errors={
(order?.status === OrderStatus.DRAFT
? orderDraftUpdate.opts.data?.draftOrderUpdate.errors
: orderUpdate.opts.data?.orderUpdate.errors) || []
}
open={params.action === "edit-billing-address"} open={params.action === "edit-billing-address"}
variant="billing" variant="billing"
onClose={closeModal} onClose={closeModal}
onConfirm={billingAddress => onConfirm={billingAddress => {
orderUpdate.mutate({ const updateMutation =
order?.status === OrderStatus.DRAFT
? orderDraftUpdate
: orderUpdate;
updateMutation.mutate({
id, id,
input: { input: {
billingAddress billingAddress
} }
}) });
} }}
/> />
</> </>
)} )}