@medusajs/draft-order 2.10.3-preview-20250914150152 → 2.10.3-preview-20250914180153

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.
@@ -11559,787 +11559,108 @@ const SalesChannelField = ({ control, order }) => {
11559
11559
  const schema$2 = objectType({
11560
11560
  sales_channel_id: stringType().min(1)
11561
11561
  });
11562
- const TransferOwnership = () => {
11562
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11563
+ const Shipping = () => {
11564
+ var _a;
11563
11565
  const { id } = reactRouterDom.useParams();
11564
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11565
- fields: "id,customer_id,customer.*"
11566
+ const { order, isPending, isError, error } = useOrder(id, {
11567
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11566
11568
  });
11569
+ const {
11570
+ order: preview,
11571
+ isPending: isPreviewPending,
11572
+ isError: isPreviewError,
11573
+ error: previewError
11574
+ } = useOrderPreview(id);
11575
+ useInitiateOrderEdit({ preview });
11576
+ const { onCancel } = useCancelOrderEdit({ preview });
11567
11577
  if (isError) {
11568
11578
  throw error;
11569
11579
  }
11570
- const isReady = !isPending && !!draft_order;
11571
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11572
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11573
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11574
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11575
- ] }),
11576
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11577
- ] });
11580
+ if (isPreviewError) {
11581
+ throw previewError;
11582
+ }
11583
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11584
+ const isReady = preview && !isPreviewPending && order && !isPending;
11585
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__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 py-16 px-6", children: [
11588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11590
+ ] }) }) }),
11591
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11592
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11594
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11595
+ ] }) });
11578
11596
  };
11579
- const TransferOwnershipForm = ({ order }) => {
11580
- var _a, _b;
11581
- const form = reactHookForm.useForm({
11582
- defaultValues: {
11583
- customer_id: order.customer_id || ""
11597
+ const ShippingForm = ({ preview, order }) => {
11598
+ var _a;
11599
+ const { setIsOpen } = useStackedModal();
11600
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11601
+ const [data, setData] = React.useState(null);
11602
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11603
+ const { shipping_options } = useShippingOptions(
11604
+ {
11605
+ id: appliedShippingOptionIds,
11606
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11584
11607
  },
11585
- resolver: zod.zodResolver(schema$1)
11586
- });
11587
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11608
+ {
11609
+ enabled: appliedShippingOptionIds.length > 0
11610
+ }
11611
+ );
11612
+ const uniqueShippingProfiles = React.useMemo(() => {
11613
+ const profiles = /* @__PURE__ */ new Map();
11614
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11615
+ profiles.set(profile.id, profile);
11616
+ });
11617
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11618
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11619
+ });
11620
+ return Array.from(profiles.values());
11621
+ }, [order.items, shipping_options]);
11588
11622
  const { handleSuccess } = useRouteModal();
11589
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11590
- const currentCustomer = order.customer ? {
11591
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11592
- value: order.customer.id
11593
- } : null;
11594
- const onSubmit = form.handleSubmit(async (data) => {
11595
- await mutateAsync(
11596
- { customer_id: data.customer_id },
11597
- {
11598
- onSuccess: () => {
11599
- ui.toast.success("Customer updated");
11600
- handleSuccess();
11601
- },
11602
- onError: (error) => {
11603
- ui.toast.error(error.message);
11604
- }
11623
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11624
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11625
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11626
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11627
+ const onSubmit = async () => {
11628
+ setIsSubmitting(true);
11629
+ let requestSucceeded = false;
11630
+ await requestOrderEdit(void 0, {
11631
+ onError: (e) => {
11632
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11633
+ },
11634
+ onSuccess: () => {
11635
+ requestSucceeded = true;
11605
11636
  }
11606
- );
11607
- });
11608
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11609
- KeyboundForm,
11610
- {
11611
- className: "flex flex-1 flex-col overflow-hidden",
11612
- onSubmit,
11613
- children: [
11614
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11615
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11616
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11617
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11618
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11619
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11620
- ] }),
11621
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11622
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11623
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11624
- ] })
11625
- ] }),
11626
- /* @__PURE__ */ jsxRuntime.jsx(
11627
- CustomerField,
11628
- {
11629
- control: form.control,
11630
- currentCustomerId: order.customer_id
11631
- }
11632
- )
11633
- ] }),
11634
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11635
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11636
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11637
- ] }) })
11638
- ]
11637
+ });
11638
+ if (!requestSucceeded) {
11639
+ setIsSubmitting(false);
11640
+ return;
11639
11641
  }
