@medusajs/draft-order 2.10.4-snapshot-20250922062130 → 2.10.4-snapshot-20250922165717

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.
@@ -9573,6 +9573,95 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
+ const CustomItems = () => {
9577
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9579
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9580
+ ] });
9581
+ };
9582
+ const CustomItemsForm = () => {
9583
+ const form = reactHookForm.useForm({
9584
+ resolver: zod.zodResolver(schema$5)
9585
+ });
9586
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9590
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9591
+ ] }) })
9592
+ ] }) });
9593
+ };
9594
+ const schema$5 = objectType({
9595
+ email: stringType().email()
9596
+ });
9597
+ const Email = () => {
9598
+ const { id } = reactRouterDom.useParams();
9599
+ const { order, isPending, isError, error } = useOrder(id, {
9600
+ fields: "+email"
9601
+ });
9602
+ if (isError) {
9603
+ throw error;
9604
+ }
9605
+ const isReady = !isPending && !!order;
9606
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9607
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9608
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9609
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9610
+ ] }),
9611
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9612
+ ] });
9613
+ };
9614
+ const EmailForm = ({ order }) => {
9615
+ const form = reactHookForm.useForm({
9616
+ defaultValues: {
9617
+ email: order.email ?? ""
9618
+ },
9619
+ resolver: zod.zodResolver(schema$4)
9620
+ });
9621
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9622
+ const { handleSuccess } = useRouteModal();
9623
+ const onSubmit = form.handleSubmit(async (data) => {
9624
+ await mutateAsync(
9625
+ { email: data.email },
9626
+ {
9627
+ onSuccess: () => {
9628
+ handleSuccess();
9629
+ },
9630
+ onError: (error) => {
9631
+ ui.toast.error(error.message);
9632
+ }
9633
+ }
9634
+ );
9635
+ });
9636
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9637
+ KeyboundForm,
9638
+ {
9639
+ className: "flex flex-1 flex-col overflow-hidden",
9640
+ onSubmit,
9641
+ children: [
9642
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9643
+ Form$2.Field,
9644
+ {
9645
+ control: form.control,
9646
+ name: "email",
9647
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9651
+ ] })
9652
+ }
9653
+ ) }),
9654
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9655
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9656
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9657
+ ] }) })
9658
+ ]
9659
+ }
9660
+ ) });
9661
+ };
9662
+ const schema$4 = objectType({
9663
+ email: stringType().email()
9664
+ });
9576
9665
  const BillingAddress = () => {
9577
9666
  const { id } = reactRouterDom.useParams();
9578
9667
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9605,7 +9694,7 @@ const BillingAddressForm = ({ order }) => {
9605
9694
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
9695
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
9696
  },
9608
- resolver: zod.zodResolver(schema$5)
9697
+ resolver: zod.zodResolver(schema$3)
9609
9698
  });
9610
9699
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
9700
  const { handleSuccess } = useRouteModal();
@@ -9762,96 +9851,7 @@ const BillingAddressForm = ({ order }) => {
9762
9851
  }
9763
9852
  ) });
9764
9853
  };
9765
- const schema$5 = addressSchema;
9766
- const CustomItems = () => {
9767
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
- ] });
9771
- };
9772
- const CustomItemsForm = () => {
9773
- const form = reactHookForm.useForm({
9774
- resolver: zod.zodResolver(schema$4)
9775
- });
9776
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
- ] }) })
9782
- ] }) });
9783
- };
9784
- const schema$4 = objectType({
9785
- email: stringType().email()
9786
- });
9787
- const Email = () => {
9788
- const { id } = reactRouterDom.useParams();
9789
- const { order, isPending, isError, error } = useOrder(id, {
9790
- fields: "+email"
9791
- });
9792
- if (isError) {
9793
- throw error;
9794
- }
9795
- const isReady = !isPending && !!order;
9796
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9797
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9799
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9800
- ] }),
9801
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9802
- ] });
9803
- };
9804
- const EmailForm = ({ order }) => {
9805
- const form = reactHookForm.useForm({
9806
- defaultValues: {
9807
- email: order.email ?? ""
9808
- },
9809
- resolver: zod.zodResolver(schema$3)
9810
- });
9811
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
- const { handleSuccess } = useRouteModal();
9813
- const onSubmit = form.handleSubmit(async (data) => {
9814
- await mutateAsync(
9815
- { email: data.email },
9816
- {
9817
- onSuccess: () => {
9818
- handleSuccess();
9819
- },
9820
- onError: (error) => {
9821
- ui.toast.error(error.message);
9822
- }
9823
- }
9824
- );
9825
- });
9826
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9827
- KeyboundForm,
9828
- {
9829
- className: "flex flex-1 flex-col overflow-hidden",
9830
- onSubmit,
9831
- children: [
9832
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9833
- Form$2.Field,
9834
- {
9835
- control: form.control,
9836
- name: "email",
9837
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9840
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9841
- ] })
9842
- }
9843
- ) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
- ] }) })
9848
- ]
9849
- }
9850
- ) });
9851
- };
9852
- const schema$3 = objectType({
9853
- email: stringType().email()
9854
- });
9854
+ const schema$3 = addressSchema;
9855
9855
  const NumberInput = React.forwardRef(
9856
9856
  ({
9857
9857
  value,
@@ -11453,1122 +11453,1122 @@ function getPromotionIds(items, shippingMethods) {
11453
11453
  }
11454
11454
  return Array.from(promotionIds);
11455
11455
  }
11456
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11457
- const Shipping = () => {
11458
- var _a;
11456
+ const SalesChannel = () => {
11459
11457
  const { id } = reactRouterDom.useParams();
11460
- const { order, isPending, isError, error } = useOrder(id, {
11461
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11462
- });
11463
- const {
11464
- order: preview,
11465
- isPending: isPreviewPending,
11466
- isError: isPreviewError,
11467
- error: previewError
11468
- } = useOrderPreview(id);
11469
- useInitiateOrderEdit({ preview });
11470
- const { onCancel } = useCancelOrderEdit({ preview });
11471
- if (isError) {
11472
- throw error;
11473
- }
11474
- if (isPreviewError) {
11475
- throw previewError;
11476
- }
11477
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11478
- const isReady = preview && !isPreviewPending && order && !isPending;
11479
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11480
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11481
- /* @__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: [
11482
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11483
- /* @__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." }) })
11484
- ] }) }) }),
11485
- /* @__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" }) }) })
11486
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11487
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11488
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11489
- ] }) });
11490
- };
11491
- const ShippingForm = ({ preview, order }) => {
11492
- var _a;
11493
- const { setIsOpen } = useStackedModal();
11494
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11495
- const [data, setData] = React.useState(null);
11496
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11497
- const { shipping_options } = useShippingOptions(
11458
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11459
+ id,
11498
11460
  {
11499
- id: appliedShippingOptionIds,
11500
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11461
+ fields: "+sales_channel_id"
11501
11462
  },
11502
11463
  {
11503
- enabled: appliedShippingOptionIds.length > 0
11464
+ enabled: !!id
11504
11465
  }
11505
11466
  );
11506
- const uniqueShippingProfiles = React.useMemo(() => {
11507
- const profiles = /* @__PURE__ */ new Map();
11508
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11509
- profiles.set(profile.id, profile);
11510
- });
11511
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11512
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11513
- });
11514
- return Array.from(profiles.values());
11515
- }, [order.items, shipping_options]);
11516
- const { handleSuccess } = useRouteModal();
11517
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11518
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11519
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11520
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11521
- const onSubmit = async () => {
11522
- setIsSubmitting(true);
11523
- let requestSucceeded = false;
11524
- await requestOrderEdit(void 0, {
11525
- onError: (e) => {
11526
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11527
- },
11528
- onSuccess: () => {
11529
- requestSucceeded = true;
11530
- }
11531
- });
11532
- if (!requestSucceeded) {
11533
- setIsSubmitting(false);
11534
- return;
11535
- }
11536
- await confirmOrderEdit(void 0, {
11537
- onError: (e) => {
11538
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11539
- },
11540
- onSuccess: () => {
11541
- handleSuccess();
11467
+ if (isError) {
11468
+ throw error;
11469
+ }
11470
+ const ISrEADY = !!draft_order && !isPending;
11471
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11474
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11475
+ ] }),
11476
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11477
+ ] });
11478
+ };
11479
+ const SalesChannelForm = ({ order }) => {
11480
+ const form = reactHookForm.useForm({
11481
+ defaultValues: {
11482
+ sales_channel_id: order.sales_channel_id || ""
11483
+ },
11484
+ resolver: zod.zodResolver(schema$2)
11485
+ });
11486
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11487
+ const { handleSuccess } = useRouteModal();
11488
+ const onSubmit = form.handleSubmit(async (data) => {
11489
+ await mutateAsync(
11490
+ {
11491
+ sales_channel_id: data.sales_channel_id
11542
11492
  },
11543
- onSettled: () => {
11544
- setIsSubmitting(false);
11545
- }
11546
- });
11547
- };
11548
- const onKeydown = React.useCallback(
11549
- (e) => {
11550
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11551
- if (data || isSubmitting) {
11552
- return;
11493
+ {
11494
+ onSuccess: () => {
11495
+ ui.toast.success("Sales channel updated");
11496
+ handleSuccess();
11497
+ },
11498
+ onError: (error) => {
11499
+ ui.toast.error(error.message);
11553
11500
  }
11554
- onSubmit();
11555
11501
  }
11502
+ );
11503
+ });
11504
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11505
+ KeyboundForm,
11506
+ {
11507
+ className: "flex flex-1 flex-col overflow-hidden",
11508
+ onSubmit,
11509
+ children: [
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11512
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11513
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11514
+ ] }) })
11515
+ ]
11516
+ }
11517
+ ) });
11518
+ };
11519
+ const SalesChannelField = ({ control, order }) => {
11520
+ const salesChannels = useComboboxData({
11521
+ queryFn: async (params) => {
11522
+ return await sdk.admin.salesChannel.list(params);
11556
11523
  },
11557
- [data, isSubmitting, onSubmit]
11524
+ queryKey: ["sales-channels"],
11525
+ getOptions: (data) => {
11526
+ return data.sales_channels.map((salesChannel) => ({
11527
+ label: salesChannel.name,
11528
+ value: salesChannel.id
11529
+ }));
11530
+ },
11531
+ defaultValue: order.sales_channel_id || void 0
11532
+ });
11533
+ return /* @__PURE__ */ jsxRuntime.jsx(
11534
+ Form$2.Field,
11535
+ {
11536
+ control,
11537
+ name: "sales_channel_id",
11538
+ render: ({ field }) => {
11539
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11541
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11542
+ Combobox,
11543
+ {
11544
+ options: salesChannels.options,
11545
+ fetchNextPage: salesChannels.fetchNextPage,
11546
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11547
+ searchValue: salesChannels.searchValue,
11548
+ onSearchValueChange: salesChannels.onSearchValueChange,
11549
+ placeholder: "Select sales channel",
11550
+ ...field
11551
+ }
11552
+ ) }),
11553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11554
+ ] });
11555
+ }
11556
+ }
11558
11557
  );
