@medusajs/draft-order 2.12.2-preview-20251204000309 → 2.12.2-preview-20251204032622

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.
@@ -9572,6 +9572,196 @@ const ID = () => {
9572
9572
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9573
9573
  ] });
9574
9574
  };
9575
+ const BillingAddress = () => {
9576
+ const { id } = reactRouterDom.useParams();
9577
+ const { order, isPending, isError, error } = useOrder(id, {
9578
+ fields: "+billing_address"
9579
+ });
9580
+ if (isError) {
9581
+ throw error;
9582
+ }
9583
+ const isReady = !isPending && !!order;
9584
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9585
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9588
+ ] }),
9589
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9590
+ ] });
9591
+ };
9592
+ const BillingAddressForm = ({ order }) => {
9593
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9594
+ const form = reactHookForm.useForm({
9595
+ defaultValues: {
9596
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9597
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9598
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9599
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9600
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9601
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9602
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9603
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9604
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9605
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9606
+ },
9607
+ resolver: zod.zodResolver(schema$5)
9608
+ });
9609
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9610
+ const { handleSuccess } = useRouteModal();
9611
+ const onSubmit = form.handleSubmit(async (data) => {
9612
+ await mutateAsync(
9613
+ { billing_address: data },
9614
+ {
9615
+ onSuccess: () => {
9616
+ handleSuccess();
9617
+ },
9618
+ onError: (error) => {
9619
+ ui.toast.error(error.message);
9620
+ }
9621
+ }
9622
+ );
9623
+ });
9624
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9625
+ KeyboundForm,
9626
+ {
9627
+ className: "flex flex-1 flex-col overflow-hidden",
9628
+ onSubmit,
9629
+ children: [
9630
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9631
+ /* @__PURE__ */ jsxRuntime.jsx(
9632
+ Form$2.Field,
9633
+ {
9634
+ control: form.control,
9635
+ name: "country_code",
9636
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9640
+ ] })
9641
+ }
9642
+ ),
9643
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9644
+ /* @__PURE__ */ jsxRuntime.jsx(
9645
+ Form$2.Field,
9646
+ {
9647
+ control: form.control,
9648
+ name: "first_name",
9649
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9653
+ ] })
9654
+ }
9655
+ ),
9656
+ /* @__PURE__ */ jsxRuntime.jsx(
9657
+ Form$2.Field,
9658
+ {
9659
+ control: form.control,
9660
+ name: "last_name",
9661
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9664
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9665
+ ] })
9666
+ }
9667
+ )
9668
+ ] }),
9669
+ /* @__PURE__ */ jsxRuntime.jsx(
9670
+ Form$2.Field,
9671
+ {
9672
+ control: form.control,
9673
+ name: "company",
9674
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9678
+ ] })
9679
+ }
9680
+ ),
9681
+ /* @__PURE__ */ jsxRuntime.jsx(
9682
+ Form$2.Field,
9683
+ {
9684
+ control: form.control,
9685
+ name: "address_1",
9686
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9689
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9690
+ ] })
9691
+ }
9692
+ ),
9693
+ /* @__PURE__ */ jsxRuntime.jsx(
9694
+ Form$2.Field,
9695
+ {
9696
+ control: form.control,
9697
+ name: "address_2",
9698
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9702
+ ] })
9703
+ }
9704
+ ),
9705
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9706
+ /* @__PURE__ */ jsxRuntime.jsx(
9707
+ Form$2.Field,
9708
+ {
9709
+ control: form.control,
9710
+ name: "postal_code",
9711
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9715
+ ] })
9716
+ }
9717
+ ),
9718
+ /* @__PURE__ */ jsxRuntime.jsx(
9719
+ Form$2.Field,
9720
+ {
9721
+ control: form.control,
9722
+ name: "city",
9723
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9727
+ ] })
9728
+ }
9729
+ )
9730
+ ] }),
9731
+ /* @__PURE__ */ jsxRuntime.jsx(
9732
+ Form$2.Field,
9733
+ {
9734
+ control: form.control,
9735
+ name: "province",
9736
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9740
+ ] })
9741
+ }
9742
+ ),
9743
+ /* @__PURE__ */ jsxRuntime.jsx(
9744
+ Form$2.Field,
9745
+ {
9746
+ control: form.control,
9747
+ name: "phone",
9748
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9752
+ ] })
9753
+ }
9754
+ )
9755
+ ] }) }),
9756
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9757
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9758
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9759
+ ] }) })
9760
+ ]
9761
+ }
9762
+ ) });
9763
+ };
9764
+ const schema$5 = addressSchema;
9575
9765
  const CustomItems = () => {
9576
9766
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9577
9767
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9580,7 +9770,7 @@ const CustomItems = () => {
9580
9770
  };
9581
9771
  const CustomItemsForm = () => {
9582
9772
  const form = reactHookForm.useForm({
9583
- resolver: zod.zodResolver(schema$5)
9773
+ resolver: zod.zodResolver(schema$4)
9584
9774
  });
9585
9775
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9586
9776
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9590,7 +9780,7 @@ const CustomItemsForm = () => {
9590
9780
  ] }) })
