@medusajs/draft-order 2.10.4-preview-20250922150158 → 2.10.4-preview-20250922210211

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.
@@ -9588,6 +9588,196 @@ const CustomItemsForm = () => {
9588
9588
  const schema$5 = objectType({
9589
9589
  email: stringType().email()
9590
9590
  });
9591
+ const BillingAddress = () => {
9592
+ const { id } = useParams();
9593
+ const { order, isPending, isError, error } = useOrder(id, {
9594
+ fields: "+billing_address"
9595
+ });
9596
+ if (isError) {
9597
+ throw error;
9598
+ }
9599
+ const isReady = !isPending && !!order;
9600
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9601
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9602
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9603
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9604
+ ] }),
9605
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9606
+ ] });
9607
+ };
9608
+ const BillingAddressForm = ({ order }) => {
9609
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9610
+ const form = useForm({
9611
+ defaultValues: {
9612
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9613
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9614
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9615
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9616
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9617
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9618
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9619
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9620
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9621
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9622
+ },
9623
+ resolver: zodResolver(schema$4)
9624
+ });
9625
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9626
+ const { handleSuccess } = useRouteModal();
9627
+ const onSubmit = form.handleSubmit(async (data) => {
9628
+ await mutateAsync(
9629
+ { billing_address: data },
9630
+ {
9631
+ onSuccess: () => {
9632
+ handleSuccess();
9633
+ },
9634
+ onError: (error) => {
9635
+ toast.error(error.message);
9636
+ }
9637
+ }
9638
+ );
9639
+ });
9640
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9641
+ KeyboundForm,
9642
+ {
9643
+ className: "flex flex-1 flex-col overflow-hidden",
9644
+ onSubmit,
9645
+ children: [
9646
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9647
+ /* @__PURE__ */ jsx(
9648
+ Form$2.Field,
9649
+ {
9650
+ control: form.control,
9651
+ name: "country_code",
9652
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9653
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9654
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9655
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9656
+ ] })
9657
+ }
9658
+ ),
9659
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9660
+ /* @__PURE__ */ jsx(
9661
+ Form$2.Field,
9662
+ {
9663
+ control: form.control,
9664
+ name: "first_name",
9665
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9666
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9667
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9668
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9669
+ ] })
9670
+ }
9671
+ ),
9672
+ /* @__PURE__ */ jsx(
9673
+ Form$2.Field,
9674
+ {
9675
+ control: form.control,
9676
+ name: "last_name",
9677
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9678
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9679
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9680
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9681
+ ] })
9682
+ }
9683
+ )
9684
+ ] }),
9685
+ /* @__PURE__ */ jsx(
9686
+ Form$2.Field,
9687
+ {
9688
+ control: form.control,
9689
+ name: "company",
9690
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9691
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9692
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9693
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9694
+ ] })
9695
+ }
9696
+ ),
9697
+ /* @__PURE__ */ jsx(
9698
+ Form$2.Field,
9699
+ {
9700
+ control: form.control,
9701
+ name: "address_1",
9702
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9703
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9704
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9705
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9706
+ ] })
9707
+ }
9708
+ ),
9709
+ /* @__PURE__ */ jsx(
9710
+ Form$2.Field,
9711
+ {
9712
+ control: form.control,
9713
+ name: "address_2",
9714
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9715
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9716
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9717
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9718
+ ] })
9719
+ }
9720
+ ),
9721
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9722
+ /* @__PURE__ */ jsx(
9723
+ Form$2.Field,
9724
+ {
9725
+ control: form.control,
9726
+ name: "postal_code",
9727
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9728
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9729
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9730
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9731
+ ] })
9732
+ }
9733
+ ),
9734
+ /* @__PURE__ */ jsx(
9735
+ Form$2.Field,
9736
+ {
9737
+ control: form.control,
9738
+ name: "city",
9739
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9740
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9741
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9742
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9743
+ ] })
9744
+ }
9745
+ )
9746
+ ] }),
9747
+ /* @__PURE__ */ jsx(
9748
+ Form$2.Field,
9749
+ {
9750
+ control: form.control,
9751
+ name: "province",
9752
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9753
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9754
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9755
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9756
+ ] })
9757
+ }
9758
+ ),
9759
+ /* @__PURE__ */ jsx(
9760
+ Form$2.Field,
9761
+ {
9762
+ control: form.control,
9763
+ name: "phone",
9764
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9765
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9766
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9767
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9768
+ ] })
9769
+ }
9770
+ )
9771
+ ] }) }),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9775
+ ] }) })
9776
+ ]
9777
+ }
9778
+ ) });
9779
+ };
9780
+ const schema$4 = addressSchema;
9591
9781
  const Email = () => {
9592
9782
  const { id } = useParams();
9593
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9610,7 +9800,7 @@ const EmailForm = ({ order }) => {
9610
9800
  defaultValues: {
9611
9801
  email: order.email ?? ""
9612
9802
  },
9613
- resolver: zodResolver(schema$4)
9803
+ resolver: zodResolver(schema$3)
9614
9804
  });