11640
- ) });
11641
- };
11642
- const CustomerField = ({ control, currentCustomerId }) => {
11643
- const customers = useComboboxData({
11644
- queryFn: async (params) => {
11645
- return await sdk.admin.customer.list({
11646
- ...params,
11647
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11648
- });
11642
+ await confirmOrderEdit(void 0, {
11643
+ onError: (e) => {
11644
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11645
+ },
11646
+ onSuccess: () => {
11647
+ handleSuccess();
11648
+ },
11649
+ onSettled: () => {
11650
+ setIsSubmitting(false);
11651
+ }
11652
+ });
11653
+ };
11654
+ const onKeydown = React.useCallback(
11655
+ (e) => {
11656
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11657
+ if (data || isSubmitting) {
11658
+ return;
11659
+ }
11660
+ onSubmit();
11661
+ }
11649
11662
  },
11650
- queryKey: ["customers"],
11651
- getOptions: (data) => {
11652
- return data.customers.map((customer) => {
11653
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11654
- return {
11655
- label: name ? `${name} (${customer.email})` : customer.email,
11656
- value: customer.id
11657
- };
11658
- });
11659
- }
11660
- });
11661
- return /* @__PURE__ */ jsxRuntime.jsx(
11662
- Form$2.Field,
11663
- {
11664
- name: "customer_id",
11665
- control,
11666
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11667
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11668
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11669
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11670
- ] }),
11671
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11672
- Combobox,
11673
- {
11674
- options: customers.options,
11675
- fetchNextPage: customers.fetchNextPage,
11676
- isFetchingNextPage: customers.isFetchingNextPage,
11677
- searchValue: customers.searchValue,
11678
- onSearchValueChange: customers.onSearchValueChange,
11679
- placeholder: "Select customer",
11680
- ...field
11681
- }
11682
- ) }),
11683
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11684
- ] })
11685
- }
11686
- );
11687
- };
11688
- const Illustration = () => {
11689
- return /* @__PURE__ */ jsxRuntime.jsxs(
11690
- "svg",
11691
- {
11692
- width: "280",
11693
- height: "180",
11694
- viewBox: "0 0 280 180",
11695
- fill: "none",
11696
- xmlns: "http://www.w3.org/2000/svg",
11697
- children: [
11698
- /* @__PURE__ */ jsxRuntime.jsx(
11699
- "rect",
11700
- {
11701
- x: "0.00428286",
11702
- y: "-0.742904",
11703
- width: "33.5",
11704
- height: "65.5",
11705
- rx: "6.75",
11706
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11707
- fill: "#D4D4D8",
11708
- stroke: "#52525B",
11709
- strokeWidth: "1.5"
11710
- }
11711
- ),
11712
- /* @__PURE__ */ jsxRuntime.jsx(
11713
- "rect",
11714
- {
11715
- x: "0.00428286",
11716
- y: "-0.742904",
11717
- width: "33.5",
11718
- height: "65.5",
11719
- rx: "6.75",
11720
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11721
- fill: "white",
11722
- stroke: "#52525B",
11723
- strokeWidth: "1.5"
11724
- }
11725
- ),
11726
- /* @__PURE__ */ jsxRuntime.jsx(
11727
- "path",
11728
- {
11729
- d: "M180.579 107.142L179.126 107.959",
11730
- stroke: "#52525B",
11731
- strokeWidth: "1.5",
11732
- strokeLinecap: "round",
11733
- strokeLinejoin: "round"
11734
- }
11735
- ),
11736
- /* @__PURE__ */ jsxRuntime.jsx(
11737
- "path",
11738
- {
11739
- opacity: "0.88",
11740
- d: "M182.305 109.546L180.257 109.534",
11741
- stroke: "#52525B",
11742
- strokeWidth: "1.5",
11743
- strokeLinecap: "round",
11744
- strokeLinejoin: "round"
11745
- }
11746
- ),
11747
- /* @__PURE__ */ jsxRuntime.jsx(
11748
- "path",
11749
- {
11750
- opacity: "0.75",
11751
- d: "M180.551 111.93L179.108 111.096",
11752
- stroke: "#52525B",
11753
- strokeWidth: "1.5",
11754
- strokeLinecap: "round",
11755
- strokeLinejoin: "round"
11756
- }
11757
- ),
11758
- /* @__PURE__ */ jsxRuntime.jsx(
11759
- "path",
11760
- {
11761
- opacity: "0.63",
11762
- d: "M176.347 112.897L176.354 111.73",
11763
- stroke: "#52525B",
11764
- strokeWidth: "1.5",
11765
- strokeLinecap: "round",
11766
- strokeLinejoin: "round"
11767
- }
11768
- ),
11769
- /* @__PURE__ */ jsxRuntime.jsx(
11770
- "path",
11771
- {
11772
- opacity: "0.5",
11773
- d: "M172.153 111.881L173.606 111.064",
11774
- stroke: "#52525B",
11775
- strokeWidth: "1.5",
11776
- strokeLinecap: "round",
11777
- strokeLinejoin: "round"
11778
- }
11779
- ),
11780
- /* @__PURE__ */ jsxRuntime.jsx(
11781
- "path",
11782
- {
11783
- opacity: "0.38",
11784
- d: "M170.428 109.478L172.476 109.489",
11785
- stroke: "#52525B",
11786
- strokeWidth: "1.5",
11787
- strokeLinecap: "round",
11788
- strokeLinejoin: "round"
11789
- }
11790
- ),
11791
- /* @__PURE__ */ jsxRuntime.jsx(
11792
- "path",
11793
- {
11794
- opacity: "0.25",
11795
- d: "M172.181 107.094L173.624 107.928",
11796
- stroke: "#52525B",
11797
- strokeWidth: "1.5",
11798
- strokeLinecap: "round",
11799
- strokeLinejoin: "round"
11800
- }
11801
- ),
11802
- /* @__PURE__ */ jsxRuntime.jsx(
11803
- "path",
11804
- {
11805
- opacity: "0.13",
11806
- d: "M176.386 106.126L176.379 107.294",
11807
- stroke: "#52525B",
11808
- strokeWidth: "1.5",
11809
- strokeLinecap: "round",
11810
- strokeLinejoin: "round"
11811
- }
11812
- ),
11813
- /* @__PURE__ */ jsxRuntime.jsx(
11814
- "rect",
11815
- {
11816
- width: "12",
11817
- height: "3",
11818
- rx: "1.5",
11819
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11820
- fill: "#D4D4D8"
11821
- }
11822
- ),
11823
- /* @__PURE__ */ jsxRuntime.jsx(
11824
- "rect",
11825
- {
11826
- x: "0.00428286",
11827
- y: "-0.742904",
11828
- width: "33.5",
11829
- height: "65.5",
11830
- rx: "6.75",
11831
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11832
- fill: "#D4D4D8",
11833
- stroke: "#52525B",
11834
- strokeWidth: "1.5"
11835
- }
11836
- ),
11837
- /* @__PURE__ */ jsxRuntime.jsx(
11838
- "rect",
11839
- {
11840
- x: "0.00428286",
11841
- y: "-0.742904",
11842
- width: "33.5",
11843
- height: "65.5",
11844
- rx: "6.75",
11845
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11846
- fill: "white",
11847
- stroke: "#52525B",
11848
- strokeWidth: "1.5"
11849
- }
11850
- ),
11851
- /* @__PURE__ */ jsxRuntime.jsx(
11852
- "rect",
11853
- {
11854
- width: "12",
11855
- height: "3",
11856
- rx: "1.5",
11857
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11858
- fill: "#D4D4D8"
11859
- }
11860
- ),
11861
- /* @__PURE__ */ jsxRuntime.jsx(
11862
- "rect",
11863
- {
11864
- width: "17",
11865
- height: "3",
11866
- rx: "1.5",
11867
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11868
- fill: "#D4D4D8"
11869
- }
11870
- ),
11871
- /* @__PURE__ */ jsxRuntime.jsx(
11872
- "rect",
11873
- {
11874
- width: "12",
11875
- height: "3",
11876
- rx: "1.5",
11877
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11878
- fill: "#D4D4D8"
11879
- }
11880
- ),
11881
- /* @__PURE__ */ jsxRuntime.jsx(
11882
- "path",
11883
- {
11884
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11885
- fill: "#A1A1AA"
11886
- }
11887
- ),
11888
- /* @__PURE__ */ jsxRuntime.jsx(
11889
- "rect",
11890
- {
11891
- width: "17",
11892
- height: "3",
11893
- rx: "1.5",
11894
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11895
- fill: "#A1A1AA"
11896
- }
11897
- ),
11898
- /* @__PURE__ */ jsxRuntime.jsx(
11899
- "rect",
11900
- {
11901
- width: "12",
11902
- height: "3",
11903
- rx: "1.5",
11904
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11905
- fill: "#A1A1AA"
11906
- }
11907
- ),
11908
- /* @__PURE__ */ jsxRuntime.jsx(
11909
- "path",
11910
- {
11911
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11912
- fill: "#52525B"
11913
- }
11914
- ),
11915
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11916
- "path",
11917
- {
11918
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11919
- stroke: "#A1A1AA",
11920
- strokeWidth: "1.5",
11921
- strokeLinecap: "round",
11922
- strokeLinejoin: "round"
11923
- }
11924
- ) }),
11925
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11926
- "path",
11927
- {
11928
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11929
- stroke: "#A1A1AA",
11930
- strokeWidth: "1.5",
11931
- strokeLinecap: "round",
11932
- strokeLinejoin: "round"
11933
- }
11934
- ) }),
11935
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11936
- "path",
11937
- {
11938
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11939
- stroke: "#A1A1AA",
11940
- strokeWidth: "1.5",
11941
- strokeLinecap: "round",
11942
- strokeLinejoin: "round"
11943
- }
11944
- ) }),
11945
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11946
- "path",
11947
- {
11948
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11949
- stroke: "#A1A1AA",
11950
- strokeWidth: "1.5",
11951
- strokeLinecap: "round",
11952
- strokeLinejoin: "round"
11953
- }
11954
- ) }),
11955
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11956
- "path",
11957
- {
11958
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11959
- stroke: "#A1A1AA",
11960
- strokeWidth: "1.5",
11961
- strokeLinecap: "round",
11962
- strokeLinejoin: "round"
11963
- }
11964
- ) }),
11965
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11966
- "path",
11967
- {
11968
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11969
- stroke: "#A1A1AA",
11970
- strokeWidth: "1.5",
11971
- strokeLinecap: "round",
11972
- strokeLinejoin: "round"
11973
- }
11974
- ) }),
11975
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
11976
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11977
- "rect",
11978
- {
11979
- width: "12",
11980
- height: "12",
11981
- fill: "white",
11982
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11983
- }
11984
- ) }),
11985
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11986
- "rect",
11987
- {
11988
- width: "12",
11989
- height: "12",
11990
- fill: "white",
11991
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11992
- }
11993
- ) }),
11994
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11995
- "rect",
11996
- {
11997
- width: "12",
11998
- height: "12",
11999
- fill: "white",
12000
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12001
- }
12002
- ) }),
12003
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12004
- "rect",
12005
- {
12006
- width: "12",
12007
- height: "12",
12008
- fill: "white",
12009
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12010
- }
12011
- ) }),
12012
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12013
- "rect",
12014
- {
12015
- width: "12",
12016
- height: "12",
12017
- fill: "white",
12018
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12019
- }
12020
- ) }),
12021
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12022
- "rect",
12023
- {
12024
- width: "12",
12025
- height: "12",
12026
- fill: "white",
12027
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12028
- }
12029
- ) })
12030
- ] })
12031
- ]
12032
- }
12033
- );
12034
- };
12035
- const schema$1 = objectType({
12036
- customer_id: stringType().min(1)
12037
- });
12038
- const ShippingAddress = () => {
12039
- const { id } = reactRouterDom.useParams();
12040
- const { order, isPending, isError, error } = useOrder(id, {
12041
- fields: "+shipping_address"
12042
- });
12043
- if (isError) {
12044
- throw error;
12045
- }
12046
- const isReady = !isPending && !!order;
12047
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12048
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12049
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12050
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12051
- ] }),
12052
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12053
- ] });
12054
- };
12055
- const ShippingAddressForm = ({ order }) => {
12056
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12057
- const form = reactHookForm.useForm({
12058
- defaultValues: {
12059
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12060
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12061
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12062
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12063
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12064
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12065
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12066
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12067
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12068
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12069
- },
12070
- resolver: zod.zodResolver(schema)
12071
- });
12072
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12073
- const { handleSuccess } = useRouteModal();
12074
- const onSubmit = form.handleSubmit(async (data) => {
12075
- await mutateAsync(
12076
- {
12077
- shipping_address: {
12078
- first_name: data.first_name,
12079
- last_name: data.last_name,
12080
- company: data.company,
12081
- address_1: data.address_1,
12082
- address_2: data.address_2,
12083
- city: data.city,
12084
- province: data.province,
12085
- country_code: data.country_code,
12086
- postal_code: data.postal_code,
12087
- phone: data.phone
12088
- }
12089
- },
12090
- {
12091
- onSuccess: () => {
12092
- handleSuccess();
12093
- },
12094
- onError: (error) => {
12095
- ui.toast.error(error.message);
12096
- }
12097
- }
12098
- );
12099
- });
12100
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12101
- KeyboundForm,
12102
- {
12103
- className: "flex flex-1 flex-col overflow-hidden",
12104
- onSubmit,
12105
- children: [
12106
- /* @__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: [
12107
- /* @__PURE__ */ jsxRuntime.jsx(
12108
- Form$2.Field,
12109
- {
12110
- control: form.control,
12111
- name: "country_code",
12112
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12113
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12114
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12115
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12116
- ] })
12117
- }
12118
- ),
12119
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12120
- /* @__PURE__ */ jsxRuntime.jsx(
12121
- Form$2.Field,
12122
- {
12123
- control: form.control,
12124
- name: "first_name",
12125
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12126
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12127
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12128
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12129
- ] })
12130
- }
12131
- ),
12132
- /* @__PURE__ */ jsxRuntime.jsx(
12133
- Form$2.Field,
12134
- {
12135
- control: form.control,
12136
- name: "last_name",
12137
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12138
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12139
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12140
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12141
- ] })
12142
- }
12143
- )
12144
- ] }),
12145
- /* @__PURE__ */ jsxRuntime.jsx(
12146
- Form$2.Field,
12147
- {
12148
- control: form.control,
12149
- name: "company",
12150
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12151
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12152
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12153
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12154
- ] })
12155
- }
12156
- ),
12157
- /* @__PURE__ */ jsxRuntime.jsx(
12158
- Form$2.Field,
12159
- {
12160
- control: form.control,
12161
- name: "address_1",
12162
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12163
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12164
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12165
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12166
- ] })
12167
- }
12168
- ),
12169
- /* @__PURE__ */ jsxRuntime.jsx(
12170
- Form$2.Field,
12171
- {
12172
- control: form.control,
12173
- name: "address_2",
12174
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12175
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12176
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12177
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12178
- ] })
12179
- }
12180
- ),
12181
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12182
- /* @__PURE__ */ jsxRuntime.jsx(
12183
- Form$2.Field,
12184
- {
12185
- control: form.control,
12186
- name: "postal_code",
12187
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12188
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12189
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12190
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12191
- ] })
12192
- }
12193
- ),
12194
- /* @__PURE__ */ jsxRuntime.jsx(
12195
- Form$2.Field,
12196
- {
12197
- control: form.control,
12198
- name: "city",
12199
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12200
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12201
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12202
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12203
- ] })
12204
- }
12205
- )
12206
- ] }),
12207
- /* @__PURE__ */ jsxRuntime.jsx(
12208
- Form$2.Field,
12209
- {
12210
- control: form.control,
12211
- name: "province",
12212
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12213
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12214
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12215
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12216
- ] })
12217
- }
12218
- ),
12219
- /* @__PURE__ */ jsxRuntime.jsx(
12220
- Form$2.Field,
12221
- {
12222
- control: form.control,
12223
- name: "phone",
12224
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12225
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12226
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12227
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12228
- ] })
12229
- }
12230
- )
12231
- ] }) }),
12232
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12233
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12234
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12235
- ] }) })
12236
- ]
12237
- }
12238
- ) });
12239
- };
12240
- const schema = addressSchema;
12241
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12242
- const Shipping = () => {
12243
- var _a;
12244
- const { id } = reactRouterDom.useParams();
12245
- const { order, isPending, isError, error } = useOrder(id, {
12246
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12247
- });
12248
- const {
12249
- order: preview,
12250
- isPending: isPreviewPending,
12251
- isError: isPreviewError,
12252
- error: previewError
12253
- } = useOrderPreview(id);
12254
- useInitiateOrderEdit({ preview });
12255
- const { onCancel } = useCancelOrderEdit({ preview });
12256
- if (isError) {
12257
- throw error;
12258
- }
12259
- if (isPreviewError) {
12260
- throw previewError;
12261
- }
12262
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12263
- const isReady = preview && !isPreviewPending && order && !isPending;
12264
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12266
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__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 py-16 px-6", children: [
12267
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12268
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12269
- ] }) }) }),
12270
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12271
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12272
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12273
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12274
- ] }) });
12275
- };
12276
- const ShippingForm = ({ preview, order }) => {
12277
- var _a;
12278
- const { setIsOpen } = useStackedModal();
12279
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12280
- const [data, setData] = React.useState(null);
12281
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12282
- const { shipping_options } = useShippingOptions(
12283
- {
12284
- id: appliedShippingOptionIds,
12285
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12286
- },
12287
- {
12288
- enabled: appliedShippingOptionIds.length > 0
12289
- }
12290
- );
12291
- const uniqueShippingProfiles = React.useMemo(() => {
12292
- const profiles = /* @__PURE__ */ new Map();
12293
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12294
- profiles.set(profile.id, profile);
12295
- });
12296
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12297
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12298
- });
12299
- return Array.from(profiles.values());
12300
- }, [order.items, shipping_options]);
12301
- const { handleSuccess } = useRouteModal();
12302
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12303
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12304
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12305
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12306
- const onSubmit = async () => {
12307
- setIsSubmitting(true);
12308
- let requestSucceeded = false;
12309
- await requestOrderEdit(void 0, {
12310
- onError: (e) => {
12311
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12312
- },
12313
- onSuccess: () => {
12314
- requestSucceeded = true;
12315
- }
12316
- });
12317
- if (!requestSucceeded) {
12318
- setIsSubmitting(false);
12319
- return;
12320
- }
12321
- await confirmOrderEdit(void 0, {
12322
- onError: (e) => {
12323
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12324
- },
12325
- onSuccess: () => {
12326
- handleSuccess();
12327
- },
12328
- onSettled: () => {
12329
- setIsSubmitting(false);
12330
- }
12331
- });
12332
- };
12333
- const onKeydown = React.useCallback(
12334
- (e) => {
12335
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12336
- if (data || isSubmitting) {
12337
- return;
12338
- }
12339
- onSubmit();
12340
- }
12341
- },
12342
- [data, isSubmitting, onSubmit]
11663
+ [data, isSubmitting, onSubmit]
12343
11664
  );