9591
9781
  ] }) });
9592
9782
  };
9593
- const schema$5 = objectType({
9783
+ const schema$4 = objectType({
9594
9784
  email: stringType().email()
9595
9785
  });
9596
9786
  const Email = () => {
@@ -9615,7 +9805,7 @@ const EmailForm = ({ order }) => {
9615
9805
  defaultValues: {
9616
9806
  email: order.email ?? ""
9617
9807
  },
9618
- resolver: zod.zodResolver(schema$4)
9808
+ resolver: zod.zodResolver(schema$3)
9619
9809
  });
9620
9810
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9621
9811
  const { handleSuccess } = useRouteModal();
@@ -9658,7 +9848,7 @@ const EmailForm = ({ order }) => {
9658
9848
  }
9659
9849
  ) });
9660
9850
  };
9661
- const schema$4 = objectType({
9851
+ const schema$3 = objectType({
9662
9852
  email: stringType().email()
9663
9853
  });
9664
9854
  const NumberInput = React.forwardRef(
@@ -11262,230 +11452,40 @@ function getPromotionIds(items, shippingMethods) {
11262
11452
  }
11263
11453
  return Array.from(promotionIds);
11264
11454
  }
11265
- const BillingAddress = () => {
11455
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11456
+ const Shipping = () => {
11457
+ var _a;
11266
11458
  const { id } = reactRouterDom.useParams();
11267
11459
  const { order, isPending, isError, error } = useOrder(id, {
11268
- fields: "+billing_address"
11460
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11269
11461
  });
11462
+ const {
11463
+ order: preview,
11464
+ isPending: isPreviewPending,
11465
+ isError: isPreviewError,
11466
+ error: previewError
11467
+ } = useOrderPreview(id);
11468
+ useInitiateOrderEdit({ preview });
11469
+ const { onCancel } = useCancelOrderEdit({ preview });
11270
11470
  if (isError) {
11271
11471
  throw error;
11272
11472
  }
11273
- const isReady = !isPending && !!order;
11274
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11275
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11276
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
11277
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
11278
- ] }),
11279
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
11280
- ] });
11281
- };
11282
- const BillingAddressForm = ({ order }) => {
11283
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11284
- const form = reactHookForm.useForm({
11285
- defaultValues: {
11286
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
11287
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
11288
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
11289
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
11290
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
11291
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
11292
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
11293
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
11294
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11295
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11296
- },
11297
- resolver: zod.zodResolver(schema$3)
11298
- });
11299
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11300
- const { handleSuccess } = useRouteModal();
11301
- const onSubmit = form.handleSubmit(async (data) => {
11302
- await mutateAsync(
11303
- { billing_address: data },
11304
- {
11305
- onSuccess: () => {
11306
- handleSuccess();
11307
- },
11308
- onError: (error) => {
11309
- ui.toast.error(error.message);
11310
- }
11311
- }
11312
- );
11313
- });
11314
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
- KeyboundForm,
11316
- {
11317
- className: "flex flex-1 flex-col overflow-hidden",
11318
- onSubmit,
11319
- children: [
11320
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11321
- /* @__PURE__ */ jsxRuntime.jsx(
11322
- Form$2.Field,
11323
- {
11324
- control: form.control,
11325
- name: "country_code",
11326
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11327
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11328
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11330
- ] })
11331
- }
11332
- ),
11333
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11334
- /* @__PURE__ */ jsxRuntime.jsx(
11335
- Form$2.Field,
11336
- {
11337
- control: form.control,
11338
- name: "first_name",
11339
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11342
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11343
- ] })
11344
- }
11345
- ),
11346
- /* @__PURE__ */ jsxRuntime.jsx(
11347
- Form$2.Field,
11348
- {
11349
- control: form.control,
11350
- name: "last_name",
11351
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11355
- ] })
11356
- }
11357
- )
11358
- ] }),
11359
- /* @__PURE__ */ jsxRuntime.jsx(
11360
- Form$2.Field,
11361
- {
11362
- control: form.control,
11363
- name: "company",
11364
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11367
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11368
- ] })
11369
- }
11370
- ),
11371
- /* @__PURE__ */ jsxRuntime.jsx(
11372
- Form$2.Field,
11373
- {
11374
- control: form.control,
11375
- name: "address_1",
11376
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11378
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11379
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11380
- ] })
11381
- }
11382
- ),
11383
- /* @__PURE__ */ jsxRuntime.jsx(
11384
- Form$2.Field,
11385
- {
11386
- control: form.control,
11387
- name: "address_2",
11388
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11389
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11390
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11391
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11392
- ] })
11393
- }
11394
- ),
11395
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11396
- /* @__PURE__ */ jsxRuntime.jsx(
11397
- Form$2.Field,
11398
- {
11399
- control: form.control,
11400
- name: "postal_code",
11401
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11402
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11403
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11404
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11405
- ] })
11406
- }
11407
- ),
11408
- /* @__PURE__ */ jsxRuntime.jsx(
11409
- Form$2.Field,
11410
- {
11411
- control: form.control,
11412
- name: "city",
11413
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11414
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11415
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11416
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11417
- ] })
11418
- }
11419
- )
11420
- ] }),
11421
- /* @__PURE__ */ jsxRuntime.jsx(
11422
- Form$2.Field,
11423
- {
11424
- control: form.control,
11425
- name: "province",
11426
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11427
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11428
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11429
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11430
- ] })
11431
- }
11432
- ),
11433
- /* @__PURE__ */ jsxRuntime.jsx(
11434
- Form$2.Field,
11435
- {
11436
- control: form.control,
11437
- name: "phone",
11438
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11440
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11441
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11442
- ] })
11443
- }
11444
- )
11445
- ] }) }),
11446
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11447
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11448
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11449
- ] }) })
11450
- ]
11451
- }
11452
- ) });
11453
- };
11454
- const schema$3 = addressSchema;
11455
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11456
- const Shipping = () => {
11457
- var _a;
11458
- const { id } = reactRouterDom.useParams();
11459
- const { order, isPending, isError, error } = useOrder(id, {
11460
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11461
- });
11462
- const {
11463
- order: preview,
11464
- isPending: isPreviewPending,
11465
- isError: isPreviewError,
11466
- error: previewError
11467
- } = useOrderPreview(id);
11468
- useInitiateOrderEdit({ preview });
11469
- const { onCancel } = useCancelOrderEdit({ preview });
11470
- if (isError) {
11471
- throw error;
11472
- }
11473
- if (isPreviewError) {
11474
- throw previewError;
11475
- }
11476
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11477
- const isReady = preview && !isPreviewPending && order && !isPending;
11478
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11479
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11480
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11481
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11482
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11483
- ] }) }) }),
11484
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11485
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11486
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11487
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11488
- ] }) });
11473
+ if (isPreviewError) {
11474
+ throw previewError;
11475
+ }
11476
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11477
+ const isReady = preview && !isPreviewPending && order && !isPending;
11478
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11479
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11480
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11481
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11482
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11483
+ ] }) }) }),
11484
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11485
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11486
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11487
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11488
+ ] }) });
11489
11489
  };
