@medusajs/draft-order 2.11.1-preview-20251023150219 → 2.11.1-preview-20251023180201

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9592,551 +9592,809 @@ const CustomItemsForm = () => {
9592
9592
  const schema$5 = objectType({
9593
9593
  email: stringType().email()
9594
9594
  });
9595
- const NumberInput = React.forwardRef(
9596
- ({
9597
- value,
9598
- onChange,
9599
- size = "base",
9600
- min = 0,
9601
- max = 100,
9602
- step = 1,
9603
- className,
9604
- disabled,
9605
- ...props
9606
- }, ref) => {
9607
- const handleChange = (event) => {
9608
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9609
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9610
- onChange(newValue);
9611
- }
9612
- };
9613
- const handleIncrement = () => {
9614
- const newValue = value + step;
9615
- if (max === void 0 || newValue <= max) {
9616
- onChange(newValue);
9617
- }
9618
- };
9619
- const handleDecrement = () => {
9620
- const newValue = value - step;
9621
- if (min === void 0 || newValue >= min) {
9622
- onChange(newValue);
9623
- }
9624
- };
9625
- return /* @__PURE__ */ jsxRuntime.jsxs(
9626
- "div",
9627
- {
9628
- className: ui.clx(
9629
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9630
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9631
- {
9632
- "h-7": size === "small",
9633
- "h-8": size === "base"
9634
- },
9635
- className
9636
- ),
9637
- children: [
9638
- /* @__PURE__ */ jsxRuntime.jsx(
9639
- "input",
9640
- {
9641
- ref,
9642
- type: "number",
9643
- value,
9644
- onChange: handleChange,
9645
- min,
9646
- max,
9647
- step,
9648
- className: ui.clx(
9649
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9650
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9651
- "placeholder:text-ui-fg-muted"
9652
- ),
9653
- ...props
9654
- }
9655
- ),
9656
- /* @__PURE__ */ jsxRuntime.jsxs(
9657
- "button",
9658
- {
9659
- className: ui.clx(
9660
- "flex items-center justify-center outline-none transition-fg",
9661
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9662
- "focus:bg-ui-bg-field-component-hover",
9663
- "hover:bg-ui-bg-field-component-hover",
9664
- {
9665
- "size-7": size === "small",
9666
- "size-8": size === "base"
9667
- }
9668
- ),
9669
- type: "button",
9670
- onClick: handleDecrement,
9671
- disabled: min !== void 0 && value <= min || disabled,
9672
- children: [
9673
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9674
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9675
- ]
9676
- }
9677
- ),
9678
- /* @__PURE__ */ jsxRuntime.jsxs(
9679
- "button",
9680
- {
9681
- className: ui.clx(
9682
- "flex items-center justify-center outline-none transition-fg",
9683
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9684
- "focus:bg-ui-bg-field-hover",
9685
- "hover:bg-ui-bg-field-hover",
9686
- {
9687
- "size-7": size === "small",
9688
- "size-8": size === "base"
9689
- }
9690
- ),
9691
- type: "button",
9692
- onClick: handleIncrement,
9693
- disabled: max !== void 0 && value >= max || disabled,
9694
- children: [
9695
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9696
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9697
- ]
9698
- }
9699
- )
9700
- ]
9701
- }
9702
- );
9595
+ const Email = () => {
9596
+ const { id } = reactRouterDom.useParams();
9597
+ const { order, isPending, isError, error } = useOrder(id, {
9598
+ fields: "+email"
9599
+ });
9600
+ if (isError) {
9601
+ throw error;
9703
9602
  }
9704
- );
9705
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9706
- const productVariantsQueryKeys = {
9707
- list: (query2) => [
9708
- PRODUCT_VARIANTS_QUERY_KEY,
9709
- query2 ? query2 : void 0
9710
- ]
9603
+ const isReady = !isPending && !!order;
9604
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9605
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9606
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9607
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9608
+ ] }),
9609
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9610
+ ] });
9711
9611
  };
9712
- const useProductVariants = (query2, options) => {
9713
- const { data, ...rest } = reactQuery.useQuery({
9714
- queryKey: productVariantsQueryKeys.list(query2),
9715
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9716
- ...options
9612
+ const EmailForm = ({ order }) => {
9613
+ const form = reactHookForm.useForm({
9614
+ defaultValues: {
9615
+ email: order.email ?? ""
9616
+ },
9617
+ resolver: zod.zodResolver(schema$4)
9717
9618
  });
9718
- return { ...data, ...rest };
9719
- };
9720
- const useCancelOrderEdit = ({ preview }) => {
9721
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9722
- const onCancel = React.useCallback(async () => {
9723
- if (!preview) {
9724
- return true;
9725
- }
9726
- let res = false;
9727
- await cancelOrderEdit(void 0, {
9728
- onError: (e) => {
9729
- ui.toast.error(e.message);
9730
- },
9731
- onSuccess: () => {
9732
- res = true;
9733
- }
9734
- });
9735
- return res;
9736
- }, [preview, cancelOrderEdit]);
9737
- return { onCancel };
9738
- };
9739
- let IS_REQUEST_RUNNING = false;
9740
- const useInitiateOrderEdit = ({
9741
- preview
9742
- }) => {
9743
- const navigate = reactRouterDom.useNavigate();
9744
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9745
- React.useEffect(() => {
9746
- async function run() {
9747
- if (IS_REQUEST_RUNNING || !preview) {
9748
- return;
9749
- }
9750
- if (preview.order_change) {
9751
- return;
9752
- }
9753
- IS_REQUEST_RUNNING = true;
9754
- await mutateAsync(void 0, {
9755
- onError: (e) => {
9756
- ui.toast.error(e.message);
9757
- navigate(`/draft-orders/${preview.id}`, { replace: true });
9758
- return;
9619
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9620
+ const { handleSuccess } = useRouteModal();
9621
+ const onSubmit = form.handleSubmit(async (data) => {
9622
+ await mutateAsync(
9623
+ { email: data.email },
9624
+ {
9625
+ onSuccess: () => {
9626
+ handleSuccess();
9627
+ },
9628
+ onError: (error) => {
9629
+ ui.toast.error(error.message);
9759
9630
  }
9760
- });
9761
- IS_REQUEST_RUNNING = false;
9631
+ }
9632
+ );
9633
+ });
9634
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9635
+ KeyboundForm,
9636
+ {
9637
+ className: "flex flex-1 flex-col overflow-hidden",
9638
+ onSubmit,
9639
+ children: [
9640
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9641
+ Form$2.Field,
9642
+ {
9643
+ control: form.control,
9644
+ name: "email",
9645
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9646
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9647
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9649
+ ] })
9650
+ }
9651
+ ) }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9653
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9654
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9655
+ ] }) })
9656
+ ]
9762
9657
  }
9763
- run();
9764
- }, [preview, navigate, mutateAsync]);
9658
+ ) });
9765
9659
  };
9766
- function convertNumber(value) {
9767
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
9768
- }
9769
- const STACKED_MODAL_ID = "items_stacked_modal";
9770
- const Items = () => {
9660
+ const schema$4 = objectType({
9661
+ email: stringType().email()
9662
+ });
9663
+ const BillingAddress = () => {
9771
9664
  const { id } = reactRouterDom.useParams();
9772
- const {
9773
- order: preview,
9774
- isPending: isPreviewPending,
9775
- isError: isPreviewError,
9776
- error: previewError
9777
- } = useOrderPreview(id, void 0, {
9778
- placeholderData: reactQuery.keepPreviousData
9665
+ const { order, isPending, isError, error } = useOrder(id, {
9666
+ fields: "+billing_address"
9779
9667
  });
9780
- useInitiateOrderEdit({ preview });
9781
- const { draft_order, isPending, isError, error } = useDraftOrder(
9782
- id,
9783
- {
9784
- fields: "currency_code"
9785
- },
9786
- {
9787
- enabled: !!id
9788
- }
9789
- );
9790
- const { onCancel } = useCancelOrderEdit({ preview });
9791
9668
  if (isError) {
9792
9669
  throw error;
9793
9670
  }
9794
- if (isPreviewError) {
9795
- throw previewError;
9796
- }
9797
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
9798
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9799
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
9800
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
9801
- ] }) });
9802
- };
9803
- const ItemsForm = ({ preview, currencyCode }) => {
9804
- var _a;
9805
- const [isSubmitting, setIsSubmitting] = React.useState(false);
9806
- const [modalContent, setModalContent] = React.useState(
9807
- null
9808
- );
9809
- const { handleSuccess } = useRouteModal();
9810
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
9811
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
9812
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
9813
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
9814
- const matches = React.useMemo(() => {
9815
- return matchSorter.matchSorter(preview.items, query2, {
9816
- keys: ["product_title", "variant_title", "variant_sku", "title"]
9817
- });
9818
- }, [preview.items, query2]);
9819
- const onSubmit = async () => {
9820
- setIsSubmitting(true);
9821
- let requestSucceeded = false;
9822
- await requestOrderEdit(void 0, {
9823
- onError: (e) => {
9824
- ui.toast.error(`Failed to request order edit: ${e.message}`);
9825
- },
9826
- onSuccess: () => {
9827
- requestSucceeded = true;
9828
- }
9829
- });
9830
- if (!requestSucceeded) {
9831
- setIsSubmitting(false);
9832
- return;
9833
- }
9834
- await confirmOrderEdit(void 0, {
9835
- onError: (e) => {
9836
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
9837
- },
9838
- onSuccess: () => {
9839
- handleSuccess();
9840
- },
9841
- onSettled: () => {
9842
- setIsSubmitting(false);
9843
- }
9844
- });
9845
- };
9846
- const onKeyDown = React.useCallback(
9847
- (e) => {
9848
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
9849
- if (modalContent || isSubmitting) {
9850
- return;
9851
- }
9852
- onSubmit();
9853
- }
9854
- },
9855
- [modalContent, isSubmitting, onSubmit]
9856
- );
9857
- React.useEffect(() => {
9858
- document.addEventListener("keydown", onKeyDown);
9859
- return () => {
9860
- document.removeEventListener("keydown", onKeyDown);
9861
- };
9862
- }, [onKeyDown]);
9863
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
9864
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
9865
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
9866
- StackedFocusModal,
9867
- {
9868
- id: STACKED_MODAL_ID,
9869
- onOpenChangeCallback: (open) => {
9870
- if (!open) {
9871
- setModalContent(null);
9872
- }
9873
- },
9874
- children: [
9875
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
9876
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9877
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
9878
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
9879
- ] }),
9880
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9881
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
9882
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
9883
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9884
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
9885
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
9886
- ] }),
9887
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
9888
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
9889
- ui.Input,
9890
- {
9891
- type: "search",
9892
- placeholder: "Search items",
9893
- value: searchValue,
9894
- onChange: (e) => onSearchValueChange(e.target.value)
9895
- }
9896
- ) }),
9897
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9898
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
9899
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9900
- /* @__PURE__ */ jsxRuntime.jsx(
9901
- StackedModalTrigger$1,
9902
- {
9903
- type: "add-items",
9904
- setModalContent
9905
- }
9906
- ),
9907
- /* @__PURE__ */ jsxRuntime.jsx(
9908
- StackedModalTrigger$1,
9909
- {
9910
- type: "add-custom-item",
9911
- setModalContent
9912
- }
9913
- )
9914
- ] })
9915
- ] })
9916
- ] })
9917
- ] }),
9918
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
9919
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
9920
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
9921
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
9922
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
9923
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
9924
- ] }) }),
9925
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
9926
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
9927
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
9928
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
9929
- Item,
9930
- {
9931
- item,
9932
- preview,
9933
- currencyCode
9934
- },
9935
- item.id
9936
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
9937
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
9938
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
9939
- 'No items found for "',
9940
- query2,
9941
- '".'
9942
- ] })
9943
- ] }) })
9944
- ] })
9945
- ] }),
9946
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9947
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
9948
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
9949
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
9950
- ui.Text,
9951
- {
9952
- size: "small",
9953
- leading: "compact",
9954
- className: "text-ui-fg-subtle",
9955
- children: [
9956
- itemCount,
9957
- " ",
9958
- itemCount === 1 ? "item" : "items"
9959
- ]
9960
- }
9961
- ) }),
9962
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
9963
- ] })
9964
- ] }) }),
9965
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
9966
- CustomItemForm,
9967
- {
9968
- orderId: preview.id,
9969
- currencyCode
9970
- }
9971
- ) : null)
9972
- ]
9973
- }
9974
- ) }),
9975
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9976
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9977
- /* @__PURE__ */ jsxRuntime.jsx(
9978
- ui.Button,
9979
- {
9980
- size: "small",
9981
- type: "button",
9982
- onClick: onSubmit,
9983
- isLoading: isSubmitting,
9984
- children: "Save"
9985
- }
9986
- )
9987
- ] }) })
9671
+ const isReady = !isPending && !!order;
9672
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9673
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9674
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9675
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9676
+ ] }),
9677
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9988
9678
  ] });