12344
11665
  React.useEffect(() => {
12345
11666
  document.addEventListener("keydown", onKeydown);
@@ -12626,425 +11947,1104 @@ const ShippingForm = ({ preview, order }) => {
12626
11947
  );
12627
11948
  }) })
12628
11949
  ] }) })
12629
- ] }) }),
12630
- /* @__PURE__ */ jsxRuntime.jsx(
12631
- StackedFocusModal,
11950
+ ] }) }),
11951
+ /* @__PURE__ */ jsxRuntime.jsx(
11952
+ StackedFocusModal,
11953
+ {
11954
+ id: STACKED_FOCUS_MODAL_ID,
11955
+ onOpenChangeCallback: (open) => {
11956
+ if (!open) {
11957
+ setData(null);
11958
+ }
11959
+ return open;
11960
+ },
11961
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11962
+ }
11963
+ )
11964
+ ] }),
11965
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11966
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11967
+ /* @__PURE__ */ jsxRuntime.jsx(
11968
+ ui.Button,
11969
+ {
11970
+ size: "small",
11971
+ type: "button",
11972
+ isLoading: isSubmitting,
11973
+ onClick: onSubmit,
11974
+ children: "Save"
11975
+ }
11976
+ )
11977
+ ] }) })
11978
+ ] });
11979
+ };
11980
+ const StackedModalTrigger = ({
11981
+ shippingProfileId,
11982
+ shippingOption,
11983
+ shippingMethod,
11984
+ setData,
11985
+ children
11986
+ }) => {
11987
+ const { setIsOpen, getIsOpen } = useStackedModal();
11988
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11989
+ const onToggle = () => {
11990
+ if (isOpen) {
11991
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11992
+ setData(null);
11993
+ } else {
11994
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11995
+ setData({
11996
+ shippingProfileId,
11997
+ shippingOption,
11998
+ shippingMethod
11999
+ });
12000
+ }
12001
+ };
12002
+ return /* @__PURE__ */ jsxRuntime.jsx(
12003
+ ui.Button,
12004
+ {
12005
+ size: "small",
12006
+ variant: "secondary",
12007
+ onClick: onToggle,
12008
+ className: "text-ui-fg-primary shrink-0",
12009
+ children
12010
+ }
12011
+ );
12012
+ };
12013
+ const ShippingProfileForm = ({
12014
+ data,
12015
+ order,
12016
+ preview
12017
+ }) => {
12018
+ var _a, _b, _c, _d, _e, _f;
12019
+ const { setIsOpen } = useStackedModal();
12020
+ const form = reactHookForm.useForm({
12021
+ resolver: zod.zodResolver(shippingMethodSchema),
12022
+ defaultValues: {
12023
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12024
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12025
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12026
+ }
12027
+ });
12028
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12029
+ const {
12030
+ mutateAsync: updateShippingMethod,
12031
+ isPending: isUpdatingShippingMethod
12032
+ } = useDraftOrderUpdateShippingMethod(order.id);
12033
+ const onSubmit = form.handleSubmit(async (values) => {
12034
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12035
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12036
+ return;
12037
+ }
12038
+ if (data.shippingMethod) {
12039
+ await updateShippingMethod(
12040
+ {
12041
+ method_id: data.shippingMethod.id,
12042
+ shipping_option_id: values.shipping_option_id,
12043
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12044
+ },
12045
+ {
12046
+ onError: (e) => {
12047
+ ui.toast.error(e.message);
12048
+ },
12049
+ onSuccess: () => {
12050
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12051
+ }
12052
+ }
12053
+ );
12054
+ return;
12055
+ }
12056
+ await addShippingMethod(
12057
+ {
12058
+ shipping_option_id: values.shipping_option_id,
12059
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12060
+ },
12061
+ {
12062
+ onError: (e) => {
12063
+ ui.toast.error(e.message);
12064
+ },
12065
+ onSuccess: () => {
12066
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12067
+ }
12068
+ }
12069
+ );
12070
+ });
12071
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12072
+ KeyboundForm,
12073
+ {
12074
+ className: "flex h-full flex-col overflow-hidden",
12075
+ onSubmit,
12076
+ children: [
12077
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12078
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__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 py-16 px-6", children: [
12079
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12080
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12081
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12082
+ ] }),
12083
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12084
+ /* @__PURE__ */ jsxRuntime.jsx(
12085
+ LocationField,
12086
+ {
12087
+ control: form.control,
12088
+ setValue: form.setValue
12089
+ }
12090
+ ),
12091
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12092
+ /* @__PURE__ */ jsxRuntime.jsx(
12093
+ ShippingOptionField,
12094
+ {
12095
+ shippingProfileId: data.shippingProfileId,
12096
+ preview,
12097
+ control: form.control
12098
+ }
12099
+ ),
12100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12101
+ /* @__PURE__ */ jsxRuntime.jsx(
12102
+ CustomAmountField,
12103
+ {
12104
+ control: form.control,
12105
+ currencyCode: order.currency_code
12106
+ }
12107
+ ),
12108
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12109
+ /* @__PURE__ */ jsxRuntime.jsx(
12110
+ ItemsPreview,
12111
+ {
12112
+ order,
12113
+ shippingProfileId: data.shippingProfileId
12114
+ }
12115
+ )
12116
+ ] }) }) }),
12117
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12118
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12119
+ /* @__PURE__ */ jsxRuntime.jsx(
12120
+ ui.Button,
12121
+ {
12122
+ size: "small",
12123
+ type: "submit",
12124
+ isLoading: isPending || isUpdatingShippingMethod,
12125
+ children: data.shippingMethod ? "Update" : "Add"
12126
+ }
12127
+ )
12128
+ ] }) })
12129
+ ]
12130
+ }
12131
+ ) }) });
12132
+ };
12133
+ const shippingMethodSchema = objectType({
12134
+ location_id: stringType(),
12135
+ shipping_option_id: stringType(),
12136
+ custom_amount: unionType([numberType(), stringType()]).optional()
12137
+ });
12138
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12139
+ const matches = order.items.filter(
12140
+ (item) => {
12141
+ var _a, _b, _c;
12142
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12143
+ }
12144
+ );
12145
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12146
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12147
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12148
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12149
+ ] }) }),
12150
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12151
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12152
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12153
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12154
+ ] }),
12155
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12156
+ "div",
12632
12157
  {
12633
- id: STACKED_FOCUS_MODAL_ID,
12634
- onOpenChangeCallback: (open) => {
12635
- if (!open) {
12636
- setData(null);
12158
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12159
+ children: [
12160
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12161
+ /* @__PURE__ */ jsxRuntime.jsx(
12162
+ Thumbnail,
12163
+ {
12164
+ thumbnail: item.thumbnail,
12165
+ alt: item.product_title ?? void 0
12166
+ }
12167
+ ),
12168
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12169
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12170
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12171
+ /* @__PURE__ */ jsxRuntime.jsxs(
12172
+ ui.Text,
12173
+ {
12174
+ size: "small",
12175
+ leading: "compact",
12176
+ className: "text-ui-fg-subtle",
12177
+ children: [
12178
+ "(",
12179
+ item.variant_title,
12180
+ ")"
12181
+ ]
12182
+ }
12183
+ )
12184
+ ] }),
12185
+ /* @__PURE__ */ jsxRuntime.jsx(
12186
+ ui.Text,
12187
+ {
12188
+ size: "small",
12189
+ leading: "compact",
12190
+ className: "text-ui-fg-subtle",
12191
+ children: item.variant_sku
12192
+ }
12193
+ )
12194
+ ] })
12195
+ ] }),
12196
+ /* @__PURE__ */ jsxRuntime.jsxs(
12197
+ ui.Text,
12198
+ {
12199
+ size: "small",
12200
+ leading: "compact",
12201
+ className: "text-ui-fg-subtle",
12202
+ children: [
12203
+ item.quantity,
12204
+ "x"
12205
+ ]
12206
+ }
12207
+ )
12208
+ ]
12209
+ },
12210
+ item.id
12211
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12212
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12213
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12214
+ 'No items found for "',
12215
+ query,
12216
+ '".'
12217
+ ] })
12218
+ ] }) })
12219
+ ] })
12220
+ ] });
12221
+ };
12222
+ const LocationField = ({ control, setValue }) => {
12223
+ const locations = useComboboxData({
12224
+ queryKey: ["locations"],
12225
+ queryFn: async (params) => {
12226
+ return await sdk.admin.stockLocation.list(params);
12227
+ },
12228
+ getOptions: (data) => {
12229
+ return data.stock_locations.map((location) => ({
12230
+ label: location.name,
12231
+ value: location.id
12232
+ }));
12233
+ }
12234
+ });
12235
+ return /* @__PURE__ */ jsxRuntime.jsx(
12236
+ Form$2.Field,
12237
+ {
12238
+ control,
12239
+ name: "location_id",
12240
+ render: ({ field: { onChange, ...field } }) => {
12241
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12242
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12243
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12244
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12245
+ ] }),
12246
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12247
+ Combobox,
12248
+ {
12249
+ options: locations.options,
12250
+ fetchNextPage: locations.fetchNextPage,
12251
+ isFetchingNextPage: locations.isFetchingNextPage,
12252
+ searchValue: locations.searchValue,
12253
+ onSearchValueChange: locations.onSearchValueChange,
12254
+ placeholder: "Select location",
12255
+ onChange: (value) => {
12256
+ setValue("shipping_option_id", "", {
12257
+ shouldDirty: true,
12258
+ shouldTouch: true
12259
+ });
12260
+ onChange(value);
12261
+ },
12262
+ ...field
12637
12263
  }
12638
- return open;
12639
- },
12640
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12641
- }
12642
- )
12643
- ] }),
12644
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12645
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12646
- /* @__PURE__ */ jsxRuntime.jsx(
12647
- ui.Button,
12648
- {
12649
- size: "small",
12650
- type: "button",
12651
- isLoading: isSubmitting,
12652
- onClick: onSubmit,
12653
- children: "Save"
12264
+ ) })
12265
+ ] }) });
12266
+ }
12267
+ }
12268
+ );
12269
+ };
12270
+ const ShippingOptionField = ({
12271
+ shippingProfileId,
12272
+ preview,
12273
+ control
12274
+ }) => {
12275
+ var _a;
12276
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12277
+ const shippingOptions = useComboboxData({
12278
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12279
+ queryFn: async (params) => {
12280
+ return await sdk.admin.shippingOption.list({
12281
+ ...params,
12282
+ stock_location_id: locationId,
12283
+ shipping_profile_id: shippingProfileId
12284
+ });
12285
+ },
12286
+ getOptions: (data) => {
12287
+ return data.shipping_options.map((option) => {
12288
+ var _a2;
12289
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12290
+ (r) => r.attribute === "is_return" && r.value === "true"
12291
+ )) {
12292
+ return void 0;
12654
12293
  }
12655
- )
12656
- ] }) })
12657
- ] });
12294
+ return {
12295
+ label: option.name,
12296
+ value: option.id
12297
+ };
12298
+ }).filter(Boolean);
12299
+ },
12300
+ enabled: !!locationId && !!shippingProfileId,
12301
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12302
+ });
12303
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12304
+ return /* @__PURE__ */ jsxRuntime.jsx(
12305
+ Form$2.Field,
12306
+ {
12307
+ control,
12308
+ name: "shipping_option_id",
12309
+ render: ({ field }) => {
12310
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12311
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12312
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12313
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12314
+ ] }),
12315
+ /* @__PURE__ */ jsxRuntime.jsx(
12316
+ ConditionalTooltip,
12317
+ {
12318
+ content: tooltipContent,
12319
+ showTooltip: !locationId || !shippingProfileId,
12320
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12321
+ Combobox,
12322
+ {
12323
+ options: shippingOptions.options,
12324
+ fetchNextPage: shippingOptions.fetchNextPage,
12325
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12326
+ searchValue: shippingOptions.searchValue,
12327
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12328
+ placeholder: "Select shipping option",
12329
+ ...field,
12330
+ disabled: !locationId || !shippingProfileId
12331
+ }
12332
+ ) }) })
12333
+ }
12334
+ )
12335
+ ] }) });
12336
+ }
12337
+ }
12338
+ );
12658
12339
  };