11490
11490
  const ShippingForm = ({ preview, order }) => {
11491
11491
  var _a;
@@ -12259,37 +12259,33 @@ const CustomAmountField = ({
12259
12259
  }
12260
12260
  );
12261
12261
  };
12262
- const ShippingAddress = () => {
12262
+ const SalesChannel = () => {
12263
12263
  const { id } = reactRouterDom.useParams();
12264
- const { order, isPending, isError, error } = useOrder(id, {
12265
- fields: "+shipping_address"
12266
- });
12264
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12265
+ id,
12266
+ {
12267
+ fields: "+sales_channel_id"
12268
+ },
12269
+ {
12270
+ enabled: !!id
12271
+ }
12272
+ );
12267
12273
  if (isError) {
12268
12274
  throw error;
12269
12275
  }
12270
- const isReady = !isPending && !!order;
12276
+ const ISrEADY = !!draft_order && !isPending;
12271
12277
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12272
12278
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12273
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12274
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12279
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12280
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12275
12281
  ] }),
12276
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12282
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12277
12283
  ] });
12278
12284
  };
12279
- const ShippingAddressForm = ({ order }) => {
12280
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12285
+ const SalesChannelForm = ({ order }) => {
12281
12286
  const form = reactHookForm.useForm({
12282
12287
  defaultValues: {
12283
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12284
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12285
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12286
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12287
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12288
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12289
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12290
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12291
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12292
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12288
+ sales_channel_id: order.sales_channel_id || ""
12293
12289
  },
12294
12290
  resolver: zod.zodResolver(schema$2)
12295
12291
  });
@@ -12298,21 +12294,11 @@ const ShippingAddressForm = ({ order }) => {
12298
12294
  const onSubmit = form.handleSubmit(async (data) => {
12299
12295
  await mutateAsync(
12300
12296
  {
12301
- shipping_address: {
12302
- first_name: data.first_name,
12303
- last_name: data.last_name,
12304
- company: data.company,
12305
- address_1: data.address_1,
12306
- address_2: data.address_2,
12307
- city: data.city,
12308
- province: data.province,
12309
- country_code: data.country_code,
12310
- postal_code: data.postal_code,
12311
- phone: data.phone
12312
- }
12297
+ sales_channel_id: data.sales_channel_id
12313
12298
  },
12314
12299
  {
12315
12300
  onSuccess: () => {
12301
+ ui.toast.success("Sales channel updated");
12316
12302
  handleSuccess();
12317
12303
  },
12318
12304
  onError: (error) => {
@@ -12327,132 +12313,7 @@ const ShippingAddressForm = ({ order }) => {
12327
12313
  className: "flex flex-1 flex-col overflow-hidden",
12328
12314
  onSubmit,
12329
12315
  children: [
12330
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12331
- /* @__PURE__ */ jsxRuntime.jsx(
12332
- Form$2.Field,
12333
- {
12334
- control: form.control,
12335
- name: "country_code",
12336
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12337
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12338
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12340
- ] })
12341
- }
12342
- ),
12343
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12344
- /* @__PURE__ */ jsxRuntime.jsx(
12345
- Form$2.Field,
12346
- {
12347
- control: form.control,
12348
- name: "first_name",
12349
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12353
- ] })
12354
- }
12355
- ),
12356
- /* @__PURE__ */ jsxRuntime.jsx(
12357
- Form$2.Field,
12358
- {
12359
- control: form.control,
12360
- name: "last_name",
12361
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12362
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12365
- ] })
12366
- }
12367
- )
12368
- ] }),
12369
- /* @__PURE__ */ jsxRuntime.jsx(
12370
- Form$2.Field,
12371
- {
12372
- control: form.control,
12373
- name: "company",
12374
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12375
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12376
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12378
- ] })
12379
- }
12380
- ),
12381
- /* @__PURE__ */ jsxRuntime.jsx(
12382
- Form$2.Field,
12383
- {
12384
- control: form.control,
12385
- name: "address_1",
12386
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12387
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12388
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12389
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12390
- ] })
12391
- }
12392
- ),
12393
- /* @__PURE__ */ jsxRuntime.jsx(
12394
- Form$2.Field,
12395
- {
12396
- control: form.control,
12397
- name: "address_2",
12398
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12399
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12400
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12401
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12402
- ] })
12403
- }
12404
- ),
12405
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12406
- /* @__PURE__ */ jsxRuntime.jsx(
12407
- Form$2.Field,
12408
- {
12409
- control: form.control,
12410
- name: "postal_code",
12411
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12412
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12413
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12414
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12415
- ] })
12416
- }
12417
- ),
12418
- /* @__PURE__ */ jsxRuntime.jsx(
12419
- Form$2.Field,
12420
- {
12421
- control: form.control,
12422
- name: "city",
12423
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12424
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12425
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12426
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12427
- ] })
12428
- }
12429
- )
12430
- ] }),
12431
- /* @__PURE__ */ jsxRuntime.jsx(
12432
- Form$2.Field,
12433
- {
12434
- control: form.control,
12435
- name: "province",
12436
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12437
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12438
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12440
- ] })
12441
- }
12442
- ),
12443
- /* @__PURE__ */ jsxRuntime.jsx(
12444
- Form$2.Field,
12445
- {
12446
- control: form.control,
12447
- name: "phone",
12448
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12451
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12452
- ] })
12453
- }
12454
- )
12455
- ] }) }),
12316
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12456
12317
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12457
12318
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12458
12319
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -12461,7 +12322,49 @@ const ShippingAddressForm = ({ order }) => {
12461
12322
  }