11559
- React.useEffect(() => {
11560
- document.addEventListener("keydown", onKeydown);
11561
- return () => {
11562
- document.removeEventListener("keydown", onKeydown);
11563
- };
11564
- }, [onKeydown]);
11565
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11566
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11567
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11568
- /* @__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: [
11569
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11570
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11571
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11572
- ] }),
11573
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11574
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11575
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11558
+ };
11559
+ const schema$2 = objectType({
11560
+ sales_channel_id: stringType().min(1)
11561
+ });
11562
+ const ShippingAddress = () => {
11563
+ const { id } = reactRouterDom.useParams();
11564
+ const { order, isPending, isError, error } = useOrder(id, {
11565
+ fields: "+shipping_address"
11566
+ });
11567
+ if (isError) {
11568
+ throw error;
11569
+ }
11570
+ const isReady = !isPending && !!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: "Edit Shipping Address" }) }),
11574
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11575
+ ] }),
11576
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11577
+ ] });
11578
+ };
11579
+ const ShippingAddressForm = ({ order }) => {
11580
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11581
+ const form = reactHookForm.useForm({
11582
+ defaultValues: {
11583
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11584
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11585
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11586
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11587
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11588
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11589
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11590
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11591
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11592
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11593
+ },
11594
+ resolver: zod.zodResolver(schema$1)
11595
+ });
11596
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11597
+ const { handleSuccess } = useRouteModal();
11598
+ const onSubmit = form.handleSubmit(async (data) => {
11599
+ await mutateAsync(
11600
+ {
11601
+ shipping_address: {
11602
+ first_name: data.first_name,
11603
+ last_name: data.last_name,
11604
+ company: data.company,
11605
+ address_1: data.address_1,
11606
+ address_2: data.address_2,
11607
+ city: data.city,
11608
+ province: data.province,
11609
+ country_code: data.country_code,
11610
+ postal_code: data.postal_code,
11611
+ phone: data.phone
11612
+ }
11613
+ },
11614
+ {
11615
+ onSuccess: () => {
11616
+ handleSuccess();
11617
+ },
11618
+ onError: (error) => {
11619
+ ui.toast.error(error.message);
11620
+ }
11621
+ }
11622
+ );
11623
+ });
11624
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11625
+ KeyboundForm,
11626
+ {
11627
+ className: "flex flex-1 flex-col overflow-hidden",
11628
+ onSubmit,
11629
+ children: [
11630
+ /* @__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: [
11631
+ /* @__PURE__ */ jsxRuntime.jsx(
11632
+ Form$2.Field,
11633
+ {
11634
+ control: form.control,
11635
+ name: "country_code",
11636
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11640
+ ] })
11641
+ }
11642
+ ),
11643
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11576
11644
  /* @__PURE__ */ jsxRuntime.jsx(
11577
- ui.Text,
11645
+ Form$2.Field,
11578
11646
  {
11579
- size: "xsmall",
11580
- weight: "plus",
11581
- className: "text-ui-fg-muted",
11582
- children: "Shipping profile"
11647
+ control: form.control,
11648
+ name: "first_name",
11649
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11652
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11653
+ ] })
11583
11654
  }
11584
11655
  ),
11585
11656
  /* @__PURE__ */ jsxRuntime.jsx(
11586
- ui.Text,
11657
+ Form$2.Field,
11587
11658
  {
11588
- size: "xsmall",
11589
- weight: "plus",
11590
- className: "text-ui-fg-muted",
11591
- children: "Action"
11659
+ control: form.control,
11660
+ name: "last_name",
11661
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11664
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11665
+ ] })
11592
11666
  }
11593
11667
  )
11594
11668
  ] }),