12659
- const StackedModalTrigger = ({
12660
- shippingProfileId,
12661
- shippingOption,
12662
- shippingMethod,
12663
- setData,
12664
- children
12340
+ const CustomAmountField = ({
12341
+ control,
12342
+ currencyCode
12665
12343
  }) => {
12666
- const { setIsOpen, getIsOpen } = useStackedModal();
12667
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12668
- const onToggle = () => {
12669
- if (isOpen) {
12670
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12671
- setData(null);
12672
- } else {
12673
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12674
- setData({
12675
- shippingProfileId,
12676
- shippingOption,
12677
- shippingMethod
12678
- });
12679
- }
12680
- };
12681
12344
  return /* @__PURE__ */ jsxRuntime.jsx(
12682
- ui.Button,
12345
+ Form$2.Field,
12683
12346
  {
12684
- size: "small",
12685
- variant: "secondary",
12686
- onClick: onToggle,
12687
- className: "text-ui-fg-primary shrink-0",
12688
- children
12347
+ control,
12348
+ name: "custom_amount",
12349
+ render: ({ field: { onChange, ...field } }) => {
12350
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12351
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12353
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12354
+ ] }),
12355
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12356
+ ui.CurrencyInput,
12357
+ {
12358
+ ...field,
12359
+ onValueChange: (value) => onChange(value),
12360
+ symbol: getNativeSymbol(currencyCode),
12361
+ code: currencyCode
12362
+ }
12363
+ ) })
12364
+ ] });
12365
+ }
12689
12366
  }