9989
9679
  };
9990
- const Item = ({ item, preview, currencyCode }) => {
9991
- if (item.variant_id) {
9992
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
9993
- }
9994
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
9995
- };
9996
- const VariantItem = ({ item, preview, currencyCode }) => {
9997
- const [editing, setEditing] = React.useState(false);
9680
+ const BillingAddressForm = ({ order }) => {
9681
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9998
9682
  const form = reactHookForm.useForm({
9999
9683
  defaultValues: {
10000
- quantity: item.quantity,
10001
- unit_price: item.unit_price
9684
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9685
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9686
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9687
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9688
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9689
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9690
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9691
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9692
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9693
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
10002
9694
  },
10003
- resolver: zod.zodResolver(variantItemSchema)
9695
+ resolver: zod.zodResolver(schema$3)
10004
9696
  });
10005
- const actionId = React.useMemo(() => {
10006
- var _a, _b;
10007
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10008
- }, [item]);
10009
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10010
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10011
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
9697
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9698
+ const { handleSuccess } = useRouteModal();
10012
9699
  const onSubmit = form.handleSubmit(async (data) => {
10013
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10014
- setEditing(false);
10015
- return;
10016
- }
10017
- if (!actionId) {
10018
- await updateOriginalItem(
10019
- {
10020
- item_id: item.id,
10021
- quantity: data.quantity,
10022
- unit_price: convertNumber(data.unit_price)
9700
+ await mutateAsync(
9701
+ { billing_address: data },
9702
+ {
9703
+ onSuccess: () => {
9704
+ handleSuccess();
10023
9705
  },
10024
- {
10025
- onSuccess: () => {
10026
- setEditing(false);
10027
- },
10028
- onError: (e) => {
10029
- ui.toast.error(e.message);
10030
- }
10031
- }
10032
- );
10033
- return;
10034
- }
10035
- await updateActionItem(
10036
- {
10037
- action_id: actionId,
10038
- quantity: data.quantity,
10039
- unit_price: convertNumber(data.unit_price)
10040
- },
10041
- {
10042
- onSuccess: () => {
10043
- setEditing(false);
10044
- },
10045
- onError: (e) => {
10046
- ui.toast.error(e.message);
9706
+ onError: (error) => {
9707
+ ui.toast.error(error.message);
10047
9708
  }
10048
9709
  }
10049
9710
  );
10050
9711
  });
10051
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10052
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10053
- /* @__PURE__ */ jsxRuntime.jsx(
10054
- Thumbnail,
10055
- {
10056
- thumbnail: item.thumbnail,
10057
- alt: item.product_title ?? void 0
10058
- }
10059
- ),
10060
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10061
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10062
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10063
- /* @__PURE__ */ jsxRuntime.jsxs(
10064
- ui.Text,
9712
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9713
+ KeyboundForm,
9714
+ {
9715
+ className: "flex flex-1 flex-col overflow-hidden",
9716
+ onSubmit,
9717
+ children: [
9718
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9719
+ /* @__PURE__ */ jsxRuntime.jsx(
9720
+ Form$2.Field,
10065
9721
  {
10066
- size: "small",
10067
- leading: "compact",
10068
- className: "text-ui-fg-subtle",
10069
- children: [
10070
- "(",
10071
- item.variant_title,
10072
- ")"
10073
- ]
9722
+ control: form.control,
9723
+ name: "country_code",
9724
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9727
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
+ ] })
10074
9729
  }
10075
- )
10076
- ] }),
10077
- /* @__PURE__ */ jsxRuntime.jsx(
10078
- ui.Text,
10079
- {
10080
- size: "small",
10081
- leading: "compact",
10082
- className: "text-ui-fg-subtle",
10083
- children: item.variant_sku
10084
- }
10085
- )
10086
- ] })
10087
- ] }),
10088
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10089
- Form$2.Field,
10090
- {
10091
- control: form.control,
10092
- name: "quantity",
10093
- render: ({ field }) => {
10094
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10095
- }
10096
- }
10097
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10098
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10099
- Form$2.Field,
10100
- {
10101
- control: form.control,
10102
- name: "unit_price",
10103
- render: ({ field: { onChange, ...field } }) => {
10104
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10105
- ui.CurrencyInput,
9730
+ ),
9731
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9732
+ /* @__PURE__ */ jsxRuntime.jsx(
9733
+ Form$2.Field,
9734
+ {
9735
+ control: form.control,
9736
+ name: "first_name",
9737
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
+ ] })
9742
+ }
9743
+ ),
9744
+ /* @__PURE__ */ jsxRuntime.jsx(
9745
+ Form$2.Field,
9746
+ {
9747
+ control: form.control,
9748
+ name: "last_name",
9749
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
+ ] })
9754
+ }
9755
+ )
9756
+ ] }),
9757
+ /* @__PURE__ */ jsxRuntime.jsx(
9758
+ Form$2.Field,
10106
9759
  {
10107
- ...field,
10108
- symbol: getNativeSymbol(currencyCode),
10109
- code: currencyCode,
10110
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
9760
+ control: form.control,
9761
+ name: "company",
9762
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9763
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9764
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9765
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9766
+ ] })
10111
9767
  }