9615
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9616
9806
  const { handleSuccess } = useRouteModal();
@@ -9653,7 +9843,7 @@ const EmailForm = ({ order }) => {
9653
9843
  }
9654
9844
  ) });
9655
9845
  };
9656
- const schema$4 = objectType({
9846
+ const schema$3 = objectType({
9657
9847
  email: stringType().email()
9658
9848
  });
9659
9849
  const NumberInput = forwardRef(
@@ -11257,72 +11447,381 @@ function getPromotionIds(items, shippingMethods) {
11257
11447
  }
11258
11448
  return Array.from(promotionIds);
11259
11449
  }
11260
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11261
- const Shipping = () => {
11262
- var _a;
11450
+ const SalesChannel = () => {
11263
11451
  const { id } = useParams();
11264
- const { order, isPending, isError, error } = useOrder(id, {
11265
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11266
- });
11267
- const {
11268
- order: preview,
11269
- isPending: isPreviewPending,
11270
- isError: isPreviewError,
11271
- error: previewError
11272
- } = useOrderPreview(id);
11273
- useInitiateOrderEdit({ preview });
11274
- const { onCancel } = useCancelOrderEdit({ preview });
11275
- if (isError) {
11276
- throw error;
11277
- }
11278
- if (isPreviewError) {
11279
- throw previewError;
11280
- }
11281
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11282
- const isReady = preview && !isPreviewPending && order && !isPending;
11283
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11284
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11285
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11286
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11287
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11288
- ] }) }) }),
11289
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11290
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11291
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11292
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11293
- ] }) });
11294
- };
11295
- const ShippingForm = ({ preview, order }) => {
11296
- var _a;
11297
- const { setIsOpen } = useStackedModal();
11298
- const [isSubmitting, setIsSubmitting] = useState(false);
11299
- const [data, setData] = useState(null);
11300
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11301
- const { shipping_options } = useShippingOptions(
11452
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11453
+ id,
11302
11454
  {
11303
- id: appliedShippingOptionIds,
11304
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11455
+ fields: "+sales_channel_id"
11305
11456
  },
11306
11457
  {
11307
- enabled: appliedShippingOptionIds.length > 0
11458
+ enabled: !!id
11308
11459
  }
11309
11460
  );
11310
- const uniqueShippingProfiles = useMemo(() => {
11311
- const profiles = /* @__PURE__ */ new Map();
11312
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11313
- profiles.set(profile.id, profile);
11314
- });
11315
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11316
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11317
- });
11318
- return Array.from(profiles.values());
11319
- }, [order.items, shipping_options]);
11320
- const { handleSuccess } = useRouteModal();
11321
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11322
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11323
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11324
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11325
- const onSubmit = async () => {
11461
+ if (isError) {
11462
+ throw error;
11463
+ }
11464
+ const ISrEADY = !!draft_order && !isPending;
11465
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
+ ] }),
11470
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11471
+ ] });
11472
+ };
11473
+ const SalesChannelForm = ({ order }) => {
11474
+ const form = useForm({
11475
+ defaultValues: {
11476
+ sales_channel_id: order.sales_channel_id || ""
11477
+ },
11478
+ resolver: zodResolver(schema$2)
11479
+ });
11480
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
+ const { handleSuccess } = useRouteModal();
11482
+ const onSubmit = form.handleSubmit(async (data) => {
11483
+ await mutateAsync(
11484
+ {
11485
+ sales_channel_id: data.sales_channel_id
11486
+ },
11487
+ {
11488
+ onSuccess: () => {
11489
+ toast.success("Sales channel updated");
11490
+ handleSuccess();
11491
+ },
11492
+ onError: (error) => {
11493
+ toast.error(error.message);
11494
+ }
11495
+ }
11496
+ );
11497
+ });
11498
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11499
+ KeyboundForm,
11500
+ {
11501
+ className: "flex flex-1 flex-col overflow-hidden",
11502
+ onSubmit,
11503
+ children: [
11504
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11507
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
+ ] }) })
11509
+ ]
11510
+ }
11511
+ ) });
11512
+ };
11513
+ const SalesChannelField = ({ control, order }) => {
11514
+ const salesChannels = useComboboxData({
11515
+ queryFn: async (params) => {
11516
+ return await sdk.admin.salesChannel.list(params);
11517
+ },
11518
+ queryKey: ["sales-channels"],
11519
+ getOptions: (data) => {
11520
+ return data.sales_channels.map((salesChannel) => ({
11521
+ label: salesChannel.name,
11522
+ value: salesChannel.id
11523
+ }));
11524
+ },
11525
+ defaultValue: order.sales_channel_id || void 0
11526
+ });
11527
+ return /* @__PURE__ */ jsx(
11528
+ Form$2.Field,
11529
+ {
11530
+ control,
11531
+ name: "sales_channel_id",
11532
+ render: ({ field }) => {
11533
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
+ Combobox,
11537
+ {
11538
+ options: salesChannels.options,
11539
+ fetchNextPage: salesChannels.fetchNextPage,
11540
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
+ searchValue: salesChannels.searchValue,
11542
+ onSearchValueChange: salesChannels.onSearchValueChange,
11543
+ placeholder: "Select sales channel",
11544
+ ...field
11545
+ }
11546
+ ) }),
11547
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
+ ] });
11549
+ }
11550
+ }
11551
+ );
11552
+ };
11553
+ const schema$2 = objectType({
11554
+ sales_channel_id: stringType().min(1)
11555
+ });
11556
+ const ShippingAddress = () => {
11557
+ const { id } = useParams();
11558
+ const { order, isPending, isError, error } = useOrder(id, {
11559
+ fields: "+shipping_address"
11560
+ });
11561
+ if (isError) {
11562
+ throw error;
11563
+ }
11564
+ const isReady = !isPending && !!order;
11565
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11566
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11567
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11568
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11569
+ ] }),
11570
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11571
+ ] });
11572
+ };
11573
+ const ShippingAddressForm = ({ order }) => {
11574
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11575
+ const form = useForm({
11576
+ defaultValues: {
11577
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11578
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11579
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11580
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11581
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11582
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11583
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11584
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11585
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11586
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11587
+ },
11588
+ resolver: zodResolver(schema$1)
11589
+ });
11590
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11591
+ const { handleSuccess } = useRouteModal();
11592
+ const onSubmit = form.handleSubmit(async (data) => {
11593
+ await mutateAsync(
11594
+ {
11595
+ shipping_address: {
11596
+ first_name: data.first_name,
11597
+ last_name: data.last_name,
11598
+ company: data.company,
11599
+ address_1: data.address_1,
11600
+ address_2: data.address_2,
11601
+ city: data.city,
11602
+ province: data.province,
11603
+ country_code: data.country_code,
11604
+ postal_code: data.postal_code,
11605
+ phone: data.phone
11606
+ }
11607
+ },
11608
+ {
11609
+ onSuccess: () => {
11610
+ handleSuccess();
11611
+ },
11612
+ onError: (error) => {
11613
+ toast.error(error.message);
11614
+ }
11615
+ }
11616
+ );
11617
+ });
11618
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11619
+ KeyboundForm,
11620
+ {
11621
+ className: "flex flex-1 flex-col overflow-hidden",
11622
+ onSubmit,
11623
+ children: [
11624
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11625
+ /* @__PURE__ */ jsx(
11626
+ Form$2.Field,
11627
+ {
11628
+ control: form.control,
11629
+ name: "country_code",
11630
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11631
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11632
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11633
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11634
+ ] })
11635
+ }
11636
+ ),
11637
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11638
+ /* @__PURE__ */ jsx(
11639
+ Form$2.Field,
11640
+ {
11641
+ control: form.control,
11642
+ name: "first_name",
11643
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11644
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11645
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11646
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11647
+ ] })
11648
+ }
11649
+ ),
11650
+ /* @__PURE__ */ jsx(
11651
+ Form$2.Field,
11652
+ {
11653
+ control: form.control,
11654
+ name: "last_name",
11655
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11656
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11657
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11658
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11659
+ ] })
11660
+ }
11661
+ )
11662
+ ] }),
11663
+ /* @__PURE__ */ jsx(
11664
+ Form$2.Field,
11665
+ {
11666
+ control: form.control,
11667
+ name: "company",
11668
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11669
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11670
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11671
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11672
+ ] })
11673
+ }
11674
+ ),
11675
+ /* @__PURE__ */ jsx(
11676
+ Form$2.Field,
11677
+ {
11678
+ control: form.control,
11679
+ name: "address_1",
11680
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11681
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11682
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11683
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11684
+ ] })
11685
+ }
11686
+ ),
11687
+ /* @__PURE__ */ jsx(
11688
+ Form$2.Field,
11689
+ {
11690
+ control: form.control,
11691
+ name: "address_2",
11692
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11693
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11694
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11695
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11696
+ ] })
11697
+ }
11698
+ ),
11699
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11700
+ /* @__PURE__ */ jsx(
11701
+ Form$2.Field,
11702
+ {
11703
+ control: form.control,
11704
+ name: "postal_code",
11705
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11706
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11707
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11708
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11709
+ ] })
11710
+ }
11711
+ ),
11712
+ /* @__PURE__ */ jsx(
11713
+ Form$2.Field,
11714
+ {
11715
+ control: form.control,
11716
+ name: "city",
11717
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11718
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11719
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11720
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11721
+ ] })
11722
+ }
11723
+ )
11724
+ ] }),
11725
+ /* @__PURE__ */ jsx(
11726
+ Form$2.Field,
11727
+ {
11728
+ control: form.control,
11729
+ name: "province",
11730
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11731
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11732
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11733
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11734
+ ] })
11735
+ }
11736
+ ),
11737
+ /* @__PURE__ */ jsx(
11738
+ Form$2.Field,
11739
+ {
11740
+ control: form.control,
11741
+ name: "phone",
11742
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11743
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11744
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11745
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11746
+ ] })
11747
+ }
11748
+ )
11749
+ ] }) }),
11750
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11751
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11752
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11753
+ ] }) })
11754
+ ]
11755
+ }
11756
+ ) });
11757
+ };
11758
+ const schema$1 = addressSchema;
11759
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11760
+ const Shipping = () => {
11761
+ var _a;
11762
+ const { id } = useParams();
11763
+ const { order, isPending, isError, error } = useOrder(id, {
11764
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11765
+ });
11766
+ const {
11767
+ order: preview,
11768
+ isPending: isPreviewPending,
11769
+ isError: isPreviewError,
11770
+ error: previewError
11771
+ } = useOrderPreview(id);
11772
+ useInitiateOrderEdit({ preview });
11773
+ const { onCancel } = useCancelOrderEdit({ preview });
11774
+ if (isError) {
11775
+ throw error;
11776
+ }
11777
+ if (isPreviewError) {
11778
+ throw previewError;
11779
+ }
11780
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11781
+ const isReady = preview && !isPreviewPending && order && !isPending;
11782
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11783
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11784
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11785
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11786
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11787
+ ] }) }) }),
11788
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11789
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11790
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11791
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11792
+ ] }) });
11793
+ };
11794
+ const ShippingForm = ({ preview, order }) => {
11795
+ var _a;
11796
+ const { setIsOpen } = useStackedModal();
11797
+ const [isSubmitting, setIsSubmitting] = useState(false);
11798
+ const [data, setData] = useState(null);
11799
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11800
+ const { shipping_options } = useShippingOptions(
11801
+ {
11802
+ id: appliedShippingOptionIds,
11803
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11804
+ },
11805
+ {
11806
+ enabled: appliedShippingOptionIds.length > 0
11807
+ }
11808
+ );
11809
+ const uniqueShippingProfiles = useMemo(() => {
11810
+ const profiles = /* @__PURE__ */ new Map();
11811
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11812
+ profiles.set(profile.id, profile);
11813
+ });
11814
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11815
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11816
+ });
11817
+ return Array.from(profiles.values());
11818
+ }, [order.items, shipping_options]);
11819
+ const { handleSuccess } = useRouteModal();
11820
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11821
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11822
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11823
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11824
+ const onSubmit = async () => {
11326
11825
  setIsSubmitting(true);
11327
11826
  let requestSucceeded = false;
11328
11827
  await requestOrderEdit(void 0, {
@@ -11994,279 +12493,76 @@ const ShippingOptionField = ({
11994
12493
  value: option.id
11995
12494
  };
11996
12495
  }).filter(Boolean);
11997
- },
11998
- enabled: !!locationId && !!shippingProfileId,
11999
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12000
- });
12001
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12002
- return /* @__PURE__ */ jsx(
12003
- Form$2.Field,
12004
- {
12005
- control,
12006
- name: "shipping_option_id",
12007
- render: ({ field }) => {
12008
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12009
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12010
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12011
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12012
- ] }),
12013
- /* @__PURE__ */ jsx(
12014
- ConditionalTooltip,
12015
- {
12016
- content: tooltipContent,
12017
- showTooltip: !locationId || !shippingProfileId,
12018
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12019
- Combobox,
12020
- {
12021
- options: shippingOptions.options,
12022
- fetchNextPage: shippingOptions.fetchNextPage,
12023
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12024
- searchValue: shippingOptions.searchValue,
12025
- onSearchValueChange: shippingOptions.onSearchValueChange,
12026
- placeholder: "Select shipping option",
12027
- ...field,
12028
- disabled: !locationId || !shippingProfileId
12029
- }
12030
- ) }) })
12031
- }
12032
- )
12033
- ] }) });
12034
- }
12035
- }
12036
- );
12037
- };
12038
- const CustomAmountField = ({
12039
- control,
12040
- currencyCode
12041
- }) => {
12042
- return /* @__PURE__ */ jsx(
12043
- Form$2.Field,
12044
- {
12045
- control,
12046
- name: "custom_amount",
12047
- render: ({ field: { onChange, ...field } }) => {
12048
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12049
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12050
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12051
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12052
- ] }),
12053
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12054
- CurrencyInput,
12055
- {
12056
- ...field,
12057
- onValueChange: (value) => onChange(value),
12058
- symbol: getNativeSymbol(currencyCode),
12059
- code: currencyCode
12060
- }
12061
- ) })
12062
- ] });
12063
- }
12064
- }
12065
- );
12066
- };
12067
- const ShippingAddress = () => {
12068
- const { id } = useParams();
12069
- const { order, isPending, isError, error } = useOrder(id, {
12070
- fields: "+shipping_address"
12071
- });
12072
- if (isError) {
12073
- throw error;
12074
- }
12075
- const isReady = !isPending && !!order;
12076
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12077
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12078
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12079
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12080
- ] }),
12081
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12082
- ] });
12083
- };
12084
- const ShippingAddressForm = ({ order }) => {
12085
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12086
- const form = useForm({
12087
- defaultValues: {
12088
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12089
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12090
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12091
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12092
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12093
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12094
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12095
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12096
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12097
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12098
- },
12099
- resolver: zodResolver(schema$3)
12100
- });
12101
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12102
- const { handleSuccess } = useRouteModal();
12103
- const onSubmit = form.handleSubmit(async (data) => {
12104
- await mutateAsync(
12105
- {
12106
- shipping_address: {
12107
- first_name: data.first_name,
12108
- last_name: data.last_name,
12109
- company: data.company,
12110
- address_1: data.address_1,
12111
- address_2: data.address_2,
12112
- city: data.city,
12113
- province: data.province,
12114
- country_code: data.country_code,
12115
- postal_code: data.postal_code,
12116
- phone: data.phone
12117
- }
12118
- },
12119
- {
12120
- onSuccess: () => {
12121
- handleSuccess();
12122
- },
12123
- onError: (error) => {
12124
- toast.error(error.message);
12125
- }
12126
- }
12127
- );
12128
- });
12129
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12130
- KeyboundForm,
12131
- {
12132
- className: "flex flex-1 flex-col overflow-hidden",
12133
- onSubmit,
12134
- children: [
12135
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12136
- /* @__PURE__ */ jsx(
12137
- Form$2.Field,
12138
- {
12139
- control: form.control,
12140
- name: "country_code",
12141
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12142
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12143
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12144
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12145
- ] })
12146
- }
12147
- ),
12148
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12149
- /* @__PURE__ */ jsx(
12150
- Form$2.Field,
12151
- {
12152
- control: form.control,
12153
- name: "first_name",
12154
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12155
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12156
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12157
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12158
- ] })
12159
- }
12160
- ),
12161
- /* @__PURE__ */ jsx(
12162
- Form$2.Field,
12163
- {
12164
- control: form.control,
12165
- name: "last_name",
12166
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12167
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12168
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12169
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12170
- ] })
12171
- }
12172
- )
12173
- ] }),
12174
- /* @__PURE__ */ jsx(
12175
- Form$2.Field,
12176
- {
12177
- control: form.control,
12178
- name: "company",
12179
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12180
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12181
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12182
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12183
- ] })
12184
- }
12185
- ),
12186
- /* @__PURE__ */ jsx(
12187
- Form$2.Field,
12188
- {
12189
- control: form.control,
12190
- name: "address_1",
12191
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12192
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12193
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12194
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12195
- ] })
12196
- }
12197
- ),
12198
- /* @__PURE__ */ jsx(
12199
- Form$2.Field,
12200
- {
12201
- control: form.control,
12202
- name: "address_2",
12203
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12204
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12205
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12206
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12207
- ] })
12208
- }
12209
- ),
12210
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12211
- /* @__PURE__ */ jsx(
12212
- Form$2.Field,
12213
- {
12214
- control: form.control,
12215
- name: "postal_code",
12216
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12217
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12218
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12219
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12220
- ] })
12221
- }
12222
- ),
12223
- /* @__PURE__ */ jsx(
12224
- Form$2.Field,
12225
- {
12226
- control: form.control,
12227
- name: "city",
12228
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12229
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12230
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12231
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12232
- ] })
12233
- }
12234
- )
12496
+ },
12497
+ enabled: !!locationId && !!shippingProfileId,
12498
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12499
+ });
12500
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12501
+ return /* @__PURE__ */ jsx(
12502
+ Form$2.Field,
12503
+ {
12504
+ control,
12505
+ name: "shipping_option_id",
12506
+ render: ({ field }) => {
12507
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12508
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12509
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12510
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12235
12511
  ] }),