12690
12367
  );
12691
12368
  };
12692
- const ShippingProfileForm = ({
12693
- data,
12694
- order,
12695
- preview
12696
- }) => {
12697
- var _a, _b, _c, _d, _e, _f;
12698
- const { setIsOpen } = useStackedModal();
12369
+ const TransferOwnership = () => {
12370
+ const { id } = reactRouterDom.useParams();
12371
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12372
+ fields: "id,customer_id,customer.*"
12373
+ });
12374
+ if (isError) {
12375
+ throw error;
12376
+ }
12377
+ const isReady = !isPending && !!draft_order;
12378
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12379
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12380
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12381
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12382
+ ] }),
12383
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12384
+ ] });
12385
+ };
12386
+ const TransferOwnershipForm = ({ order }) => {
12387
+ var _a, _b;
12699
12388
  const form = reactHookForm.useForm({
12700
- resolver: zod.zodResolver(shippingMethodSchema),
12701
12389
  defaultValues: {
12702
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12703
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12704
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12390
+ customer_id: order.customer_id || ""
12391
+ },
12392
+ resolver: zod.zodResolver(schema$1)
12393
+ });
12394
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12395
+ const { handleSuccess } = useRouteModal();
12396
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12397
+ const currentCustomer = order.customer ? {
12398
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12399
+ value: order.customer.id
12400
+ } : null;
12401
+ const onSubmit = form.handleSubmit(async (data) => {
12402
+ await mutateAsync(
12403
+ { customer_id: data.customer_id },
12404
+ {
12405
+ onSuccess: () => {
12406
+ ui.toast.success("Customer updated");
12407
+ handleSuccess();
12408
+ },
12409
+ onError: (error) => {
12410
+ ui.toast.error(error.message);
12411
+ }
12412
+ }
12413
+ );
12414
+ });
12415
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12416
+ KeyboundForm,
12417
+ {
12418
+ className: "flex flex-1 flex-col overflow-hidden",
12419
+ onSubmit,
12420
+ children: [
12421
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12422
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12423
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12424
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12425
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12426
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12427
+ ] }),
12428
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12429
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12430
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12431
+ ] })
12432
+ ] }),
12433
+ /* @__PURE__ */ jsxRuntime.jsx(
12434
+ CustomerField,
12435
+ {
12436
+ control: form.control,
12437
+ currentCustomerId: order.customer_id
12438
+ }
12439
+ )
12440
+ ] }),
12441
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12442
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12443
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12444
+ ] }) })
12445
+ ]
12446
+ }
12447
+ ) });
12448
+ };
12449
+ const CustomerField = ({ control, currentCustomerId }) => {
12450
+ const customers = useComboboxData({
12451
+ queryFn: async (params) => {
12452
+ return await sdk.admin.customer.list({
12453
+ ...params,
12454
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12455
+ });
12456
+ },
12457
+ queryKey: ["customers"],
12458
+ getOptions: (data) => {
12459
+ return data.customers.map((customer) => {
12460
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12461
+ return {
12462
+ label: name ? `${name} (${customer.email})` : customer.email,
12463
+ value: customer.id
12464
+ };
12465
+ });
12705
12466
  }
12706
12467
  });
12707
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12708
- const {
12709
- mutateAsync: updateShippingMethod,
12710
- isPending: isUpdatingShippingMethod
12711
- } = useDraftOrderUpdateShippingMethod(order.id);
12712
- const onSubmit = form.handleSubmit(async (values) => {
12713
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12714
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12715
- return;
12468
+ return /* @__PURE__ */ jsxRuntime.jsx(
12469
+ Form$2.Field,
12470
+ {
12471
+ name: "customer_id",
12472
+ control,
12473
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12474
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12475
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12476
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12477
+ ] }),
12478
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12479
+ Combobox,
12480
+ {
12481
+ options: customers.options,
12482
+ fetchNextPage: customers.fetchNextPage,
12483
+ isFetchingNextPage: customers.isFetchingNextPage,
12484
+ searchValue: customers.searchValue,
12485
+ onSearchValueChange: customers.onSearchValueChange,
12486
+ placeholder: "Select customer",
12487
+ ...field
12488
+ }
12489
+ ) }),
12490
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12491
+ ] })
12716
12492
  }