10112
- ) }) });
10113
- }
9768
+ ),
9769
+ /* @__PURE__ */ jsxRuntime.jsx(
9770
+ Form$2.Field,
9771
+ {
9772
+ control: form.control,
9773
+ name: "address_1",
9774
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9775
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9776
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9777
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9778
+ ] })
9779
+ }
9780
+ ),
9781
+ /* @__PURE__ */ jsxRuntime.jsx(
9782
+ Form$2.Field,
9783
+ {
9784
+ control: form.control,
9785
+ name: "address_2",
9786
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9787
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9788
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9789
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9790
+ ] })
9791
+ }
9792
+ ),
9793
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9794
+ /* @__PURE__ */ jsxRuntime.jsx(
9795
+ Form$2.Field,
9796
+ {
9797
+ control: form.control,
9798
+ name: "postal_code",
9799
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9800
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9801
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9802
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9803
+ ] })
9804
+ }
9805
+ ),
9806
+ /* @__PURE__ */ jsxRuntime.jsx(
9807
+ Form$2.Field,
9808
+ {
9809
+ control: form.control,
9810
+ name: "city",
9811
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9812
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9813
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9814
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9815
+ ] })
9816
+ }
9817
+ )
9818
+ ] }),
9819
+ /* @__PURE__ */ jsxRuntime.jsx(
9820
+ Form$2.Field,
9821
+ {
9822
+ control: form.control,
9823
+ name: "province",
9824
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9825
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9826
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9827
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9828
+ ] })
9829
+ }
9830
+ ),
9831
+ /* @__PURE__ */ jsxRuntime.jsx(
9832
+ Form$2.Field,
9833
+ {
9834
+ control: form.control,
9835
+ name: "phone",
9836
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9837
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9838
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9839
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9840
+ ] })
9841
+ }
9842
+ )
9843
+ ] }) }),
9844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
+ ] }) })
9848
+ ]
9849
+ }
9850
+ ) });
9851
+ };
9852
+ const schema$3 = addressSchema;
9853
+ const NumberInput = React.forwardRef(
9854
+ ({
9855
+ value,
9856
+ onChange,
9857
+ size = "base",
9858
+ min = 0,
9859
+ max = 100,
9860
+ step = 1,
9861
+ className,
9862
+ disabled,
9863
+ ...props
9864
+ }, ref) => {
9865
+ const handleChange = (event) => {
9866
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9867
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9868
+ onChange(newValue);
10114
9869
  }
10115
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10116
- /* @__PURE__ */ jsxRuntime.jsx(
10117
- ui.IconButton,
10118
- {
10119
- type: "button",
10120
- size: "small",
10121
- onClick: editing ? onSubmit : () => {
10122
- setEditing(true);
10123
- },
10124
- disabled: isPending,
10125
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
9870
+ };
9871
+ const handleIncrement = () => {
9872
+ const newValue = value + step;
9873
+ if (max === void 0 || newValue <= max) {
9874
+ onChange(newValue);
10126
9875
  }
10127
- )
10128
- ] }) }) });
10129
- };
10130
- const variantItemSchema = objectType({
10131
- quantity: numberType(),
10132
- unit_price: unionType([numberType(), stringType()])
10133
- });
10134
- const CustomItem = ({ item, preview, currencyCode }) => {
10135
- const [editing, setEditing] = React.useState(false);
10136
- const { quantity, unit_price, title } = item;
10137
- const form = reactHookForm.useForm({
10138
- defaultValues: {
10139
- title,
9876
+ };
9877
+ const handleDecrement = () => {
9878
+ const newValue = value - step;
9879
+ if (min === void 0 || newValue >= min) {
9880
+ onChange(newValue);
9881
+ }
9882
+ };
9883
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9884
+ "div",
9885
+ {
9886
+ className: ui.clx(
9887
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9888
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9889
+ {
9890
+ "h-7": size === "small",
9891
+ "h-8": size === "base"
9892
+ },
9893
+ className
9894
+ ),
9895
+ children: [
9896
+ /* @__PURE__ */ jsxRuntime.jsx(
9897
+ "input",
9898
+ {
9899
+ ref,
9900
+ type: "number",
9901
+ value,
9902
+ onChange: handleChange,
9903
+ min,
9904
+ max,
9905
+ step,
9906
+ className: ui.clx(
9907
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9908
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9909
+ "placeholder:text-ui-fg-muted"
9910
+ ),
9911
+ ...props
9912
+ }
9913
+ ),
9914
+ /* @__PURE__ */ jsxRuntime.jsxs(
9915
+ "button",
9916
+ {
9917
+ className: ui.clx(
9918
+ "flex items-center justify-center outline-none transition-fg",
9919
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9920
+ "focus:bg-ui-bg-field-component-hover",
9921
+ "hover:bg-ui-bg-field-component-hover",
9922
+ {
9923
+ "size-7": size === "small",
9924
+ "size-8": size === "base"
9925
+ }
9926
+ ),
9927
+ type: "button",
9928
+ onClick: handleDecrement,
9929
+ disabled: min !== void 0 && value <= min || disabled,
9930
+ children: [
9931
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9932
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9933
+ ]
9934
+ }
9935
+ ),
9936
+ /* @__PURE__ */ jsxRuntime.jsxs(
9937
+ "button",
9938
+ {
9939
+ className: ui.clx(
9940
+ "flex items-center justify-center outline-none transition-fg",
9941
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9942
+ "focus:bg-ui-bg-field-hover",
9943
+ "hover:bg-ui-bg-field-hover",
9944
+ {
9945
+ "size-7": size === "small",
9946
+ "size-8": size === "base"
9947
+ }
9948
+ ),
9949
+ type: "button",
9950
+ onClick: handleIncrement,
9951
+ disabled: max !== void 0 && value >= max || disabled,
9952
+ children: [
9953
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9954
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9955
+ ]
9956
+ }
9957
+ )
9958
+ ]
9959
+ }
9960
+ );
9961
+ }
9962
+ );
9963
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9964
+ const productVariantsQueryKeys = {
9965
+ list: (query2) => [
9966
+ PRODUCT_VARIANTS_QUERY_KEY,
9967
+ query2 ? query2 : void 0
9968
+ ]
9969
+ };
9970
+ const useProductVariants = (query2, options) => {
9971
+ const { data, ...rest } = reactQuery.useQuery({
9972
+ queryKey: productVariantsQueryKeys.list(query2),
9973
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9974
+ ...options
9975
+ });
9976
+ return { ...data, ...rest };
9977
+ };
9978
+ const useCancelOrderEdit = ({ preview }) => {
9979
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9980
+ const onCancel = React.useCallback(async () => {
9981
+ if (!preview) {
9982
+ return true;
9983
+ }
9984
+ let res = false;
9985
+ await cancelOrderEdit(void 0, {
9986
+ onError: (e) => {
9987
+ ui.toast.error(e.message);
9988
+ },
9989
+ onSuccess: () => {
9990
+ res = true;
9991
+ }
9992
+ });
9993
+ return res;
9994
+ }, [preview, cancelOrderEdit]);
9995
+ return { onCancel };
9996
+ };
9997
+ let IS_REQUEST_RUNNING = false;
9998
+ const useInitiateOrderEdit = ({
9999
+ preview
10000
+ }) => {
10001
+ const navigate = reactRouterDom.useNavigate();
10002
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10003
+ React.useEffect(() => {
10004
+ async function run() {
10005
+ if (IS_REQUEST_RUNNING || !preview) {
10006
+ return;
10007
+ }
10008
+ if (preview.order_change) {
10009
+ return;
10010
+ }
10011
+ IS_REQUEST_RUNNING = true;
10012
+ await mutateAsync(void 0, {
10013
+ onError: (e) => {
10014
+ ui.toast.error(e.message);
10015
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10016
+ return;
10017
+ }
10018
+ });
10019
+ IS_REQUEST_RUNNING = false;
10020
+ }
10021
+ run();
10022
+ }, [preview, navigate, mutateAsync]);
10023
+ };
10024
+ function convertNumber(value) {
10025
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10026
+ }
10027
+ const STACKED_MODAL_ID = "items_stacked_modal";
10028
+ const Items = () => {
10029
+ const { id } = reactRouterDom.useParams();
10030
+ const {
10031
+ order: preview,
10032
+ isPending: isPreviewPending,
10033
+ isError: isPreviewError,
10034
+ error: previewError
10035
+ } = useOrderPreview(id, void 0, {
10036
+ placeholderData: reactQuery.keepPreviousData
10037
+ });
10038
+ useInitiateOrderEdit({ preview });
10039
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10040
+ id,
10041
+ {
10042
+ fields: "currency_code"
10043
+ },
10044
+ {
10045
+ enabled: !!id
10046
+ }
10047
+ );
10048
+ const { onCancel } = useCancelOrderEdit({ preview });
10049
+ if (isError) {
10050
+ throw error;
10051
+ }
10052
+ if (isPreviewError) {
10053
+ throw previewError;
10054
+ }
10055
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10056
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10057
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10058
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10059
+ ] }) });
10060
+ };
10061
+ const ItemsForm = ({ preview, currencyCode }) => {
10062
+ var _a;
10063
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10064
+ const [modalContent, setModalContent] = React.useState(
10065
+ null
10066
+ );
10067
+ const { handleSuccess } = useRouteModal();
10068
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10069
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10070
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10071
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10072
+ const matches = React.useMemo(() => {
10073
+ return matchSorter.matchSorter(preview.items, query2, {
10074
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10075
+ });
10076
+ }, [preview.items, query2]);
10077
+ const onSubmit = async () => {
10078
+ setIsSubmitting(true);
10079
+ let requestSucceeded = false;
10080
+ await requestOrderEdit(void 0, {
10081
+ onError: (e) => {
10082
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10083
+ },
10084
+ onSuccess: () => {
10085
+ requestSucceeded = true;
10086
+ }
10087
+ });
10088
+ if (!requestSucceeded) {
10089
+ setIsSubmitting(false);
10090
+ return;
10091
+ }
10092
+ await confirmOrderEdit(void 0, {
10093
+ onError: (e) => {
10094
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10095
+ },
10096
+ onSuccess: () => {
10097
+ handleSuccess();
10098
+ },
10099
+ onSettled: () => {
10100
+ setIsSubmitting(false);
10101
+ }
10102
+ });
10103
+ };
10104
+ const onKeyDown = React.useCallback(
10105
+ (e) => {
10106
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10107
+ if (modalContent || isSubmitting) {
10108
+ return;
10109
+ }
10110
+ onSubmit();
10111
+ }
10112
+ },
10113
+ [modalContent, isSubmitting, onSubmit]
10114
+ );
10115
+ React.useEffect(() => {
10116
+ document.addEventListener("keydown", onKeyDown);
10117
+ return () => {
10118
+ document.removeEventListener("keydown", onKeyDown);
10119
+ };
10120
+ }, [onKeyDown]);
10121
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10122
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10123
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10124
+ StackedFocusModal,
10125
+ {
10126
+ id: STACKED_MODAL_ID,
10127
+ onOpenChangeCallback: (open) => {
10128
+ if (!open) {
10129
+ setModalContent(null);
10130
+ }
10131
+ },
10132
+ children: [
10133
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10134
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10135
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10136
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
10137
+ ] }),
10138
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10139
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10140
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10141
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10142
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10143
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10144
+ ] }),
10145
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10146
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10147
+ ui.Input,
10148
+ {
10149
+ type: "search",
10150
+ placeholder: "Search items",
10151
+ value: searchValue,
10152
+ onChange: (e) => onSearchValueChange(e.target.value)
10153
+ }
10154
+ ) }),
10155
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10156
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10157
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10158
+ /* @__PURE__ */ jsxRuntime.jsx(
10159
+ StackedModalTrigger$1,
10160
+ {
10161
+ type: "add-items",
10162
+ setModalContent
10163
+ }
10164
+ ),
10165
+ /* @__PURE__ */ jsxRuntime.jsx(
10166
+ StackedModalTrigger$1,
10167
+ {
10168
+ type: "add-custom-item",
10169
+ setModalContent
10170
+ }
10171
+ )
10172
+ ] })
10173
+ ] })
10174
+ ] })
10175
+ ] }),
10176
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10177
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10178
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10179
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10180
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10181
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
10182
+ ] }) }),
10183
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10184
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10185
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10186
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10187
+ Item,
10188
+ {
10189
+ item,
10190
+ preview,
10191
+ currencyCode
10192
+ },
10193
+ item.id
10194
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10195
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10196
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10197
+ 'No items found for "',
10198
+ query2,
10199
+ '".'
10200
+ ] })
10201
+ ] }) })
10202
+ ] })
10203
+ ] }),
10204
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10205
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10206
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10207
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10208
+ ui.Text,
10209
+ {
10210
+ size: "small",
10211
+ leading: "compact",
10212
+ className: "text-ui-fg-subtle",
10213
+ children: [
10214
+ itemCount,
10215
+ " ",
10216
+ itemCount === 1 ? "item" : "items"
10217
+ ]
10218
+ }
10219
+ ) }),
10220
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10221
+ ] })
10222
+ ] }) }),
10223
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10224
+ CustomItemForm,
10225
+ {
10226
+ orderId: preview.id,
10227
+ currencyCode
10228
+ }
10229
+ ) : null)
10230
+ ]
10231
+ }
10232
+ ) }),
10233
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10234
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10235
+ /* @__PURE__ */ jsxRuntime.jsx(
10236
+ ui.Button,
10237
+ {
10238
+ size: "small",
10239
+ type: "button",
10240
+ onClick: onSubmit,
10241
+ isLoading: isSubmitting,
10242
+ children: "Save"
10243
+ }
10244
+ )
10245
+ ] }) })
10246
+ ] });
10247
+ };
10248
+ const Item = ({ item, preview, currencyCode }) => {
10249
+ if (item.variant_id) {
10250
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10251
+ }
10252
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10253
+ };
10254
+ const VariantItem = ({ item, preview, currencyCode }) => {
10255
+ const [editing, setEditing] = React.useState(false);
10256
+ const form = reactHookForm.useForm({
10257
+ defaultValues: {
10258
+ quantity: item.quantity,
10259
+ unit_price: item.unit_price
10260
+ },
10261
+ resolver: zod.zodResolver(variantItemSchema)
10262
+ });
10263
+ const actionId = React.useMemo(() => {
10264
+ var _a, _b;
10265
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10266
+ }, [item]);
10267
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10268
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10269
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10270
+ const onSubmit = form.handleSubmit(async (data) => {
10271
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10272
+ setEditing(false);
10273
+ return;
10274
+ }
10275
+ if (!actionId) {
10276
+ await updateOriginalItem(
10277
+ {
10278
+ item_id: item.id,
10279
+ quantity: data.quantity,
10280
+ unit_price: convertNumber(data.unit_price)
10281
+ },
10282
+ {
10283
+ onSuccess: () => {
10284
+ setEditing(false);
10285
+ },
10286
+ onError: (e) => {
10287
+ ui.toast.error(e.message);
10288
+ }
10289
+ }
10290
+ );
10291
+ return;
10292
+ }
10293
+ await updateActionItem(
10294
+ {
10295
+ action_id: actionId,
10296
+ quantity: data.quantity,
10297
+ unit_price: convertNumber(data.unit_price)
10298
+ },
10299
+ {
10300
+ onSuccess: () => {
10301
+ setEditing(false);
10302
+ },
10303
+ onError: (e) => {
10304
+ ui.toast.error(e.message);
10305
+ }
10306
+ }
10307
+ );
10308
+ });
10309
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10310
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10311
+ /* @__PURE__ */ jsxRuntime.jsx(
10312
+ Thumbnail,
10313
+ {
10314
+ thumbnail: item.thumbnail,
10315
+ alt: item.product_title ?? void 0
10316
+ }
10317
+ ),
10318
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10319
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10320
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10321
+ /* @__PURE__ */ jsxRuntime.jsxs(
10322
+ ui.Text,
10323
+ {
10324
+ size: "small",
10325
+ leading: "compact",
10326
+ className: "text-ui-fg-subtle",
10327
+ children: [
10328
+ "(",
10329
+ item.variant_title,
10330
+ ")"
10331
+ ]
10332
+ }
10333
+ )
10334
+ ] }),
10335
+ /* @__PURE__ */ jsxRuntime.jsx(
10336
+ ui.Text,
10337
+ {
10338
+ size: "small",
10339
+ leading: "compact",
10340
+ className: "text-ui-fg-subtle",
10341
+ children: item.variant_sku
10342
+ }
10343
+ )
10344
+ ] })
10345
+ ] }),
10346
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10347
+ Form$2.Field,
10348
+ {
10349
+ control: form.control,
10350
+ name: "quantity",
10351
+ render: ({ field }) => {
10352
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10353
+ }
10354
+ }
10355
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10356
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10357
+ Form$2.Field,
10358
+ {
10359
+ control: form.control,
10360
+ name: "unit_price",
10361
+ render: ({ field: { onChange, ...field } }) => {
10362
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10363
+ ui.CurrencyInput,
10364
+ {
10365
+ ...field,
10366
+ symbol: getNativeSymbol(currencyCode),
10367
+ code: currencyCode,
10368
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10369
+ }
10370
+ ) }) });
10371
+ }
10372
+ }
10373
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10374
+ /* @__PURE__ */ jsxRuntime.jsx(
10375
+ ui.IconButton,
10376
+ {
10377
+ type: "button",
10378
+ size: "small",
10379
+ onClick: editing ? onSubmit : () => {
10380
+ setEditing(true);
10381
+ },
10382
+ disabled: isPending,
10383
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10384
+ }
10385
+ )
10386
+ ] }) }) });
10387
+ };
10388
+ const variantItemSchema = objectType({
10389
+ quantity: numberType(),
10390
+ unit_price: unionType([numberType(), stringType()])
10391
+ });
10392
+ const CustomItem = ({ item, preview, currencyCode }) => {
10393
+ const [editing, setEditing] = React.useState(false);
10394
+ const { quantity, unit_price, title } = item;
10395
+ const form = reactHookForm.useForm({
10396
+ defaultValues: {
10397
+ title,
10140
10398
  quantity,
10141
10399
  unit_price
10142
10400
  },
@@ -10789,710 +11047,465 @@ const MetadataForm = ({ orderId, metadata }) => {
10789
11047
  ]
10790
11048
  }
10791
11049
  ),
10792
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10793
- /* @__PURE__ */ jsxRuntime.jsxs(
10794
- ui.DropdownMenu.Item,
10795
- {
10796
- className: "gap-x-2",
10797
- onClick: () => deleteRow(index),
10798
- children: [
10799
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10800
- "Delete row"
10801
- ]
10802
- }
10803
- )
10804
- ] })
10805
- ] })
10806
- ] })
10807
- },
10808
- field.id
10809
- );
10810
- })
10811
- ] }),
10812
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10813
- ] }),
10814
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10815
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10816
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10817
- ] }) })
10818
- ]
10819
- }
10820
- ) });
10821
- };
10822
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10823
- return /* @__PURE__ */ jsxRuntime.jsx(
10824
- "input",
10825
- {
10826
- ref,
10827
- ...props,
10828
- autoComplete: "off",
10829
- className: ui.clx(
10830
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10831
- className
10832
- )
10833
- }
10834
- );
10835
- });
10836
- GridInput.displayName = "MetadataForm.GridInput";
10837
- const PlaceholderInner = () => {
10838
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10839
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10840
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10841
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10842
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10843
- ] }) })
10844
- ] });
10845
- };
10846
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10847
- function getDefaultValues(metadata) {
10848
- if (!metadata || !Object.keys(metadata).length) {
10849
- return [
10850
- {
10851
- key: "",
10852
- value: "",
10853
- disabled: false
10854
- }
10855
- ];
10856
- }
10857
- return Object.entries(metadata).map(([key, value]) => {
10858
- if (!EDITABLE_TYPES.includes(typeof value)) {
10859
- return {
10860
- key,
10861
- value,
10862
- disabled: true
10863
- };
10864
- }
10865
- let stringValue = value;
10866
- if (typeof value !== "string") {
10867
- stringValue = JSON.stringify(value);
10868
- }
10869
- return {
10870
- key,
10871
- value: stringValue,
10872
- original_key: key
10873
- };
10874
- });
10875
- }
10876
- function parseValues(values) {
10877
- const metadata = values.metadata;
10878
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10879
- if (isEmpty) {
10880
- return null;
10881
- }
10882
- const update = {};
10883
- metadata.forEach((field) => {
10884
- let key = field.key;
10885
- let value = field.value;
10886
- const disabled = field.disabled;
10887
- if (!key || !value) {
10888
- return;
10889
- }
10890
- if (disabled) {
10891
- update[key] = value;
10892
- return;
10893
- }
10894
- key = key.trim();
10895
- value = value.trim();
10896
- if (value === "true") {
10897
- update[key] = true;
10898
- } else if (value === "false") {
10899
- update[key] = false;
10900
- } else {
10901
- const parsedNumber = parseFloat(value);
10902
- if (!isNaN(parsedNumber)) {
10903
- update[key] = parsedNumber;
10904
- } else {
10905
- update[key] = value;
10906
- }
10907
- }
10908
- });
10909
- return update;
10910
- }
10911
- function getHasUneditableRows(metadata) {
10912
- if (!metadata) {
10913
- return false;
10914
- }
10915
- return Object.values(metadata).some(
10916
- (value) => !EDITABLE_TYPES.includes(typeof value)
10917
- );
10918
- }
10919
- const PROMOTION_QUERY_KEY = "promotions";
10920
- const promotionsQueryKeys = {
10921
- list: (query2) => [
10922
- PROMOTION_QUERY_KEY,
10923
- query2 ? query2 : void 0
10924
- ],
10925
- detail: (id, query2) => [
10926
- PROMOTION_QUERY_KEY,
10927
- id,
10928
- query2 ? query2 : void 0
10929
- ]
10930
- };
10931
- const usePromotions = (query2, options) => {
10932
- const { data, ...rest } = reactQuery.useQuery({
10933
- queryKey: promotionsQueryKeys.list(query2),
10934
- queryFn: async () => sdk.admin.promotion.list(query2),
10935
- ...options
10936
- });
10937
- return { ...data, ...rest };
10938
- };
10939
- const Promotions = () => {
10940
- const { id } = reactRouterDom.useParams();
10941
- const {
10942
- order: preview,
10943
- isError: isPreviewError,
10944
- error: previewError
10945
- } = useOrderPreview(id, void 0);
10946
- useInitiateOrderEdit({ preview });
10947
- const { onCancel } = useCancelOrderEdit({ preview });
10948
- if (isPreviewError) {
10949
- throw previewError;
10950
- }
10951
- const isReady = !!preview;
10952
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10953
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10954
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10955
- ] });
10956
- };
10957
- const PromotionForm = ({ preview }) => {
10958
- const { items, shipping_methods } = preview;
10959
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10960
- const [comboboxValue, setComboboxValue] = React.useState("");
10961
- const { handleSuccess } = useRouteModal();
10962
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10963
- const promoIds = getPromotionIds(items, shipping_methods);
10964
- const { promotions, isPending, isError, error } = usePromotions(
10965
- {
10966
- id: promoIds
10967
- },
10968
- {
10969
- enabled: !!promoIds.length
10970
- }
10971
- );
10972
- const comboboxData = useComboboxData({
10973
- queryKey: ["promotions", "combobox", promoIds],
10974
- queryFn: async (params) => {
10975
- return await sdk.admin.promotion.list({
10976
- ...params,
10977
- id: {
10978
- $nin: promoIds
10979
- }
10980
- });
10981
- },
10982
- getOptions: (data) => {
10983
- return data.promotions.map((promotion) => ({
10984
- label: promotion.code,
10985
- value: promotion.code
10986
- }));
10987
- }
10988
- });
10989
- const add = async (value) => {
10990
- if (!value) {
10991
- return;
10992
- }
10993
- addPromotions(
10994
- {
10995
- promo_codes: [value]
10996
- },
10997
- {
10998
- onError: (e) => {
10999
- ui.toast.error(e.message);
11000
- comboboxData.onSearchValueChange("");
11001
- setComboboxValue("");
11002
- },
11003
- onSuccess: () => {
11004
- comboboxData.onSearchValueChange("");
11005
- setComboboxValue("");
11006
- }
11007
- }
11008
- );
11009
- };
11010
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11011
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11012
- const onSubmit = async () => {
11013
- setIsSubmitting(true);
11014
- let requestSucceeded = false;
11015
- await requestOrderEdit(void 0, {
11016
- onError: (e) => {
11017
- ui.toast.error(e.message);
11018
- },
11019
- onSuccess: () => {
11020
- requestSucceeded = true;
11021
- }
11022
- });
11023
- if (!requestSucceeded) {
11024
- setIsSubmitting(false);
11025
- return;
11026
- }
11027
- await confirmOrderEdit(void 0, {
11028
- onError: (e) => {
11029
- ui.toast.error(e.message);
11030
- },
11031
- onSuccess: () => {
11032
- handleSuccess();
11033
- },
11034
- onSettled: () => {
11035
- setIsSubmitting(false);
11036
- }
11037
- });
11038
- };
11039
- if (isError) {
11040
- throw error;
11041
- }
11042
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11043
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11044
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11045
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11046
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11047
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11050
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11051
+ /* @__PURE__ */ jsxRuntime.jsxs(
11052
+ ui.DropdownMenu.Item,
11053
+ {
11054
+ className: "gap-x-2",
11055
+ onClick: () => deleteRow(index),
11056
+ children: [
11057
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11058
+ "Delete row"
11059
+ ]
11060
+ }
11061
+ )
11062
+ ] })
11063
+ ] })
11064
+ ] })
11065
+ },
11066
+ field.id
11067
+ );
11068
+ })
11069
+ ] }),
11070
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11048
11071
  ] }),
