@medusajs/draft-order 2.10.4-preview-20250928210151 → 2.10.4-preview-20250929000333

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,6 +9567,196 @@ 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;
9570
9760
  const CustomItems = () => {
9571
9761
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
9762
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9575,7 +9765,7 @@ const CustomItems = () => {
9575
9765
  };
9576
9766
  const CustomItemsForm = () => {
9577
9767
  const form = useForm({
9578
- resolver: zodResolver(schema$5)
9768
+ resolver: zodResolver(schema$4)
9579
9769
  });
9580
9770
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
9771
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9585,7 +9775,7 @@ const CustomItemsForm = () => {
9585
9775
  ] }) })
9586
9776
  ] }) });
9587
9777
  };
9588
- const schema$5 = objectType({
9778
+ const schema$4 = objectType({
9589
9779
  email: stringType().email()
9590
9780
  });
9591
9781
  const Email = () => {
@@ -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,336 +11447,40 @@ function getPromotionIds(items, shippingMethods) {
11257
11447
  }
11258
11448
  return Array.from(promotionIds);
11259
11449
  }
11260
- const BillingAddress = () => {
11450
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11451
+ const Shipping = () => {
11452
+ var _a;
11261
11453
  const { id } = useParams();
11262
11454
  const { order, isPending, isError, error } = useOrder(id, {
11263
- fields: "+billing_address"
11455
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11264
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 });
11265
11465
  if (isError) {
11266
11466
  throw error;
11267
11467
  }
11268
- const isReady = !isPending && !!order;
11269
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11270
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11271
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
11272
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
11273
- ] }),
11274
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
11275
- ] });
11276
- };
11277
- const BillingAddressForm = ({ order }) => {
11278
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11279
- const form = useForm({
11280
- defaultValues: {
11281
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
11282
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
11283
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
11284
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
11285
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
11286
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
11287
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
11288
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
11289
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11290
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11291
- },
11292
- resolver: zodResolver(schema$3)
11293
- });
11294
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11295
- const { handleSuccess } = useRouteModal();
11296
- const onSubmit = form.handleSubmit(async (data) => {
11297
- await mutateAsync(
11298
- { billing_address: data },
11299
- {
11300
- onSuccess: () => {
11301
- handleSuccess();
11302
- },
11303
- onError: (error) => {
11304
- toast.error(error.message);
11305
- }
11306
- }
11307
- );
11308
- });
11309
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11310
- KeyboundForm,
11311
- {
11312
- className: "flex flex-1 flex-col overflow-hidden",
11313
- onSubmit,
11314
- children: [
11315
- /* @__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: [
11316
- /* @__PURE__ */ jsx(
11317
- Form$2.Field,
11318
- {
11319
- control: form.control,
11320
- name: "country_code",
11321
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11322
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11323
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11324
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11325
- ] })
11326
- }
11327
- ),
11328
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11329
- /* @__PURE__ */ jsx(
11330
- Form$2.Field,
11331
- {
11332
- control: form.control,
11333
- name: "first_name",
11334
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11335
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11336
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11337
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11338
- ] })
11339
- }
11340
- ),
11341
- /* @__PURE__ */ jsx(
11342
- Form$2.Field,
11343
- {
11344
- control: form.control,
11345
- name: "last_name",
11346
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11347
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11348
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11349
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11350
- ] })
11351
- }
11352
- )
11353
- ] }),
11354
- /* @__PURE__ */ jsx(
11355
- Form$2.Field,
11356
- {
11357
- control: form.control,
11358
- name: "company",
11359
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11360
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11361
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11362
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11363
- ] })
11364
- }
11365
- ),
11366
- /* @__PURE__ */ jsx(
11367
- Form$2.Field,
11368
- {
11369
- control: form.control,
11370
- name: "address_1",
11371
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11372
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11373
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11374
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11375
- ] })
11376
- }
11377
- ),
11378
- /* @__PURE__ */ jsx(
11379
- Form$2.Field,
11380
- {
11381
- control: form.control,
11382
- name: "address_2",
11383
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11384
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11385
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11386
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11387
- ] })
11388
- }
11389
- ),
11390
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11391
- /* @__PURE__ */ jsx(
11392
- Form$2.Field,
11393
- {
11394
- control: form.control,
11395
- name: "postal_code",
11396
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11397
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11398
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11399
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11400
- ] })
11401
- }
11402
- ),
11403
- /* @__PURE__ */ jsx(
11404
- Form$2.Field,
11405
- {
11406
- control: form.control,
11407
- name: "city",
11408
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11409
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11410
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11411
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11412
- ] })
11413
- }
11414
- )
11415
- ] }),
11416
- /* @__PURE__ */ jsx(
11417
- Form$2.Field,
11418
- {
11419
- control: form.control,
11420
- name: "province",
11421
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11422
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11423
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11424
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11425
- ] })
11426
- }
11427
- ),
11428
- /* @__PURE__ */ jsx(
11429
- Form$2.Field,
11430
- {
11431
- control: form.control,
11432
- name: "phone",
11433
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11434
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11435
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11436
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11437
- ] })
11438
- }
11439
- )
11440
- ] }) }),
11441
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11442
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11443
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11444
- ] }) })
11445
- ]
11446
- }
11447
- ) });
11448
- };
11449
- const schema$3 = addressSchema;
11450
- const SalesChannel = () => {
11451
- const { id } = useParams();
11452
- const { draft_order, isPending, isError, error } = useDraftOrder(
11453
- id,
11454
- {
11455
- fields: "+sales_channel_id"
11456
- },
11457
- {
11458
- enabled: !!id
11459
- }
11460
- );
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 STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
- const Shipping = () => {
11558
- var _a;
11559
- const { id } = useParams();
11560
- const { order, isPending, isError, error } = useOrder(id, {
11561
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11562
- });
11563
- const {
11564
- order: preview,
11565
- isPending: isPreviewPending,
11566
- isError: isPreviewError,
11567
- error: previewError
11568
- } = useOrderPreview(id);
11569
- useInitiateOrderEdit({ preview });
11570
- const { onCancel } = useCancelOrderEdit({ preview });
11571
- if (isError) {
11572
- throw error;
11573
- }
11574
- if (isPreviewError) {
11575
- throw previewError;
11576
- }
11577
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
- const isReady = preview && !isPreviewPending && order && !isPending;
11579
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
- /* @__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: [
11582
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11583
- /* @__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." }) })
11584
- ] }) }) }),
11585
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11586
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11587
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11588
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11589
- ] }) });
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
+ ] }) });
11590
11484
  };
11591
11485
  const ShippingForm = ({ preview, order }) => {
11592
11486
  var _a;
@@ -12360,6 +12254,112 @@ const CustomAmountField = ({
12360
12254
  }
12361
12255
  );
12362
12256
  };
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
12363
  const ShippingAddress = () => {
12364
12364
  const { id } = useParams();
12365
12365
  const { order, isPending, isError, error } = useOrder(id, {
@@ -13059,6 +13059,10 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
+ {
13063
+ Component: BillingAddress,
13064
+ path: "/draft-orders/:id/billing-address"
13065
+ },
13062
13066
  {
13063
13067
  Component: CustomItems,
13064
13068
  path: "/draft-orders/:id/custom-items"
@@ -13080,17 +13084,13 @@ const routeModule = {
13080
13084
  path: "/draft-orders/:id/promotions"
13081
13085
  },
13082
13086
  {
13083
- Component: BillingAddress,
13084
- path: "/draft-orders/:id/billing-address"
13087
+ Component: Shipping,
13088
+ path: "/draft-orders/:id/shipping"
13085
13089
  },
13086
13090
  {
13087
13091
  Component: SalesChannel,
13088
13092
  path: "/draft-orders/:id/sales-channel"
13089
13093
  },
13090
- {
13091
- Component: Shipping,
13092
- path: "/draft-orders/:id/shipping"
13093
- },
13094
13094
  {
13095
13095
  Component: ShippingAddress,
13096
13096
  path: "/draft-orders/:id/shipping-address"