12462
12323
  ) });
12463
12324
  };
12464
- const schema$2 = addressSchema;
12325
+ const SalesChannelField = ({ control, order }) => {
12326
+ const salesChannels = useComboboxData({
12327
+ queryFn: async (params) => {
12328
+ return await sdk.admin.salesChannel.list(params);
12329
+ },
12330
+ queryKey: ["sales-channels"],
12331
+ getOptions: (data) => {
12332
+ return data.sales_channels.map((salesChannel) => ({
12333
+ label: salesChannel.name,
12334
+ value: salesChannel.id
12335
+ }));
12336
+ },
12337
+ defaultValue: order.sales_channel_id || void 0
12338
+ });
12339
+ return /* @__PURE__ */ jsxRuntime.jsx(
12340
+ Form$2.Field,
12341
+ {
12342
+ control,
12343
+ name: "sales_channel_id",
12344
+ render: ({ field }) => {
12345
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12346
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12347
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12348
+ Combobox,
12349
+ {
12350
+ options: salesChannels.options,
12351
+ fetchNextPage: salesChannels.fetchNextPage,
12352
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12353
+ searchValue: salesChannels.searchValue,
12354
+ onSearchValueChange: salesChannels.onSearchValueChange,
12355
+ placeholder: "Select sales channel",
12356
+ ...field
12357
+ }
12358
+ ) }),
12359
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12360
+ ] });
12361
+ }
12362
+ }
12363
+ );
12364
+ };
12365
+ const schema$2 = objectType({
12366
+ sales_channel_id: stringType().min(1)
12367
+ });
12465
12368
  const TransferOwnership = () => {
12466
12369
  const { id } = reactRouterDom.useParams();
12467
12370
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12938,33 +12841,37 @@ const Illustration = () => {
12938
12841
  const schema$1 = objectType({
12939
12842
  customer_id: stringType().min(1)
12940
12843
  });
12941
- const SalesChannel = () => {
12844
+ const ShippingAddress = () => {
12942
12845
  const { id } = reactRouterDom.useParams();
12943
- const { draft_order, isPending, isError, error } = useDraftOrder(
12944
- id,
12945
- {
12946
- fields: "+sales_channel_id"
12947
- },
12948
- {
12949
- enabled: !!id
12950
- }
12951
- );
12846
+ const { order, isPending, isError, error } = useOrder(id, {
12847
+ fields: "+shipping_address"
12848
+ });
12952
12849
  if (isError) {
12953
12850
  throw error;
12954
12851
  }
12955
- const ISrEADY = !!draft_order && !isPending;
12852
+ const isReady = !isPending && !!order;
12956
12853
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12957
12854
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12958
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12855
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12856
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12960
12857
  ] }),
12961
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12858
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12962
12859
  ] });