11049
- /* @__PURE__ */ jsxRuntime.jsx(
11050
- Combobox,
11051
- {
11052
- id: "promotion-combobox",
11053
- "aria-describedby": "promotion-combobox-hint",
11054
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11055
- fetchNextPage: comboboxData.fetchNextPage,
11056
- options: comboboxData.options,
11057
- onSearchValueChange: comboboxData.onSearchValueChange,
11058
- searchValue: comboboxData.searchValue,
11059
- disabled: comboboxData.disabled || isAddingPromotions,
11060
- onChange: add,
11061
- value: comboboxValue
11062
- }
11063
- )
11064
- ] }),
11065
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11066
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11067
- PromotionItem,
11068
- {
11069
- promotion,
11070
- orderId: preview.id,
11071
- isLoading: isPending
11072
- },
11073
- promotion.id
11074
- )) })
11075
- ] }) }),
11076
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11077
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11078
- /* @__PURE__ */ jsxRuntime.jsx(
11079
- ui.Button,
11080
- {
11081
- size: "small",
11082
- type: "submit",
11083
- isLoading: isSubmitting || isAddingPromotions,
11084
- children: "Save"
11085
- }
11072
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11074
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11075
+ ] }) })
11076
+ ]
11077
+ }
11078
+ ) });
11079
+ };
11080
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11081
+ return /* @__PURE__ */ jsxRuntime.jsx(
11082
+ "input",
11083
+ {
11084
+ ref,
11085
+ ...props,
11086
+ autoComplete: "off",
11087
+ className: ui.clx(
11088
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11089
+ className
11086
11090
  )
11091
+ }
11092
+ );
11093
+ });
11094
+ GridInput.displayName = "MetadataForm.GridInput";
11095
+ const PlaceholderInner = () => {
11096
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11097
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11099
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11087
11101
  ] }) })