12236
12512
  /* @__PURE__ */ jsx(
12237
- Form$2.Field,
12513
+ ConditionalTooltip,
12238
12514
  {
12239
- control: form.control,
12240
- name: "province",
12241
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12242
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12243
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12244
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12245
- ] })
12515
+ content: tooltipContent,
12516
+ showTooltip: !locationId || !shippingProfileId,
12517
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12518
+ Combobox,
12519
+ {
12520
+ options: shippingOptions.options,
12521
+ fetchNextPage: shippingOptions.fetchNextPage,
12522
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12523
+ searchValue: shippingOptions.searchValue,
12524
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12525
+ placeholder: "Select shipping option",
12526
+ ...field,
12527
+ disabled: !locationId || !shippingProfileId
12528
+ }
12529
+ ) }) })
12246
12530
  }
12247
- ),
12248
- /* @__PURE__ */ jsx(
12249
- Form$2.Field,
12531
+ )
12532
+ ] }) });
12533
+ }
12534
+ }
12535
+ );
12536
+ };
12537
+ const CustomAmountField = ({
12538
+ control,
12539
+ currencyCode
12540
+ }) => {
12541
+ return /* @__PURE__ */ jsx(
12542
+ Form$2.Field,
12543
+ {
12544
+ control,
12545
+ name: "custom_amount",
12546
+ render: ({ field: { onChange, ...field } }) => {
12547
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12548
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12549
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12550
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12551
+ ] }),
12552
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12553
+ CurrencyInput,
12250
12554
  {
12251
- control: form.control,
12252
- name: "phone",
12253
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12254
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12255
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12256
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12257
- ] })
12555
+ ...field,
12556
+ onValueChange: (value) => onChange(value),
12557
+ symbol: getNativeSymbol(currencyCode),
12558
+ code: currencyCode
12258
12559
  }