11595
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11596
- var _a2, _b, _c, _d, _e, _f, _g;
11597
- const items = getItemsWithShippingProfile(
11598
- profile.id,
11599
- order.items
11600
- );
11601
- const hasItems = items.length > 0;
11602
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11603
- (option) => option.shipping_profile_id === profile.id
11604
- );
11605
- const shippingMethod = preview.shipping_methods.find(
11606
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11607
- );
11608
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11609
- (action) => action.action === "SHIPPING_ADD"
11610
- );
11611
- return /* @__PURE__ */ jsxRuntime.jsxs(
11612
- radixUi.Accordion.Item,
11613
- {
11614
- value: profile.id,
11615
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11616
- children: [
11617
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11618
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11619
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11620
- ui.IconButton,
11621
- {
11622
- size: "2xsmall",
11623
- variant: "transparent",
11624
- className: "group/trigger",
11625
- disabled: !hasItems,
11626
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11627
- }
11628
- ) }),
11629
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11630
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11631
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11632
- /* @__PURE__ */ jsxRuntime.jsx(
11633
- ui.Text,
11634
- {
11635
- size: "small",
11636
- weight: "plus",
11637
- leading: "compact",
11638
- children: profile.name
11639
- }
11640
- ),
11641
- /* @__PURE__ */ jsxRuntime.jsxs(
11642
- ui.Text,
11643
- {
11644
- size: "small",
11645
- leading: "compact",
11646
- className: "text-ui-fg-subtle",
11647
- children: [
11648
- items.length,
11649
- " ",
11650
- pluralize(items.length, "items", "item")
11651
- ]
11652
- }
11653
- )
11654
- ] })
11655
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11656
- /* @__PURE__ */ jsxRuntime.jsx(
11657
- ui.Tooltip,
11658
- {
11659
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11660
- var _a3, _b2, _c2;
11661
- return /* @__PURE__ */ jsxRuntime.jsx(
11662
- "li",
11663
- {
11664
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11665
- },
11666
- item.id
11667
- );
11668
- }) }),
11669
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11670
- ui.Badge,
11671
- {
11672
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11673
- size: "xsmall",
11674
- children: [
11675
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11676
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11677
- items.reduce(
11678
- (acc, item) => acc + item.quantity,
11679
- 0
11680
- ),
11681
- "x",
11682
- " ",
11683
- pluralize(items.length, "items", "item")
11684
- ] })
11685
- ]
11686
- }
11687
- )
11688
- }
11689
- ),
11690
- /* @__PURE__ */ jsxRuntime.jsx(
11691
- ui.Tooltip,
11692
- {
11693
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11694
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11695
- ui.Badge,
11696
- {
11697
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11698
- size: "xsmall",
11699
- children: [
11700
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11701
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11702
- ]
11703
- }
11704
- )
11705
- }
11706
- ),
11707
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11708
- ui.Badge,
11709
- {
11710
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11711
- size: "xsmall",
11712
- children: [
11713
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11714
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11715
- ]
11716
- }
11717
- ) })
11718
- ] })
11719
- ] }),
11720
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11721
- ActionMenu,
11722
- {
11723
- groups: [
11724
- {
11725
- actions: [
11726
- hasItems ? {
11727
- label: "Edit shipping option",
11728
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11729
- onClick: () => {
11730
- setIsOpen(
11731
- STACKED_FOCUS_MODAL_ID,
11732
- true
11733
- );
11734
- setData({
11735
- shippingProfileId: profile.id,
11736
- shippingOption,
11737
- shippingMethod
11738
- });
11739
- }
11740
- } : void 0,
11741
- {
11742
- label: "Remove shipping option",
11743
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11744
- onClick: () => {
11745
- if (shippingMethod) {
11746
- if (addShippingMethodAction) {
11747
- removeActionShippingMethod(
11748
- addShippingMethodAction.id
11749
- );
11750
- } else {
11751
- removeShippingMethod(
11752
- shippingMethod.id
11753
- );
11754
- }
11755
- }
11756
- }
11757
- }
11758
- ].filter(Boolean)
11759
- }
11760
- ]
11761
- }
11762
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11763
- StackedModalTrigger,
11764
- {
11765
- shippingProfileId: profile.id,
11766
- shippingOption,
11767
- shippingMethod,
11768
- setData,
11769
- children: "Add shipping option"
11770
- }
11771
- )
11772
- ] }),
11773
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11774
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11775
- items.map((item, idx) => {
11776
- var _a3, _b2, _c2, _d2, _e2;
11777
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11778
- /* @__PURE__ */ jsxRuntime.jsxs(
11779
- "div",
11780
- {
11781
- className: "px-3 flex items-center gap-x-3",
11782
- children: [
11783
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11784
- ui.Divider,
11785
- {
11786
- variant: "dashed",
11787
- orientation: "vertical"
11788
- }
11789
- ) }),
11790
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11791
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11792
- ui.Text,
11793
- {
11794
- size: "small",
11795
- leading: "compact",
11796
- className: "text-ui-fg-subtle",
11797
- children: [
11798
- item.quantity,
11799
- "x"
11800
- ]
11801
- }
11802
- ) }),
11803
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11804
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11805
- /* @__PURE__ */ jsxRuntime.jsxs(
11806
- ui.Text,
11807
- {
11808
- size: "small",
11809
- leading: "compact",
11810
- weight: "plus",
11811
- children: [
11812
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11813
- " (",
11814
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11815
- ")"
11816
- ]
11817
- }
11818
- ),
11819
- /* @__PURE__ */ jsxRuntime.jsx(
11820
- ui.Text,
11821
- {
11822
- size: "small",
11823
- leading: "compact",
11824
- className: "text-ui-fg-subtle",
11825
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11826
- }
11827
- )
11828
- ] })
11829
- ] })
11830
- ]
11831
- },
11832
- item.id
11833
- ),
11834
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11835
- ] }, item.id);
11836
- })
11837
- ] })
11838
- ]
11839
- },
11840
- profile.id
11841
- );
11842
- }) })
11843
- ] }) })
11844
- ] }) }),
11845
- /* @__PURE__ */ jsxRuntime.jsx(
11846
- StackedFocusModal,
11847
- {
11848
- id: STACKED_FOCUS_MODAL_ID,
11849
- onOpenChangeCallback: (open) => {
11850
- if (!open) {
11851
- setData(null);
11852
- }
11853
- return open;
11854
- },
11855
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11856
- }
11857
- )
11858
- ] }),
11859
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11860
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11861
- /* @__PURE__ */ jsxRuntime.jsx(
11862
- ui.Button,
11863
- {
11864
- size: "small",
11865
- type: "button",
11866
- isLoading: isSubmitting,
11867
- onClick: onSubmit,
11868
- children: "Save"
11869
- }
11870
- )
11871
- ] }) })
11872
- ] });
11873
- };
11874
- const StackedModalTrigger = ({
11875
- shippingProfileId,
11876
- shippingOption,
11877
- shippingMethod,
11878
- setData,
11879
- children
11880
- }) => {
11881
- const { setIsOpen, getIsOpen } = useStackedModal();
11882
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11883
- const onToggle = () => {
11884
- if (isOpen) {
11885
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11886
- setData(null);
11887
- } else {
11888
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11889
- setData({
11890
- shippingProfileId,
11891
- shippingOption,
11892
- shippingMethod
11893
- });
11894
- }
11895
- };
11896
- return /* @__PURE__ */ jsxRuntime.jsx(
11897
- ui.Button,
11898
- {
11899
- size: "small",
11900
- variant: "secondary",
11901
- onClick: onToggle,
11902
- className: "text-ui-fg-primary shrink-0",
11903
- children
11904
- }
11905
- );
11906
- };
11907
- const ShippingProfileForm = ({
11908
- data,
11909
- order,
11910
- preview
11911
- }) => {
11912
- var _a, _b, _c, _d, _e, _f;
11913
- const { setIsOpen } = useStackedModal();
11914
- const form = reactHookForm.useForm({
11915
- resolver: zod.zodResolver(shippingMethodSchema),
11916
- defaultValues: {
11917
- 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,
11918
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11919
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11920
- }
11921
- });
11922
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11923
- const {
11924
- mutateAsync: updateShippingMethod,
11925
- isPending: isUpdatingShippingMethod
11926
- } = useDraftOrderUpdateShippingMethod(order.id);
11927
- const onSubmit = form.handleSubmit(async (values) => {
11928
- if (lodash.isEqual(values, form.formState.defaultValues)) {
11929
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11930
- return;
11931
- }
11932
- if (data.shippingMethod) {
11933
- await updateShippingMethod(
11934
- {
11935
- method_id: data.shippingMethod.id,
11936
- shipping_option_id: values.shipping_option_id,
11937
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11938
- },
11939
- {
11940
- onError: (e) => {
11941
- ui.toast.error(e.message);
11942
- },
11943
- onSuccess: () => {
11944
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11945
- }
11946
- }
11947
- );
11948
- return;
11949
- }
11950
- await addShippingMethod(
11951
- {
11952
- shipping_option_id: values.shipping_option_id,
11953
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11954
- },
11955
- {
11956
- onError: (e) => {
11957
- ui.toast.error(e.message);
11958
- },
11959
- onSuccess: () => {
11960
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11961
- }
11962
- }
11963
- );
11964
- });
11965
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11966
- KeyboundForm,
11967
- {
11968
- className: "flex h-full flex-col overflow-hidden",
11969
- onSubmit,
11970
- children: [
11971
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11972
- /* @__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: [
11973
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11974
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11975
- /* @__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." }) })
11976
- ] }),
11977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11978
11669
  /* @__PURE__ */ jsxRuntime.jsx(
11979
- LocationField,
11670
+ Form$2.Field,
11980
11671
  {
11981
11672
  control: form.control,
11982
- setValue: form.setValue
11673
+ name: "company",
11674
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11678
+ ] })
11983
11679
  }
11984
11680
  ),