11088
11102
  ] });
11089
11103
  };
11090
- const PromotionItem = ({
11091
- promotion,
11092
- orderId,
11093
- isLoading
11094
- }) => {
11095
- var _a;
11096
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11097
- const onRemove = async () => {
11098
- removePromotions(
11099
- {
11100
- promo_codes: [promotion.code]
11101
- },
11104
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11105
+ function getDefaultValues(metadata) {
11106
+ if (!metadata || !Object.keys(metadata).length) {
11107
+ return [
11102
11108
  {
11103
- onError: (e) => {
11104
- ui.toast.error(e.message);
11105
- }
11109
+ key: "",
11110
+ value: "",
11111
+ disabled: false
11106
11112
  }
11107
- );
11108
- };
11109
- const displayValue = getDisplayValue(promotion);
11110
- return /* @__PURE__ */ jsxRuntime.jsxs(
11111
- "div",
11112
- {
11113
- className: ui.clx(
11114
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11115
- {
11116
- "animate-pulse": isLoading
11117
- }
11118
- ),
11119
- children: [
11120
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11121
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11122
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11123
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11124
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11125
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11126
- ] }),
11127
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11128
- ] })
11129
- ] }),
11130
- /* @__PURE__ */ jsxRuntime.jsx(
11131
- ui.IconButton,
11132
- {
11133
- size: "small",
11134
- type: "button",
11135
- variant: "transparent",
11136
- onClick: onRemove,
11137
- isLoading: isPending || isLoading,
11138
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11139
- }
11140
- )
11141
- ]
11142
- },
11143
- promotion.id
11144
- );
11145
- };
11146
- function getDisplayValue(promotion) {
11147
- var _a, _b, _c, _d;
11148
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11149
- if (!value) {
11150
- return null;
11113
+ ];
11151
11114
  }
11152
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11153
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11154
- if (!currency) {
11155
- return null;
11115
+ return Object.entries(metadata).map(([key, value]) => {
11116
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11117
+ return {
11118
+ key,
11119
+ value,
11120
+ disabled: true
11121
+ };
11156
11122
  }
11157
- return getLocaleAmount(value, currency);
11158
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11159
- return formatPercentage(value);
11160
- }
11161
- return null;
11123
+ let stringValue = value;
11124
+ if (typeof value !== "string") {
11125
+ stringValue = JSON.stringify(value);
11126
+ }
11127
+ return {
11128
+ key,
11129
+ value: stringValue,
11130
+ original_key: key
11131
+ };
11132
+ });
11162
11133
  }
11163
- const formatter = new Intl.NumberFormat([], {
11164
- style: "percent",
11165
- minimumFractionDigits: 2
11166
- });
11167
- const formatPercentage = (value, isPercentageValue = false) => {
11168
- let val = value || 0;
11169
- if (!isPercentageValue) {
11170
- val = val / 100;
11134
+ function parseValues(values) {
11135
+ const metadata = values.metadata;
11136
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11137
+ if (isEmpty) {
11138
+ return null;
11171
11139
  }
11172
- return formatter.format(val);
11173
- };
11174
- function getPromotionIds(items, shippingMethods) {
11175
- const promotionIds = /* @__PURE__ */ new Set();
11176
- for (const item of items) {
11177
- if (item.adjustments) {
11178
- for (const adjustment of item.adjustments) {
11179
- if (adjustment.promotion_id) {
11180
- promotionIds.add(adjustment.promotion_id);
11181
- }
11182
- }
11140
+ const update = {};
11141
+ metadata.forEach((field) => {
11142
+ let key = field.key;
11143
+ let value = field.value;
11144
+ const disabled = field.disabled;
11145
+ if (!key || !value) {
11146
+ return;
11183
11147
  }
11184
- }
11185
- for (const shippingMethod of shippingMethods) {
11186
- if (shippingMethod.adjustments) {
11187
- for (const adjustment of shippingMethod.adjustments) {
11188
- if (adjustment.promotion_id) {
11189
- promotionIds.add(adjustment.promotion_id);
11190
- }
11148
+ if (disabled) {
11149
+ update[key] = value;
11150
+ return;
11151
+ }
11152
+ key = key.trim();
11153
+ value = value.trim();
11154
+ if (value === "true") {
11155
+ update[key] = true;
11156
+ } else if (value === "false") {
11157
+ update[key] = false;
11158
+ } else {
11159
+ const parsedNumber = parseFloat(value);
11160
+ if (!isNaN(parsedNumber)) {
11161
+ update[key] = parsedNumber;
11162
+ } else {
11163
+ update[key] = value;
11191
11164
  }
11192
11165
  }
11166
+ });
11167
+ return update;
11168
+ }
11169
+ function getHasUneditableRows(metadata) {
11170
+ if (!metadata) {
11171
+ return false;
11193
11172
  }
11194
- return Array.from(promotionIds);
11173
+ return Object.values(metadata).some(
11174
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11175
+ );
11195
11176
  }
11196
- const SalesChannel = () => {
11177
+ const PROMOTION_QUERY_KEY = "promotions";
11178
+ const promotionsQueryKeys = {
11179
+ list: (query2) => [
11180
+ PROMOTION_QUERY_KEY,
11181
+ query2 ? query2 : void 0
11182
+ ],
11183
+ detail: (id, query2) => [
11184
+ PROMOTION_QUERY_KEY,
11185
+ id,
11186
+ query2 ? query2 : void 0
11187
+ ]
11188
+ };
11189
+ const usePromotions = (query2, options) => {
11190
+ const { data, ...rest } = reactQuery.useQuery({
11191
+ queryKey: promotionsQueryKeys.list(query2),
11192
+ queryFn: async () => sdk.admin.promotion.list(query2),
11193
+ ...options
11194
+ });
11195
+ return { ...data, ...rest };
11196
+ };
11197
+ const Promotions = () => {
11197
11198
  const { id } = reactRouterDom.useParams();
11198
- const { draft_order, isPending, isError, error } = useDraftOrder(
11199
- id,
11199
+ const {
11200
+ order: preview,
11201
+ isError: isPreviewError,
11202
+ error: previewError
11203
+ } = useOrderPreview(id, void 0);
11204
+ useInitiateOrderEdit({ preview });
11205
+ const { onCancel } = useCancelOrderEdit({ preview });
11206
+ if (isPreviewError) {
11207
+ throw previewError;
11208
+ }
11209
+ const isReady = !!preview;
11210
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11211
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11212
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11213
+ ] });
11214
+ };
11215
+ const PromotionForm = ({ preview }) => {
11216
+ const { items, shipping_methods } = preview;
11217
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11218
+ const [comboboxValue, setComboboxValue] = React.useState("");
11219
+ const { handleSuccess } = useRouteModal();
11220
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11221
+ const promoIds = getPromotionIds(items, shipping_methods);
11222
+ const { promotions, isPending, isError, error } = usePromotions(
11200
11223
  {
11201
- fields: "+sales_channel_id"
11224
+ id: promoIds
11202
11225
  },
11203
11226
  {
11204
- enabled: !!id
11227
+ enabled: !!promoIds.length
11205
11228
  }
11206
11229
  );
11207
- if (isError) {
11208
- throw error;
11209
- }
11210
- const ISrEADY = !!draft_order && !isPending;
11211
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11212
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11213
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11214
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11215
- ] }),
11216
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11217
- ] });
11218
- };
11219
- const SalesChannelForm = ({ order }) => {
11220
- const form = reactHookForm.useForm({
11221
- defaultValues: {
11222
- sales_channel_id: order.sales_channel_id || ""
11230
+ const comboboxData = useComboboxData({
11231
+ queryKey: ["promotions", "combobox", promoIds],
11232
+ queryFn: async (params) => {
11233
+ return await sdk.admin.promotion.list({
11234
+ ...params,
11235
+ id: {
11236
+ $nin: promoIds
11237
+ }
11238
+ });
11223
11239
  },
11224
- resolver: zod.zodResolver(schema$4)
11240
+ getOptions: (data) => {
11241
+ return data.promotions.map((promotion) => ({
11242
+ label: promotion.code,
11243
+ value: promotion.code
11244
+ }));
11245
+ }
11225
11246
  });
11226
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11227
- const { handleSuccess } = useRouteModal();
11228
- const onSubmit = form.handleSubmit(async (data) => {
11229
- await mutateAsync(
11247
+ const add = async (value) => {
11248
+ if (!value) {
11249
+ return;
11250
+ }
11251
+ addPromotions(
11230
11252
  {
11231
- sales_channel_id: data.sales_channel_id
11253
+ promo_codes: [value]
11232
11254
  },
11233
11255
  {
11234
- onSuccess: () => {
11235
- ui.toast.success("Sales channel updated");
11236
- handleSuccess();
11256
+ onError: (e) => {
11257
+ ui.toast.error(e.message);
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
11237
11260
  },
11238
- onError: (error) => {
11239
- ui.toast.error(error.message);
11261
+ onSuccess: () => {
11262
+ comboboxData.onSearchValueChange("");
11263
+ setComboboxValue("");
11240
11264
  }
11241
11265
  }
11242
11266
  );
11243
- });
11244
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11245
- KeyboundForm,
11246
- {
11247
- className: "flex flex-1 flex-col overflow-hidden",
11248
- onSubmit,
11249
- children: [
11250
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11251
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11252
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11253
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11254
- ] }) })
11255
- ]
11256
- }
11257
- ) });
11258
- };
11259
- const SalesChannelField = ({ control, order }) => {
11260
- const salesChannels = useComboboxData({
11261
- queryFn: async (params) => {
11262
- return await sdk.admin.salesChannel.list(params);
11263
- },
11264
- queryKey: ["sales-channels"],
11265
- getOptions: (data) => {
11266
- return data.sales_channels.map((salesChannel) => ({
11267
- label: salesChannel.name,
11268
- value: salesChannel.id
11269
- }));
11270
- },
11271
- defaultValue: order.sales_channel_id || void 0
11272
- });
11273
- return /* @__PURE__ */ jsxRuntime.jsx(
11274
- Form$2.Field,
11275
- {
11276
- control,
11277
- name: "sales_channel_id",
11278
- render: ({ field }) => {
11279
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11280
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11281
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11282
- Combobox,
11283
- {
11284
- options: salesChannels.options,
11285
- fetchNextPage: salesChannels.fetchNextPage,
11286
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11287
- searchValue: salesChannels.searchValue,
11288
- onSearchValueChange: salesChannels.onSearchValueChange,
11289
- placeholder: "Select sales channel",
11290
- ...field
11291
- }
11292
- ) }),
11293
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11294
- ] });
11267
+ };
11268
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11269
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11270
+ const onSubmit = async () => {
11271
+ setIsSubmitting(true);
11272
+ let requestSucceeded = false;
11273
+ await requestOrderEdit(void 0, {
11274
+ onError: (e) => {
11275
+ ui.toast.error(e.message);
11276
+ },
11277
+ onSuccess: () => {
11278
+ requestSucceeded = true;
11295
11279
  }
11280
+ });
11281
+ if (!requestSucceeded) {
11282
+ setIsSubmitting(false);
11283
+ return;
11296
11284
  }
11297
- );
11298
- };
11299
- const schema$4 = objectType({
11300
- sales_channel_id: stringType().min(1)
11301
- });
11302
- const ShippingAddress = () => {
11303
- const { id } = reactRouterDom.useParams();
11304
- const { order, isPending, isError, error } = useOrder(id, {
11305
- fields: "+shipping_address"
11306
- });
11285
+ await confirmOrderEdit(void 0, {
11286
+ onError: (e) => {
11287
+ ui.toast.error(e.message);
11288
+ },
11289
+ onSuccess: () => {
11290
+ handleSuccess();
11291
+ },
11292
+ onSettled: () => {
11293
+ setIsSubmitting(false);
11294
+ }
11295
+ });
11296
+ };
11307
11297
  if (isError) {
11308
11298
  throw error;
11309
11299
  }