12717
- if (data.shippingMethod) {
12718
- await updateShippingMethod(
12719
- {
12720
- method_id: data.shippingMethod.id,
12721
- shipping_option_id: values.shipping_option_id,
12722
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12723
- },
12724
- {
12725
- onError: (e) => {
12726
- ui.toast.error(e.message);
12727
- },
12728
- onSuccess: () => {
12729
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12493
+ );
12494
+ };
12495
+ const Illustration = () => {
12496
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12497
+ "svg",
12498
+ {
12499
+ width: "280",
12500
+ height: "180",
12501
+ viewBox: "0 0 280 180",
12502
+ fill: "none",
12503
+ xmlns: "http://www.w3.org/2000/svg",
12504
+ children: [
12505
+ /* @__PURE__ */ jsxRuntime.jsx(
12506
+ "rect",
12507
+ {
12508
+ x: "0.00428286",
12509
+ y: "-0.742904",
12510
+ width: "33.5",
12511
+ height: "65.5",
12512
+ rx: "6.75",
12513
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12514
+ fill: "#D4D4D8",
12515
+ stroke: "#52525B",
12516
+ strokeWidth: "1.5"
12517
+ }
12518
+ ),
12519
+ /* @__PURE__ */ jsxRuntime.jsx(
12520
+ "rect",
12521
+ {
12522
+ x: "0.00428286",
12523
+ y: "-0.742904",
12524
+ width: "33.5",
12525
+ height: "65.5",
12526
+ rx: "6.75",
12527
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12528
+ fill: "white",
12529
+ stroke: "#52525B",
12530
+ strokeWidth: "1.5"
12531
+ }
12532
+ ),
12533
+ /* @__PURE__ */ jsxRuntime.jsx(
12534
+ "path",
12535
+ {
12536
+ d: "M180.579 107.142L179.126 107.959",
12537
+ stroke: "#52525B",
12538
+ strokeWidth: "1.5",
12539
+ strokeLinecap: "round",
12540
+ strokeLinejoin: "round"
12541
+ }
12542
+ ),
12543
+ /* @__PURE__ */ jsxRuntime.jsx(
12544
+ "path",
12545
+ {
12546
+ opacity: "0.88",
12547
+ d: "M182.305 109.546L180.257 109.534",
12548
+ stroke: "#52525B",
12549
+ strokeWidth: "1.5",
12550
+ strokeLinecap: "round",
12551
+ strokeLinejoin: "round"
12730
12552
  }
12731
- }
12732
- );
12733
- return;
12734
- }
12735
- await addShippingMethod(
12736
- {
12737
- shipping_option_id: values.shipping_option_id,
12738
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12739
- },
12740
- {
12741
- onError: (e) => {
12742
- ui.toast.error(e.message);
12743
- },
12744
- onSuccess: () => {
12745
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12746
- }
12747
- }
12748
- );
12749
- });
12750
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12751
- KeyboundForm,
12752
- {
12753
- className: "flex h-full flex-col overflow-hidden",
12754
- onSubmit,
12755
- children: [
12756
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12757
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__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 py-16 px-6", children: [
12758
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12759
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12760
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12761
- ] }),
12762
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12763
- /* @__PURE__ */ jsxRuntime.jsx(
12764
- LocationField,
12553
+ ),
12554
+ /* @__PURE__ */ jsxRuntime.jsx(
12555
+ "path",
12556
+ {
12557
+ opacity: "0.75",
12558
+ d: "M180.551 111.93L179.108 111.096",
12559
+ stroke: "#52525B",
12560
+ strokeWidth: "1.5",
12561
+ strokeLinecap: "round",
12562
+ strokeLinejoin: "round"
12563
+ }
12564
+ ),
12565
+ /* @__PURE__ */ jsxRuntime.jsx(
12566
+ "path",
12567
+ {
12568
+ opacity: "0.63",
12569
+ d: "M176.347 112.897L176.354 111.73",
12570
+ stroke: "#52525B",
12571
+ strokeWidth: "1.5",
12572
+ strokeLinecap: "round",
12573
+ strokeLinejoin: "round"
12574
+ }
12575
+ ),
12576
+ /* @__PURE__ */ jsxRuntime.jsx(
12577
+ "path",
12578
+ {
12579
+ opacity: "0.5",
12580
+ d: "M172.153 111.881L173.606 111.064",
12581
+ stroke: "#52525B",
12582
+ strokeWidth: "1.5",
12583
+ strokeLinecap: "round",
12584
+ strokeLinejoin: "round"
12585
+ }
12586
+ ),
12587
+ /* @__PURE__ */ jsxRuntime.jsx(
12588
+ "path",
12589
+ {
12590
+ opacity: "0.38",
12591
+ d: "M170.428 109.478L172.476 109.489",
12592
+ stroke: "#52525B",
12593
+ strokeWidth: "1.5",
12594
+ strokeLinecap: "round",
12595
+ strokeLinejoin: "round"
12596
+ }
12597
+ ),
12598
+ /* @__PURE__ */ jsxRuntime.jsx(
12599
+ "path",
12600
+ {
12601
+ opacity: "0.25",
12602
+ d: "M172.181 107.094L173.624 107.928",
12603
+ stroke: "#52525B",
12604
+ strokeWidth: "1.5",
12605
+ strokeLinecap: "round",
12606
+ strokeLinejoin: "round"
12607
+ }
12608
+ ),
12609
+ /* @__PURE__ */ jsxRuntime.jsx(
12610
+ "path",
12611
+ {
12612
+ opacity: "0.13",
12613
+ d: "M176.386 106.126L176.379 107.294",
12614
+ stroke: "#52525B",
12615
+ strokeWidth: "1.5",
12616
+ strokeLinecap: "round",
12617
+ strokeLinejoin: "round"
12618
+ }
12619
+ ),
12620
+ /* @__PURE__ */ jsxRuntime.jsx(
12621
+ "rect",
12622
+ {
12623
+ width: "12",
12624
+ height: "3",
12625
+ rx: "1.5",
12626
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12627
+ fill: "#D4D4D8"
12628
+ }
12629
+ ),
12630
+ /* @__PURE__ */ jsxRuntime.jsx(
12631
+ "rect",
12632
+ {
12633
+ x: "0.00428286",
12634
+ y: "-0.742904",
12635
+ width: "33.5",
12636
+ height: "65.5",
12637
+ rx: "6.75",
12638
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12639
+ fill: "#D4D4D8",
12640
+ stroke: "#52525B",
12641
+ strokeWidth: "1.5"
12642
+ }
12643
+ ),
12644
+ /* @__PURE__ */ jsxRuntime.jsx(
12645
+ "rect",
12646
+ {
12647
+ x: "0.00428286",
12648
+ y: "-0.742904",
12649
+ width: "33.5",
12650
+ height: "65.5",
12651
+ rx: "6.75",
12652
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12653
+ fill: "white",
12654
+ stroke: "#52525B",
12655
+ strokeWidth: "1.5"
12656
+ }
12657
+ ),
12658
+ /* @__PURE__ */ jsxRuntime.jsx(
12659
+ "rect",
12660
+ {
12661
+ width: "12",
12662
+ height: "3",
12663
+ rx: "1.5",
12664
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12665
+ fill: "#D4D4D8"
12666
+ }
12667
+ ),
12668
+ /* @__PURE__ */ jsxRuntime.jsx(
12669
+ "rect",
12670
+ {
12671
+ width: "17",
12672
+ height: "3",
12673
+ rx: "1.5",
12674
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12675
+ fill: "#D4D4D8"
12676
+ }
12677
+ ),
12678
+ /* @__PURE__ */ jsxRuntime.jsx(
12679
+ "rect",
12680
+ {
12681
+ width: "12",
12682
+ height: "3",
12683
+ rx: "1.5",
12684
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12685
+ fill: "#D4D4D8"
12686
+ }
12687
+ ),
12688
+ /* @__PURE__ */ jsxRuntime.jsx(
12689
+ "path",
12690
+ {
12691
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12692
+ fill: "#A1A1AA"
12693
+ }
12694
+ ),
12695
+ /* @__PURE__ */ jsxRuntime.jsx(
12696
+ "rect",
12697
+ {
12698
+ width: "17",
12699
+ height: "3",
12700
+ rx: "1.5",
12701
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12702
+ fill: "#A1A1AA"
12703
+ }
12704
+ ),
12705
+ /* @__PURE__ */ jsxRuntime.jsx(
12706
+ "rect",
12707
+ {
12708
+ width: "12",
12709
+ height: "3",
12710
+ rx: "1.5",
12711
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12712
+ fill: "#A1A1AA"
12713
+ }
12714
+ ),
12715
+ /* @__PURE__ */ jsxRuntime.jsx(
12716
+ "path",
12717
+ {
12718
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12719
+ fill: "#52525B"
12720
+ }
12721
+ ),
12722
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12723
+ "path",
12724
+ {
12725
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12726
+ stroke: "#A1A1AA",
12727
+ strokeWidth: "1.5",
12728
+ strokeLinecap: "round",
12729
+ strokeLinejoin: "round"
12730
+ }
12731
+ ) }),
12732
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12733
+ "path",
12734
+ {
12735
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12736
+ stroke: "#A1A1AA",
12737
+ strokeWidth: "1.5",
12738
+ strokeLinecap: "round",
12739
+ strokeLinejoin: "round"
12740
+ }
12741
+ ) }),
12742
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12743
+ "path",
12744
+ {
12745
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12746
+ stroke: "#A1A1AA",
12747
+ strokeWidth: "1.5",
12748
+ strokeLinecap: "round",
12749
+ strokeLinejoin: "round"
12750
+ }
12751
+ ) }),
12752
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12753
+ "path",
12754
+ {
12755
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12756
+ stroke: "#A1A1AA",
12757
+ strokeWidth: "1.5",
12758
+ strokeLinecap: "round",
12759
+ strokeLinejoin: "round"
12760
+ }
12761
+ ) }),
12762
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12763
+ "path",
12764
+ {
12765
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12766
+ stroke: "#A1A1AA",
12767
+ strokeWidth: "1.5",
12768
+ strokeLinecap: "round",
12769
+ strokeLinejoin: "round"
12770
+ }
12771
+ ) }),
12772
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12773
+ "path",
12774
+ {
12775
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12776
+ stroke: "#A1A1AA",
12777
+ strokeWidth: "1.5",
12778
+ strokeLinecap: "round",
12779
+ strokeLinejoin: "round"
12780
+ }
12781
+ ) }),
12782
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12783
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12784
+ "rect",
12765
12785
  {
12766
- control: form.control,
12767
- setValue: form.setValue
12786
+ width: "12",
12787
+ height: "12",
12788
+ fill: "white",
12789
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12768
12790
  }