11985
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11986
11681
  /* @__PURE__ */ jsxRuntime.jsx(
11987
- ShippingOptionField,
11682
+ Form$2.Field,
11988
11683
  {
11989
- shippingProfileId: data.shippingProfileId,
11990
- preview,
11991
- control: form.control
11684
+ control: form.control,
11685
+ name: "address_1",
11686
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11689
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11690
+ ] })
11992
11691
  }
11993
11692
  ),
11994
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11995
11693
  /* @__PURE__ */ jsxRuntime.jsx(
11996
- CustomAmountField,
11694
+ Form$2.Field,
11997
11695
  {
11998
11696
  control: form.control,
11999
- currencyCode: order.currency_code
11697
+ name: "address_2",
11698
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11702
+ ] })
12000
11703
  }
12001
11704
  ),
12002
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11705
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11706
+ /* @__PURE__ */ jsxRuntime.jsx(
11707
+ Form$2.Field,
11708
+ {
11709
+ control: form.control,
11710
+ name: "postal_code",
11711
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11715
+ ] })
11716
+ }
11717
+ ),
11718
+ /* @__PURE__ */ jsxRuntime.jsx(
11719
+ Form$2.Field,
11720
+ {
11721
+ control: form.control,
11722
+ name: "city",
11723
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11727
+ ] })
11728
+ }
11729
+ )
11730
+ ] }),
12003
11731
  /* @__PURE__ */ jsxRuntime.jsx(
12004
- ItemsPreview,
11732
+ Form$2.Field,
12005
11733
  {
12006
- order,
12007
- shippingProfileId: data.shippingProfileId
11734
+ control: form.control,
11735
+ name: "province",
11736
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11740
+ ] })
12008
11741
  }
12009
- )
12010
- ] }) }) }),
12011
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12012
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11742
+ ),
12013
11743
  /* @__PURE__ */ jsxRuntime.jsx(
12014
- ui.Button,
11744
+ Form$2.Field,
12015
11745
  {
12016
- size: "small",
12017
- type: "submit",
12018
- isLoading: isPending || isUpdatingShippingMethod,
12019
- children: data.shippingMethod ? "Update" : "Add"
11746
+ control: form.control,
11747
+ name: "phone",
11748
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11752
+ ] })
12020
11753
  }
12021
11754
  )
11755
+ ] }) }),
11756
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11757
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11758
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12022
11759
  ] }) })
12023
11760
  ]
12024
11761
  }
12025
- ) }) });
11762
+ ) });
12026
11763
  };
12027
- const shippingMethodSchema = objectType({
12028
- location_id: stringType(),
12029
- shipping_option_id: stringType(),
12030
- custom_amount: unionType([numberType(), stringType()]).optional()
12031
- });
12032
- const ItemsPreview = ({ order, shippingProfileId }) => {
12033
- const matches = order.items.filter(
12034
- (item) => {
12035
- var _a, _b, _c;
12036
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11764
+ const schema$1 = addressSchema;
11765
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11766
+ const Shipping = () => {
11767
+ var _a;
11768
+ const { id } = reactRouterDom.useParams();
11769
+ const { order, isPending, isError, error } = useOrder(id, {
11770
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11771
+ });
11772
+ const {
11773
+ order: preview,
11774
+ isPending: isPreviewPending,
11775
+ isError: isPreviewError,
11776
+ error: previewError
11777
+ } = useOrderPreview(id);
11778
+ useInitiateOrderEdit({ preview });
11779
+ const { onCancel } = useCancelOrderEdit({ preview });
11780
+ if (isError) {
11781
+ throw error;
11782
+ }
11783
+ if (isPreviewError) {
11784
+ throw previewError;
11785
+ }
11786
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11787
+ const isReady = preview && !isPreviewPending && order && !isPending;
11788
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11789
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11790
+ /* @__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: [
11791
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11792
+ /* @__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." }) })
11793
+ ] }) }) }),
11794
+ /* @__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" }) }) })
11795
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11796
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11797
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11798
+ ] }) });
11799
+ };
11800
+ const ShippingForm = ({ preview, order }) => {
11801
+ var _a;
11802
+ const { setIsOpen } = useStackedModal();
11803
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11804
+ const [data, setData] = React.useState(null);
11805
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11806
+ const { shipping_options } = useShippingOptions(
11807
+ {
11808
+ id: appliedShippingOptionIds,
11809
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11810
+ },
11811
+ {
11812
+ enabled: appliedShippingOptionIds.length > 0
12037
11813
  }
12038
11814
  );
12039
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12040
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12041
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12042
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12043
- ] }) }),
12044
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12045
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12046
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12047
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12048
- ] }),
12049
- /* @__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(
12050
- "div",
12051
- {
12052
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12053
- children: [
12054
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12055
- /* @__PURE__ */ jsxRuntime.jsx(
12056
- Thumbnail,
12057
- {
12058
- thumbnail: item.thumbnail,
12059
- alt: item.product_title ?? void 0
12060
- }
12061
- ),
12062
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12063
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12064
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12065
- /* @__PURE__ */ jsxRuntime.jsxs(
12066
- ui.Text,
12067
- {
12068
- size: "small",
12069
- leading: "compact",
12070
- className: "text-ui-fg-subtle",
12071
- children: [
12072
- "(",
12073
- item.variant_title,
12074
- ")"
12075
- ]
12076
- }
12077
- )
12078
- ] }),
12079
- /* @__PURE__ */ jsxRuntime.jsx(
12080
- ui.Text,
12081
- {
12082
- size: "small",
12083
- leading: "compact",
12084
- className: "text-ui-fg-subtle",
12085
- children: item.variant_sku
12086
- }
12087
- )
12088
- ] })
12089
- ] }),
12090
- /* @__PURE__ */ jsxRuntime.jsxs(
11815
+ const uniqueShippingProfiles = React.useMemo(() => {
11816
+ const profiles = /* @__PURE__ */ new Map();
11817
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11818
+ profiles.set(profile.id, profile);
11819
+ });
11820
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11821
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11822
+ });
11823
+ return Array.from(profiles.values());
11824
+ }, [order.items, shipping_options]);
11825
+ const { handleSuccess } = useRouteModal();
11826
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11827
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11828
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11829
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11830
+ const onSubmit = async () => {
11831
+ setIsSubmitting(true);
11832
+ let requestSucceeded = false;
11833
+ await requestOrderEdit(void 0, {
11834
+ onError: (e) => {
11835
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11836
+ },
11837
+ onSuccess: () => {
11838
+ requestSucceeded = true;
11839
+ }
11840
+ });
11841
+ if (!requestSucceeded) {
11842
+ setIsSubmitting(false);
11843
+ return;
11844
+ }
11845
+ await confirmOrderEdit(void 0, {
11846
+ onError: (e) => {
11847
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11848
+ },
11849
+ onSuccess: () => {
11850
+ handleSuccess();
11851
+ },
11852
+ onSettled: () => {
11853
+ setIsSubmitting(false);
11854
+ }
11855
+ });
11856
+ };
11857
+ const onKeydown = React.useCallback(
11858
+ (e) => {
11859
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11860
+ if (data || isSubmitting) {
11861
+ return;
11862
+ }
11863
+ onSubmit();
11864
+ }
11865
+ },
11866
+ [data, isSubmitting, onSubmit]
11867
+ );
11868
+ React.useEffect(() => {
11869
+ document.addEventListener("keydown", onKeydown);
11870
+ return () => {
11871
+ document.removeEventListener("keydown", onKeydown);
11872
+ };
11873
+ }, [onKeydown]);
11874
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11875
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11876
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11877
+ /* @__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: [
11878
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11879
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11880
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11881
+ ] }),
11882
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11883
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11884
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11885
+ /* @__PURE__ */ jsxRuntime.jsx(
12091
11886
  ui.Text,
12092
11887
  {
12093
- size: "small",
12094
- leading: "compact",
12095
- className: "text-ui-fg-subtle",
12096
- children: [
12097
- item.quantity,
12098
- "x"
12099
- ]
12100
- }
12101
- )
12102
- ]
12103
- },
12104
- item.id
12105
- )) : /* @__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: [
12106
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12107
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12108
- 'No items found for "',
12109
- query,
12110
- '".'
12111
- ] })
12112
- ] }) })
12113
- ] })
12114
- ] });
12115
- };
12116
- const LocationField = ({ control, setValue }) => {
12117
- const locations = useComboboxData({
12118
- queryKey: ["locations"],
12119
- queryFn: async (params) => {
12120
- return await sdk.admin.stockLocation.list(params);
12121
- },
12122
- getOptions: (data) => {
12123
- return data.stock_locations.map((location) => ({
12124
- label: location.name,
12125
- value: location.id
12126
- }));
12127
- }
12128
- });
12129
- return /* @__PURE__ */ jsxRuntime.jsx(
12130
- Form$2.Field,
12131
- {
12132
- control,
12133
- name: "location_id",
12134
- render: ({ field: { onChange, ...field } }) => {
12135
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12136
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12137
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12138
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11888
+ size: "xsmall",
11889
+ weight: "plus",
11890
+ className: "text-ui-fg-muted",
11891
+ children: "Shipping profile"
11892
+ }
11893
+ ),
11894
+ /* @__PURE__ */ jsxRuntime.jsx(
11895
+ ui.Text,
11896
+ {
11897
+ size: "xsmall",
11898
+ weight: "plus",
11899
+ className: "text-ui-fg-muted",
11900
+ children: "Action"
11901
+ }
11902
+ )
12139
11903
  ] }),