11310
- const isReady = !isPending && !!order;
11311
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11312
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11313
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11314
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11315
- ] }),
11316
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11317
- ] });
11318
- };
11319
- const ShippingAddressForm = ({ order }) => {
11320
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11321
- const form = reactHookForm.useForm({
11322
- defaultValues: {
11323
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11324
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11325
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11326
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11327
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11328
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11329
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11330
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11331
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11332
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11333
- },
11334
- resolver: zod.zodResolver(schema$3)
11335
- });
11336
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11337
- const { handleSuccess } = useRouteModal();
11338
- const onSubmit = form.handleSubmit(async (data) => {
11339
- await mutateAsync(
11340
- {
11341
- shipping_address: {
11342
- first_name: data.first_name,
11343
- last_name: data.last_name,
11344
- company: data.company,
11345
- address_1: data.address_1,
11346
- address_2: data.address_2,
11347
- city: data.city,
11348
- province: data.province,
11349
- country_code: data.country_code,
11350
- postal_code: data.postal_code,
11351
- phone: data.phone
11300
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11301
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11302
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11305
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11306
+ ] }),
11307
+ /* @__PURE__ */ jsxRuntime.jsx(
11308
+ Combobox,
11309
+ {
11310
+ id: "promotion-combobox",
11311
+ "aria-describedby": "promotion-combobox-hint",
11312
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11313
+ fetchNextPage: comboboxData.fetchNextPage,
11314
+ options: comboboxData.options,
11315
+ onSearchValueChange: comboboxData.onSearchValueChange,
11316
+ searchValue: comboboxData.searchValue,
11317
+ disabled: comboboxData.disabled || isAddingPromotions,
11318
+ onChange: add,
11319
+ value: comboboxValue
11320
+ }
11321
+ )
11322
+ ] }),
11323
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11324
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11325
+ PromotionItem,
11326
+ {
11327
+ promotion,
11328
+ orderId: preview.id,
11329
+ isLoading: isPending
11330
+ },
11331
+ promotion.id
11332
+ )) })
11333
+ ] }) }),
11334
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11335
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11336
+ /* @__PURE__ */ jsxRuntime.jsx(
11337
+ ui.Button,
11338
+ {
11339
+ size: "small",
11340
+ type: "submit",
11341
+ isLoading: isSubmitting || isAddingPromotions,
11342
+ children: "Save"
11352
11343
  }
11344
+ )
11345
+ ] }) })
11346
+ ] });
11347
+ };
11348
+ const PromotionItem = ({
11349
+ promotion,
11350
+ orderId,
11351
+ isLoading
11352
+ }) => {
11353
+ var _a;
11354
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11355
+ const onRemove = async () => {
11356
+ removePromotions(
11357
+ {
11358
+ promo_codes: [promotion.code]
11353
11359
  },
11354
11360
  {
11355
- onSuccess: () => {
11356
- handleSuccess();
11357
- },
11358
- onError: (error) => {
11359
- ui.toast.error(error.message);
11361
+ onError: (e) => {
11362
+ ui.toast.error(e.message);
11360
11363
  }
11361
11364
  }
11362
11365
  );
11363
- });
11364
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11365
- KeyboundForm,
11366
+ };
11367
+ const displayValue = getDisplayValue(promotion);
11368
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11369
+ "div",
11366
11370
  {
11367
- className: "flex flex-1 flex-col overflow-hidden",
11368
- onSubmit,
11371
+ className: ui.clx(
11372
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11373
+ {
11374
+ "animate-pulse": isLoading
11375
+ }
11376
+ ),
11369
11377
  children: [
11370
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11371
- /* @__PURE__ */ jsxRuntime.jsx(
11372
- Form$2.Field,
11373
- {
11374
- control: form.control,
11375
- name: "country_code",
11376
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11378
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11379
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11380
- ] })
11381
- }
11382
- ),
11383
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11384
- /* @__PURE__ */ jsxRuntime.jsx(
11385
- Form$2.Field,
11386
- {
11387
- control: form.control,
11388
- name: "first_name",
11389
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11390
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11391
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11392
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11393
- ] })
11394
- }
11395
- ),
11396
- /* @__PURE__ */ jsxRuntime.jsx(
11397
- Form$2.Field,
11398
- {
11399
- control: form.control,
11400
- name: "last_name",
11401
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11402
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11403
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11404
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11405
- ] })
11406
- }
11407
- )
11408
- ] }),
11409
- /* @__PURE__ */ jsxRuntime.jsx(
11410
- Form$2.Field,
11411
- {
11412
- control: form.control,
11413
- name: "company",
11414
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11415
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11416
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11417
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11418
- ] })
11419
- }
11420
- ),
11421
- /* @__PURE__ */ jsxRuntime.jsx(
11422
- Form$2.Field,
11423
- {
11424
- control: form.control,
11425
- name: "address_1",
11426
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11427
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11428
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11429
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11430
- ] })
11431
- }
11432
- ),
11433
- /* @__PURE__ */ jsxRuntime.jsx(
11434
- Form$2.Field,
11435
- {
11436
- control: form.control,
11437
- name: "address_2",
11438
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11440
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11441
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11442
- ] })
11443
- }
11444
- ),
11445
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11446
- /* @__PURE__ */ jsxRuntime.jsx(
11447
- Form$2.Field,
11448
- {
11449
- control: form.control,
11450
- name: "postal_code",
11451
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11452
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11453
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11454
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11455
- ] })
11456
- }
11457
- ),
11458
- /* @__PURE__ */ jsxRuntime.jsx(
11459
- Form$2.Field,
11460
- {
11461
- control: form.control,
11462
- name: "city",
11463
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11464
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11465
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11466
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11467
- ] })
11468
- }
11469
- )
11470
- ] }),
11471
- /* @__PURE__ */ jsxRuntime.jsx(
11472
- Form$2.Field,
11473
- {
11474
- control: form.control,
11475
- name: "province",
11476
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11477
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11478
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11479
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11480
- ] })
11481
- }
11482
- ),
11483
- /* @__PURE__ */ jsxRuntime.jsx(
11484
- Form$2.Field,
11485
- {
11486
- control: form.control,
11487
- name: "phone",
11488
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11489
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11490
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11491
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11492
- ] })
11493
- }
11494
- )
11495
- ] }) }),
11378
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11379
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11380
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11381
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11382
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11383
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11384
+ ] }),
11385
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11386
+ ] })
11387
+ ] }),
11388
+ /* @__PURE__ */ jsxRuntime.jsx(
11389
+ ui.IconButton,
11390
+ {
11391
+ size: "small",
11392
+ type: "button",
11393
+ variant: "transparent",
11394
+ onClick: onRemove,
11395
+ isLoading: isPending || isLoading,
11396
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11397
+ }
11398
+ )
11399
+ ]
11400
+ },
11401
+ promotion.id
11402
+ );
11403
+ };
11404
+ function getDisplayValue(promotion) {
11405
+ var _a, _b, _c, _d;
11406
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11407
+ if (!value) {
11408
+ return null;
11409
+ }
11410
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11411
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11412
+ if (!currency) {
11413
+ return null;
11414
+ }
11415
+ return getLocaleAmount(value, currency);
11416
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11417
+ return formatPercentage(value);
11418
+ }
11419
+ return null;
11420
+ }
11421
+ const formatter = new Intl.NumberFormat([], {
11422
+ style: "percent",
11423
+ minimumFractionDigits: 2
11424
+ });
11425
+ const formatPercentage = (value, isPercentageValue = false) => {
11426
+ let val = value || 0;
11427
+ if (!isPercentageValue) {
11428
+ val = val / 100;
11429
+ }
11430
+ return formatter.format(val);
11431
+ };
11432
+ function getPromotionIds(items, shippingMethods) {
11433
+ const promotionIds = /* @__PURE__ */ new Set();
11434
+ for (const item of items) {
11435
+ if (item.adjustments) {
11436
+ for (const adjustment of item.adjustments) {
11437
+ if (adjustment.promotion_id) {
11438
+ promotionIds.add(adjustment.promotion_id);
11439
+ }
11440
+ }
11441
+ }
11442
+ }
11443
+ for (const shippingMethod of shippingMethods) {
11444
+ if (shippingMethod.adjustments) {
11445
+ for (const adjustment of shippingMethod.adjustments) {
11446
+ if (adjustment.promotion_id) {
11447
+ promotionIds.add(adjustment.promotion_id);
11448
+ }
11449
+ }
11450
+ }
11451
+ }
11452
+ return Array.from(promotionIds);
11453
+ }
11454
+ const SalesChannel = () => {
11455
+ const { id } = reactRouterDom.useParams();
11456
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11457
+ id,
11458
+ {
11459
+ fields: "+sales_channel_id"
11460
+ },
11461
+ {
11462
+ enabled: !!id
11463
+ }
11464
+ );
11465
+ if (isError) {
11466
+ throw error;
11467
+ }
11468
+ const ISrEADY = !!draft_order && !isPending;
11469
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11470
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11471
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11472
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11473
+ ] }),
11474
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11475
+ ] });
11476
+ };
11477
+ const SalesChannelForm = ({ order }) => {
11478
+ const form = reactHookForm.useForm({
11479
+ defaultValues: {
11480
+ sales_channel_id: order.sales_channel_id || ""
11481
+ },
11482
+ resolver: zod.zodResolver(schema$2)
11483
+ });
11484
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11485
+ const { handleSuccess } = useRouteModal();
11486
+ const onSubmit = form.handleSubmit(async (data) => {
11487
+ await mutateAsync(
11488
+ {
11489
+ sales_channel_id: data.sales_channel_id
11490
+ },
11491
+ {
11492
+ onSuccess: () => {
11493
+ ui.toast.success("Sales channel updated");
11494
+ handleSuccess();
11495
+ },
11496
+ onError: (error) => {
11497
+ ui.toast.error(error.message);
11498
+ }
11499
+ }
11500
+ );
11501
+ });
11502
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11503
+ KeyboundForm,
11504
+ {
11505
+ className: "flex flex-1 flex-col overflow-hidden",
11506
+ onSubmit,
11507
+ children: [
11508
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11496
11509
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11497
11510
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11498
11511
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11501,7 +11514,49 @@ const ShippingAddressForm = ({ order }) => {
11501
11514
  }
11502
11515
  ) });