12769
- ),
12770
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12771
- /* @__PURE__ */ jsxRuntime.jsx(
12772
- ShippingOptionField,
12791
+ ) }),
12792
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12793
+ "rect",
12773
12794
  {
12774
- shippingProfileId: data.shippingProfileId,
12775
- preview,
12776
- control: form.control
12795
+ width: "12",
12796
+ height: "12",
12797
+ fill: "white",
12798
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12777
12799
  }
12778
- ),
12779
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12780
- /* @__PURE__ */ jsxRuntime.jsx(
12781
- CustomAmountField,
12800
+ ) }),
12801
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12802
+ "rect",
12782
12803
  {
12783
- control: form.control,
12784
- currencyCode: order.currency_code
12804
+ width: "12",
12805
+ height: "12",
12806
+ fill: "white",
12807
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12785
12808
  }
12786
- ),
12787
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12788
- /* @__PURE__ */ jsxRuntime.jsx(
12789
- ItemsPreview,
12809
+ ) }),
12810
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12811
+ "rect",
12790
12812
  {
12791
- order,
12792
- shippingProfileId: data.shippingProfileId
12813
+ width: "12",
12814
+ height: "12",
12815
+ fill: "white",
12816
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12793
12817
  }
12794
- )
12795
- ] }) }) }),
12796
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12797
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12798
- /* @__PURE__ */ jsxRuntime.jsx(
12799
- ui.Button,
12818
+ ) }),
12819
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12820
+ "rect",
12800
12821
  {
12801
- size: "small",
12802
- type: "submit",
12803
- isLoading: isPending || isUpdatingShippingMethod,
12804
- children: data.shippingMethod ? "Update" : "Add"
12822
+ width: "12",
12823
+ height: "12",
12824
+ fill: "white",
12825
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12805
12826
  }
12806
- )
12807
- ] }) })
12808
- ]
12809
- }
12810
- ) }) });
12811
- };
12812
- const shippingMethodSchema = objectType({
12813
- location_id: stringType(),
12814
- shipping_option_id: stringType(),
12815
- custom_amount: unionType([numberType(), stringType()]).optional()
12816
- });
12817
- const ItemsPreview = ({ order, shippingProfileId }) => {
12818
- const matches = order.items.filter(
12819
- (item) => {
12820
- var _a, _b, _c;
12821
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12822
- }
12823
- );
12824
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12825
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12826
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12827
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12828
- ] }) }),
12829
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12830
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12831
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12832
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12833
- ] }),
12834
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12835
- "div",
12836
- {
12837
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12838
- children: [
12839
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12840
- /* @__PURE__ */ jsxRuntime.jsx(
12841
- Thumbnail,
12842
- {
12843
- thumbnail: item.thumbnail,
12844
- alt: item.product_title ?? void 0
12845
- }
12846
- ),
12847
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12848
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12849
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12850
- /* @__PURE__ */ jsxRuntime.jsxs(
12851
- ui.Text,
12852
- {
12853
- size: "small",
12854
- leading: "compact",
12855
- className: "text-ui-fg-subtle",
12856
- children: [
12857
- "(",
12858
- item.variant_title,
12859
- ")"
12860
- ]
12861
- }
12862
- )
12863
- ] }),
12864
- /* @__PURE__ */ jsxRuntime.jsx(
12865
- ui.Text,
12866
- {
12867
- size: "small",
12868
- leading: "compact",
12869
- className: "text-ui-fg-subtle",
12870
- children: item.variant_sku
12871
- }
12872
- )
12873
- ] })
12874
- ] }),
12875
- /* @__PURE__ */ jsxRuntime.jsxs(
12876
- ui.Text,
12877
- {
12878
- size: "small",
12879
- leading: "compact",
12880
- className: "text-ui-fg-subtle",
12881
- children: [
12882
- item.quantity,
12883
- "x"
12884
- ]
12885
- }
12886
- )
12887
- ]
12888
- },
12889
- item.id
12890
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12891
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12892
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12893
- 'No items found for "',
12894
- query,
12895
- '".'
12896
- ] })
12897
- ] }) })
12898
- ] })
12899
- ] });
12900
- };
12901
- const LocationField = ({ control, setValue }) => {
12902
- const locations = useComboboxData({
12903
- queryKey: ["locations"],
12904
- queryFn: async (params) => {
12905
- return await sdk.admin.stockLocation.list(params);
12906
- },
12907
- getOptions: (data) => {
12908
- return data.stock_locations.map((location) => ({
12909
- label: location.name,
12910
- value: location.id
12911
- }));
12912
- }
12913
- });
12914
- return /* @__PURE__ */ jsxRuntime.jsx(
12915
- Form$2.Field,
12916
- {
12917
- control,
12918
- name: "location_id",
12919
- render: ({ field: { onChange, ...field } }) => {
12920
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12921
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12922
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12923
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12924
- ] }),
12925
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12926
- Combobox,
12827
+ ) }),
12828
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12829
+ "rect",
12927
12830
  {
12928
- options: locations.options,
12929
- fetchNextPage: locations.fetchNextPage,
12930
- isFetchingNextPage: locations.isFetchingNextPage,
12931
- searchValue: locations.searchValue,
12932
- onSearchValueChange: locations.onSearchValueChange,
12933
- placeholder: "Select location",
12934
- onChange: (value) => {
12935
- setValue("shipping_option_id", "", {
12936
- shouldDirty: true,
12937
- shouldTouch: true
12938
- });
12939
- onChange(value);
12940
- },
12941
- ...field
12831
+ width: "12",
12832
+ height: "12",
12833
+ fill: "white",
12834
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12942
12835
  }