12140
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12141
- Combobox,
12142
- {
12143
- options: locations.options,
12144
- fetchNextPage: locations.fetchNextPage,
12145
- isFetchingNextPage: locations.isFetchingNextPage,
12146
- searchValue: locations.searchValue,
12147
- onSearchValueChange: locations.onSearchValueChange,
12148
- placeholder: "Select location",
12149
- onChange: (value) => {
12150
- setValue("shipping_option_id", "", {
12151
- shouldDirty: true,
12152
- shouldTouch: true
12153
- });
12154
- onChange(value);
11904
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11905
+ var _a2, _b, _c, _d, _e, _f, _g;
11906
+ const items = getItemsWithShippingProfile(
11907
+ profile.id,
11908
+ order.items
11909
+ );
11910
+ const hasItems = items.length > 0;
11911
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11912
+ (option) => option.shipping_profile_id === profile.id
11913
+ );
11914
+ const shippingMethod = preview.shipping_methods.find(
11915
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11916
+ );
11917
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11918
+ (action) => action.action === "SHIPPING_ADD"
11919
+ );
11920
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11921
+ radixUi.Accordion.Item,
11922
+ {
11923
+ value: profile.id,
11924
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11925
+ children: [
11926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11927
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11928
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11929
+ ui.IconButton,
11930
+ {
11931
+ size: "2xsmall",
11932
+ variant: "transparent",
11933
+ className: "group/trigger",
11934
+ disabled: !hasItems,
11935
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11936
+ }
11937
+ ) }),
11938
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11939
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11940
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11941
+ /* @__PURE__ */ jsxRuntime.jsx(
11942
+ ui.Text,
11943
+ {
11944
+ size: "small",
11945
+ weight: "plus",
11946
+ leading: "compact",
11947
+ children: profile.name
11948
+ }
11949
+ ),
11950
+ /* @__PURE__ */ jsxRuntime.jsxs(
11951
+ ui.Text,
11952
+ {
11953
+ size: "small",
11954
+ leading: "compact",
11955
+ className: "text-ui-fg-subtle",
11956
+ children: [
11957
+ items.length,
11958
+ " ",
11959
+ pluralize(items.length, "items", "item")
11960
+ ]
11961
+ }
11962
+ )
11963
+ ] })
11964
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11965
+ /* @__PURE__ */ jsxRuntime.jsx(
11966
+ ui.Tooltip,
11967
+ {
11968
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11969
+ var _a3, _b2, _c2;
11970
+ return /* @__PURE__ */ jsxRuntime.jsx(
11971
+ "li",
11972
+ {
11973
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11974
+ },
11975
+ item.id
11976
+ );
11977
+ }) }),
11978
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11979
+ ui.Badge,
11980
+ {
11981
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11982
+ size: "xsmall",
11983
+ children: [
11984
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11985
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11986
+ items.reduce(
11987
+ (acc, item) => acc + item.quantity,
11988
+ 0
11989
+ ),
11990
+ "x",
11991
+ " ",
11992
+ pluralize(items.length, "items", "item")
11993
+ ] })
11994
+ ]
11995
+ }
11996
+ )
11997
+ }
11998
+ ),
11999
+ /* @__PURE__ */ jsxRuntime.jsx(
12000
+ ui.Tooltip,
12001
+ {
12002
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12003
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12004
+ ui.Badge,
12005
+ {
12006
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12007
+ size: "xsmall",
12008
+ children: [
12009
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12010
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12011
+ ]
12012
+ }
12013
+ )
12014
+ }
12015
+ ),
12016
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12017
+ ui.Badge,
12018
+ {
12019
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12020
+ size: "xsmall",
12021
+ children: [
12022
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12023
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12024
+ ]
12025
+ }
12026
+ ) })
12027
+ ] })
12028
+ ] }),
12029
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12030
+ ActionMenu,
12031
+ {
12032
+ groups: [
12033
+ {
12034
+ actions: [
12035
+ hasItems ? {
12036
+ label: "Edit shipping option",
12037
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12038
+ onClick: () => {
12039
+ setIsOpen(
12040
+ STACKED_FOCUS_MODAL_ID,
12041
+ true
12042
+ );
12043
+ setData({
12044
+ shippingProfileId: profile.id,
12045
+ shippingOption,
12046
+ shippingMethod
12047
+ });
12048
+ }
12049
+ } : void 0,
12050
+ {
12051
+ label: "Remove shipping option",
12052
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12053
+ onClick: () => {
12054
+ if (shippingMethod) {
12055
+ if (addShippingMethodAction) {
12056
+ removeActionShippingMethod(
12057
+ addShippingMethodAction.id
12058
+ );
12059
+ } else {
12060
+ removeShippingMethod(
12061
+ shippingMethod.id
12062
+ );
12063
+ }
12064
+ }
12065
+ }
12066
+ }
12067
+ ].filter(Boolean)
12068
+ }
12069
+ ]
12070
+ }
12071
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12072
+ StackedModalTrigger,
12073
+ {
12074
+ shippingProfileId: profile.id,
12075
+ shippingOption,
12076
+ shippingMethod,
12077
+ setData,
12078
+ children: "Add shipping option"
12079
+ }
12080
+ )
12081
+ ] }),
12082
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12083
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12084
+ items.map((item, idx) => {
12085
+ var _a3, _b2, _c2, _d2, _e2;
12086
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12087
+ /* @__PURE__ */ jsxRuntime.jsxs(
12088
+ "div",
12089
+ {
12090
+ className: "px-3 flex items-center gap-x-3",
12091
+ children: [
12092
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12093
+ ui.Divider,
12094
+ {
12095
+ variant: "dashed",
12096
+ orientation: "vertical"
12097
+ }
12098
+ ) }),
12099
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12100
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12101
+ ui.Text,
12102
+ {
12103
+ size: "small",
12104
+ leading: "compact",
12105
+ className: "text-ui-fg-subtle",
12106
+ children: [
12107
+ item.quantity,
12108
+ "x"
12109
+ ]
12110
+ }
12111
+ ) }),
12112
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12113
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12114
+ /* @__PURE__ */ jsxRuntime.jsxs(
12115
+ ui.Text,
12116
+ {
12117
+ size: "small",
12118
+ leading: "compact",
12119
+ weight: "plus",
12120
+ children: [
12121
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12122
+ " (",
12123
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12124
+ ")"
12125
+ ]
12126
+ }
12127
+ ),
12128
+ /* @__PURE__ */ jsxRuntime.jsx(
12129
+ ui.Text,
12130
+ {
12131
+ size: "small",
12132
+ leading: "compact",
12133
+ className: "text-ui-fg-subtle",
12134
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12135
+ }
12136
+ )
12137
+ ] })
12138
+ ] })
12139
+ ]
12140
+ },
12141
+ item.id
12142
+ ),
12143
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12144
+ ] }, item.id);
12145
+ })
12146
+ ] })
12147
+ ]
12155
12148
  },