11503
11516
  };
11504
- const schema$3 = addressSchema;
11517
+ const SalesChannelField = ({ control, order }) => {
11518
+ const salesChannels = useComboboxData({
11519
+ queryFn: async (params) => {
11520
+ return await sdk.admin.salesChannel.list(params);
11521
+ },
11522
+ queryKey: ["sales-channels"],
11523
+ getOptions: (data) => {
11524
+ return data.sales_channels.map((salesChannel) => ({
11525
+ label: salesChannel.name,
11526
+ value: salesChannel.id
11527
+ }));
11528
+ },
11529
+ defaultValue: order.sales_channel_id || void 0
11530
+ });
11531
+ return /* @__PURE__ */ jsxRuntime.jsx(
11532
+ Form$2.Field,
11533
+ {
11534
+ control,
11535
+ name: "sales_channel_id",
11536
+ render: ({ field }) => {
11537
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11538
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11539
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11540
+ Combobox,
11541
+ {
11542
+ options: salesChannels.options,
11543
+ fetchNextPage: salesChannels.fetchNextPage,
11544
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11545
+ searchValue: salesChannels.searchValue,
11546
+ onSearchValueChange: salesChannels.onSearchValueChange,
11547
+ placeholder: "Select sales channel",
11548
+ ...field
11549
+ }
11550
+ ) }),
11551
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11552
+ ] });
11553
+ }
11554
+ }
11555
+ );
11556
+ };
11557
+ const schema$2 = objectType({
11558
+ sales_channel_id: stringType().min(1)
11559
+ });
11505
11560
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11506
11561
  const Shipping = () => {
11507
11562
  var _a;
@@ -12256,59 +12311,262 @@ const ShippingOptionField = ({
12256
12311
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12257
12312
  ] }),
12258
12313
  /* @__PURE__ */ jsxRuntime.jsx(
12259
- ConditionalTooltip,
12314
+ ConditionalTooltip,
12315
+ {
12316
+ content: tooltipContent,
12317
+ showTooltip: !locationId || !shippingProfileId,
12318
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12319
+ Combobox,
12320
+ {
12321
+ options: shippingOptions.options,
12322
+ fetchNextPage: shippingOptions.fetchNextPage,
12323
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12324
+ searchValue: shippingOptions.searchValue,
12325
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12326
+ placeholder: "Select shipping option",
12327
+ ...field,
12328
+ disabled: !locationId || !shippingProfileId
12329
+ }
12330
+ ) }) })
12331
+ }
12332
+ )
12333
+ ] }) });
12334
+ }
12335
+ }
12336
+ );
12337
+ };
12338
+ const CustomAmountField = ({
12339
+ control,
12340
+ currencyCode
12341
+ }) => {
12342
+ return /* @__PURE__ */ jsxRuntime.jsx(
12343
+ Form$2.Field,
12344
+ {
12345
+ control,
12346
+ name: "custom_amount",
12347
+ render: ({ field: { onChange, ...field } }) => {
12348
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12349
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12350
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12351
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12352
+ ] }),
12353
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12354
+ ui.CurrencyInput,
12355
+ {
12356
+ ...field,
12357
+ onValueChange: (value) => onChange(value),
12358
+ symbol: getNativeSymbol(currencyCode),
12359
+ code: currencyCode
12360
+ }
12361
+ ) })
12362
+ ] });
12363
+ }
12364
+ }
12365
+ );
12366
+ };
12367
+ const ShippingAddress = () => {
12368
+ const { id } = reactRouterDom.useParams();
12369
+ const { order, isPending, isError, error } = useOrder(id, {
12370
+ fields: "+shipping_address"
12371
+ });
12372
+ if (isError) {
12373
+ throw error;
12374
+ }
12375
+ const isReady = !isPending && !!order;
12376
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12377
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12378
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12379
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12380
+ ] }),
12381
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12382
+ ] });
12383
+ };
12384
+ const ShippingAddressForm = ({ order }) => {
12385
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12386
+ const form = reactHookForm.useForm({
12387
+ defaultValues: {
12388
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12389
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12390
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12391
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12392
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12393
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12394
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12395
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12396
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12397
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12398
+ },
12399
+ resolver: zod.zodResolver(schema$1)
12400
+ });
12401
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12402
+ const { handleSuccess } = useRouteModal();
12403
+ const onSubmit = form.handleSubmit(async (data) => {
12404
+ await mutateAsync(
12405
+ {
12406
+ shipping_address: {
12407
+ first_name: data.first_name,
12408
+ last_name: data.last_name,
12409
+ company: data.company,
12410
+ address_1: data.address_1,
12411
+ address_2: data.address_2,
12412
+ city: data.city,
12413
+ province: data.province,
12414
+ country_code: data.country_code,
12415
+ postal_code: data.postal_code,
12416
+ phone: data.phone
12417
+ }
12418
+ },
12419
+ {
12420
+ onSuccess: () => {
12421
+ handleSuccess();
12422
+ },
12423
+ onError: (error) => {
12424
+ ui.toast.error(error.message);
12425
+ }
12426
+ }
12427
+ );
12428
+ });
12429
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12430
+ KeyboundForm,
12431
+ {
12432
+ className: "flex flex-1 flex-col overflow-hidden",
12433
+ onSubmit,
12434
+ children: [
12435
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12436
+ /* @__PURE__ */ jsxRuntime.jsx(
12437
+ Form$2.Field,
12438
+ {
12439
+ control: form.control,
12440
+ name: "country_code",
12441
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12442
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12443
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12445
+ ] })
12446
+ }
12447
+ ),
12448
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12449
+ /* @__PURE__ */ jsxRuntime.jsx(
12450
+ Form$2.Field,
12451
+ {
12452
+ control: form.control,
12453
+ name: "first_name",
12454
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12455
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12456
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12458
+ ] })
12459
+ }
12460
+ ),
12461
+ /* @__PURE__ */ jsxRuntime.jsx(
12462
+ Form$2.Field,
12463
+ {
12464
+ control: form.control,
12465
+ name: "last_name",
12466
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12467
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12468
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12470
+ ] })
12471
+ }
12472
+ )
12473
+ ] }),
12474
+ /* @__PURE__ */ jsxRuntime.jsx(
12475
+ Form$2.Field,
12260
12476
  {
12261
- content: tooltipContent,
12262
- showTooltip: !locationId || !shippingProfileId,
12263
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12264
- Combobox,
12265
- {
12266
- options: shippingOptions.options,
12267
- fetchNextPage: shippingOptions.fetchNextPage,
12268
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12269
- searchValue: shippingOptions.searchValue,
12270
- onSearchValueChange: shippingOptions.onSearchValueChange,
12271
- placeholder: "Select shipping option",
12272
- ...field,
12273
- disabled: !locationId || !shippingProfileId
12274
- }
12275
- ) }) })
12477
+ control: form.control,
12478
+ name: "company",
12479
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12480
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12481
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12483
+ ] })
12276
12484
  }
12277
- )
12278
- ] }) });
12279
- }
12280
- }
12281
- );
12282
- };
12283
- const CustomAmountField = ({
12284
- control,
12285
- currencyCode
12286
- }) => {
12287
- return /* @__PURE__ */ jsxRuntime.jsx(
12288
- Form$2.Field,
12289
- {
12290
- control,
12291
- name: "custom_amount",
12292
- render: ({ field: { onChange, ...field } }) => {
12293
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12294
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12295
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12296
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12485
+ ),
12486
+ /* @__PURE__ */ jsxRuntime.jsx(
12487
+ Form$2.Field,
12488
+ {
12489
+ control: form.control,
12490
+ name: "address_1",
12491
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12492
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12493
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12495
+ ] })
12496
+ }
12497
+ ),
12498
+ /* @__PURE__ */ jsxRuntime.jsx(
12499
+ Form$2.Field,
12500
+ {
12501
+ control: form.control,
12502
+ name: "address_2",
12503
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12504
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12505
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12507
+ ] })
12508
+ }
12509
+ ),
12510
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12511
+ /* @__PURE__ */ jsxRuntime.jsx(
12512
+ Form$2.Field,
12513
+ {
12514
+ control: form.control,
12515
+ name: "postal_code",
12516
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12517
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12518
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12520
+ ] })
12521
+ }
12522
+ ),
12523
+ /* @__PURE__ */ jsxRuntime.jsx(
12524
+ Form$2.Field,
12525
+ {
12526
+ control: form.control,
12527
+ name: "city",
12528
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12529
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12530
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12532
+ ] })
12533
+ }
12534
+ )
12297
12535
  ] }),
12298
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12299
- ui.CurrencyInput,
12536
+ /* @__PURE__ */ jsxRuntime.jsx(
12537
+ Form$2.Field,
12300
12538
  {
12301
- ...field,
12302
- onValueChange: (value) => onChange(value),
12303
- symbol: getNativeSymbol(currencyCode),
12304
- code: currencyCode
12539
+ control: form.control,
12540
+ name: "province",
12541
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12542
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12545
+ ] })
12305
12546
  }