12943
12836
  ) })
12944
- ] }) });
12945
- }
12837
+ ] })
12838
+ ]
12946
12839
  }
12947
12840
  );
12948
12841
  };
12949
- const ShippingOptionField = ({
12950
- shippingProfileId,
12951
- preview,
12952
- control
12953
- }) => {
12954
- var _a;
12955
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12956
- const shippingOptions = useComboboxData({
12957
- queryKey: ["shipping_options", locationId, shippingProfileId],
12958
- queryFn: async (params) => {
12959
- return await sdk.admin.shippingOption.list({
12960
- ...params,
12961
- stock_location_id: locationId,
12962
- shipping_profile_id: shippingProfileId
12963
- });
12842
+ const schema$1 = objectType({
12843
+ customer_id: stringType().min(1)
12844
+ });
12845
+ const ShippingAddress = () => {
12846
+ const { id } = reactRouterDom.useParams();
12847
+ const { order, isPending, isError, error } = useOrder(id, {
12848
+ fields: "+shipping_address"
12849
+ });
12850
+ if (isError) {
12851
+ throw error;
12852
+ }
12853
+ const isReady = !isPending && !!order;
12854
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12855
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12856
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12857
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12858
+ ] }),
12859
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12860
+ ] });
12861
+ };
12862
+ const ShippingAddressForm = ({ order }) => {
12863
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12864
+ const form = reactHookForm.useForm({
12865
+ defaultValues: {
12866
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12867
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12868
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12869
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12870
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12871
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12872
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12873
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12874
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12875
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12964
12876
  },
12965
- getOptions: (data) => {
12966
- return data.shipping_options.map((option) => {
12967
- var _a2;
12968
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12969
- (r) => r.attribute === "is_return" && r.value === "true"
12970
- )) {
12971
- return void 0;
12877
+ resolver: zod.zodResolver(schema)
12878
+ });
12879
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12880
+ const { handleSuccess } = useRouteModal();
12881
+ const onSubmit = form.handleSubmit(async (data) => {
12882
+ await mutateAsync(
12883
+ {
12884
+ shipping_address: {
12885
+ first_name: data.first_name,
12886
+ last_name: data.last_name,
12887
+ company: data.company,
12888
+ address_1: data.address_1,
12889
+ address_2: data.address_2,
12890
+ city: data.city,
12891
+ province: data.province,
12892
+ country_code: data.country_code,
12893
+ postal_code: data.postal_code,
12894
+ phone: data.phone
12972
12895
  }
12973
- return {
12974
- label: option.name,
12975
- value: option.id
12976
- };
12977
- }).filter(Boolean);
12978
- },
12979
- enabled: !!locationId && !!shippingProfileId,
12980
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12896
+ },
12897
+ {
12898
+ onSuccess: () => {
12899
+ handleSuccess();
12900
+ },
12901
+ onError: (error) => {
12902
+ ui.toast.error(error.message);
12903
+ }
12904
+ }
12905
+ );
12981
12906
  });
12982
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12983
- return /* @__PURE__ */ jsxRuntime.jsx(
12984
- Form$2.Field,
12907
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12908
+ KeyboundForm,
12985
12909
  {
12986
- control,
12987
- name: "shipping_option_id",
12988
- render: ({ field }) => {
12989
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12990
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12991
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12992
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12910
+ className: "flex flex-1 flex-col overflow-hidden",
12911
+ onSubmit,
12912
+ children: [
12913
+ /* @__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: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "country_code",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12927
+ /* @__PURE__ */ jsxRuntime.jsx(
12928
+ Form$2.Field,
12929
+ {
12930
+ control: form.control,
12931
+ name: "first_name",
12932
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12935
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12936
+ ] })
12937
+ }
12938
+ ),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(
12940
+ Form$2.Field,
12941
+ {
12942
+ control: form.control,
12943
+ name: "last_name",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12949
+ }
12950
+ )
12993
12951
  ] }),
12994
12952
  /* @__PURE__ */ jsxRuntime.jsx(
12995
- ConditionalTooltip,
12953
+ Form$2.Field,
12996
12954
  {
12997
- content: tooltipContent,
12998
- showTooltip: !locationId || !shippingProfileId,
12999
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13000
- Combobox,
13001
- {
13002
- options: shippingOptions.options,
13003
- fetchNextPage: shippingOptions.fetchNextPage,
13004
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
13005
- searchValue: shippingOptions.searchValue,
13006
- onSearchValueChange: shippingOptions.onSearchValueChange,
13007
- placeholder: "Select shipping option",
13008
- ...field,
13009
- disabled: !locationId || !shippingProfileId
13010
- }
13011
- ) }) })
12955
+ control: form.control,
12956
+ name: "company",
12957
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12960
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12961
+ ] })
13012
12962
  }
13013
- )
13014
- ] }) });
13015
- }
13016
- }
13017
- );
13018
- };
13019
- const CustomAmountField = ({
13020
- control,
13021
- currencyCode
13022
- }) => {
13023
- return /* @__PURE__ */ jsxRuntime.jsx(
13024
- Form$2.Field,
13025
- {
13026
- control,
13027
- name: "custom_amount",
13028
- render: ({ field: { onChange, ...field } }) => {
13029
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13030
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12963
+ ),
12964
+ /* @__PURE__ */ jsxRuntime.jsx(
12965
+ Form$2.Field,
12966
+ {
12967
+ control: form.control,
12968
+ name: "address_1",
12969
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12973
+ ] })
12974
+ }
12975
+ ),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "address_2",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12989
+ /* @__PURE__ */ jsxRuntime.jsx(
12990
+ Form$2.Field,
12991
+ {
12992
+ control: form.control,
12993
+ name: "postal_code",
12994
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12998
+ ] })
12999
+ }
13000
+ ),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13003
+ {
13004
+ control: form.control,
13005
+ name: "city",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13011
+ }
13012
+ )
13033
13013
  ] }),
13034
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13035
- ui.CurrencyInput,
13014
+ /* @__PURE__ */ jsxRuntime.jsx(
13015
+ Form$2.Field,
13036
13016
  {
13037
- ...field,
13038
- onValueChange: (value) => onChange(value),
13039
- symbol: getNativeSymbol(currencyCode),
13040
- code: currencyCode
13017
+ control: form.control,
13018
+ name: "province",
13019
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13022
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13023
+ ] })
13041
13024
  }
13042
- ) })
13043
- ] });
13044
- }
13025
+ ),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(
13027
+ Form$2.Field,
13028
+ {
13029
+ control: form.control,
13030
+ name: "phone",
13031
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13035
+ ] })
13036
+ }
13037
+ )
13038
+ ] }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13042
+ ] }) })
13043
+ ]
13045
13044
  }
13046
- );
13045
+ ) });
13047
13046
  };
13047
+ const schema = addressSchema;
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13093,6 +13093,10 @@ const routeModule = {
13093
13093
  Component: SalesChannel,
13094
13094
  path: "/draft-orders/:id/sales-channel"
13095
13095
  },
13096
+ {
13097
+ Component: Shipping,
13098
+ path: "/draft-orders/:id/shipping"
13099
+ },
13096
13100
  {
13097
13101
  Component: TransferOwnership,
13098
13102
  path: "/draft-orders/:id/transfer-ownership"
@@ -13100,10 +13104,6 @@ const routeModule = {
13100
13104
  {
13101
13105
  Component: ShippingAddress,
13102
13106
  path: "/draft-orders/:id/shipping-address"
13103
- },
13104
- {
13105
- Component: Shipping,
13106
- path: "/draft-orders/:id/shipping"
13107
13107
  }
13108
13108
  ]
13109
13109
  }