12156
- ...field
12149
+ profile.id
12150
+ );
12151
+ }) })
12152
+ ] }) })
12153
+ ] }) }),
12154
+ /* @__PURE__ */ jsxRuntime.jsx(
12155
+ StackedFocusModal,
12156
+ {
12157
+ id: STACKED_FOCUS_MODAL_ID,
12158
+ onOpenChangeCallback: (open) => {
12159
+ if (!open) {
12160
+ setData(null);
12157
12161
  }
12158
- ) })
12159
- ] }) });
12160
- }
12161
- }
12162
- );
12163
- };
12164
- const ShippingOptionField = ({
12165
- shippingProfileId,
12166
- preview,
12167
- control
12168
- }) => {
12169
- var _a;
12170
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12171
- const shippingOptions = useComboboxData({
12172
- queryKey: ["shipping_options", locationId, shippingProfileId],
12173
- queryFn: async (params) => {
12174
- return await sdk.admin.shippingOption.list({
12175
- ...params,
12176
- stock_location_id: locationId,
12177
- shipping_profile_id: shippingProfileId
12178
- });
12179
- },
12180
- getOptions: (data) => {
12181
- return data.shipping_options.map((option) => {
12182
- var _a2;
12183
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12184
- (r) => r.attribute === "is_return" && r.value === "true"
12185
- )) {
12186
- return void 0;
12162
+ return open;
12163
+ },
12164
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12187
12165
  }
12188
- return {
12189
- label: option.name,
12190
- value: option.id
12191
- };
12192
- }).filter(Boolean);
12193
- },
12194
- enabled: !!locationId && !!shippingProfileId,
12195
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12196
- });
12197
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12198
- return /* @__PURE__ */ jsxRuntime.jsx(
12199
- Form$2.Field,
12200
- {
12201
- control,
12202
- name: "shipping_option_id",
12203
- render: ({ field }) => {
12204
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12205
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12206
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12207
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12208
- ] }),
12209
- /* @__PURE__ */ jsxRuntime.jsx(
12210
- ConditionalTooltip,
12211
- {
12212
- content: tooltipContent,
12213
- showTooltip: !locationId || !shippingProfileId,
12214
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12215
- Combobox,
12216
- {
12217
- options: shippingOptions.options,
12218
- fetchNextPage: shippingOptions.fetchNextPage,
12219
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12220
- searchValue: shippingOptions.searchValue,
12221
- onSearchValueChange: shippingOptions.onSearchValueChange,
12222
- placeholder: "Select shipping option",
12223
- ...field,
12224
- disabled: !locationId || !shippingProfileId
12225
- }
12226
- ) }) })
12227
- }
12228
- )
12229
- ] }) });
12230
- }
12231
- }
12232
- );
12233
- };
12234
- const CustomAmountField = ({
12235
- control,
12236
- currencyCode
12237
- }) => {
12238
- return /* @__PURE__ */ jsxRuntime.jsx(
12239
- Form$2.Field,
12240
- {
12241
- control,
12242
- name: "custom_amount",
12243
- render: ({ field: { onChange, ...field } }) => {
12244
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12245
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12246
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12247
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12248
- ] }),
12249
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12250
- ui.CurrencyInput,
12251
- {
12252
- ...field,
12253
- onValueChange: (value) => onChange(value),
12254
- symbol: getNativeSymbol(currencyCode),
12255
- code: currencyCode
12256
- }
12257
- ) })
12258
- ] });
12259
- }
12260
- }
12261
- );
12262
- };
12263
- const SalesChannel = () => {
12264
- const { id } = reactRouterDom.useParams();
12265
- const { draft_order, isPending, isError, error } = useDraftOrder(
12266
- id,
12267
- {
12268
- fields: "+sales_channel_id"
12269
- },
12270
- {
12271
- enabled: !!id
12272
- }
12273
- );
12274
- if (isError) {
12275
- throw error;
12276
- }
12277
- const ISrEADY = !!draft_order && !isPending;
12278
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12279
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12280
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12281
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12166
+ )
12282
12167
  ] }),
12283
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12284
- ] });
12285
- };
12286
- const SalesChannelForm = ({ order }) => {
12287
- const form = reactHookForm.useForm({
12288
- defaultValues: {
12289
- sales_channel_id: order.sales_channel_id || ""
12290
- },
12291
- resolver: zod.zodResolver(schema$2)
12292
- });
12293
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12294
- const { handleSuccess } = useRouteModal();
12295
- const onSubmit = form.handleSubmit(async (data) => {
12296
- await mutateAsync(
12297
- {
12298
- sales_channel_id: data.sales_channel_id
12299
- },
12300
- {
12301
- onSuccess: () => {
12302
- ui.toast.success("Sales channel updated");
12303
- handleSuccess();
12304
- },
12305
- onError: (error) => {
12306
- ui.toast.error(error.message);
12168
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12169
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12170
+ /* @__PURE__ */ jsxRuntime.jsx(
12171
+ ui.Button,
12172
+ {
12173
+ size: "small",
12174
+ type: "button",
12175
+ isLoading: isSubmitting,
12176
+ onClick: onSubmit,
12177
+ children: "Save"
12307
12178
  }
12308
- }
12309
- );
12310
- });
12311
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12312
- KeyboundForm,
12313
- {
12314
- className: "flex flex-1 flex-col overflow-hidden",
12315
- onSubmit,
12316
- children: [
12317
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12318
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12319
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12320
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12321
- ] }) })
12322
- ]
12323
- }
12324
- ) });
12179
+ )
12180
+ ] }) })
12181
+ ] });
12325
12182
  };
12326
- const SalesChannelField = ({ control, order }) => {
12327
- const salesChannels = useComboboxData({
12328
- queryFn: async (params) => {
12329
- return await sdk.admin.salesChannel.list(params);
12330
- },
12331
- queryKey: ["sales-channels"],
12332
- getOptions: (data) => {
12333
- return data.sales_channels.map((salesChannel) => ({
12334
- label: salesChannel.name,
12335
- value: salesChannel.id
12336
- }));
12337
- },
12338
- defaultValue: order.sales_channel_id || void 0
12339
- });
12340
- return /* @__PURE__ */ jsxRuntime.jsx(
12341
- Form$2.Field,
12342
- {
12343
- control,
12344
- name: "sales_channel_id",
12345
- render: ({ field }) => {
12346
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12347
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12348
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12349
- Combobox,
12350
- {
12351
- options: salesChannels.options,
12352
- fetchNextPage: salesChannels.fetchNextPage,
12353
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12354
- searchValue: salesChannels.searchValue,
12355
- onSearchValueChange: salesChannels.onSearchValueChange,
12356
- placeholder: "Select sales channel",
12357
- ...field
12358
- }
12359
- ) }),
12360
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12361
- ] });
12362
- }
12183
+ const StackedModalTrigger = ({
12184
+ shippingProfileId,
12185
+ shippingOption,
12186
+ shippingMethod,
12187
+ setData,
12188
+ children
12189
+ }) => {
12190
+ const { setIsOpen, getIsOpen } = useStackedModal();
12191
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12192
+ const onToggle = () => {
12193
+ if (isOpen) {
12194
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12195
+ setData(null);
12196
+ } else {
12197
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12198
+ setData({
12199
+ shippingProfileId,
12200
+ shippingOption,
12201
+ shippingMethod
12202
+ });
12203
+ }
12204
+ };
12205
+ return /* @__PURE__ */ jsxRuntime.jsx(
12206
+ ui.Button,
12207
+ {
12208
+ size: "small",
12209
+ variant: "secondary",
12210
+ onClick: onToggle,
12211
+ className: "text-ui-fg-primary shrink-0",
12212
+ children
12363
12213
  }
12364
12214
  );
12365
12215
  };
