@medusajs/draft-order 2.10.4-preview-20251011090154 → 2.10.4-preview-20251011120205

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.
@@ -9567,217 +9567,6 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const BillingAddress = () => {
9571
- const { id } = useParams();
9572
- const { order, isPending, isError, error } = useOrder(id, {
9573
- fields: "+billing_address"
9574
- });
9575
- if (isError) {
9576
- throw error;
9577
- }
9578
- const isReady = !isPending && !!order;
9579
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
- ] }),
9584
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9585
- ] });
9586
- };
9587
- const BillingAddressForm = ({ order }) => {
9588
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9589
- const form = useForm({
9590
- defaultValues: {
9591
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
- },
9602
- resolver: zodResolver(schema$5)
9603
- });
9604
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
- const { handleSuccess } = useRouteModal();
9606
- const onSubmit = form.handleSubmit(async (data) => {
9607
- await mutateAsync(
9608
- { billing_address: data },
9609
- {
9610
- onSuccess: () => {
9611
- handleSuccess();
9612
- },
9613
- onError: (error) => {
9614
- toast.error(error.message);
9615
- }
9616
- }
9617
- );
9618
- });
9619
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
- KeyboundForm,
9621
- {
9622
- className: "flex flex-1 flex-col overflow-hidden",
9623
- onSubmit,
9624
- children: [
9625
- /* @__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: [
9626
- /* @__PURE__ */ jsx(
9627
- Form$2.Field,
9628
- {
9629
- control: form.control,
9630
- name: "country_code",
9631
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
- ] })
9636
- }
9637
- ),
9638
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
- /* @__PURE__ */ jsx(
9640
- Form$2.Field,
9641
- {
9642
- control: form.control,
9643
- name: "first_name",
9644
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
- ] })
9649
- }
9650
- ),
9651
- /* @__PURE__ */ jsx(
9652
- Form$2.Field,
9653
- {
9654
- control: form.control,
9655
- name: "last_name",
9656
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
- ] })
9661
- }
9662
- )
9663
- ] }),
9664
- /* @__PURE__ */ jsx(
9665
- Form$2.Field,
9666
- {
9667
- control: form.control,
9668
- name: "company",
9669
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
- ] })
9674
- }
9675
- ),
9676
- /* @__PURE__ */ jsx(
9677
- Form$2.Field,
9678
- {
9679
- control: form.control,
9680
- name: "address_1",
9681
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
- ] })
9686
- }
9687
- ),
9688
- /* @__PURE__ */ jsx(
9689
- Form$2.Field,
9690
- {
9691
- control: form.control,
9692
- name: "address_2",
9693
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
- ] })
9698
- }
9699
- ),
9700
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
- /* @__PURE__ */ jsx(
9702
- Form$2.Field,
9703
- {
9704
- control: form.control,
9705
- name: "postal_code",
9706
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
- ] })
9711
- }
9712
- ),
9713
- /* @__PURE__ */ jsx(
9714
- Form$2.Field,
9715
- {
9716
- control: form.control,
9717
- name: "city",
9718
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
- ] })
9723
- }
9724
- )
9725
- ] }),
9726
- /* @__PURE__ */ jsx(
9727
- Form$2.Field,
9728
- {
9729
- control: form.control,
9730
- name: "province",
9731
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
- ] })
9736
- }
9737
- ),
9738
- /* @__PURE__ */ jsx(
9739
- Form$2.Field,
9740
- {
9741
- control: form.control,
9742
- name: "phone",
9743
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
- ] })
9748
- }
9749
- )
9750
- ] }) }),
9751
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
- ] }) })
9755
- ]
9756
- }
9757
- ) });
9758
- };
9759
- const schema$5 = addressSchema;
9760
- const CustomItems = () => {
9761
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
- ] });
9765
- };
9766
- const CustomItemsForm = () => {
9767
- const form = useForm({
9768
- resolver: zodResolver(schema$4)
9769
- });
9770
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
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", children: "Save" })
9775
- ] }) })
9776
- ] }) });
9777
- };
9778
- const schema$4 = objectType({
9779
- email: stringType().email()
9780
- });
9781
9570
  const Email = () => {
9782
9571
  const { id } = useParams();
9783
9572
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9800,7 +9589,7 @@ const EmailForm = ({ order }) => {
9800
9589
  defaultValues: {
9801
9590
  email: order.email ?? ""
9802
9591
  },
9803
- resolver: zodResolver(schema$3)
9592
+ resolver: zodResolver(schema$5)
9804
9593
  });