12963
12860
  };
12964
- const SalesChannelForm = ({ order }) => {
12861
+ const ShippingAddressForm = ({ order }) => {
12862
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12965
12863
  const form = reactHookForm.useForm({
12966
12864
  defaultValues: {
12967
- sales_channel_id: order.sales_channel_id || ""
12865
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12866
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12867
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12868
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12869
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12870
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12871
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12872
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12873
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12874
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12968
12875
  },
12969
12876
  resolver: zod.zodResolver(schema)
12970
12877
  });
@@ -12973,11 +12880,21 @@ const SalesChannelForm = ({ order }) => {
12973
12880
  const onSubmit = form.handleSubmit(async (data) => {
12974
12881
  await mutateAsync(
12975
12882
  {
12976
- sales_channel_id: data.sales_channel_id
12883
+ shipping_address: {
12884
+ first_name: data.first_name,
12885
+ last_name: data.last_name,
12886
+ company: data.company,
12887
+ address_1: data.address_1,
12888
+ address_2: data.address_2,
12889
+ city: data.city,
12890
+ province: data.province,
12891
+ country_code: data.country_code,
12892
+ postal_code: data.postal_code,
12893
+ phone: data.phone
12894
+ }
12977
12895
  },
12978
12896
  {
12979
12897
  onSuccess: () => {
12980
- ui.toast.success("Sales channel updated");
12981
12898
  handleSuccess();
12982
12899
  },
12983
12900
  onError: (error) => {
@@ -12992,7 +12909,132 @@ const SalesChannelForm = ({ order }) => {
12992
12909
  className: "flex flex-1 flex-col overflow-hidden",
12993
12910
  onSubmit,
12994
12911
  children: [
12995
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12912
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12913
+ /* @__PURE__ */ jsxRuntime.jsx(
12914
+ Form$2.Field,
12915
+ {
12916
+ control: form.control,
12917
+ name: "country_code",
12918
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12919
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12922
+ ] })
12923
+ }
12924
+ ),
12925
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12926
+ /* @__PURE__ */ jsxRuntime.jsx(
12927
+ Form$2.Field,
12928
+ {
12929
+ control: form.control,
12930
+ name: "first_name",
12931
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
+ ] })
12936
+ }
12937
+ ),
12938
+ /* @__PURE__ */ jsxRuntime.jsx(
12939
+ Form$2.Field,
12940
+ {
12941
+ control: form.control,
12942
+ name: "last_name",
12943
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12944
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12947
+ ] })
12948
+ }
12949
+ )
12950
+ ] }),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12953
+ {
12954
+ control: form.control,
12955
+ name: "company",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
+ ] })
12961
+ }
12962
+ ),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(
12964
+ Form$2.Field,
12965
+ {
12966
+ control: form.control,
12967
+ name: "address_1",
12968
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
+ ] })
12973
+ }
12974
+ ),
12975
+ /* @__PURE__ */ jsxRuntime.jsx(
12976
+ Form$2.Field,
12977
+ {
12978
+ control: form.control,
12979
+ name: "address_2",
12980
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12981
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12984
+ ] })
12985
+ }
12986
+ ),
12987
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12988
+ /* @__PURE__ */ jsxRuntime.jsx(
12989
+ Form$2.Field,
12990
+ {
12991
+ control: form.control,
12992
+ name: "postal_code",
12993
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
+ ] })
12998
+ }
12999
+ ),
13000
+ /* @__PURE__ */ jsxRuntime.jsx(
13001
+ Form$2.Field,
13002
+ {
13003
+ control: form.control,
13004
+ name: "city",
13005
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13006
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13009
+ ] })
13010
+ }
13011
+ )
13012
+ ] }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control: form.control,
13017
+ name: "province",
13018
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
+ ] })
13023
+ }
13024
+ ),
13025
+ /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Form$2.Field,
13027
+ {
13028
+ control: form.control,
13029
+ name: "phone",
13030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
+ ] })
13035
+ }
13036
+ )
13037
+ ] }) }),
12996
13038
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12997
13039
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12998
13040
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13001,49 +13043,7 @@ const SalesChannelForm = ({ order }) => {
13001
13043
  }