12259
- )
12260
- ] }) }),
12261
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12262
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12263
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12264
- ] }) })
12265
- ]
12560
+ ) })
12561
+ ] });
12562
+ }
12266
12563
  }
12267
- ) });
12564
+ );
12268
12565
  };
12269
- const schema$3 = addressSchema;
12270
12566
  const TransferOwnership = () => {
12271
12567
  const { id } = useParams();
12272
12568
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12290,7 +12586,7 @@ const TransferOwnershipForm = ({ order }) => {
12290
12586
  defaultValues: {
12291
12587
  customer_id: order.customer_id || ""
12292
12588
  },
12293
- resolver: zodResolver(schema$2)
12589
+ resolver: zodResolver(schema)
12294
12590
  });
12295
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12296
12592
  const { handleSuccess } = useRouteModal();
@@ -12673,371 +12969,75 @@ const Illustration = () => {
12673
12969
  /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12674
12970
  "path",
12675
12971
  {
12676
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12677
- stroke: "#A1A1AA",
12678
- strokeWidth: "1.5",
12679
- strokeLinecap: "round",
12680
- strokeLinejoin: "round"
12681
- }
12682
- ) }),
12683
- /* @__PURE__ */ jsxs("defs", { children: [
12684
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12685
- "rect",
12686
- {
12687
- width: "12",
12688
- height: "12",
12689
- fill: "white",
12690
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12691
- }
12692
- ) }),
12693
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12694
- "rect",
12695
- {
12696
- width: "12",
12697
- height: "12",
12698
- fill: "white",
12699
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12700
- }
12701
- ) }),
12702
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12703
- "rect",
12704
- {
12705
- width: "12",
12706
- height: "12",
12707
- fill: "white",
12708
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12709
- }
12710
- ) }),
12711
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12712
- "rect",
12713
- {
12714
- width: "12",
12715
- height: "12",
12716
- fill: "white",
12717
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12718
- }
12719
- ) }),
12720
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12721
- "rect",
12722
- {
12723
- width: "12",
12724
- height: "12",
12725
- fill: "white",
12726
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12727
- }
12728
- ) }),
12729
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12730
- "rect",
12731
- {
12732
- width: "12",
12733
- height: "12",
12734
- fill: "white",
12735
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12736
- }
12737
- ) })
12738
- ] })
12739
- ]
12740
- }
12741
- );
12742
- };
12743
- const schema$2 = objectType({
12744
- customer_id: stringType().min(1)
12745
- });
12746
- const BillingAddress = () => {
12747
- const { id } = useParams();
12748
- const { order, isPending, isError, error } = useOrder(id, {
12749
- fields: "+billing_address"
12750
- });
12751
- if (isError) {
12752
- throw error;
12753
- }
12754
- const isReady = !isPending && !!order;
12755
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12756
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12757
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12758
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12759
- ] }),
12760
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12761
- ] });
12762
- };
12763
- const BillingAddressForm = ({ order }) => {
12764
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12765
- const form = useForm({
12766
- defaultValues: {
12767
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12768
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12769
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12770
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12771
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12772
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12773
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12774
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12775
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12776
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12777
- },
12778
- resolver: zodResolver(schema$1)
12779
- });
12780
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12781
- const { handleSuccess } = useRouteModal();
12782
- const onSubmit = form.handleSubmit(async (data) => {
12783
- await mutateAsync(
12784
- { billing_address: data },
12785
- {
12786
- onSuccess: () => {
12787
- handleSuccess();
12788
- },
12789
- onError: (error) => {
12790
- toast.error(error.message);
12791
- }
12792
- }
12793
- );
12794
- });
12795
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12796
- KeyboundForm,
12797
- {
12798
- className: "flex flex-1 flex-col overflow-hidden",
12799
- onSubmit,
12800
- children: [
12801
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12802
- /* @__PURE__ */ jsx(
12803
- Form$2.Field,
12804
- {
12805
- control: form.control,
12806
- name: "country_code",
12807
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12808
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12809
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12810
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12811
- ] })
12812
- }
12813
- ),
12814
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12815
- /* @__PURE__ */ jsx(
12816
- Form$2.Field,
12817
- {
12818
- control: form.control,
12819
- name: "first_name",
12820
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12821
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12822
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12823
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12824
- ] })
12825
- }
12826
- ),
12827
- /* @__PURE__ */ jsx(
12828
- Form$2.Field,
12829
- {
12830
- control: form.control,
12831
- name: "last_name",
12832
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12833
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12834
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12835
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12836
- ] })
12837
- }
12838
- )
12839
- ] }),
12840
- /* @__PURE__ */ jsx(
12841
- Form$2.Field,
12972
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
+ stroke: "#A1A1AA",
12974
+ strokeWidth: "1.5",
12975
+ strokeLinecap: "round",
12976
+ strokeLinejoin: "round"
12977
+ }
12978
+ ) }),
12979
+ /* @__PURE__ */ jsxs("defs", { children: [
12980
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
+ "rect",
12842
12982
  {
12843
- control: form.control,
12844
- name: "company",
12845
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12846
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12847
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12848
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12849
- ] })
12983
+ width: "12",
12984
+ height: "12",
12985
+ fill: "white",
12986
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12850
12987
  }