9805
9594
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
9595
  const { handleSuccess } = useRouteModal();
@@ -9843,7 +9632,7 @@ const EmailForm = ({ order }) => {
9843
9632
  }
9844
9633
  ) });
9845
9634
  };
9846
- const schema$3 = objectType({
9635
+ const schema$5 = objectType({
9847
9636
  email: stringType().email()
9848
9637
  });
9849
9638
  const NumberInput = forwardRef(
@@ -11447,44 +11236,150 @@ function getPromotionIds(items, shippingMethods) {
11447
11236
  }
11448
11237
  return Array.from(promotionIds);
11449
11238
  }
11450
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11451
- const Shipping = () => {
11452
- var _a;
11239
+ const SalesChannel = () => {
11453
11240
  const { id } = useParams();
11454
- const { order, isPending, isError, error } = useOrder(id, {
11455
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11456
- });
11457
- const {
11458
- order: preview,
11459
- isPending: isPreviewPending,
11460
- isError: isPreviewError,
11461
- error: previewError
11462
- } = useOrderPreview(id);
11463
- useInitiateOrderEdit({ preview });
11464
- const { onCancel } = useCancelOrderEdit({ preview });
11241
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11242
+ id,
11243
+ {
11244
+ fields: "+sales_channel_id"
11245
+ },
11246
+ {
11247
+ enabled: !!id
11248
+ }
11249
+ );
11465
11250
  if (isError) {
11466
11251
  throw error;
11467
11252
  }
11468
- if (isPreviewError) {
11469
- throw previewError;
11470
- }
11471
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11472
- const isReady = preview && !isPreviewPending && order && !isPending;
11473
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11474
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11475
- /* @__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: [
11476
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11477
- /* @__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." }) })
11478
- ] }) }) }),
11479
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11480
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11481
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11482
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11483
- ] }) });
11484
- };
11485
- const ShippingForm = ({ preview, order }) => {
11486
- var _a;
11487
- const { setIsOpen } = useStackedModal();
11253
+ const ISrEADY = !!draft_order && !isPending;
11254
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11255
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11256
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11257
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11258
+ ] }),
11259
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11260
+ ] });
11261
+ };
11262
+ const SalesChannelForm = ({ order }) => {
11263
+ const form = useForm({
11264
+ defaultValues: {
11265
+ sales_channel_id: order.sales_channel_id || ""
11266
+ },
11267
+ resolver: zodResolver(schema$4)
11268
+ });
11269
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11270
+ const { handleSuccess } = useRouteModal();
11271
+ const onSubmit = form.handleSubmit(async (data) => {
11272
+ await mutateAsync(
11273
+ {
11274
+ sales_channel_id: data.sales_channel_id
11275
+ },
11276
+ {
11277
+ onSuccess: () => {
11278
+ toast.success("Sales channel updated");
11279
+ handleSuccess();
11280
+ },
11281
+ onError: (error) => {
11282
+ toast.error(error.message);
11283
+ }
11284
+ }
11285
+ );
11286
+ });
11287
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11288
+ KeyboundForm,
11289
+ {
11290
+ className: "flex flex-1 flex-col overflow-hidden",
11291
+ onSubmit,
11292
+ children: [
11293
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11294
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11295
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11296
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11297
+ ] }) })
11298
+ ]
11299
+ }
11300
+ ) });
11301
+ };
11302
+ const SalesChannelField = ({ control, order }) => {
11303
+ const salesChannels = useComboboxData({
11304
+ queryFn: async (params) => {
11305
+ return await sdk.admin.salesChannel.list(params);
11306
+ },
11307
+ queryKey: ["sales-channels"],
11308
+ getOptions: (data) => {
11309
+ return data.sales_channels.map((salesChannel) => ({
11310
+ label: salesChannel.name,
11311
+ value: salesChannel.id
11312
+ }));
11313
+ },
11314
+ defaultValue: order.sales_channel_id || void 0
11315
+ });
11316
+ return /* @__PURE__ */ jsx(
11317
+ Form$2.Field,
11318
+ {
11319
+ control,
11320
+ name: "sales_channel_id",
11321
+ render: ({ field }) => {
11322
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11323
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11324
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11325
+ Combobox,
11326
+ {
11327
+ options: salesChannels.options,
11328
+ fetchNextPage: salesChannels.fetchNextPage,
11329
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11330
+ searchValue: salesChannels.searchValue,
11331
+ onSearchValueChange: salesChannels.onSearchValueChange,
11332
+ placeholder: "Select sales channel",
11333
+ ...field
11334
+ }
11335
+ ) }),
11336
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11337
+ ] });
11338
+ }
11339
+ }
11340
+ );
11341
+ };
11342
+ const schema$4 = objectType({
11343
+ sales_channel_id: stringType().min(1)
11344
+ });
11345
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11346
+ const Shipping = () => {
11347
+ var _a;
11348
+ const { id } = useParams();
11349
+ const { order, isPending, isError, error } = useOrder(id, {
11350
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11351
+ });
11352
+ const {
11353
+ order: preview,
11354
+ isPending: isPreviewPending,
11355
+ isError: isPreviewError,
11356
+ error: previewError
11357
+ } = useOrderPreview(id);
11358
+ useInitiateOrderEdit({ preview });
11359
+ const { onCancel } = useCancelOrderEdit({ preview });
11360
+ if (isError) {
11361
+ throw error;
11362
+ }
11363
+ if (isPreviewError) {
11364
+ throw previewError;
11365
+ }
11366
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11367
+ const isReady = preview && !isPreviewPending && order && !isPending;
11368
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11369
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11370
+ /* @__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: [
11371
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11372
+ /* @__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." }) })
11373
+ ] }) }) }),
11374
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11375
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11376
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11377
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11378
+ ] }) });
11379
+ };
11380
+ const ShippingForm = ({ preview, order }) => {
11381
+ var _a;
11382
+ const { setIsOpen } = useStackedModal();
11488
11383
  const [isSubmitting, setIsSubmitting] = useState(false);
11489
11384
  const [data, setData] = useState(null);
11490
11385
  const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
@@ -12254,112 +12149,6 @@ const CustomAmountField = ({
12254
12149
  }
12255
12150
  );
12256
12151
  };
12257
- const SalesChannel = () => {
12258
- const { id } = useParams();
12259
- const { draft_order, isPending, isError, error } = useDraftOrder(
12260
- id,
12261
- {
12262
- fields: "+sales_channel_id"
12263
- },
12264
- {
12265
- enabled: !!id
12266
- }
12267
- );
12268
- if (isError) {
12269
- throw error;
12270
- }
12271
- const ISrEADY = !!draft_order && !isPending;
12272
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12273
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12274
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12275
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12276
- ] }),
12277
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12278
- ] });
12279
- };
12280
- const SalesChannelForm = ({ order }) => {
12281
- const form = useForm({
12282
- defaultValues: {
12283
- sales_channel_id: order.sales_channel_id || ""
12284
- },
12285
- resolver: zodResolver(schema$2)
12286
- });
12287
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12288
- const { handleSuccess } = useRouteModal();
12289
- const onSubmit = form.handleSubmit(async (data) => {
12290
- await mutateAsync(
12291
- {
12292
- sales_channel_id: data.sales_channel_id
12293
- },
12294
- {
12295
- onSuccess: () => {
12296
- toast.success("Sales channel updated");
12297
- handleSuccess();
12298
- },
12299
- onError: (error) => {
12300
- toast.error(error.message);
12301
- }
12302
- }
12303
- );
12304
- });
12305
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12306
- KeyboundForm,
12307
- {
12308
- className: "flex flex-1 flex-col overflow-hidden",
12309
- onSubmit,
12310
- children: [
12311
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12312
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12313
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12314
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12315
- ] }) })
12316
- ]
12317
- }
12318
- ) });
12319
- };
12320
- const SalesChannelField = ({ control, order }) => {
12321
- const salesChannels = useComboboxData({
12322
- queryFn: async (params) => {
12323
- return await sdk.admin.salesChannel.list(params);
12324
- },
12325
- queryKey: ["sales-channels"],
12326
- getOptions: (data) => {
12327
- return data.sales_channels.map((salesChannel) => ({
12328
- label: salesChannel.name,
12329
- value: salesChannel.id
12330
- }));
12331
- },
12332
- defaultValue: order.sales_channel_id || void 0
12333
- });
12334
- return /* @__PURE__ */ jsx(
12335
- Form$2.Field,
12336
- {
12337
- control,
12338
- name: "sales_channel_id",
12339
- render: ({ field }) => {
12340
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12341
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12342
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12343
- Combobox,
12344
- {
12345
- options: salesChannels.options,
12346
- fetchNextPage: salesChannels.fetchNextPage,
12347
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12348
- searchValue: salesChannels.searchValue,
12349
- onSearchValueChange: salesChannels.onSearchValueChange,
12350
- placeholder: "Select sales channel",
12351
- ...field
12352
- }
12353
- ) }),
12354
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12355
- ] });
12356
- }
12357
- }
12358
- );
12359
- };
12360
- const schema$2 = objectType({
12361
- sales_channel_id: stringType().min(1)
12362
- });
12363
12152
  const ShippingAddress = () => {
12364
12153
  const { id } = useParams();
12365
12154
  const { order, isPending, isError, error } = useOrder(id, {
@@ -12392,7 +12181,7 @@ const ShippingAddressForm = ({ order }) => {
12392
12181
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
12182
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12394
12183
  },
12395
- resolver: zodResolver(schema$1)
12184
+ resolver: zodResolver(schema$3)
12396
12185
  });
12397
12186
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
12187
  const { handleSuccess } = useRouteModal();
@@ -12562,7 +12351,7 @@ const ShippingAddressForm = ({ order }) => {
12562
12351
  }
12563
12352
  ) });