12366
- const schema$2 = objectType({
12367
- sales_channel_id: stringType().min(1)
12368
- });
12369
- const ShippingAddress = () => {
12370
- const { id } = reactRouterDom.useParams();
12371
- const { order, isPending, isError, error } = useOrder(id, {
12372
- fields: "+shipping_address"
12373
- });
12374
- if (isError) {
12375
- throw error;
12376
- }
12377
- const isReady = !isPending && !!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: "Edit Shipping Address" }) }),
12381
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12382
- ] }),
12383
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12384
- ] });
12385
- };
12386
- const ShippingAddressForm = ({ order }) => {
12387
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12216
+ const ShippingProfileForm = ({
12217
+ data,
12218
+ order,
12219
+ preview
12220
+ }) => {
12221
+ var _a, _b, _c, _d, _e, _f;
12222
+ const { setIsOpen } = useStackedModal();
12388
12223
  const form = reactHookForm.useForm({
12224
+ resolver: zod.zodResolver(shippingMethodSchema),
12389
12225
  defaultValues: {
12390
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12391
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12392
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12393
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12394
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12395
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12396
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12397
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12398
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12399
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12400
- },
12401
- resolver: zod.zodResolver(schema$1)
12226
+ 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,
12227
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12228
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12229
+ }
12402
12230
  });
12403
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12404
- const { handleSuccess } = useRouteModal();
12405
- const onSubmit = form.handleSubmit(async (data) => {
12406
- await mutateAsync(
12407
- {
12408
- shipping_address: {
12409
- first_name: data.first_name,
12410
- last_name: data.last_name,
12411
- company: data.company,
12412
- address_1: data.address_1,
12413
- address_2: data.address_2,
12414
- city: data.city,
12415
- province: data.province,
12416
- country_code: data.country_code,
12417
- postal_code: data.postal_code,
12418
- phone: data.phone
12231
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12232
+ const {
12233
+ mutateAsync: updateShippingMethod,
12234
+ isPending: isUpdatingShippingMethod
12235
+ } = useDraftOrderUpdateShippingMethod(order.id);
12236
+ const onSubmit = form.handleSubmit(async (values) => {
12237
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12238
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12239
+ return;
12240
+ }
12241
+ if (data.shippingMethod) {
12242
+ await updateShippingMethod(
12243
+ {
12244
+ method_id: data.shippingMethod.id,
12245
+ shipping_option_id: values.shipping_option_id,
12246
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12247
+ },
12248
+ {
12249
+ onError: (e) => {
12250
+ ui.toast.error(e.message);
12251
+ },
12252
+ onSuccess: () => {
12253
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12254
+ }
12419
12255
  }
12256
+ );
12257
+ return;
12258
+ }
12259
+ await addShippingMethod(
12260
+ {
12261
+ shipping_option_id: values.shipping_option_id,
12262
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12420
12263
  },
12421
12264
  {
12422
- onSuccess: () => {
12423
- handleSuccess();
12265
+ onError: (e) => {
12266
+ ui.toast.error(e.message);
12424
12267
  },
12425
- onError: (error) => {
12426
- ui.toast.error(error.message);
12268
+ onSuccess: () => {
12269
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12427
12270
  }
12428
12271
  }
12429
12272
  );
12430
12273
  });
12431
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12274
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12432
12275
  KeyboundForm,
12433
12276
  {
12434
- className: "flex flex-1 flex-col overflow-hidden",
12277
+ className: "flex h-full flex-col overflow-hidden",
12435
12278
  onSubmit,
12436
12279
  children: [
12437
- /* @__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: [
12280
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12281
+ /* @__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: [
12282
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12283
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12284
+ /* @__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." }) })
12285
+ ] }),
12286
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12438
12287
  /* @__PURE__ */ jsxRuntime.jsx(
12439
- Form$2.Field,
12288
+ LocationField,
12440
12289
  {
12441
12290
  control: form.control,
12442
- name: "country_code",
12443
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12444
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12445
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12446
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12447
- ] })
12291
+ setValue: form.setValue
12448
12292
  }
12449
12293
  ),
12450
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12451
- /* @__PURE__ */ jsxRuntime.jsx(
12452
- Form$2.Field,
12453
- {
12454
- control: form.control,
12455
- name: "first_name",
12456
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12457
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12458
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12459
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12460
- ] })
12461
- }
12462
- ),
12463
- /* @__PURE__ */ jsxRuntime.jsx(
12464
- Form$2.Field,
12465
- {
12466
- control: form.control,
12467
- name: "last_name",
12468
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12469
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12470
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12471
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12472
- ] })
12473
- }
12474
- )
12475
- ] }),
12294
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12476
12295
  /* @__PURE__ */ jsxRuntime.jsx(
12477
- Form$2.Field,
12296
+ ShippingOptionField,
12478
12297
  {
12479
- control: form.control,
12480
- name: "company",
12481
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12482
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12483
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12484
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12485
- ] })
12298
+ shippingProfileId: data.shippingProfileId,
12299
+ preview,
12300
+ control: form.control
12486
12301
  }
12487
12302
  ),
12303
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12488
12304
  /* @__PURE__ */ jsxRuntime.jsx(
12489
- Form$2.Field,
12305
+ CustomAmountField,
12490
12306
  {
12491
12307
  control: form.control,
12492
- name: "address_1",
12493
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12494
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12495
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12496
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12497
- ] })
12308
+ currencyCode: order.currency_code
12498
12309
  }
12499
12310
  ),
12311
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12500
12312
  /* @__PURE__ */ jsxRuntime.jsx(
12501
- Form$2.Field,
12313
+ ItemsPreview,
12502
12314
  {
12503
- control: form.control,
12504
- name: "address_2",
12505
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12506
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12507
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12508
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12315
+ order,
12316
+ shippingProfileId: data.shippingProfileId
12317
+ }
12318
+ )
12319
+ ] }) }) }),
12320
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12321
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12322
+ /* @__PURE__ */ jsxRuntime.jsx(
12323
+ ui.Button,
12324
+ {
12325
+ size: "small",
12326
+ type: "submit",
12327
+ isLoading: isPending || isUpdatingShippingMethod,
12328
+ children: data.shippingMethod ? "Update" : "Add"
12329
+ }
12330
+ )
12331
+ ] }) })
12332
+ ]
12333
+ }
12334
+ ) }) });
12335
+ };
12336
+ const shippingMethodSchema = objectType({
12337
+ location_id: stringType(),
12338
+ shipping_option_id: stringType(),
12339
+ custom_amount: unionType([numberType(), stringType()]).optional()
12340
+ });
12341
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12342
+ const matches = order.items.filter(
12343
+ (item) => {
12344
+ var _a, _b, _c;
12345
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12346
+ }
12347
+ );
12348
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12349
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12350
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12351
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12352
+ ] }) }),
12353
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12354
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12355
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12356
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12357
+ ] }),
12358
+ /* @__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(
12359
+ "div",
12360
+ {
12361
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12362
+ children: [
12363
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12364
+ /* @__PURE__ */ jsxRuntime.jsx(
12365
+ Thumbnail,
12366
+ {
12367
+ thumbnail: item.thumbnail,
12368
+ alt: item.product_title ?? void 0
12369
+ }
12370
+ ),
12371
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12372
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12373
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12374
+ /* @__PURE__ */ jsxRuntime.jsxs(
12375
+ ui.Text,
12376
+ {
12377
+ size: "small",
12378
+ leading: "compact",
12379
+ className: "text-ui-fg-subtle",
12380
+ children: [
12381
+ "(",
12382
+ item.variant_title,
12383
+ ")"
12384
+ ]
12385
+ }
12386
+ )
12387
+ ] }),
12388
+ /* @__PURE__ */ jsxRuntime.jsx(
12389
+ ui.Text,
12390
+ {
12391
+ size: "small",
12392
+ leading: "compact",
12393
+ className: "text-ui-fg-subtle",
12394
+ children: item.variant_sku
12395
+ }
12396
+ )
12509
12397
  ] })
