2021-03-23 17:13:39 +00:00
|
|
|
import { WindowTitle } from "@saleor/components/WindowTitle";
|
|
|
|
import { DEFAULT_INITIAL_SEARCH_DATA } from "@saleor/config";
|
2022-02-02 11:22:39 +00:00
|
|
|
import { useCustomerAddressesQuery } from "@saleor/customers/queries";
|
2021-03-23 17:13:39 +00:00
|
|
|
import useNavigator from "@saleor/hooks/useNavigator";
|
|
|
|
import OrderCannotCancelOrderDialog from "@saleor/orders/components/OrderCannotCancelOrderDialog";
|
2022-02-02 11:22:39 +00:00
|
|
|
import { OrderCustomerAddressesEditDialogOutput } from "@saleor/orders/components/OrderCustomerAddressesEditDialog/types";
|
2021-08-20 14:36:05 +00:00
|
|
|
import OrderFulfillmentApproveDialog from "@saleor/orders/components/OrderFulfillmentApproveDialog";
|
2021-03-23 17:13:39 +00:00
|
|
|
import OrderInvoiceEmailSendDialog from "@saleor/orders/components/OrderInvoiceEmailSendDialog";
|
2021-08-20 14:36:05 +00:00
|
|
|
import {
|
|
|
|
OrderFulfillmentApprove,
|
|
|
|
OrderFulfillmentApproveVariables
|
|
|
|
} from "@saleor/orders/types/OrderFulfillmentApprove";
|
2022-02-02 11:22:39 +00:00
|
|
|
import {
|
|
|
|
OrderUpdate,
|
|
|
|
OrderUpdateVariables
|
|
|
|
} from "@saleor/orders/types/OrderUpdate";
|
2021-03-23 17:13:39 +00:00
|
|
|
import { OrderDiscountProvider } from "@saleor/products/components/OrderDiscountProviders/OrderDiscountProvider";
|
|
|
|
import { OrderLineDiscountProvider } from "@saleor/products/components/OrderDiscountProviders/OrderLineDiscountProvider";
|
2021-08-20 14:36:05 +00:00
|
|
|
import { PartialMutationProviderOutput } from "@saleor/types";
|
2021-05-10 15:25:54 +00:00
|
|
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
2021-03-23 17:13:39 +00:00
|
|
|
import { useWarehouseList } from "@saleor/warehouses/queries";
|
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
|
|
|
import { customerUrl } from "../../../../customers/urls";
|
2022-02-01 09:58:06 +00:00
|
|
|
import {
|
|
|
|
extractMutationErrors,
|
|
|
|
getMutationState,
|
|
|
|
getStringOrPlaceholder
|
|
|
|
} from "../../../../misc";
|
2021-03-23 17:13:39 +00:00
|
|
|
import { productUrl } from "../../../../products/urls";
|
|
|
|
import { FulfillmentStatus } from "../../../../types/globalTypes";
|
2022-02-02 11:22:39 +00:00
|
|
|
import OrderAddressFields from "../../../components/OrderAddressFields/OrderAddressFields";
|
2021-03-23 17:13:39 +00:00
|
|
|
import OrderCancelDialog from "../../../components/OrderCancelDialog";
|
|
|
|
import OrderDetailsPage from "../../../components/OrderDetailsPage";
|
|
|
|
import OrderFulfillmentCancelDialog from "../../../components/OrderFulfillmentCancelDialog";
|
|
|
|
import OrderFulfillmentTrackingDialog from "../../../components/OrderFulfillmentTrackingDialog";
|
|
|
|
import OrderMarkAsPaidDialog from "../../../components/OrderMarkAsPaidDialog/OrderMarkAsPaidDialog";
|
|
|
|
import OrderPaymentDialog from "../../../components/OrderPaymentDialog";
|
|
|
|
import OrderPaymentVoidDialog from "../../../components/OrderPaymentVoidDialog";
|
|
|
|
import OrderProductAddDialog from "../../../components/OrderProductAddDialog";
|
|
|
|
import OrderShippingMethodEditDialog from "../../../components/OrderShippingMethodEditDialog";
|
|
|
|
import { useOrderVariantSearch } from "../../../queries";
|
|
|
|
import {
|
|
|
|
orderFulfillUrl,
|
|
|
|
orderListUrl,
|
|
|
|
orderRefundUrl,
|
|
|
|
orderReturnPath,
|
|
|
|
orderUrl,
|
|
|
|
OrderUrlQueryParams
|
|
|
|
} from "../../../urls";
|
2022-02-02 11:22:39 +00:00
|
|
|
import { isAnyAddressEditModalOpen } from "../OrderDraftDetails";
|
2021-03-23 17:13:39 +00:00
|
|
|
|
|
|
|
interface OrderUnconfirmedDetailsProps {
|
|
|
|
id: string;
|
|
|
|
params: OrderUrlQueryParams;
|
|
|
|
data: any;
|
|
|
|
orderAddNote: any;
|
|
|
|
orderLineUpdate: any;
|
|
|
|
orderLineDelete: any;
|
|
|
|
orderInvoiceRequest: any;
|
|
|
|
handleSubmit: any;
|
2022-02-02 11:22:39 +00:00
|
|
|
orderUpdate: PartialMutationProviderOutput<OrderUpdate, OrderUpdateVariables>;
|
2021-03-23 17:13:39 +00:00
|
|
|
orderCancel: any;
|
|
|
|
orderShippingMethodUpdate: any;
|
|
|
|
orderLinesAdd: any;
|
|
|
|
orderPaymentMarkAsPaid: any;
|
|
|
|
orderVoid: any;
|
|
|
|
orderPaymentCapture: any;
|
2021-08-20 14:36:05 +00:00
|
|
|
orderFulfillmentApprove: PartialMutationProviderOutput<
|
|
|
|
OrderFulfillmentApprove,
|
|
|
|
OrderFulfillmentApproveVariables
|
|
|
|
>;
|
2021-03-23 17:13:39 +00:00
|
|
|
orderFulfillmentCancel: any;
|
|
|
|
orderFulfillmentUpdateTracking: any;
|
|
|
|
orderInvoiceSend: any;
|
|
|
|
updateMetadataOpts: any;
|
|
|
|
updatePrivateMetadataOpts: any;
|
|
|
|
openModal: any;
|
|
|
|
closeModal: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const OrderUnconfirmedDetails: React.FC<OrderUnconfirmedDetailsProps> = ({
|
|
|
|
id,
|
|
|
|
params,
|
|
|
|
data,
|
|
|
|
orderAddNote,
|
|
|
|
orderLineUpdate,
|
|
|
|
orderLineDelete,
|
|
|
|
orderInvoiceRequest,
|
|
|
|
handleSubmit,
|
2022-02-02 11:22:39 +00:00
|
|
|
orderUpdate,
|
2021-03-23 17:13:39 +00:00
|
|
|
orderCancel,
|
|
|
|
orderShippingMethodUpdate,
|
|
|
|
orderLinesAdd,
|
|
|
|
orderPaymentMarkAsPaid,
|
|
|
|
orderVoid,
|
|
|
|
orderPaymentCapture,
|
2021-08-20 14:36:05 +00:00
|
|
|
orderFulfillmentApprove,
|
2021-03-23 17:13:39 +00:00
|
|
|
orderFulfillmentCancel,
|
|
|
|
orderFulfillmentUpdateTracking,
|
|
|
|
orderInvoiceSend,
|
|
|
|
updateMetadataOpts,
|
|
|
|
updatePrivateMetadataOpts,
|
|
|
|
openModal,
|
|
|
|
closeModal
|
|
|
|
}) => {
|
|
|
|
const order = data.order;
|
2021-08-20 14:36:05 +00:00
|
|
|
const shop = data.shop;
|
2021-03-23 17:13:39 +00:00
|
|
|
const navigate = useNavigator();
|
|
|
|
|
|
|
|
const {
|
|
|
|
loadMore,
|
|
|
|
search: variantSearch,
|
|
|
|
result: variantSearchOpts
|
|
|
|
} = useOrderVariantSearch({
|
2021-04-20 14:06:39 +00:00
|
|
|
variables: { ...DEFAULT_INITIAL_SEARCH_DATA, channel: order.channel.slug }
|
2021-03-23 17:13:39 +00:00
|
|
|
});
|
|
|
|
const warehouses = useWarehouseList({
|
|
|
|
displayLoader: true,
|
|
|
|
variables: {
|
|
|
|
first: 30
|
|
|
|
}
|
|
|
|
});
|
2022-02-02 11:22:39 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
data: customerAddresses,
|
|
|
|
loading: customerAddressesLoading
|
|
|
|
} = useCustomerAddressesQuery({
|
|
|
|
variables: {
|
|
|
|
id: order?.user?.id
|
|
|
|
},
|
|
|
|
skip: !order?.user?.id || !isAnyAddressEditModalOpen(params.action)
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleCustomerChangeAddresses = async (
|
|
|
|
data: Partial<OrderCustomerAddressesEditDialogOutput>
|
|
|
|
): Promise<any> =>
|
|
|
|
orderUpdate.mutate({
|
|
|
|
id,
|
|
|
|
input: data
|
|
|
|
});
|
|
|
|
|
2021-03-23 17:13:39 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
const [transactionReference, setTransactionReference] = React.useState("");
|
|
|
|
|
|
|
|
const handleBack = () => navigate(orderListUrl());
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle
|
|
|
|
title={intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "Order #{orderNumber}",
|
|
|
|
description: "window title"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
orderNumber: getStringOrPlaceholder(order.number)
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<OrderDiscountProvider order={order}>
|
|
|
|
<OrderLineDiscountProvider order={order}>
|
|
|
|
<OrderDetailsPage
|
|
|
|
onOrderReturn={() => navigate(orderReturnPath(id))}
|
|
|
|
disabled={
|
|
|
|
updateMetadataOpts.loading || updatePrivateMetadataOpts.loading
|
|
|
|
}
|
|
|
|
onNoteAdd={variables =>
|
2022-02-01 09:58:06 +00:00
|
|
|
extractMutationErrors(
|
|
|
|
orderAddNote.mutate({
|
|
|
|
input: variables,
|
|
|
|
order: id
|
|
|
|
})
|
|
|
|
)
|
2021-03-23 17:13:39 +00:00
|
|
|
}
|
|
|
|
onBack={handleBack}
|
|
|
|
order={order}
|
2021-08-20 14:36:05 +00:00
|
|
|
shop={shop}
|
2021-03-23 17:13:39 +00:00
|
|
|
onOrderLineAdd={() => openModal("add-order-line")}
|
|
|
|
onOrderLineChange={(id, data) =>
|
|
|
|
orderLineUpdate.mutate({
|
|
|
|
id,
|
|
|
|
input: data
|
|
|
|
})
|
|
|
|
}
|
|
|
|
onOrderLineRemove={id => orderLineDelete.mutate({ id })}
|
|
|
|
onShippingMethodEdit={() => openModal("edit-shipping")}
|
|
|
|
saveButtonBarState={getMutationState(
|
|
|
|
updateMetadataOpts.called || updatePrivateMetadataOpts.called,
|
|
|
|
updateMetadataOpts.loading || updatePrivateMetadataOpts.loading,
|
|
|
|
[
|
|
|
|
...(updateMetadataOpts.data?.deleteMetadata.errors || []),
|
|
|
|
...(updateMetadataOpts.data?.updateMetadata.errors || []),
|
|
|
|
...(updatePrivateMetadataOpts.data?.deletePrivateMetadata
|
|
|
|
.errors || []),
|
|
|
|
...(updatePrivateMetadataOpts.data?.updatePrivateMetadata
|
|
|
|
.errors || [])
|
|
|
|
]
|
|
|
|
)}
|
2022-01-24 13:50:17 +00:00
|
|
|
shippingMethods={data?.order?.shippingMethods || []}
|
2021-03-23 17:13:39 +00:00
|
|
|
onOrderCancel={() => openModal("cancel")}
|
|
|
|
onOrderFulfill={() => navigate(orderFulfillUrl(id))}
|
2021-08-20 14:36:05 +00:00
|
|
|
onFulfillmentApprove={fulfillmentId =>
|
|
|
|
navigate(
|
|
|
|
orderUrl(id, {
|
|
|
|
action: "approve-fulfillment",
|
|
|
|
id: fulfillmentId
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2021-03-23 17:13:39 +00:00
|
|
|
onFulfillmentCancel={fulfillmentId =>
|
|
|
|
navigate(
|
|
|
|
orderUrl(id, {
|
|
|
|
action: "cancel-fulfillment",
|
|
|
|
id: fulfillmentId
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
onFulfillmentTrackingNumberUpdate={fulfillmentId =>
|
|
|
|
navigate(
|
|
|
|
orderUrl(id, {
|
|
|
|
action: "edit-fulfillment",
|
|
|
|
id: fulfillmentId
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
onPaymentCapture={() => openModal("capture")}
|
|
|
|
onPaymentVoid={() => openModal("void")}
|
|
|
|
onPaymentRefund={() => navigate(orderRefundUrl(id))}
|
|
|
|
onProductClick={id => () => navigate(productUrl(id))}
|
|
|
|
onBillingAddressEdit={() => openModal("edit-billing-address")}
|
|
|
|
onShippingAddressEdit={() => openModal("edit-shipping-address")}
|
|
|
|
onPaymentPaid={() => openModal("mark-paid")}
|
|
|
|
onProfileView={() => navigate(customerUrl(order.user.id))}
|
|
|
|
onInvoiceClick={id =>
|
|
|
|
window.open(
|
|
|
|
order.invoices.find(invoice => invoice.id === id)?.url,
|
|
|
|
"_blank"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
onInvoiceGenerate={() =>
|
|
|
|
orderInvoiceRequest.mutate({
|
|
|
|
orderId: id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
onInvoiceSend={id => openModal("invoice-send", { id })}
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
/>
|
|
|
|
</OrderLineDiscountProvider>
|
|
|
|
</OrderDiscountProvider>
|
|
|
|
<OrderCannotCancelOrderDialog
|
|
|
|
onClose={closeModal}
|
|
|
|
open={
|
|
|
|
params.action === "cancel" &&
|
|
|
|
order?.fulfillments.some(
|
|
|
|
fulfillment => fulfillment.status === FulfillmentStatus.FULFILLED
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<OrderCancelDialog
|
|
|
|
confirmButtonState={orderCancel.opts.status}
|
|
|
|
errors={orderCancel.opts.data?.orderCancel.errors || []}
|
|
|
|
number={order?.number}
|
|
|
|
open={params.action === "cancel"}
|
|
|
|
onClose={closeModal}
|
|
|
|
onSubmit={() =>
|
|
|
|
orderCancel.mutate({
|
|
|
|
id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<OrderShippingMethodEditDialog
|
|
|
|
confirmButtonState={orderShippingMethodUpdate.opts.status}
|
|
|
|
errors={
|
|
|
|
orderShippingMethodUpdate.opts.data?.orderUpdateShipping.errors || []
|
|
|
|
}
|
|
|
|
open={params.action === "edit-shipping"}
|
|
|
|
shippingMethod={order?.shippingMethod?.id}
|
2022-01-24 13:50:17 +00:00
|
|
|
shippingMethods={order?.shippingMethods}
|
2021-03-23 17:13:39 +00:00
|
|
|
onClose={closeModal}
|
|
|
|
onSubmit={variables =>
|
2022-02-01 09:58:06 +00:00
|
|
|
extractMutationErrors(
|
|
|
|
orderShippingMethodUpdate.mutate({
|
|
|
|
id,
|
|
|
|
input: {
|
|
|
|
shippingMethod: variables.shippingMethod
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
2021-03-23 17:13:39 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
<OrderProductAddDialog
|
|
|
|
confirmButtonState={orderLinesAdd.opts.status}
|
|
|
|
errors={orderLinesAdd.opts.data?.orderLinesCreate.errors || []}
|
|
|
|
loading={variantSearchOpts.loading}
|
|
|
|
open={params.action === "add-order-line"}
|
|
|
|
hasMore={variantSearchOpts.data?.search.pageInfo.hasNextPage}
|
2021-05-10 15:25:54 +00:00
|
|
|
products={mapEdgesToItems(variantSearchOpts?.data?.search)}
|
2021-03-23 17:13:39 +00:00
|
|
|
selectedChannelId={order?.channel?.id}
|
|
|
|
onClose={closeModal}
|
|
|
|
onFetch={variantSearch}
|
|
|
|
onFetchMore={loadMore}
|
|
|
|
onSubmit={variants =>
|
|
|
|
orderLinesAdd.mutate({
|
|
|
|
id,
|
|
|
|
input: variants.map(variant => ({
|
|
|
|
quantity: 1,
|
|
|
|
variantId: variant.id
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<OrderMarkAsPaidDialog
|
|
|
|
confirmButtonState={orderPaymentMarkAsPaid.opts.status}
|
|
|
|
errors={orderPaymentMarkAsPaid.opts.data?.orderMarkAsPaid.errors || []}
|
|
|
|
onClose={closeModal}
|
|
|
|
onConfirm={() =>
|
|
|
|
orderPaymentMarkAsPaid.mutate({
|
|
|
|
id,
|
|
|
|
transactionReference
|
|
|
|
})
|
|
|
|
}
|
|
|
|
open={params.action === "mark-paid"}
|
|
|
|
transactionReference={transactionReference}
|
|
|
|
handleTransactionReference={({ target }) =>
|
|
|
|
setTransactionReference(target.value)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<OrderPaymentVoidDialog
|
|
|
|
confirmButtonState={orderVoid.opts.status}
|
|
|
|
errors={orderVoid.opts.data?.orderVoid.errors || []}
|
|
|
|
open={params.action === "void"}
|
|
|
|
onClose={closeModal}
|
|
|
|
onConfirm={() => orderVoid.mutate({ id })}
|
|
|
|
/>
|
|
|
|
<OrderPaymentDialog
|
|
|
|
confirmButtonState={orderPaymentCapture.opts.status}
|
|
|
|
errors={orderPaymentCapture.opts.data?.orderCapture.errors || []}
|
|
|
|
initial={order?.total.gross.amount}
|
|
|
|
open={params.action === "capture"}
|
|
|
|
onClose={closeModal}
|
|
|
|
onSubmit={variables =>
|
|
|
|
orderPaymentCapture.mutate({
|
|
|
|
...variables,
|
|
|
|
id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
2021-08-20 14:36:05 +00:00
|
|
|
<OrderFulfillmentApproveDialog
|
|
|
|
confirmButtonState={orderFulfillmentApprove.opts.status}
|
|
|
|
errors={
|
|
|
|
orderFulfillmentApprove.opts.data?.orderFulfillmentApprove.errors ||
|
|
|
|
[]
|
|
|
|
}
|
|
|
|
open={params.action === "approve-fulfillment"}
|
|
|
|
onConfirm={({ notifyCustomer }) =>
|
|
|
|
orderFulfillmentApprove.mutate({
|
|
|
|
id: params.id,
|
|
|
|
notifyCustomer
|
|
|
|
})
|
|
|
|
}
|
|
|
|
onClose={closeModal}
|
|
|
|
/>
|
2021-03-23 17:13:39 +00:00
|
|
|
<OrderFulfillmentCancelDialog
|
|
|
|
confirmButtonState={orderFulfillmentCancel.opts.status}
|
|
|
|
errors={
|
|
|
|
orderFulfillmentCancel.opts.data?.orderFulfillmentCancel.errors || []
|
|
|
|
}
|
|
|
|
open={params.action === "cancel-fulfillment"}
|
2021-05-10 15:25:54 +00:00
|
|
|
warehouses={mapEdgesToItems(warehouses?.data?.warehouses)}
|
2021-03-23 17:13:39 +00:00
|
|
|
onConfirm={variables =>
|
|
|
|
orderFulfillmentCancel.mutate({
|
|
|
|
id: params.id,
|
|
|
|
input: variables
|
|
|
|
})
|
|
|
|
}
|
|
|
|
onClose={closeModal}
|
|
|
|
/>
|
|
|
|
<OrderFulfillmentTrackingDialog
|
|
|
|
confirmButtonState={orderFulfillmentUpdateTracking.opts.status}
|
|
|
|
errors={
|
|
|
|
orderFulfillmentUpdateTracking.opts.data
|
|
|
|
?.orderFulfillmentUpdateTracking.errors || []
|
|
|
|
}
|
|
|
|
open={params.action === "edit-fulfillment"}
|
|
|
|
trackingNumber={getStringOrPlaceholder(
|
|
|
|
data?.order?.fulfillments.find(
|
|
|
|
fulfillment => fulfillment.id === params.id
|
|
|
|
)?.trackingNumber
|
|
|
|
)}
|
|
|
|
onConfirm={variables =>
|
|
|
|
orderFulfillmentUpdateTracking.mutate({
|
|
|
|
id: params.id,
|
|
|
|
input: {
|
|
|
|
...variables,
|
|
|
|
notifyCustomer: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
onClose={closeModal}
|
|
|
|
/>
|
|
|
|
<OrderInvoiceEmailSendDialog
|
|
|
|
confirmButtonState={orderInvoiceSend.opts.status}
|
|
|
|
errors={orderInvoiceSend.opts.data?.invoiceSendEmail.errors || []}
|
|
|
|
open={params.action === "invoice-send"}
|
|
|
|
invoice={order?.invoices?.find(invoice => invoice.id === params.id)}
|
|
|
|
onClose={closeModal}
|
|
|
|
onSend={() => orderInvoiceSend.mutate({ id: params.id })}
|
|
|
|
/>
|
2022-02-02 11:22:39 +00:00
|
|
|
<OrderAddressFields
|
|
|
|
action={params?.action}
|
|
|
|
customerAddressesLoading={customerAddressesLoading}
|
|
|
|
orderShippingAddress={order?.shippingAddress}
|
|
|
|
orderBillingAddress={order?.billingAddress}
|
|
|
|
isDraft={false}
|
|
|
|
countries={data?.shop?.countries}
|
|
|
|
customer={customerAddresses?.user}
|
|
|
|
onClose={closeModal}
|
|
|
|
onConfirm={handleCustomerChangeAddresses}
|
|
|
|
confirmButtonState={orderUpdate.opts.status}
|
|
|
|
errors={orderUpdate.opts.data?.orderUpdate.errors}
|
|
|
|
/>
|
2021-03-23 17:13:39 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default OrderUnconfirmedDetails;
|