12306
- ) })
12307
- ] });
12308
- }
12547
+ ),
12548
+ /* @__PURE__ */ jsxRuntime.jsx(
12549
+ Form$2.Field,
12550
+ {
12551
+ control: form.control,
12552
+ name: "phone",
12553
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12557
+ ] })
12558
+ }
12559
+ )
12560
+ ] }) }),
12561
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12562
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12564
+ ] }) })
12565
+ ]
12309
12566
  }
12310
- );
12567
+ ) });
12311
12568
  };
12569
+ const schema$1 = addressSchema;
12312
12570
  const TransferOwnership = () => {
12313
12571
  const { id } = reactRouterDom.useParams();
12314
12572
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12332,7 +12590,7 @@ const TransferOwnershipForm = ({ order }) => {
12332
12590
  defaultValues: {
12333
12591
  customer_id: order.customer_id || ""
12334
12592
  },
12335
- resolver: zod.zodResolver(schema$2)
12593
+ resolver: zod.zodResolver(schema)
12336
12594
  });
12337
12595
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12338
12596
  const { handleSuccess } = useRouteModal();
@@ -12719,330 +12977,72 @@ const Illustration = () => {
12719
12977
  stroke: "#A1A1AA",
12720
12978
  strokeWidth: "1.5",
12721
12979
  strokeLinecap: "round",
12722
- strokeLinejoin: "round"
12723
- }
12724
- ) }),
12725
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12726
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12727
- "rect",
12728
- {
12729
- width: "12",
12730
- height: "12",
12731
- fill: "white",
12732
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12733
- }
12734
- ) }),
12735
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12736
- "rect",
12737
- {
12738
- width: "12",
12739
- height: "12",
12740
- fill: "white",
12741
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12742
- }
12743
- ) }),
12744
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12745
- "rect",
12746
- {
12747
- width: "12",
12748
- height: "12",
12749
- fill: "white",
12750
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12751
- }
12752
- ) }),
12753
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12754
- "rect",
12755
- {
12756
- width: "12",
12757
- height: "12",
12758
- fill: "white",
12759
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12760
- }
12761
- ) }),
12762
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12763
- "rect",
12764
- {
12765
- width: "12",
12766
- height: "12",
12767
- fill: "white",
12768
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12769
- }
12770
- ) }),
12771
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12772
- "rect",
12773
- {
12774
- width: "12",
12775
- height: "12",
12776
- fill: "white",
12777
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12778
- }
12779
- ) })
12780
- ] })
12781
- ]
12782
- }
12783
- );
12784
- };
12785
- const schema$2 = objectType({
12786
- customer_id: stringType().min(1)
12787
- });
12788
- const Email = () => {
12789
- const { id } = reactRouterDom.useParams();
12790
- const { order, isPending, isError, error } = useOrder(id, {
12791
- fields: "+email"
12792
- });
12793
- if (isError) {
12794
- throw error;
12795
- }
12796
- const isReady = !isPending && !!order;
12797
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12798
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12799
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12800
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12801
- ] }),
12802
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12803
- ] });
12804
- };
12805
- const EmailForm = ({ order }) => {
12806
- const form = reactHookForm.useForm({
12807
- defaultValues: {
12808
- email: order.email ?? ""
12809
- },
12810
- resolver: zod.zodResolver(schema$1)
12811
- });
12812
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12813
- const { handleSuccess } = useRouteModal();
12814
- const onSubmit = form.handleSubmit(async (data) => {
12815
- await mutateAsync(
12816
- { email: data.email },
12817
- {
12818
- onSuccess: () => {
12819
- handleSuccess();
12820
- },
12821
- onError: (error) => {
12822
- ui.toast.error(error.message);
12823
- }
12824
- }
12825
- );
12826
- });
12827
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12828
- KeyboundForm,
12829
- {
12830
- className: "flex flex-1 flex-col overflow-hidden",
12831
- onSubmit,
12832
- children: [
12833
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
12834
- Form$2.Field,
12835
- {
12836
- control: form.control,
12837
- name: "email",
12838
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
12840
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12841
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12842
- ] })
12980
+ strokeLinejoin: "round"
12843
12981
  }
12844
12982
  ) }),
12845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12846
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12847
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12848
- ] }) })
12849
- ]
12850
- }
12851
- ) });
12852
- };
12853
- const schema$1 = objectType({
12854
- email: stringType().email()
12855
- });
12856
- const BillingAddress = () => {
12857
- const { id } = reactRouterDom.useParams();
12858
- const { order, isPending, isError, error } = useOrder(id, {
12859
- fields: "+billing_address"
12860
- });
12861
- if (isError) {
12862
- throw error;
12863
- }
12864
- const isReady = !isPending && !!order;
12865
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12866
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12867
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12868
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12869
- ] }),
12870
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12871
- ] });
12872
- };
12873
- const BillingAddressForm = ({ order }) => {
12874
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12875
- const form = reactHookForm.useForm({
12876
- defaultValues: {
12877
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12878
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12879
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12880
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12881
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12882
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12883
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12884
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12885
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12886
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12887
- },
12888
- resolver: zod.zodResolver(schema)
12889
- });
12890
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12891
- const { handleSuccess } = useRouteModal();
12892
- const onSubmit = form.handleSubmit(async (data) => {
12893
- await mutateAsync(
12894
- { billing_address: data },
12895
- {
12896
- onSuccess: () => {
12897
- handleSuccess();
12898
- },
12899
- onError: (error) => {
12900
- ui.toast.error(error.message);
12901
- }
12902
- }
12903
- );
12904
- });
12905
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12906
- KeyboundForm,
12907
- {
12908
- className: "flex flex-1 flex-col overflow-hidden",
12909
- onSubmit,
12910
- children: [
12911
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12912
- /* @__PURE__ */ jsxRuntime.jsx(
12913
- Form$2.Field,
12983
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12984
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12985
+ "rect",
12914
12986
  {
12915
- control: form.control,
12916
- name: "country_code",
12917
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12918
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12919
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12921
- ] })
12987
+ width: "12",
12988
+ height: "12",
12989
+ fill: "white",
12990
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12922
12991
  }
12923
- ),
12924
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12925
- /* @__PURE__ */ jsxRuntime.jsx(
12926
- Form$2.Field,
12927
- {
12928
- control: form.control,
12929
- name: "first_name",
12930
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12931
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12932
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12934
- ] })
12935
- }
12936
- ),
12937
- /* @__PURE__ */ jsxRuntime.jsx(
12938
- Form$2.Field,
12939
- {
12940
- control: form.control,
12941
- name: "last_name",
12942
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12943
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12944
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12946
- ] })
12947
- }
12948
- )
12949
- ] }),
12950
- /* @__PURE__ */ jsxRuntime.jsx(
12951
- Form$2.Field,
12992
+ ) }),
12993
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12994
+ "rect",
12952
12995
  {
12953
- control: form.control,
12954
- name: "company",
12955
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12956
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12957
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
- ] })
12996
+ width: "12",
12997
+ height: "12",
12998
+ fill: "white",
12999
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12960
13000
  }
12961
- ),
12962
- /* @__PURE__ */ jsxRuntime.jsx(
12963
- Form$2.Field,
13001
+ ) }),
13002
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13003
+ "rect",
12964
13004
  {
12965
- control: form.control,
12966
- name: "address_1",
12967
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12968
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12971
- ] })
13005
+ width: "12",
13006
+ height: "12",
13007
+ fill: "white",
13008
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12972
13009
  }
12973
- ),
12974
- /* @__PURE__ */ jsxRuntime.jsx(
12975
- Form$2.Field,
13010
+ ) }),
13011
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13012
+ "rect",
12976
13013
  {
12977
- control: form.control,
12978
- name: "address_2",
12979
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12980
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12981
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12983
- ] })
13014
+ width: "12",
13015
+ height: "12",
13016
+ fill: "white",
13017
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12984
13018
  }
12985
- ),
12986
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12987
- /* @__PURE__ */ jsxRuntime.jsx(
12988
- Form$2.Field,
12989
- {
12990
- control: form.control,
12991
- name: "postal_code",
12992
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12993
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12994
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12996
- ] })
12997
- }
12998
- ),
12999
- /* @__PURE__ */ jsxRuntime.jsx(
13000
- Form$2.Field,
13001
- {
13002
- control: form.control,
13003
- name: "city",
13004
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13005
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13006
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13008
- ] })
13009
- }
13010
- )
13011
- ] }),
13012
- /* @__PURE__ */ jsxRuntime.jsx(
13013
- Form$2.Field,
13019
+ ) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13021
+ "rect",
13014
13022
  {
13015
- control: form.control,
13016
- name: "province",
13017
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
- ] })
13023
+ width: "12",
13024
+ height: "12",
13025
+ fill: "white",
13026
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13022
13027
  }
13023
- ),
13024
- /* @__PURE__ */ jsxRuntime.jsx(
13025
- Form$2.Field,
13028
+ ) }),
13029
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13030
+ "rect",
13026
13031
  {
13027
- control: form.control,
13028
- name: "phone",
13029
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
- ] })
13032
+ width: "12",
13033
+ height: "12",
13034
+ fill: "white",
13035
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13034
13036
  }
13035
- )
13036
- ] }) }),
13037
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13039
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13040
- ] }) })
13037
+ ) })
13038
+ ] })
13041
13039
  ]
13042
13040
  }
13043
- ) });
13041
+ );
13044
13042
  };
13045
- const schema = addressSchema;
13043
+ const schema = objectType({
13044
+ customer_id: stringType().min(1)
13045
+ });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13067,6 +13067,14 @@ const routeModule = {
13067
13067
  Component: CustomItems,
13068
13068
  path: "/draft-orders/:id/custom-items"
13069
13069
  },
13070
+ {
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13073
+ },
13074
+ {
13075
+ Component: BillingAddress,
13076
+ path: "/draft-orders/:id/billing-address"
13077
+ },
13070
13078
  {
13071
13079
  Component: Items,
13072
13080
  path: "/draft-orders/:id/items"
@@ -13083,25 +13091,17 @@ const routeModule = {
13083
13091
  Component: SalesChannel,
13084
13092
  path: "/draft-orders/:id/sales-channel"
13085
13093
  },
13086
- {
13087
- Component: ShippingAddress,
13088
- path: "/draft-orders/:id/shipping-address"
13089
- },
13090
13094
  {
13091
13095
  Component: Shipping,
13092
13096
  path: "/draft-orders/:id/shipping"
13093
13097
  },
13094
13098
  {
13095
- Component: TransferOwnership,
13096
- path: "/draft-orders/:id/transfer-ownership"
13097
- },
13098
- {
13099
- Component: Email,
13100
- path: "/draft-orders/:id/email"
13099
+ Component: ShippingAddress,
13100
+ path: "/draft-orders/:id/shipping-address"
13101
13101
  },
13102
13102
  {
13103
- Component: BillingAddress,
13104
- path: "/draft-orders/:id/billing-address"
13103
+ Component: TransferOwnership,
13104
+ path: "/draft-orders/:id/transfer-ownership"
13105
13105
  }
13106
13106
  ]
13107
13107
  }