12510
- }
12511
- ),
12512
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12513
- /* @__PURE__ */ jsxRuntime.jsx(
12514
- Form$2.Field,
12515
- {
12516
- control: form.control,
12517
- name: "postal_code",
12518
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12519
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12521
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12522
- ] })
12523
- }
12524
- ),
12525
- /* @__PURE__ */ jsxRuntime.jsx(
12526
- Form$2.Field,
12398
+ ] }),
12399
+ /* @__PURE__ */ jsxRuntime.jsxs(
12400
+ ui.Text,
12527
12401
  {
12528
- control: form.control,
12529
- name: "city",
12530
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12534
- ] })
12402
+ size: "small",
12403
+ leading: "compact",
12404
+ className: "text-ui-fg-subtle",
12405
+ children: [
12406
+ item.quantity,
12407
+ "x"
12408
+ ]
12535
12409
  }
12536
12410
  )
12411
+ ]
12412
+ },
12413
+ item.id
12414
+ )) : /* @__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: [
12415
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12416
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12417
+ 'No items found for "',
12418
+ query,
12419
+ '".'
12420
+ ] })
12421
+ ] }) })
12422
+ ] })
12423
+ ] });
12424
+ };
12425
+ const LocationField = ({ control, setValue }) => {
12426
+ const locations = useComboboxData({
12427
+ queryKey: ["locations"],
12428
+ queryFn: async (params) => {
12429
+ return await sdk.admin.stockLocation.list(params);
12430
+ },
12431
+ getOptions: (data) => {
12432
+ return data.stock_locations.map((location) => ({
12433
+ label: location.name,
12434
+ value: location.id
12435
+ }));
12436
+ }
12437
+ });
12438
+ return /* @__PURE__ */ jsxRuntime.jsx(
12439
+ Form$2.Field,
12440
+ {
12441
+ control,
12442
+ name: "location_id",
12443
+ render: ({ field: { onChange, ...field } }) => {
12444
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12445
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12447
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12537
12448
  ] }),
12538
- /* @__PURE__ */ jsxRuntime.jsx(
12539
- Form$2.Field,
12449
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12450
+ Combobox,
12540
12451
  {
12541
- control: form.control,
12542
- name: "province",
12543
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12546
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12547
- ] })
12452
+ options: locations.options,
12453
+ fetchNextPage: locations.fetchNextPage,
12454
+ isFetchingNextPage: locations.isFetchingNextPage,
12455
+ searchValue: locations.searchValue,
12456
+ onSearchValueChange: locations.onSearchValueChange,
12457
+ placeholder: "Select location",
12458
+ onChange: (value) => {
12459
+ setValue("shipping_option_id", "", {
12460
+ shouldDirty: true,
12461
+ shouldTouch: true
12462
+ });
12463
+ onChange(value);
12464
+ },
12465
+ ...field
12548
12466
  }
12549
- ),
12467
+ ) })
12468
+ ] }) });
12469
+ }
12470
+ }
12471
+ );
12472
+ };
12473
+ const ShippingOptionField = ({
12474
+ shippingProfileId,
12475
+ preview,
12476
+ control
12477
+ }) => {
12478
+ var _a;
12479
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12480
+ const shippingOptions = useComboboxData({
12481
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12482
+ queryFn: async (params) => {
12483
+ return await sdk.admin.shippingOption.list({
12484
+ ...params,
12485
+ stock_location_id: locationId,
12486
+ shipping_profile_id: shippingProfileId
12487
+ });
12488
+ },
12489
+ getOptions: (data) => {
12490
+ return data.shipping_options.map((option) => {
12491
+ var _a2;
12492
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12493
+ (r) => r.attribute === "is_return" && r.value === "true"
12494
+ )) {
12495
+ return void 0;
12496
+ }
12497
+ return {
12498
+ label: option.name,
12499
+ value: option.id
12500
+ };
12501
+ }).filter(Boolean);
12502
+ },
12503
+ enabled: !!locationId && !!shippingProfileId,
12504
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12505
+ });
12506
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12507
+ return /* @__PURE__ */ jsxRuntime.jsx(
12508
+ Form$2.Field,
12509
+ {
12510
+ control,
12511
+ name: "shipping_option_id",
12512
+ render: ({ field }) => {
12513
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12514
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12515
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12516
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12517
+ ] }),
12550
12518
  /* @__PURE__ */ jsxRuntime.jsx(
12551
- Form$2.Field,
12519
+ ConditionalTooltip,
12552
12520
  {
12553
- control: form.control,
12554
- name: "phone",
12555
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12558
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12559
- ] })
12521
+ content: tooltipContent,
12522
+ showTooltip: !locationId || !shippingProfileId,
12523
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12524
+ Combobox,
12525
+ {
12526
+ options: shippingOptions.options,
12527
+ fetchNextPage: shippingOptions.fetchNextPage,
12528
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12529
+ searchValue: shippingOptions.searchValue,
12530
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12531
+ placeholder: "Select shipping option",
12532
+ ...field,
12533
+ disabled: !locationId || !shippingProfileId
12534
+ }
12535
+ ) }) })
12560
12536
  }
12561
12537
  )
12562
- ] }) }),
12563
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12564
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12565
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12566
- ] }) })
12567
- ]
12538
+ ] }) });
12539
+ }
12568
12540
  }
12569
- ) });
12541
+ );
12542
+ };
12543
+ const CustomAmountField = ({
12544
+ control,
12545
+ currencyCode
12546
+ }) => {
12547
+ return /* @__PURE__ */ jsxRuntime.jsx(
12548
+ Form$2.Field,
12549
+ {
12550
+ control,
12551
+ name: "custom_amount",
12552
+ render: ({ field: { onChange, ...field } }) => {
12553
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12554
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12557
+ ] }),
12558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12559
+ ui.CurrencyInput,
12560
+ {
12561
+ ...field,
12562
+ onValueChange: (value) => onChange(value),
12563
+ symbol: getNativeSymbol(currencyCode),
12564
+ code: currencyCode
12565
+ }
12566
+ ) })
12567
+ ] });
12568
+ }
12569
+ }
12570
+ );
12570
12571
  };
12571
- const schema$1 = addressSchema;
12572
12572
  const TransferOwnership = () => {
12573
12573
  const { id } = reactRouterDom.useParams();
12574
12574
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13065,10 +13065,6 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13071
- },
13072
13068
  {
13073
13069
  Component: CustomItems,
13074
13070
  path: "/draft-orders/:id/custom-items"
@@ -13077,6 +13073,10 @@ const routeModule = {
13077
13073
  Component: Email,
13078
13074
  path: "/draft-orders/:id/email"
13079
13075
  },
13076
+ {
13077
+ Component: BillingAddress,
13078
+ path: "/draft-orders/:id/billing-address"
13079
+ },
13080
13080
  {
13081
13081
  Component: Items,
13082
13082
  path: "/draft-orders/:id/items"
@@ -13089,10 +13089,6 @@ const routeModule = {
13089
13089
  Component: Promotions,
13090
13090
  path: "/draft-orders/:id/promotions"
13091
13091
  },
13092
- {
13093
- Component: Shipping,
13094
- path: "/draft-orders/:id/shipping"
13095
- },
13096
13092
  {
13097
13093
  Component: SalesChannel,
13098
13094
  path: "/draft-orders/:id/sales-channel"
@@ -13101,6 +13097,10 @@ const routeModule = {
13101
13097
  Component: ShippingAddress,
13102
13098
  path: "/draft-orders/:id/shipping-address"
13103
13099
  },
13100
+ {
13101
+ Component: Shipping,
13102
+ path: "/draft-orders/:id/shipping"
13103
+ },
13104
13104
  {
13105
13105
  Component: TransferOwnership,
13106
13106
  path: "/draft-orders/:id/transfer-ownership"