12851
- ),
12852
- /* @__PURE__ */ jsx(
12853
- Form$2.Field,
12988
+ ) }),
12989
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
+ "rect",
12854
12991
  {
12855
- control: form.control,
12856
- name: "address_1",
12857
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12858
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12859
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12860
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12861
- ] })
12992
+ width: "12",
12993
+ height: "12",
12994
+ fill: "white",
12995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12862
12996
  }
12863
- ),
12864
- /* @__PURE__ */ jsx(
12865
- Form$2.Field,
12997
+ ) }),
12998
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
+ "rect",
12866
13000
  {
12867
- control: form.control,
12868
- name: "address_2",
12869
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12870
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12871
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12872
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12873
- ] })
13001
+ width: "12",
13002
+ height: "12",
13003
+ fill: "white",
13004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12874
13005
  }
12875
- ),
12876
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12877
- /* @__PURE__ */ jsx(
12878
- Form$2.Field,
12879
- {
12880
- control: form.control,
12881
- name: "postal_code",
12882
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12883
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12884
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12885
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12886
- ] })
12887
- }
12888
- ),
12889
- /* @__PURE__ */ jsx(
12890
- Form$2.Field,
12891
- {
12892
- control: form.control,
12893
- name: "city",
12894
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12895
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12896
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12897
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12898
- ] })
12899
- }
12900
- )
12901
- ] }),
12902
- /* @__PURE__ */ jsx(
12903
- Form$2.Field,
13006
+ ) }),
13007
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
+ "rect",
12904
13009
  {
12905
- control: form.control,
12906
- name: "province",
12907
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12908
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12909
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12910
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12911
- ] })
13010
+ width: "12",
13011
+ height: "12",
13012
+ fill: "white",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12912
13014
  }