13002
13044
  ) });
13003
13045
  };
13004
- const SalesChannelField = ({ control, order }) => {
13005
- const salesChannels = useComboboxData({
13006
- queryFn: async (params) => {
13007
- return await sdk.admin.salesChannel.list(params);
13008
- },
13009
- queryKey: ["sales-channels"],
13010
- getOptions: (data) => {
13011
- return data.sales_channels.map((salesChannel) => ({
13012
- label: salesChannel.name,
13013
- value: salesChannel.id
13014
- }));
13015
- },
13016
- defaultValue: order.sales_channel_id || void 0
13017
- });
13018
- return /* @__PURE__ */ jsxRuntime.jsx(
13019
- Form$2.Field,
13020
- {
13021
- control,
13022
- name: "sales_channel_id",
13023
- render: ({ field }) => {
13024
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13027
- Combobox,
13028
- {
13029
- options: salesChannels.options,
13030
- fetchNextPage: salesChannels.fetchNextPage,
13031
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13032
- searchValue: salesChannels.searchValue,
13033
- onSearchValueChange: salesChannels.onSearchValueChange,
13034
- placeholder: "Select sales channel",
13035
- ...field
13036
- }
13037
- ) }),
13038
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13039
- ] });
13040
- }
13041
- }
13042
- );
13043
- };
13044
- const schema = objectType({
13045
- sales_channel_id: stringType().min(1)
13046
- });
13046
+ const schema = addressSchema;
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
13049
13049
  routes: [
@@ -13064,6 +13064,10 @@ const routeModule = {
13064
13064
  handle,
13065
13065
  loader,
13066
13066
  children: [
13067
+ {
13068
+ Component: BillingAddress,
13069
+ path: "/draft-orders/:id/billing-address"
13070
+ },
13067
13071
  {
13068
13072
  Component: CustomItems,
13069
13073
  path: "/draft-orders/:id/custom-items"
@@ -13084,25 +13088,21 @@ const routeModule = {
13084
13088
  Component: Promotions,
13085
13089
  path: "/draft-orders/:id/promotions"
13086
13090
  },
13087
- {
13088
- Component: BillingAddress,
13089
- path: "/draft-orders/:id/billing-address"
13090
- },
13091
13091
  {
13092
13092
  Component: Shipping,
13093
13093
  path: "/draft-orders/:id/shipping"
13094
13094
  },
13095
13095
  {
13096
- Component: ShippingAddress,
13097
- path: "/draft-orders/:id/shipping-address"
13096
+ Component: SalesChannel,
13097
+ path: "/draft-orders/:id/sales-channel"
13098
13098
  },
13099
13099
  {
13100
13100
  Component: TransferOwnership,
13101
13101
  path: "/draft-orders/:id/transfer-ownership"
13102
13102
  },
13103
13103
  {
13104
- Component: SalesChannel,
13105
- path: "/draft-orders/:id/sales-channel"
13104
+ Component: ShippingAddress,
13105
+ path: "/draft-orders/:id/shipping-address"
13106
13106
  }
13107
13107
  ]
13108
13108
  }