12564
12353
  };
12565
- const schema$1 = addressSchema;
12354
+ const schema$3 = addressSchema;
12566
12355
  const TransferOwnership = () => {
12567
12356
  const { id } = useParams();
12568
12357
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12586,7 +12375,7 @@ const TransferOwnershipForm = ({ order }) => {
12586
12375
  defaultValues: {
12587
12376
  customer_id: order.customer_id || ""
12588
12377
  },
12589
- resolver: zodResolver(schema)
12378
+ resolver: zodResolver(schema$2)
12590
12379
  });
12591
12380
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
12381
  const { handleSuccess } = useRouteModal();
@@ -13036,9 +12825,220 @@ const Illustration = () => {
13036
12825
  }
13037
12826
  );
13038
12827
  };
13039
- const schema = objectType({
12828
+ const schema$2 = objectType({
13040
12829
  customer_id: stringType().min(1)
13041
12830
  });
12831
+ const BillingAddress = () => {
12832
+ const { id } = useParams();
12833
+ const { order, isPending, isError, error } = useOrder(id, {
12834
+ fields: "+billing_address"
12835
+ });
12836
+ if (isError) {
12837
+ throw error;
12838
+ }
12839
+ const isReady = !isPending && !!order;
12840
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12841
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12842
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12843
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12844
+ ] }),
12845
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12846
+ ] });
12847
+ };
12848
+ const BillingAddressForm = ({ order }) => {
12849
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12850
+ const form = useForm({
12851
+ defaultValues: {
12852
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12853
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12854
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12855
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12856
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12857
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12858
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12859
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12860
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12861
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12862
+ },
12863
+ resolver: zodResolver(schema$1)
12864
+ });
12865
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12866
+ const { handleSuccess } = useRouteModal();
12867
+ const onSubmit = form.handleSubmit(async (data) => {
12868
+ await mutateAsync(
12869
+ { billing_address: data },
12870
+ {
12871
+ onSuccess: () => {
12872
+ handleSuccess();
12873
+ },
12874
+ onError: (error) => {
12875
+ toast.error(error.message);
12876
+ }
12877
+ }
12878
+ );
12879
+ });
12880
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12881
+ KeyboundForm,
12882
+ {
12883
+ className: "flex flex-1 flex-col overflow-hidden",
12884
+ onSubmit,
12885
+ children: [
12886
+ /* @__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: [
12887
+ /* @__PURE__ */ jsx(
12888
+ Form$2.Field,
12889
+ {
12890
+ control: form.control,
12891
+ name: "country_code",
12892
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12893
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12894
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12895
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12896
+ ] })
12897
+ }
12898
+ ),
12899
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12900
+ /* @__PURE__ */ jsx(
12901
+ Form$2.Field,
12902
+ {
12903
+ control: form.control,
12904
+ name: "first_name",
12905
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12906
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12907
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12908
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12909
+ ] })
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ Form$2.Field,
12914
+ {
12915
+ control: form.control,
12916
+ name: "last_name",
12917
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12918
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12919
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12920
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12921
+ ] })
12922
+ }
12923
+ )
12924
+ ] }),
12925
+ /* @__PURE__ */ jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "company",
12930
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12931
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12932
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12933
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12934
+ ] })
12935
+ }
12936
+ ),
12937
+ /* @__PURE__ */ jsx(
12938
+ Form$2.Field,
12939
+ {
12940
+ control: form.control,
12941
+ name: "address_1",
12942
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12943
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12944
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12945
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12946
+ ] })
12947
+ }
12948
+ ),
12949
+ /* @__PURE__ */ jsx(
12950
+ Form$2.Field,
12951
+ {
12952
+ control: form.control,
12953
+ name: "address_2",
12954
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12955
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12956
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12957
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12958
+ ] })
12959
+ }
12960
+ ),
12961
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12962
+ /* @__PURE__ */ jsx(
12963
+ Form$2.Field,
12964
+ {
12965
+ control: form.control,
12966
+ name: "postal_code",
12967
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12968
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12969
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12970
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12971
+ ] })
12972
+ }
12973
+ ),
12974
+ /* @__PURE__ */ jsx(
12975
+ Form$2.Field,
12976
+ {
12977
+ control: form.control,
12978
+ name: "city",
12979
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12980
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12981
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12982
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12983
+ ] })
12984
+ }
12985
+ )
12986
+ ] }),
12987
+ /* @__PURE__ */ jsx(
12988
+ Form$2.Field,
12989
+ {
12990
+ control: form.control,
12991
+ name: "province",
12992
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12993
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12994
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12995
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12996
+ ] })
12997
+ }
12998
+ ),
12999
+ /* @__PURE__ */ jsx(
13000
+ Form$2.Field,
13001
+ {
13002
+ control: form.control,
13003
+ name: "phone",
13004
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13005
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13006
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13007
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13008
+ ] })
13009
+ }
13010
+ )
13011
+ ] }) }),
13012
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13013
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13014
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13015
+ ] }) })
13016
+ ]
13017
+ }
13018
+ ) });
13019
+ };
13020
+ const schema$1 = addressSchema;
13021
+ const CustomItems = () => {
13022
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
13023
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
13024
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
13025
+ ] });
13026
+ };
13027
+ const CustomItemsForm = () => {
13028
+ const form = useForm({
13029
+ resolver: zodResolver(schema)
13030
+ });
13031
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13032
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
13033
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
13036
+ ] }) })
13037
+ ] }) });
13038
+ };
13039
+ const schema = objectType({
13040
+ email: stringType().email()
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,14 +13059,6 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
- {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13065
- },
13066
- {
13067
- Component: CustomItems,
13068
- path: "/draft-orders/:id/custom-items"
13069
- },
13070
13062
  {
13071
13063
  Component: Email,
13072
13064
  path: "/draft-orders/:id/email"
@@ -13083,14 +13075,14 @@ const routeModule = {
13083
13075
  Component: Promotions,
13084
13076
  path: "/draft-orders/:id/promotions"
13085
13077
  },
13086
- {
13087
- Component: Shipping,
13088
- path: "/draft-orders/:id/shipping"
13089
- },
13090
13078
  {
13091
13079
  Component: SalesChannel,
13092
13080
  path: "/draft-orders/:id/sales-channel"
13093
13081
  },
13082
+ {
13083
+ Component: Shipping,
13084
+ path: "/draft-orders/:id/shipping"
13085
+ },
13094
13086
  {
13095
13087
  Component: ShippingAddress,
13096
13088
  path: "/draft-orders/:id/shipping-address"
@@ -13098,6 +13090,14 @@ const routeModule = {
13098
13090
  {
13099
13091
  Component: TransferOwnership,
13100
13092
  path: "/draft-orders/:id/transfer-ownership"
13093
+ },
13094
+ {
13095
+ Component: BillingAddress,
13096
+ path: "/draft-orders/:id/billing-address"
13097
+ },
13098
+ {
13099
+ Component: CustomItems,
13100
+ path: "/draft-orders/:id/custom-items"
13101
13101
  }
13102
13102
  ]
13103
13103
  }