12913
- ),
12914
- /* @__PURE__ */ jsx(
12915
- Form$2.Field,
13015
+ ) }),
13016
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
+ "rect",
12916
13018
  {
12917
- control: form.control,
12918
- name: "phone",
12919
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12920
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12921
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12922
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12923
- ] })
13019
+ width: "12",
13020
+ height: "12",
13021
+ fill: "white",
13022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12924
13023
  }
12925
- )
12926
- ] }) }),
12927
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12928
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12929
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12930
- ] }) })
12931
- ]
12932
- }
12933
- ) });
12934
- };
12935
- const schema$1 = addressSchema;
12936
- const SalesChannel = () => {
12937
- const { id } = useParams();
12938
- const { draft_order, isPending, isError, error } = useDraftOrder(
12939
- id,
12940
- {
12941
- fields: "+sales_channel_id"
12942
- },
12943
- {
12944
- enabled: !!id
12945
- }
12946
- );
12947
- if (isError) {
12948
- throw error;
12949
- }
12950
- const ISrEADY = !!draft_order && !isPending;
12951
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12952
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12953
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12954
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12955
- ] }),
12956
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12957
- ] });
12958
- };
12959
- const SalesChannelForm = ({ order }) => {
12960
- const form = useForm({
12961
- defaultValues: {
12962
- sales_channel_id: order.sales_channel_id || ""
12963
- },
12964
- resolver: zodResolver(schema)
12965
- });
12966
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12967
- const { handleSuccess } = useRouteModal();
12968
- const onSubmit = form.handleSubmit(async (data) => {
12969
- await mutateAsync(
12970
- {
12971
- sales_channel_id: data.sales_channel_id
12972
- },
12973
- {
12974
- onSuccess: () => {
12975
- toast.success("Sales channel updated");
12976
- handleSuccess();
12977
- },
12978
- onError: (error) => {
12979
- toast.error(error.message);
12980
- }
12981
- }
12982
- );
12983
- });
12984
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12985
- KeyboundForm,
12986
- {
12987
- className: "flex flex-1 flex-col overflow-hidden",
12988
- onSubmit,
12989
- children: [
12990
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12991
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12992
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12993
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12994
- ] }) })
12995
- ]
12996
- }
12997
- ) });
12998
- };
12999
- const SalesChannelField = ({ control, order }) => {
13000
- const salesChannels = useComboboxData({
13001
- queryFn: async (params) => {
13002
- return await sdk.admin.salesChannel.list(params);
13003
- },
13004
- queryKey: ["sales-channels"],
13005
- getOptions: (data) => {
13006
- return data.sales_channels.map((salesChannel) => ({
13007
- label: salesChannel.name,
13008
- value: salesChannel.id
13009
- }));
13010
- },
13011
- defaultValue: order.sales_channel_id || void 0
13012
- });
13013
- return /* @__PURE__ */ jsx(
13014
- Form$2.Field,
13015
- {
13016
- control,
13017
- name: "sales_channel_id",
13018
- render: ({ field }) => {
13019
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13020
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13021
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13022
- Combobox,
13024
+ ) }),
13025
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
+ "rect",
13023
13027
  {
13024
- options: salesChannels.options,
13025
- fetchNextPage: salesChannels.fetchNextPage,
13026
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13027
- searchValue: salesChannels.searchValue,
13028
- onSearchValueChange: salesChannels.onSearchValueChange,
13029
- placeholder: "Select sales channel",
13030
- ...field
13028
+ width: "12",
13029
+ height: "12",
13030
+ fill: "white",
13031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13031
13032
  }
13032
- ) }),
13033
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13034
- ] });
13035
- }
13033
+ ) })
13034
+ ] })
13035
+ ]
13036
13036
  }
