@medusajs/draft-order 2.10.3 → 2.10.4-preview-20250918180157

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,28 @@ const EmailForm = ({ order }) => {
9843
9632
  }
9844
9633
  ) });
9845
9634
  };
9846
- const schema$3 = objectType({
9635
+ const schema$5 = objectType({
9636
+ email: stringType().email()
9637
+ });
9638
+ const CustomItems = () => {
9639
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9640
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9641
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9642
+ ] });
9643
+ };
9644
+ const CustomItemsForm = () => {
9645
+ const form = useForm({
9646
+ resolver: zodResolver(schema$4)
9647
+ });
9648
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9649
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9650
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9651
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9652
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9653
+ ] }) })
9654
+ ] }) });
9655
+ };
9656
+ const schema$4 = objectType({
9847
9657
  email: stringType().email()
9848
9658
  });
9849
9659
  const NumberInput = forwardRef(
@@ -11447,33 +11257,329 @@ function getPromotionIds(items, shippingMethods) {
11447
11257
  }
11448
11258
  return Array.from(promotionIds);
11449
11259
  }
11450
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11451
- const Shipping = () => {
11452
- var _a;
11260
+ const BillingAddress = () => {
11453
11261
  const { id } = useParams();
11454
11262
  const { order, isPending, isError, error } = useOrder(id, {
11455
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11263
+ fields: "+billing_address"
11456
11264
  });
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 });
11465
11265
  if (isError) {
11466
11266
  throw error;
11467
11267
  }
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" }) }),
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" }) }),
11477
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." }) })
11478
11584
  ] }) }) }),
11479
11585
  /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
@@ -12286,7 +12392,7 @@ const ShippingAddressForm = ({ order }) => {
12286
12392
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12287
12393
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12288
12394
  },
12289
- resolver: zodResolver(schema$2)
12395
+ resolver: zodResolver(schema$1)
12290
12396
  });
12291
12397
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12292
12398
  const { handleSuccess } = useRouteModal();
@@ -12456,7 +12562,7 @@ const ShippingAddressForm = ({ order }) => {
12456
12562
  }
12457
12563
  ) });
12458
12564
  };
12459
- const schema$2 = addressSchema;
12565
+ const schema$1 = addressSchema;
12460
12566
  const TransferOwnership = () => {
12461
12567
  const { id } = useParams();
12462
12568
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12480,7 +12586,7 @@ const TransferOwnershipForm = ({ order }) => {
12480
12586
  defaultValues: {
12481
12587
  customer_id: order.customer_id || ""
12482
12588
  },
12483
- resolver: zodResolver(schema$1)
12589
+ resolver: zodResolver(schema)
12484
12590
  });
12485
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12486
12592
  const { handleSuccess } = useRouteModal();
@@ -12930,114 +13036,8 @@ const Illustration = () => {
12930
13036
  }
12931
13037
  );
12932
13038
  };
12933
- const schema$1 = objectType({
12934
- customer_id: stringType().min(1)
12935
- });
12936
- const SalesChannel = () => {
12937
- const { id } = useParams();
12938
- const { draft_order, isPending, isError, error } = useDraftOrder(
12939
- id,
12940
- {
12941
- fields: "+sales_channel_id"
12942
- },
12943
- {
12944
- enabled: !!id
12945
- }
12946
- );
12947
- if (isError) {
12948
- throw error;
12949
- }
12950
- const ISrEADY = !!draft_order && !isPending;
12951
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12952
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12953
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12954
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12955
- ] }),
12956
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12957
- ] });
12958
- };
12959
- const SalesChannelForm = ({ order }) => {
12960
- const form = useForm({
12961
- defaultValues: {
12962
- sales_channel_id: order.sales_channel_id || ""
12963
- },
12964
- resolver: zodResolver(schema)
12965
- });
12966
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12967
- const { handleSuccess } = useRouteModal();
12968
- const onSubmit = form.handleSubmit(async (data) => {
12969
- await mutateAsync(
12970
- {
12971
- sales_channel_id: data.sales_channel_id
12972
- },
12973
- {
12974
- onSuccess: () => {
12975
- toast.success("Sales channel updated");
12976
- handleSuccess();
12977
- },
12978
- onError: (error) => {
12979
- toast.error(error.message);
12980
- }
12981
- }
12982
- );
12983
- });
12984
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12985
- KeyboundForm,
12986
- {
12987
- className: "flex flex-1 flex-col overflow-hidden",
12988
- onSubmit,
12989
- children: [
12990
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12991
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12992
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12993
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12994
- ] }) })
12995
- ]
12996
- }
12997
- ) });
12998
- };
12999
- const SalesChannelField = ({ control, order }) => {
13000
- const salesChannels = useComboboxData({
13001
- queryFn: async (params) => {
13002
- return await sdk.admin.salesChannel.list(params);
13003
- },
13004
- queryKey: ["sales-channels"],
13005
- getOptions: (data) => {
13006
- return data.sales_channels.map((salesChannel) => ({
13007
- label: salesChannel.name,
13008
- value: salesChannel.id
13009
- }));
13010
- },
13011
- defaultValue: order.sales_channel_id || void 0
13012
- });
13013
- return /* @__PURE__ */ jsx(
13014
- Form$2.Field,
13015
- {
13016
- control,
13017
- name: "sales_channel_id",
13018
- render: ({ field }) => {
13019
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13020
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13021
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13022
- Combobox,
13023
- {
13024
- options: salesChannels.options,
13025
- fetchNextPage: salesChannels.fetchNextPage,
13026
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13027
- searchValue: salesChannels.searchValue,
13028
- onSearchValueChange: salesChannels.onSearchValueChange,
13029
- placeholder: "Select sales channel",
13030
- ...field
13031
- }
13032
- ) }),
13033
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13034
- ] });
13035
- }
13036
- }
13037
- );
13038
- };
13039
13039
  const schema = objectType({
13040
- sales_channel_id: stringType().min(1)
13040
+ customer_id: stringType().min(1)
13041
13041
  });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
@@ -13060,17 +13060,13 @@ const routeModule = {
13060
13060
  loader,
13061
13061
  children: [
13062
13062
  {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13063
+ Component: Email,
13064
+ path: "/draft-orders/:id/email"
13065
13065
  },
13066
13066
  {
13067
13067
  Component: CustomItems,
13068
13068
  path: "/draft-orders/:id/custom-items"
13069
13069
  },
13070
- {
13071
- Component: Email,
13072
- path: "/draft-orders/:id/email"
13073
- },
13074
13070
  {
13075
13071
  Component: Items,
13076
13072
  path: "/draft-orders/:id/items"
@@ -13083,6 +13079,14 @@ const routeModule = {
13083
13079
  Component: Promotions,
13084
13080
  path: "/draft-orders/:id/promotions"
13085
13081
  },
13082
+ {
13083
+ Component: BillingAddress,
13084
+ path: "/draft-orders/:id/billing-address"
13085
+ },
13086
+ {
13087
+ Component: SalesChannel,
13088
+ path: "/draft-orders/:id/sales-channel"
13089
+ },
13086
13090
  {
13087
13091
  Component: Shipping,
13088
13092
  path: "/draft-orders/:id/shipping"
@@ -13094,10 +13098,6 @@ const routeModule = {
13094
13098
  {
13095
13099
  Component: TransferOwnership,
13096
13100
  path: "/draft-orders/:id/transfer-ownership"
13097
- },
13098
- {
13099
- Component: SalesChannel,
13100
- path: "/draft-orders/:id/sales-channel"
13101
13101
  }
13102
13102
  ]
13103
13103
  }