13037
13037
  );
13038
13038
  };
13039
13039
  const schema = objectType({
13040
- sales_channel_id: stringType().min(1)
13040
+ customer_id: stringType().min(1)
13041
13041
  });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
@@ -13063,6 +13063,10 @@ const routeModule = {
13063
13063
  Component: CustomItems,
13064
13064
  path: "/draft-orders/:id/custom-items"
13065
13065
  },
13066
+ {
13067
+ Component: BillingAddress,
13068
+ path: "/draft-orders/:id/billing-address"
13069
+ },
13066
13070
  {
13067
13071
  Component: Email,
13068
13072
  path: "/draft-orders/:id/email"
@@ -13080,24 +13084,20 @@ const routeModule = {
13080
13084
  path: "/draft-orders/:id/promotions"
13081
13085
  },
13082
13086
  {
13083
- Component: Shipping,
13084
- path: "/draft-orders/:id/shipping"
13087
+ Component: SalesChannel,
13088
+ path: "/draft-orders/:id/sales-channel"
13085
13089
  },
13086
13090
  {
13087
13091
  Component: ShippingAddress,
13088
13092
  path: "/draft-orders/:id/shipping-address"
13089
13093
  },
13090
13094
  {
13091
- Component: TransferOwnership,
13092
- path: "/draft-orders/:id/transfer-ownership"
13093
- },
13094
- {
13095
- Component: BillingAddress,
13096
- path: "/draft-orders/:id/billing-address"
13095
+ Component: Shipping,
13096
+ path: "/draft-orders/:id/shipping"
13097
13097
  },
13098
13098
  {
13099
- Component: SalesChannel,
13100
- path: "/draft-orders/:id/sales-channel"
13099
+ Component: TransferOwnership,
13100
+ path: "/draft-orders/:id/transfer-ownership"
13101
13101
  }
13102
13102
  ]
13103
13103
  }