@medusajs/draft-order 2.10.3-preview-20250915120202 → 2.10.3-snapshot-20250915125232

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.
@@ -9573,196 +9573,27 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const BillingAddress = () => {
9577
- const { id } = reactRouterDom.useParams();
9578
- const { order, isPending, isError, error } = useOrder(id, {
9579
- fields: "+billing_address"
9580
- });
9581
- if (isError) {
9582
- throw error;
9583
- }
9584
- const isReady = !isPending && !!order;
9576
+ const CustomItems = () => {
9585
9577
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9588
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9589
- ] }),
9590
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9578
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9579
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9591
9580
  ] });
9592
9581
  };
9593
- const BillingAddressForm = ({ order }) => {
9594
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9582
+ const CustomItemsForm = () => {
9595
9583
  const form = reactHookForm.useForm({
9596
- defaultValues: {
9597
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9598
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9599
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9600
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9601
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9602
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9603
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9604
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9605
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
- },
9608
9584
  resolver: zod.zodResolver(schema$5)
9609
9585
  });
9610
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
- const { handleSuccess } = useRouteModal();
9612
- const onSubmit = form.handleSubmit(async (data) => {
9613
- await mutateAsync(
9614
- { billing_address: data },
9615
- {
9616
- onSuccess: () => {
9617
- handleSuccess();
9618
- },
9619
- onError: (error) => {
9620
- ui.toast.error(error.message);
9621
- }
9622
- }
9623
- );
9624
- });
9625
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9626
- KeyboundForm,
9627
- {
9628
- className: "flex flex-1 flex-col overflow-hidden",
9629
- onSubmit,
9630
- children: [
9631
- /* @__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: [
9632
- /* @__PURE__ */ jsxRuntime.jsx(
9633
- Form$2.Field,
9634
- {
9635
- control: form.control,
9636
- name: "country_code",
9637
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9640
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9641
- ] })
9642
- }
9643
- ),
9644
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9645
- /* @__PURE__ */ jsxRuntime.jsx(
9646
- Form$2.Field,
9647
- {
9648
- control: form.control,
9649
- name: "first_name",
9650
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9653
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9654
- ] })
9655
- }
9656
- ),
9657
- /* @__PURE__ */ jsxRuntime.jsx(
9658
- Form$2.Field,
9659
- {
9660
- control: form.control,
9661
- name: "last_name",
9662
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9665
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9666
- ] })
9667
- }
9668
- )
9669
- ] }),
9670
- /* @__PURE__ */ jsxRuntime.jsx(
9671
- Form$2.Field,
9672
- {
9673
- control: form.control,
9674
- name: "company",
9675
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9678
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9679
- ] })
9680
- }
9681
- ),
9682
- /* @__PURE__ */ jsxRuntime.jsx(
9683
- Form$2.Field,
9684
- {
9685
- control: form.control,
9686
- name: "address_1",
9687
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9690
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9691
- ] })
9692
- }
9693
- ),
9694
- /* @__PURE__ */ jsxRuntime.jsx(
9695
- Form$2.Field,
9696
- {
9697
- control: form.control,
9698
- name: "address_2",
9699
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9702
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9703
- ] })
9704
- }
9705
- ),
9706
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9707
- /* @__PURE__ */ jsxRuntime.jsx(
9708
- Form$2.Field,
9709
- {
9710
- control: form.control,
9711
- name: "postal_code",
9712
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9715
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9716
- ] })
9717
- }
9718
- ),
9719
- /* @__PURE__ */ jsxRuntime.jsx(
9720
- Form$2.Field,
9721
- {
9722
- control: form.control,
9723
- name: "city",
9724
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9727
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
- ] })
9729
- }
9730
- )
9731
- ] }),
9732
- /* @__PURE__ */ jsxRuntime.jsx(
9733
- Form$2.Field,
9734
- {
9735
- control: form.control,
9736
- name: "province",
9737
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
- ] })
9742
- }
9743
- ),
9744
- /* @__PURE__ */ jsxRuntime.jsx(
9745
- Form$2.Field,
9746
- {
9747
- control: form.control,
9748
- name: "phone",
9749
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
- ] })
9754
- }
9755
- )
9756
- ] }) }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9760
- ] }) })
9761
- ]
9762
- }
9763
- ) });
9586
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9590
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9591
+ ] }) })
9592
+ ] }) });
9764
9593
  };
9765
- const schema$5 = addressSchema;
9594
+ const schema$5 = objectType({
9595
+ email: stringType().email()
9596
+ });
9766
9597
  const Email = () => {
9767
9598
  const { id } = reactRouterDom.useParams();
9768
9599
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9831,27 +9662,6 @@ const EmailForm = ({ order }) => {
9831
9662
  const schema$4 = objectType({
9832
9663
  email: stringType().email()
9833
9664
  });
9834
- const CustomItems = () => {
9835
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9836
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9837
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9838
- ] });
9839
- };
9840
- const CustomItemsForm = () => {
9841
- const form = reactHookForm.useForm({
9842
- resolver: zod.zodResolver(schema$3)
9843
- });
9844
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9846
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9847
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9848
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9849
- ] }) })
9850
- ] }) });
9851
- };
9852
- const schema$3 = objectType({
9853
- email: stringType().email()
9854
- });
9855
9665
  const NumberInput = React.forwardRef(
9856
9666
  ({
9857
9667
  value,
@@ -11453,47 +11263,153 @@ function getPromotionIds(items, shippingMethods) {
11453
11263
  }
11454
11264
  return Array.from(promotionIds);
11455
11265
  }
11456
- const ShippingAddress = () => {
11266
+ const SalesChannel = () => {
11457
11267
  const { id } = reactRouterDom.useParams();
11458
- const { order, isPending, isError, error } = useOrder(id, {
11459
- fields: "+shipping_address"
11460
- });
11268
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11269
+ id,
11270
+ {
11271
+ fields: "+sales_channel_id"
11272
+ },
11273
+ {
11274
+ enabled: !!id
11275
+ }
11276
+ );
11461
11277
  if (isError) {
11462
11278
  throw error;
11463
11279
  }
11464
- const isReady = !isPending && !!order;
11280
+ const ISrEADY = !!draft_order && !isPending;
11465
11281
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11466
11282
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11467
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11468
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11283
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11284
+ /* @__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" }) })
11469
11285
  ] }),
11470
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11286
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11471
11287
  ] });
11472
11288
  };
11473
- const ShippingAddressForm = ({ order }) => {
11474
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11289
+ const SalesChannelForm = ({ order }) => {
11475
11290
  const form = reactHookForm.useForm({
11476
11291
  defaultValues: {
11477
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11478
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11479
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11480
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11481
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11482
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11483
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11484
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11485
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11486
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11292
+ sales_channel_id: order.sales_channel_id || ""
11487
11293
  },
11488
- resolver: zod.zodResolver(schema$2)
11294
+ resolver: zod.zodResolver(schema$3)
11489
11295
  });
11490
11296
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11491
11297
  const { handleSuccess } = useRouteModal();
11492
11298
  const onSubmit = form.handleSubmit(async (data) => {
11493
11299
  await mutateAsync(
11494
11300
  {
11495
- shipping_address: {
11496
- first_name: data.first_name,
11301
+ sales_channel_id: data.sales_channel_id
11302
+ },
11303
+ {
11304
+ onSuccess: () => {
11305
+ ui.toast.success("Sales channel updated");
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.jsx(SalesChannelField, { control: form.control, order }) }),
11321
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11322
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11323
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11324
+ ] }) })
11325
+ ]
11326
+ }
11327
+ ) });
11328
+ };
11329
+ const SalesChannelField = ({ control, order }) => {
11330
+ const salesChannels = useComboboxData({
11331
+ queryFn: async (params) => {
11332
+ return await sdk.admin.salesChannel.list(params);
11333
+ },
11334
+ queryKey: ["sales-channels"],
11335
+ getOptions: (data) => {
11336
+ return data.sales_channels.map((salesChannel) => ({
11337
+ label: salesChannel.name,
11338
+ value: salesChannel.id
11339
+ }));
11340
+ },
11341
+ defaultValue: order.sales_channel_id || void 0
11342
+ });
11343
+ return /* @__PURE__ */ jsxRuntime.jsx(
11344
+ Form$2.Field,
11345
+ {
11346
+ control,
11347
+ name: "sales_channel_id",
11348
+ render: ({ field }) => {
11349
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11350
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11351
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11352
+ Combobox,
11353
+ {
11354
+ options: salesChannels.options,
11355
+ fetchNextPage: salesChannels.fetchNextPage,
11356
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11357
+ searchValue: salesChannels.searchValue,
11358
+ onSearchValueChange: salesChannels.onSearchValueChange,
11359
+ placeholder: "Select sales channel",
11360
+ ...field
11361
+ }
11362
+ ) }),
11363
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11364
+ ] });
11365
+ }
11366
+ }
11367
+ );
11368
+ };
11369
+ const schema$3 = objectType({
11370
+ sales_channel_id: stringType().min(1)
11371
+ });
11372
+ const ShippingAddress = () => {
11373
+ const { id } = reactRouterDom.useParams();
11374
+ const { order, isPending, isError, error } = useOrder(id, {
11375
+ fields: "+shipping_address"
11376
+ });
11377
+ if (isError) {
11378
+ throw error;
11379
+ }
11380
+ const isReady = !isPending && !!order;
11381
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11382
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11383
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11384
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11385
+ ] }),
11386
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11387
+ ] });
11388
+ };
11389
+ const ShippingAddressForm = ({ order }) => {
11390
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11391
+ const form = reactHookForm.useForm({
11392
+ defaultValues: {
11393
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11394
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11395
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11396
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11397
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11398
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11399
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11400
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11401
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11402
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11403
+ },
11404
+ resolver: zod.zodResolver(schema$2)
11405
+ });
11406
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11407
+ const { handleSuccess } = useRouteModal();
11408
+ const onSubmit = form.handleSubmit(async (data) => {
11409
+ await mutateAsync(
11410
+ {
11411
+ shipping_address: {
11412
+ first_name: data.first_name,
11497
11413
  last_name: data.last_name,
11498
11414
  company: data.company,
11499
11415
  address_1: data.address_1,
@@ -11656,948 +11572,141 @@ const ShippingAddressForm = ({ order }) => {
11656
11572
  ) });
11657
11573
  };
11658
11574
  const schema$2 = addressSchema;
11659
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11660
- const Shipping = () => {
11661
- var _a;
11575
+ const TransferOwnership = () => {
11662
11576
  const { id } = reactRouterDom.useParams();
11663
- const { order, isPending, isError, error } = useOrder(id, {
11664
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11577
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11578
+ fields: "id,customer_id,customer.*"
11665
11579
  });
11666
- const {
11667
- order: preview,
11668
- isPending: isPreviewPending,
11669
- isError: isPreviewError,
11670
- error: previewError
11671
- } = useOrderPreview(id);
11672
- useInitiateOrderEdit({ preview });
11673
- const { onCancel } = useCancelOrderEdit({ preview });
11674
11580
  if (isError) {
11675
11581
  throw error;
11676
11582
  }
11677
- if (isPreviewError) {
11678
- throw previewError;
11679
- }
11680
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11681
- const isReady = preview && !isPreviewPending && order && !isPending;
11682
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11683
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11684
- /* @__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 py-16 px-6", children: [
11685
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11686
- /* @__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." }) })
11687
- ] }) }) }),
11688
- /* @__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" }) }) })
11689
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11690
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11691
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11692
- ] }) });
11583
+ const isReady = !isPending && !!draft_order;
11584
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11585
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11588
+ ] }),
11589
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11590
+ ] });
11693
11591
  };
11694
- const ShippingForm = ({ preview, order }) => {
11695
- var _a;
11696
- const { setIsOpen } = useStackedModal();
11697
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11698
- const [data, setData] = React.useState(null);
11699
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11700
- const { shipping_options } = useShippingOptions(
11701
- {
11702
- id: appliedShippingOptionIds,
11703
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11592
+ const TransferOwnershipForm = ({ order }) => {
11593
+ var _a, _b;
11594
+ const form = reactHookForm.useForm({
11595
+ defaultValues: {
11596
+ customer_id: order.customer_id || ""
11704
11597
  },
11705
- {
11706
- enabled: appliedShippingOptionIds.length > 0
11707
- }
11708
- );
11709
- const uniqueShippingProfiles = React.useMemo(() => {
11710
- const profiles = /* @__PURE__ */ new Map();
11711
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11712
- profiles.set(profile.id, profile);
11713
- });
11714
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11715
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11716
- });
11717
- return Array.from(profiles.values());
11718
- }, [order.items, shipping_options]);
11598
+ resolver: zod.zodResolver(schema$1)
11599
+ });
11600
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11719
11601
  const { handleSuccess } = useRouteModal();
11720
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11721
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11722
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11723
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11724
- const onSubmit = async () => {
11725
- setIsSubmitting(true);
11726
- let requestSucceeded = false;
11727
- await requestOrderEdit(void 0, {
11728
- onError: (e) => {
11729
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11730
- },
11731
- onSuccess: () => {
11732
- requestSucceeded = true;
11733
- }
11734
- });
11735
- if (!requestSucceeded) {
11736
- setIsSubmitting(false);
11737
- return;
11738
- }
11739
- await confirmOrderEdit(void 0, {
11740
- onError: (e) => {
11741
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11742
- },
11743
- onSuccess: () => {
11744
- handleSuccess();
11745
- },
11746
- onSettled: () => {
11747
- setIsSubmitting(false);
11748
- }
11749
- });
11750
- };
11751
- const onKeydown = React.useCallback(
11752
- (e) => {
11753
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11754
- if (data || isSubmitting) {
11755
- return;
11602
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11603
+ const currentCustomer = order.customer ? {
11604
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11605
+ value: order.customer.id
11606
+ } : null;
11607
+ const onSubmit = form.handleSubmit(async (data) => {
11608
+ await mutateAsync(
11609
+ { customer_id: data.customer_id },
11610
+ {
11611
+ onSuccess: () => {
11612
+ ui.toast.success("Customer updated");
11613
+ handleSuccess();
11614
+ },
11615
+ onError: (error) => {
11616
+ ui.toast.error(error.message);
11756
11617
  }
11757
- onSubmit();
11758
11618
  }
11759
- },
11760
- [data, isSubmitting, onSubmit]
11761
- );
11762
- React.useEffect(() => {
11763
- document.addEventListener("keydown", onKeydown);
11764
- return () => {
11765
- document.removeEventListener("keydown", onKeydown);
11766
- };
11767
- }, [onKeydown]);
11768
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11769
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11770
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11771
- /* @__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 py-16 px-6", children: [
11772
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11773
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11774
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11775
- ] }),
11776
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11777
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11778
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11779
- /* @__PURE__ */ jsxRuntime.jsx(
11780
- ui.Text,
11781
- {
11782
- size: "xsmall",
11783
- weight: "plus",
11784
- className: "text-ui-fg-muted",
11785
- children: "Shipping profile"
11786
- }
11787
- ),
11788
- /* @__PURE__ */ jsxRuntime.jsx(
11789
- ui.Text,
11790
- {
11791
- size: "xsmall",
11792
- weight: "plus",
11793
- className: "text-ui-fg-muted",
11794
- children: "Action"
11795
- }
11796
- )
11619
+ );
11620
+ });
11621
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11622
+ KeyboundForm,
11623
+ {
11624
+ className: "flex flex-1 flex-col overflow-hidden",
11625
+ onSubmit,
11626
+ children: [
11627
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11628
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11629
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11630
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11631
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11632
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11633
+ ] }),
11634
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11635
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11636
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11637
+ ] })
11797
11638
  ] }),
11798
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11799
- var _a2, _b, _c, _d, _e, _f, _g;
11800
- const items = getItemsWithShippingProfile(
11801
- profile.id,
11802
- order.items
11803
- );
11804
- const hasItems = items.length > 0;
11805
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11806
- (option) => option.shipping_profile_id === profile.id
11807
- );
11808
- const shippingMethod = preview.shipping_methods.find(
11809
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11810
- );
11811
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11812
- (action) => action.action === "SHIPPING_ADD"
11813
- );
11814
- return /* @__PURE__ */ jsxRuntime.jsxs(
11815
- radixUi.Accordion.Item,
11816
- {
11817
- value: profile.id,
11818
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11819
- children: [
11820
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11821
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11822
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11823
- ui.IconButton,
11824
- {
11825
- size: "2xsmall",
11826
- variant: "transparent",
11827
- className: "group/trigger",
11828
- disabled: !hasItems,
11829
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11830
- }
11831
- ) }),
11832
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11833
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11834
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11835
- /* @__PURE__ */ jsxRuntime.jsx(
11836
- ui.Text,
11837
- {
11838
- size: "small",
11839
- weight: "plus",
11840
- leading: "compact",
11841
- children: profile.name
11842
- }
11843
- ),
11844
- /* @__PURE__ */ jsxRuntime.jsxs(
11845
- ui.Text,
11846
- {
11847
- size: "small",
11848
- leading: "compact",
11849
- className: "text-ui-fg-subtle",
11850
- children: [
11851
- items.length,
11852
- " ",
11853
- pluralize(items.length, "items", "item")
11854
- ]
11855
- }
11856
- )
11857
- ] })
11858
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11859
- /* @__PURE__ */ jsxRuntime.jsx(
11860
- ui.Tooltip,
11861
- {
11862
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11863
- var _a3, _b2, _c2;
11864
- return /* @__PURE__ */ jsxRuntime.jsx(
11865
- "li",
11866
- {
11867
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11868
- },
11869
- item.id
11870
- );
11871
- }) }),
11872
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11873
- ui.Badge,
11874
- {
11875
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11876
- size: "xsmall",
11877
- children: [
11878
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11879
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11880
- items.reduce(
11881
- (acc, item) => acc + item.quantity,
11882
- 0
11883
- ),
11884
- "x",
11885
- " ",
11886
- pluralize(items.length, "items", "item")
11887
- ] })
11888
- ]
11889
- }
11890
- )
11891
- }
11892
- ),
11893
- /* @__PURE__ */ jsxRuntime.jsx(
11894
- ui.Tooltip,
11895
- {
11896
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11897
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11898
- ui.Badge,
11899
- {
11900
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11901
- size: "xsmall",
11902
- children: [
11903
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11904
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11905
- ]
11906
- }
11907
- )
11908
- }
11909
- ),
11910
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11911
- ui.Badge,
11912
- {
11913
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11914
- size: "xsmall",
11915
- children: [
11916
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11917
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11918
- ]
11919
- }
11920
- ) })
11921
- ] })
11922
- ] }),
11923
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11924
- ActionMenu,
11925
- {
11926
- groups: [
11927
- {
11928
- actions: [
11929
- hasItems ? {
11930
- label: "Edit shipping option",
11931
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11932
- onClick: () => {
11933
- setIsOpen(
11934
- STACKED_FOCUS_MODAL_ID,
11935
- true
11936
- );
11937
- setData({
11938
- shippingProfileId: profile.id,
11939
- shippingOption,
11940
- shippingMethod
11941
- });
11942
- }
11943
- } : void 0,
11944
- {
11945
- label: "Remove shipping option",
11946
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11947
- onClick: () => {
11948
- if (shippingMethod) {
11949
- if (addShippingMethodAction) {
11950
- removeActionShippingMethod(
11951
- addShippingMethodAction.id
11952
- );
11953
- } else {
11954
- removeShippingMethod(
11955
- shippingMethod.id
11956
- );
11957
- }
11958
- }
11959
- }
11960
- }
11961
- ].filter(Boolean)
11962
- }
11963
- ]
11964
- }
11965
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11966
- StackedModalTrigger,
11967
- {
11968
- shippingProfileId: profile.id,
11969
- shippingOption,
11970
- shippingMethod,
11971
- setData,
11972
- children: "Add shipping option"
11973
- }
11974
- )
11975
- ] }),
11976
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11978
- items.map((item, idx) => {
11979
- var _a3, _b2, _c2, _d2, _e2;
11980
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11981
- /* @__PURE__ */ jsxRuntime.jsxs(
11982
- "div",
11983
- {
11984
- className: "px-3 flex items-center gap-x-3",
11985
- children: [
11986
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11987
- ui.Divider,
11988
- {
11989
- variant: "dashed",
11990
- orientation: "vertical"
11991
- }
11992
- ) }),
11993
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11994
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11995
- ui.Text,
11996
- {
11997
- size: "small",
11998
- leading: "compact",
11999
- className: "text-ui-fg-subtle",
12000
- children: [
12001
- item.quantity,
12002
- "x"
12003
- ]
12004
- }
12005
- ) }),
12006
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12007
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12008
- /* @__PURE__ */ jsxRuntime.jsxs(
12009
- ui.Text,
12010
- {
12011
- size: "small",
12012
- leading: "compact",
12013
- weight: "plus",
12014
- children: [
12015
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12016
- " (",
12017
- (_c2 = item.variant) == null ? void 0 : _c2.title,
12018
- ")"
12019
- ]
12020
- }
12021
- ),
12022
- /* @__PURE__ */ jsxRuntime.jsx(
12023
- ui.Text,
12024
- {
12025
- size: "small",
12026
- leading: "compact",
12027
- className: "text-ui-fg-subtle",
12028
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12029
- }
12030
- )
12031
- ] })
12032
- ] })
12033
- ]
12034
- },
12035
- item.id
12036
- ),
12037
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12038
- ] }, item.id);
12039
- })
12040
- ] })
12041
- ]
12042
- },
12043
- profile.id
12044
- );
12045
- }) })
12046
- ] }) })
12047
- ] }) }),
12048
- /* @__PURE__ */ jsxRuntime.jsx(
12049
- StackedFocusModal,
12050
- {
12051
- id: STACKED_FOCUS_MODAL_ID,
12052
- onOpenChangeCallback: (open) => {
12053
- if (!open) {
12054
- setData(null);
11639
+ /* @__PURE__ */ jsxRuntime.jsx(
11640
+ CustomerField,
11641
+ {
11642
+ control: form.control,
11643
+ currentCustomerId: order.customer_id
12055
11644
  }
12056
- return open;
12057
- },
12058
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12059
- }
12060
- )
12061
- ] }),
12062
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12063
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12064
- /* @__PURE__ */ jsxRuntime.jsx(
12065
- ui.Button,
12066
- {
12067
- size: "small",
12068
- type: "button",
12069
- isLoading: isSubmitting,
12070
- onClick: onSubmit,
12071
- children: "Save"
12072
- }
12073
- )
12074
- ] }) })
12075
- ] });
11645
+ )
11646
+ ] }),
11647
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11648
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11649
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11650
+ ] }) })
11651
+ ]
11652
+ }
11653
+ ) });
12076
11654
  };
12077
- const StackedModalTrigger = ({
12078
- shippingProfileId,
12079
- shippingOption,
12080
- shippingMethod,
12081
- setData,
12082
- children
12083
- }) => {
12084
- const { setIsOpen, getIsOpen } = useStackedModal();
12085
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12086
- const onToggle = () => {
12087
- if (isOpen) {
12088
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12089
- setData(null);
12090
- } else {
12091
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12092
- setData({
12093
- shippingProfileId,
12094
- shippingOption,
12095
- shippingMethod
11655
+ const CustomerField = ({ control, currentCustomerId }) => {
11656
+ const customers = useComboboxData({
11657
+ queryFn: async (params) => {
11658
+ return await sdk.admin.customer.list({
11659
+ ...params,
11660
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11661
+ });
11662
+ },
11663
+ queryKey: ["customers"],
11664
+ getOptions: (data) => {
11665
+ return data.customers.map((customer) => {
11666
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11667
+ return {
11668
+ label: name ? `${name} (${customer.email})` : customer.email,
11669
+ value: customer.id
11670
+ };
12096
11671
  });
12097
11672
  }
12098
- };
11673
+ });
12099
11674
  return /* @__PURE__ */ jsxRuntime.jsx(
12100
- ui.Button,
11675
+ Form$2.Field,
12101
11676
  {
12102
- size: "small",
12103
- variant: "secondary",
12104
- onClick: onToggle,
12105
- className: "text-ui-fg-primary shrink-0",
12106
- children
11677
+ name: "customer_id",
11678
+ control,
11679
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11680
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11681
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11682
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11683
+ ] }),
11684
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11685
+ Combobox,
11686
+ {
11687
+ options: customers.options,
11688
+ fetchNextPage: customers.fetchNextPage,
11689
+ isFetchingNextPage: customers.isFetchingNextPage,
11690
+ searchValue: customers.searchValue,
11691
+ onSearchValueChange: customers.onSearchValueChange,
11692
+ placeholder: "Select customer",
11693
+ ...field
11694
+ }
11695
+ ) }),
11696
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11697
+ ] })
12107
11698
  }
12108
11699
  );
12109
11700
  };
12110
- const ShippingProfileForm = ({
12111
- data,
12112
- order,
12113
- preview
12114
- }) => {
12115
- var _a, _b, _c, _d, _e, _f;
12116
- const { setIsOpen } = useStackedModal();
12117
- const form = reactHookForm.useForm({
12118
- resolver: zod.zodResolver(shippingMethodSchema),
12119
- defaultValues: {
12120
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12121
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12122
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12123
- }
12124
- });
12125
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12126
- const {
12127
- mutateAsync: updateShippingMethod,
12128
- isPending: isUpdatingShippingMethod
12129
- } = useDraftOrderUpdateShippingMethod(order.id);
12130
- const onSubmit = form.handleSubmit(async (values) => {
12131
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12132
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12133
- return;
12134
- }
12135
- if (data.shippingMethod) {
12136
- await updateShippingMethod(
12137
- {
12138
- method_id: data.shippingMethod.id,
12139
- shipping_option_id: values.shipping_option_id,
12140
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12141
- },
12142
- {
12143
- onError: (e) => {
12144
- ui.toast.error(e.message);
12145
- },
12146
- onSuccess: () => {
12147
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12148
- }
12149
- }
12150
- );
12151
- return;
12152
- }
12153
- await addShippingMethod(
12154
- {
12155
- shipping_option_id: values.shipping_option_id,
12156
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12157
- },
12158
- {
12159
- onError: (e) => {
12160
- ui.toast.error(e.message);
12161
- },
12162
- onSuccess: () => {
12163
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12164
- }
12165
- }
12166
- );
12167
- });
12168
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12169
- KeyboundForm,
11701
+ const Illustration = () => {
11702
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11703
+ "svg",
12170
11704
  {
12171
- className: "flex h-full flex-col overflow-hidden",
12172
- onSubmit,
12173
- children: [
12174
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12175
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.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 py-16 px-6", children: [
12176
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12177
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12178
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12179
- ] }),
12180
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12181
- /* @__PURE__ */ jsxRuntime.jsx(
12182
- LocationField,
12183
- {
12184
- control: form.control,
12185
- setValue: form.setValue
12186
- }
12187
- ),
12188
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12189
- /* @__PURE__ */ jsxRuntime.jsx(
12190
- ShippingOptionField,
12191
- {
12192
- shippingProfileId: data.shippingProfileId,
12193
- preview,
12194
- control: form.control
12195
- }
12196
- ),
12197
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12198
- /* @__PURE__ */ jsxRuntime.jsx(
12199
- CustomAmountField,
12200
- {
12201
- control: form.control,
12202
- currencyCode: order.currency_code
12203
- }
12204
- ),
12205
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12206
- /* @__PURE__ */ jsxRuntime.jsx(
12207
- ItemsPreview,
12208
- {
12209
- order,
12210
- shippingProfileId: data.shippingProfileId
12211
- }
12212
- )
12213
- ] }) }) }),
12214
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12215
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12216
- /* @__PURE__ */ jsxRuntime.jsx(
12217
- ui.Button,
12218
- {
12219
- size: "small",
12220
- type: "submit",
12221
- isLoading: isPending || isUpdatingShippingMethod,
12222
- children: data.shippingMethod ? "Update" : "Add"
12223
- }
12224
- )
12225
- ] }) })
12226
- ]
12227
- }
12228
- ) }) });
12229
- };
12230
- const shippingMethodSchema = objectType({
12231
- location_id: stringType(),
12232
- shipping_option_id: stringType(),
12233
- custom_amount: unionType([numberType(), stringType()]).optional()
12234
- });
12235
- const ItemsPreview = ({ order, shippingProfileId }) => {
12236
- const matches = order.items.filter(
12237
- (item) => {
12238
- var _a, _b, _c;
12239
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12240
- }
12241
- );
12242
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12243
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12244
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12245
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12246
- ] }) }),
12247
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12248
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12249
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12250
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12251
- ] }),
12252
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12253
- "div",
12254
- {
12255
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12256
- children: [
12257
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12258
- /* @__PURE__ */ jsxRuntime.jsx(
12259
- Thumbnail,
12260
- {
12261
- thumbnail: item.thumbnail,
12262
- alt: item.product_title ?? void 0
12263
- }
12264
- ),
12265
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12266
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12267
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12268
- /* @__PURE__ */ jsxRuntime.jsxs(
12269
- ui.Text,
12270
- {
12271
- size: "small",
12272
- leading: "compact",
12273
- className: "text-ui-fg-subtle",
12274
- children: [
12275
- "(",
12276
- item.variant_title,
12277
- ")"
12278
- ]
12279
- }
12280
- )
12281
- ] }),
12282
- /* @__PURE__ */ jsxRuntime.jsx(
12283
- ui.Text,
12284
- {
12285
- size: "small",
12286
- leading: "compact",
12287
- className: "text-ui-fg-subtle",
12288
- children: item.variant_sku
12289
- }
12290
- )
12291
- ] })
12292
- ] }),
12293
- /* @__PURE__ */ jsxRuntime.jsxs(
12294
- ui.Text,
12295
- {
12296
- size: "small",
12297
- leading: "compact",
12298
- className: "text-ui-fg-subtle",
12299
- children: [
12300
- item.quantity,
12301
- "x"
12302
- ]
12303
- }
12304
- )
12305
- ]
12306
- },
12307
- item.id
12308
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12309
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12310
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12311
- 'No items found for "',
12312
- query,
12313
- '".'
12314
- ] })
12315
- ] }) })
12316
- ] })
12317
- ] });
12318
- };
12319
- const LocationField = ({ control, setValue }) => {
12320
- const locations = useComboboxData({
12321
- queryKey: ["locations"],
12322
- queryFn: async (params) => {
12323
- return await sdk.admin.stockLocation.list(params);
12324
- },
12325
- getOptions: (data) => {
12326
- return data.stock_locations.map((location) => ({
12327
- label: location.name,
12328
- value: location.id
12329
- }));
12330
- }
12331
- });
12332
- return /* @__PURE__ */ jsxRuntime.jsx(
12333
- Form$2.Field,
12334
- {
12335
- control,
12336
- name: "location_id",
12337
- render: ({ field: { onChange, ...field } }) => {
12338
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12339
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12342
- ] }),
12343
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12344
- Combobox,
12345
- {
12346
- options: locations.options,
12347
- fetchNextPage: locations.fetchNextPage,
12348
- isFetchingNextPage: locations.isFetchingNextPage,
12349
- searchValue: locations.searchValue,
12350
- onSearchValueChange: locations.onSearchValueChange,
12351
- placeholder: "Select location",
12352
- onChange: (value) => {
12353
- setValue("shipping_option_id", "", {
12354
- shouldDirty: true,
12355
- shouldTouch: true
12356
- });
12357
- onChange(value);
12358
- },
12359
- ...field
12360
- }
12361
- ) })
12362
- ] }) });
12363
- }
12364
- }
12365
- );
12366
- };
12367
- const ShippingOptionField = ({
12368
- shippingProfileId,
12369
- preview,
12370
- control
12371
- }) => {
12372
- var _a;
12373
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12374
- const shippingOptions = useComboboxData({
12375
- queryKey: ["shipping_options", locationId, shippingProfileId],
12376
- queryFn: async (params) => {
12377
- return await sdk.admin.shippingOption.list({
12378
- ...params,
12379
- stock_location_id: locationId,
12380
- shipping_profile_id: shippingProfileId
12381
- });
12382
- },
12383
- getOptions: (data) => {
12384
- return data.shipping_options.map((option) => {
12385
- var _a2;
12386
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12387
- (r) => r.attribute === "is_return" && r.value === "true"
12388
- )) {
12389
- return void 0;
12390
- }
12391
- return {
12392
- label: option.name,
12393
- value: option.id
12394
- };
12395
- }).filter(Boolean);
12396
- },
12397
- enabled: !!locationId && !!shippingProfileId,
12398
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12399
- });
12400
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12401
- return /* @__PURE__ */ jsxRuntime.jsx(
12402
- Form$2.Field,
12403
- {
12404
- control,
12405
- name: "shipping_option_id",
12406
- render: ({ field }) => {
12407
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12408
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12409
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12410
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12411
- ] }),
12412
- /* @__PURE__ */ jsxRuntime.jsx(
12413
- ConditionalTooltip,
12414
- {
12415
- content: tooltipContent,
12416
- showTooltip: !locationId || !shippingProfileId,
12417
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12418
- Combobox,
12419
- {
12420
- options: shippingOptions.options,
12421
- fetchNextPage: shippingOptions.fetchNextPage,
12422
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12423
- searchValue: shippingOptions.searchValue,
12424
- onSearchValueChange: shippingOptions.onSearchValueChange,
12425
- placeholder: "Select shipping option",
12426
- ...field,
12427
- disabled: !locationId || !shippingProfileId
12428
- }
12429
- ) }) })
12430
- }
12431
- )
12432
- ] }) });
12433
- }
12434
- }
12435
- );
12436
- };
12437
- const CustomAmountField = ({
12438
- control,
12439
- currencyCode
12440
- }) => {
12441
- return /* @__PURE__ */ jsxRuntime.jsx(
12442
- Form$2.Field,
12443
- {
12444
- control,
12445
- name: "custom_amount",
12446
- render: ({ field: { onChange, ...field } }) => {
12447
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12448
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12451
- ] }),
12452
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12453
- ui.CurrencyInput,
12454
- {
12455
- ...field,
12456
- onValueChange: (value) => onChange(value),
12457
- symbol: getNativeSymbol(currencyCode),
12458
- code: currencyCode
12459
- }
12460
- ) })
12461
- ] });
12462
- }
12463
- }
12464
- );
12465
- };
12466
- const TransferOwnership = () => {
12467
- const { id } = reactRouterDom.useParams();
12468
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12469
- fields: "id,customer_id,customer.*"
12470
- });
12471
- if (isError) {
12472
- throw error;
12473
- }
12474
- const isReady = !isPending && !!draft_order;
12475
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12476
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12477
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12478
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12479
- ] }),
12480
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12481
- ] });
12482
- };
12483
- const TransferOwnershipForm = ({ order }) => {
12484
- var _a, _b;
12485
- const form = reactHookForm.useForm({
12486
- defaultValues: {
12487
- customer_id: order.customer_id || ""
12488
- },
12489
- resolver: zod.zodResolver(schema$1)
12490
- });
12491
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12492
- const { handleSuccess } = useRouteModal();
12493
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12494
- const currentCustomer = order.customer ? {
12495
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12496
- value: order.customer.id
12497
- } : null;
12498
- const onSubmit = form.handleSubmit(async (data) => {
12499
- await mutateAsync(
12500
- { customer_id: data.customer_id },
12501
- {
12502
- onSuccess: () => {
12503
- ui.toast.success("Customer updated");
12504
- handleSuccess();
12505
- },
12506
- onError: (error) => {
12507
- ui.toast.error(error.message);
12508
- }
12509
- }
12510
- );
12511
- });
12512
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12513
- KeyboundForm,
12514
- {
12515
- className: "flex flex-1 flex-col overflow-hidden",
12516
- onSubmit,
12517
- children: [
12518
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12519
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12520
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12521
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12522
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12523
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12524
- ] }),
12525
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12526
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12527
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12528
- ] })
12529
- ] }),
12530
- /* @__PURE__ */ jsxRuntime.jsx(
12531
- CustomerField,
12532
- {
12533
- control: form.control,
12534
- currentCustomerId: order.customer_id
12535
- }
12536
- )
12537
- ] }),
12538
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12539
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12540
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12541
- ] }) })
12542
- ]
12543
- }
12544
- ) });
12545
- };
12546
- const CustomerField = ({ control, currentCustomerId }) => {
12547
- const customers = useComboboxData({
12548
- queryFn: async (params) => {
12549
- return await sdk.admin.customer.list({
12550
- ...params,
12551
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12552
- });
12553
- },
12554
- queryKey: ["customers"],
12555
- getOptions: (data) => {
12556
- return data.customers.map((customer) => {
12557
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12558
- return {
12559
- label: name ? `${name} (${customer.email})` : customer.email,
12560
- value: customer.id
12561
- };
12562
- });
12563
- }
12564
- });
12565
- return /* @__PURE__ */ jsxRuntime.jsx(
12566
- Form$2.Field,
12567
- {
12568
- name: "customer_id",
12569
- control,
12570
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12571
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12572
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12573
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12574
- ] }),
12575
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12576
- Combobox,
12577
- {
12578
- options: customers.options,
12579
- fetchNextPage: customers.fetchNextPage,
12580
- isFetchingNextPage: customers.isFetchingNextPage,
12581
- searchValue: customers.searchValue,
12582
- onSearchValueChange: customers.onSearchValueChange,
12583
- placeholder: "Select customer",
12584
- ...field
12585
- }
12586
- ) }),
12587
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12588
- ] })
12589
- }
12590
- );
12591
- };
12592
- const Illustration = () => {
12593
- return /* @__PURE__ */ jsxRuntime.jsxs(
12594
- "svg",
12595
- {
12596
- width: "280",
12597
- height: "180",
12598
- viewBox: "0 0 280 180",
12599
- fill: "none",
12600
- xmlns: "http://www.w3.org/2000/svg",
11705
+ width: "280",
11706
+ height: "180",
11707
+ viewBox: "0 0 280 180",
11708
+ fill: "none",
11709
+ xmlns: "http://www.w3.org/2000/svg",
12601
11710
  children: [
12602
11711
  /* @__PURE__ */ jsxRuntime.jsx(
12603
11712
  "rect",
@@ -12875,97 +11984,908 @@ const Illustration = () => {
12875
11984
  strokeLinecap: "round",
12876
11985
  strokeLinejoin: "round"
12877
11986
  }
12878
- ) }),
12879
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12880
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12881
- "rect",
11987
+ ) }),
11988
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
11989
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11990
+ "rect",
11991
+ {
11992
+ width: "12",
11993
+ height: "12",
11994
+ fill: "white",
11995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11996
+ }
11997
+ ) }),
11998
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11999
+ "rect",
12000
+ {
12001
+ width: "12",
12002
+ height: "12",
12003
+ fill: "white",
12004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12005
+ }
12006
+ ) }),
12007
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12008
+ "rect",
12009
+ {
12010
+ width: "12",
12011
+ height: "12",
12012
+ fill: "white",
12013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12014
+ }
12015
+ ) }),
12016
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12017
+ "rect",
12018
+ {
12019
+ width: "12",
12020
+ height: "12",
12021
+ fill: "white",
12022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12023
+ }
12024
+ ) }),
12025
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12026
+ "rect",
12027
+ {
12028
+ width: "12",
12029
+ height: "12",
12030
+ fill: "white",
12031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12032
+ }
12033
+ ) }),
12034
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12035
+ "rect",
12036
+ {
12037
+ width: "12",
12038
+ height: "12",
12039
+ fill: "white",
12040
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12041
+ }
12042
+ ) })
12043
+ ] })
12044
+ ]
12045
+ }
12046
+ );
12047
+ };
12048
+ const schema$1 = objectType({
12049
+ customer_id: stringType().min(1)
12050
+ });
12051
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
12052
+ const Shipping = () => {
12053
+ var _a;
12054
+ const { id } = reactRouterDom.useParams();
12055
+ const { order, isPending, isError, error } = useOrder(id, {
12056
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12057
+ });
12058
+ const {
12059
+ order: preview,
12060
+ isPending: isPreviewPending,
12061
+ isError: isPreviewError,
12062
+ error: previewError
12063
+ } = useOrderPreview(id);
12064
+ useInitiateOrderEdit({ preview });
12065
+ const { onCancel } = useCancelOrderEdit({ preview });
12066
+ if (isError) {
12067
+ throw error;
12068
+ }
12069
+ if (isPreviewError) {
12070
+ throw previewError;
12071
+ }
12072
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12073
+ const isReady = preview && !isPreviewPending && order && !isPending;
12074
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12075
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12076
+ /* @__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 py-16 px-6", children: [
12077
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12078
+ /* @__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." }) })
12079
+ ] }) }) }),
12080
+ /* @__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" }) }) })
12081
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12082
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12083
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12084
+ ] }) });
12085
+ };
12086
+ const ShippingForm = ({ preview, order }) => {
12087
+ var _a;
12088
+ const { setIsOpen } = useStackedModal();
12089
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12090
+ const [data, setData] = React.useState(null);
12091
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12092
+ const { shipping_options } = useShippingOptions(
12093
+ {
12094
+ id: appliedShippingOptionIds,
12095
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12096
+ },
12097
+ {
12098
+ enabled: appliedShippingOptionIds.length > 0
12099
+ }
12100
+ );
12101
+ const uniqueShippingProfiles = React.useMemo(() => {
12102
+ const profiles = /* @__PURE__ */ new Map();
12103
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12104
+ profiles.set(profile.id, profile);
12105
+ });
12106
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12107
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12108
+ });
12109
+ return Array.from(profiles.values());
12110
+ }, [order.items, shipping_options]);
12111
+ const { handleSuccess } = useRouteModal();
12112
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12113
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12114
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12115
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12116
+ const onSubmit = async () => {
12117
+ setIsSubmitting(true);
12118
+ let requestSucceeded = false;
12119
+ await requestOrderEdit(void 0, {
12120
+ onError: (e) => {
12121
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12122
+ },
12123
+ onSuccess: () => {
12124
+ requestSucceeded = true;
12125
+ }
12126
+ });
12127
+ if (!requestSucceeded) {
12128
+ setIsSubmitting(false);
12129
+ return;
12130
+ }
12131
+ await confirmOrderEdit(void 0, {
12132
+ onError: (e) => {
12133
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12134
+ },
12135
+ onSuccess: () => {
12136
+ handleSuccess();
12137
+ },
12138
+ onSettled: () => {
12139
+ setIsSubmitting(false);
12140
+ }
12141
+ });
12142
+ };
12143
+ const onKeydown = React.useCallback(
12144
+ (e) => {
12145
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12146
+ if (data || isSubmitting) {
12147
+ return;
12148
+ }
12149
+ onSubmit();
12150
+ }
12151
+ },
12152
+ [data, isSubmitting, onSubmit]
12153
+ );
12154
+ React.useEffect(() => {
12155
+ document.addEventListener("keydown", onKeydown);
12156
+ return () => {
12157
+ document.removeEventListener("keydown", onKeydown);
12158
+ };
12159
+ }, [onKeydown]);
12160
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12161
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12162
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12163
+ /* @__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 py-16 px-6", children: [
12164
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12165
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12166
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
12167
+ ] }),
12168
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12169
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
12170
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12171
+ /* @__PURE__ */ jsxRuntime.jsx(
12172
+ ui.Text,
12173
+ {
12174
+ size: "xsmall",
12175
+ weight: "plus",
12176
+ className: "text-ui-fg-muted",
12177
+ children: "Shipping profile"
12178
+ }
12179
+ ),
12180
+ /* @__PURE__ */ jsxRuntime.jsx(
12181
+ ui.Text,
12182
+ {
12183
+ size: "xsmall",
12184
+ weight: "plus",
12185
+ className: "text-ui-fg-muted",
12186
+ children: "Action"
12187
+ }
12188
+ )
12189
+ ] }),
12190
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12191
+ var _a2, _b, _c, _d, _e, _f, _g;
12192
+ const items = getItemsWithShippingProfile(
12193
+ profile.id,
12194
+ order.items
12195
+ );
12196
+ const hasItems = items.length > 0;
12197
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12198
+ (option) => option.shipping_profile_id === profile.id
12199
+ );
12200
+ const shippingMethod = preview.shipping_methods.find(
12201
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12202
+ );
12203
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12204
+ (action) => action.action === "SHIPPING_ADD"
12205
+ );
12206
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12207
+ radixUi.Accordion.Item,
12208
+ {
12209
+ value: profile.id,
12210
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12211
+ children: [
12212
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
12213
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
12214
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
12215
+ ui.IconButton,
12216
+ {
12217
+ size: "2xsmall",
12218
+ variant: "transparent",
12219
+ className: "group/trigger",
12220
+ disabled: !hasItems,
12221
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
12222
+ }
12223
+ ) }),
12224
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12225
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
12226
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
12227
+ /* @__PURE__ */ jsxRuntime.jsx(
12228
+ ui.Text,
12229
+ {
12230
+ size: "small",
12231
+ weight: "plus",
12232
+ leading: "compact",
12233
+ children: profile.name
12234
+ }
12235
+ ),
12236
+ /* @__PURE__ */ jsxRuntime.jsxs(
12237
+ ui.Text,
12238
+ {
12239
+ size: "small",
12240
+ leading: "compact",
12241
+ className: "text-ui-fg-subtle",
12242
+ children: [
12243
+ items.length,
12244
+ " ",
12245
+ pluralize(items.length, "items", "item")
12246
+ ]
12247
+ }
12248
+ )
12249
+ ] })
12250
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
12251
+ /* @__PURE__ */ jsxRuntime.jsx(
12252
+ ui.Tooltip,
12253
+ {
12254
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
12255
+ var _a3, _b2, _c2;
12256
+ return /* @__PURE__ */ jsxRuntime.jsx(
12257
+ "li",
12258
+ {
12259
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12260
+ },
12261
+ item.id
12262
+ );
12263
+ }) }),
12264
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12265
+ ui.Badge,
12266
+ {
12267
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12268
+ size: "xsmall",
12269
+ children: [
12270
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
12271
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
12272
+ items.reduce(
12273
+ (acc, item) => acc + item.quantity,
12274
+ 0
12275
+ ),
12276
+ "x",
12277
+ " ",
12278
+ pluralize(items.length, "items", "item")
12279
+ ] })
12280
+ ]
12281
+ }
12282
+ )
12283
+ }
12284
+ ),
12285
+ /* @__PURE__ */ jsxRuntime.jsx(
12286
+ ui.Tooltip,
12287
+ {
12288
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12289
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12290
+ ui.Badge,
12291
+ {
12292
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12293
+ size: "xsmall",
12294
+ children: [
12295
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12296
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12297
+ ]
12298
+ }
12299
+ )
12300
+ }
12301
+ ),
12302
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12303
+ ui.Badge,
12304
+ {
12305
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12306
+ size: "xsmall",
12307
+ children: [
12308
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12309
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12310
+ ]
12311
+ }
12312
+ ) })
12313
+ ] })
12314
+ ] }),
12315
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12316
+ ActionMenu,
12317
+ {
12318
+ groups: [
12319
+ {
12320
+ actions: [
12321
+ hasItems ? {
12322
+ label: "Edit shipping option",
12323
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12324
+ onClick: () => {
12325
+ setIsOpen(
12326
+ STACKED_FOCUS_MODAL_ID,
12327
+ true
12328
+ );
12329
+ setData({
12330
+ shippingProfileId: profile.id,
12331
+ shippingOption,
12332
+ shippingMethod
12333
+ });
12334
+ }
12335
+ } : void 0,
12336
+ {
12337
+ label: "Remove shipping option",
12338
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12339
+ onClick: () => {
12340
+ if (shippingMethod) {
12341
+ if (addShippingMethodAction) {
12342
+ removeActionShippingMethod(
12343
+ addShippingMethodAction.id
12344
+ );
12345
+ } else {
12346
+ removeShippingMethod(
12347
+ shippingMethod.id
12348
+ );
12349
+ }
12350
+ }
12351
+ }
12352
+ }
12353
+ ].filter(Boolean)
12354
+ }
12355
+ ]
12356
+ }
12357
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12358
+ StackedModalTrigger,
12359
+ {
12360
+ shippingProfileId: profile.id,
12361
+ shippingOption,
12362
+ shippingMethod,
12363
+ setData,
12364
+ children: "Add shipping option"
12365
+ }
12366
+ )
12367
+ ] }),
12368
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12369
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12370
+ items.map((item, idx) => {
12371
+ var _a3, _b2, _c2, _d2, _e2;
12372
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12373
+ /* @__PURE__ */ jsxRuntime.jsxs(
12374
+ "div",
12375
+ {
12376
+ className: "px-3 flex items-center gap-x-3",
12377
+ children: [
12378
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12379
+ ui.Divider,
12380
+ {
12381
+ variant: "dashed",
12382
+ orientation: "vertical"
12383
+ }
12384
+ ) }),
12385
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12386
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12387
+ ui.Text,
12388
+ {
12389
+ size: "small",
12390
+ leading: "compact",
12391
+ className: "text-ui-fg-subtle",
12392
+ children: [
12393
+ item.quantity,
12394
+ "x"
12395
+ ]
12396
+ }
12397
+ ) }),
12398
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12399
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12400
+ /* @__PURE__ */ jsxRuntime.jsxs(
12401
+ ui.Text,
12402
+ {
12403
+ size: "small",
12404
+ leading: "compact",
12405
+ weight: "plus",
12406
+ children: [
12407
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12408
+ " (",
12409
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12410
+ ")"
12411
+ ]
12412
+ }
12413
+ ),
12414
+ /* @__PURE__ */ jsxRuntime.jsx(
12415
+ ui.Text,
12416
+ {
12417
+ size: "small",
12418
+ leading: "compact",
12419
+ className: "text-ui-fg-subtle",
12420
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12421
+ }
12422
+ )
12423
+ ] })
12424
+ ] })
12425
+ ]
12426
+ },
12427
+ item.id
12428
+ ),
12429
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12430
+ ] }, item.id);
12431
+ })
12432
+ ] })
12433
+ ]
12434
+ },
12435
+ profile.id
12436
+ );
12437
+ }) })
12438
+ ] }) })
12439
+ ] }) }),
12440
+ /* @__PURE__ */ jsxRuntime.jsx(
12441
+ StackedFocusModal,
12442
+ {
12443
+ id: STACKED_FOCUS_MODAL_ID,
12444
+ onOpenChangeCallback: (open) => {
12445
+ if (!open) {
12446
+ setData(null);
12447
+ }
12448
+ return open;
12449
+ },
12450
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12451
+ }
12452
+ )
12453
+ ] }),
12454
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12455
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12456
+ /* @__PURE__ */ jsxRuntime.jsx(
12457
+ ui.Button,
12458
+ {
12459
+ size: "small",
12460
+ type: "button",
12461
+ isLoading: isSubmitting,
12462
+ onClick: onSubmit,
12463
+ children: "Save"
12464
+ }
12465
+ )
12466
+ ] }) })
12467
+ ] });
12468
+ };
12469
+ const StackedModalTrigger = ({
12470
+ shippingProfileId,
12471
+ shippingOption,
12472
+ shippingMethod,
12473
+ setData,
12474
+ children
12475
+ }) => {
12476
+ const { setIsOpen, getIsOpen } = useStackedModal();
12477
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12478
+ const onToggle = () => {
12479
+ if (isOpen) {
12480
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12481
+ setData(null);
12482
+ } else {
12483
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12484
+ setData({
12485
+ shippingProfileId,
12486
+ shippingOption,
12487
+ shippingMethod
12488
+ });
12489
+ }
12490
+ };
12491
+ return /* @__PURE__ */ jsxRuntime.jsx(
12492
+ ui.Button,
12493
+ {
12494
+ size: "small",
12495
+ variant: "secondary",
12496
+ onClick: onToggle,
12497
+ className: "text-ui-fg-primary shrink-0",
12498
+ children
12499
+ }
12500
+ );
12501
+ };
12502
+ const ShippingProfileForm = ({
12503
+ data,
12504
+ order,
12505
+ preview
12506
+ }) => {
12507
+ var _a, _b, _c, _d, _e, _f;
12508
+ const { setIsOpen } = useStackedModal();
12509
+ const form = reactHookForm.useForm({
12510
+ resolver: zod.zodResolver(shippingMethodSchema),
12511
+ defaultValues: {
12512
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12513
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12514
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12515
+ }
12516
+ });
12517
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12518
+ const {
12519
+ mutateAsync: updateShippingMethod,
12520
+ isPending: isUpdatingShippingMethod
12521
+ } = useDraftOrderUpdateShippingMethod(order.id);
12522
+ const onSubmit = form.handleSubmit(async (values) => {
12523
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12524
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12525
+ return;
12526
+ }
12527
+ if (data.shippingMethod) {
12528
+ await updateShippingMethod(
12529
+ {
12530
+ method_id: data.shippingMethod.id,
12531
+ shipping_option_id: values.shipping_option_id,
12532
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12533
+ },
12534
+ {
12535
+ onError: (e) => {
12536
+ ui.toast.error(e.message);
12537
+ },
12538
+ onSuccess: () => {
12539
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12540
+ }
12541
+ }
12542
+ );
12543
+ return;
12544
+ }
12545
+ await addShippingMethod(
12546
+ {
12547
+ shipping_option_id: values.shipping_option_id,
12548
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12549
+ },
12550
+ {
12551
+ onError: (e) => {
12552
+ ui.toast.error(e.message);
12553
+ },
12554
+ onSuccess: () => {
12555
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12556
+ }
12557
+ }
12558
+ );
12559
+ });
12560
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12561
+ KeyboundForm,
12562
+ {
12563
+ className: "flex h-full flex-col overflow-hidden",
12564
+ onSubmit,
12565
+ children: [
12566
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12567
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.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 py-16 px-6", children: [
12568
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12569
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12570
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12571
+ ] }),
12572
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12573
+ /* @__PURE__ */ jsxRuntime.jsx(
12574
+ LocationField,
12882
12575
  {
12883
- width: "12",
12884
- height: "12",
12885
- fill: "white",
12886
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12576
+ control: form.control,
12577
+ setValue: form.setValue
12887
12578
  }
12888
- ) }),
12889
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12890
- "rect",
12579
+ ),
12580
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12581
+ /* @__PURE__ */ jsxRuntime.jsx(
12582
+ ShippingOptionField,
12891
12583
  {
12892
- width: "12",
12893
- height: "12",
12894
- fill: "white",
12895
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12584
+ shippingProfileId: data.shippingProfileId,
12585
+ preview,
12586
+ control: form.control
12587
+ }
12588
+ ),
12589
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12590
+ /* @__PURE__ */ jsxRuntime.jsx(
12591
+ CustomAmountField,
12592
+ {
12593
+ control: form.control,
12594
+ currencyCode: order.currency_code
12595
+ }
12596
+ ),
12597
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12598
+ /* @__PURE__ */ jsxRuntime.jsx(
12599
+ ItemsPreview,
12600
+ {
12601
+ order,
12602
+ shippingProfileId: data.shippingProfileId
12896
12603
  }
12897
- ) }),
12898
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12899
- "rect",
12604
+ )
12605
+ ] }) }) }),
12606
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12607
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12608
+ /* @__PURE__ */ jsxRuntime.jsx(
12609
+ ui.Button,
12900
12610
  {
12901
- width: "12",
12902
- height: "12",
12903
- fill: "white",
12904
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12611
+ size: "small",
12612
+ type: "submit",
12613
+ isLoading: isPending || isUpdatingShippingMethod,
12614
+ children: data.shippingMethod ? "Update" : "Add"
12905
12615
  }
12906
- ) }),
12907
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12908
- "rect",
12616
+ )
12617
+ ] }) })
12618
+ ]
12619
+ }
12620
+ ) }) });
12621
+ };
12622
+ const shippingMethodSchema = objectType({
12623
+ location_id: stringType(),
12624
+ shipping_option_id: stringType(),
12625
+ custom_amount: unionType([numberType(), stringType()]).optional()
12626
+ });
12627
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12628
+ const matches = order.items.filter(
12629
+ (item) => {
12630
+ var _a, _b, _c;
12631
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12632
+ }
12633
+ );
12634
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12635
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12636
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12637
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12638
+ ] }) }),
12639
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12640
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12641
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12642
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12643
+ ] }),
12644
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12645
+ "div",
12646
+ {
12647
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12648
+ children: [
12649
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12650
+ /* @__PURE__ */ jsxRuntime.jsx(
12651
+ Thumbnail,
12652
+ {
12653
+ thumbnail: item.thumbnail,
12654
+ alt: item.product_title ?? void 0
12655
+ }
12656
+ ),
12657
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12658
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12659
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12660
+ /* @__PURE__ */ jsxRuntime.jsxs(
12661
+ ui.Text,
12662
+ {
12663
+ size: "small",
12664
+ leading: "compact",
12665
+ className: "text-ui-fg-subtle",
12666
+ children: [
12667
+ "(",
12668
+ item.variant_title,
12669
+ ")"
12670
+ ]
12671
+ }
12672
+ )
12673
+ ] }),
12674
+ /* @__PURE__ */ jsxRuntime.jsx(
12675
+ ui.Text,
12676
+ {
12677
+ size: "small",
12678
+ leading: "compact",
12679
+ className: "text-ui-fg-subtle",
12680
+ children: item.variant_sku
12681
+ }
12682
+ )
12683
+ ] })
12684
+ ] }),
12685
+ /* @__PURE__ */ jsxRuntime.jsxs(
12686
+ ui.Text,
12687
+ {
12688
+ size: "small",
12689
+ leading: "compact",
12690
+ className: "text-ui-fg-subtle",
12691
+ children: [
12692
+ item.quantity,
12693
+ "x"
12694
+ ]
12695
+ }
12696
+ )
12697
+ ]
12698
+ },
12699
+ item.id
12700
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12701
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12702
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12703
+ 'No items found for "',
12704
+ query,
12705
+ '".'
12706
+ ] })
12707
+ ] }) })
12708
+ ] })
12709
+ ] });
12710
+ };
12711
+ const LocationField = ({ control, setValue }) => {
12712
+ const locations = useComboboxData({
12713
+ queryKey: ["locations"],
12714
+ queryFn: async (params) => {
12715
+ return await sdk.admin.stockLocation.list(params);
12716
+ },
12717
+ getOptions: (data) => {
12718
+ return data.stock_locations.map((location) => ({
12719
+ label: location.name,
12720
+ value: location.id
12721
+ }));
12722
+ }
12723
+ });
12724
+ return /* @__PURE__ */ jsxRuntime.jsx(
12725
+ Form$2.Field,
12726
+ {
12727
+ control,
12728
+ name: "location_id",
12729
+ render: ({ field: { onChange, ...field } }) => {
12730
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12731
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12732
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12733
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12734
+ ] }),
12735
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12736
+ Combobox,
12909
12737
  {
12910
- width: "12",
12911
- height: "12",
12912
- fill: "white",
12913
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12738
+ options: locations.options,
12739
+ fetchNextPage: locations.fetchNextPage,
12740
+ isFetchingNextPage: locations.isFetchingNextPage,
12741
+ searchValue: locations.searchValue,
12742
+ onSearchValueChange: locations.onSearchValueChange,
12743
+ placeholder: "Select location",
12744
+ onChange: (value) => {
12745
+ setValue("shipping_option_id", "", {
12746
+ shouldDirty: true,
12747
+ shouldTouch: true
12748
+ });
12749
+ onChange(value);
12750
+ },
12751
+ ...field
12914
12752
  }
12915
- ) }),
12916
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12917
- "rect",
12753
+ ) })
12754
+ ] }) });
12755
+ }
12756
+ }
12757
+ );
12758
+ };
12759
+ const ShippingOptionField = ({
12760
+ shippingProfileId,
12761
+ preview,
12762
+ control
12763
+ }) => {
12764
+ var _a;
12765
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12766
+ const shippingOptions = useComboboxData({
12767
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12768
+ queryFn: async (params) => {
12769
+ return await sdk.admin.shippingOption.list({
12770
+ ...params,
12771
+ stock_location_id: locationId,
12772
+ shipping_profile_id: shippingProfileId
12773
+ });
12774
+ },
12775
+ getOptions: (data) => {
12776
+ return data.shipping_options.map((option) => {
12777
+ var _a2;
12778
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12779
+ (r) => r.attribute === "is_return" && r.value === "true"
12780
+ )) {
12781
+ return void 0;
12782
+ }
12783
+ return {
12784
+ label: option.name,
12785
+ value: option.id
12786
+ };
12787
+ }).filter(Boolean);
12788
+ },
12789
+ enabled: !!locationId && !!shippingProfileId,
12790
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12791
+ });
12792
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12793
+ return /* @__PURE__ */ jsxRuntime.jsx(
12794
+ Form$2.Field,
12795
+ {
12796
+ control,
12797
+ name: "shipping_option_id",
12798
+ render: ({ field }) => {
12799
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12800
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12801
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12802
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12803
+ ] }),
12804
+ /* @__PURE__ */ jsxRuntime.jsx(
12805
+ ConditionalTooltip,
12918
12806
  {
12919
- width: "12",
12920
- height: "12",
12921
- fill: "white",
12922
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12807
+ content: tooltipContent,
12808
+ showTooltip: !locationId || !shippingProfileId,
12809
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12810
+ Combobox,
12811
+ {
12812
+ options: shippingOptions.options,
12813
+ fetchNextPage: shippingOptions.fetchNextPage,
12814
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12815
+ searchValue: shippingOptions.searchValue,
12816
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12817
+ placeholder: "Select shipping option",
12818
+ ...field,
12819
+ disabled: !locationId || !shippingProfileId
12820
+ }
12821
+ ) }) })
12923
12822
  }
12924
- ) }),
12925
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12926
- "rect",
12823
+ )
12824
+ ] }) });
12825
+ }
12826
+ }
12827
+ );
12828
+ };
12829
+ const CustomAmountField = ({
12830
+ control,
12831
+ currencyCode
12832
+ }) => {
12833
+ return /* @__PURE__ */ jsxRuntime.jsx(
12834
+ Form$2.Field,
12835
+ {
12836
+ control,
12837
+ name: "custom_amount",
12838
+ render: ({ field: { onChange, ...field } }) => {
12839
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12840
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12841
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12842
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12843
+ ] }),
12844
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12845
+ ui.CurrencyInput,
12927
12846
  {
12928
- width: "12",
12929
- height: "12",
12930
- fill: "white",
12931
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12847
+ ...field,
12848
+ onValueChange: (value) => onChange(value),
12849
+ symbol: getNativeSymbol(currencyCode),
12850
+ code: currencyCode
12932
12851
  }
12933
12852
  ) })
12934
- ] })
12935
- ]
12853
+ ] });
12854
+ }
12936
12855
  }
12937
12856
  );
12938
12857
  };
12939
- const schema$1 = objectType({
12940
- customer_id: stringType().min(1)
12941
- });
12942
- const SalesChannel = () => {
12858
+ const BillingAddress = () => {
12943
12859
  const { id } = reactRouterDom.useParams();
12944
- const { draft_order, isPending, isError, error } = useDraftOrder(
12945
- id,
12946
- {
12947
- fields: "+sales_channel_id"
12948
- },
12949
- {
12950
- enabled: !!id
12951
- }
12952
- );
12860
+ const { order, isPending, isError, error } = useOrder(id, {
12861
+ fields: "+billing_address"
12862
+ });
12953
12863
  if (isError) {
12954
12864
  throw error;
12955
12865
  }
12956
- const ISrEADY = !!draft_order && !isPending;
12866
+ const isReady = !isPending && !!order;
12957
12867
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12958
12868
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12959
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12960
- /* @__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" }) })
12869
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12870
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12961
12871
  ] }),
12962
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12872
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12963
12873
  ] });
12964
12874
  };
12965
- const SalesChannelForm = ({ order }) => {
12875
+ const BillingAddressForm = ({ order }) => {
12876
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12966
12877
  const form = reactHookForm.useForm({
12967
12878
  defaultValues: {
12968
- sales_channel_id: order.sales_channel_id || ""
12879
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12880
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12881
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12882
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12883
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12884
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12885
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12886
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12887
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12888
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12969
12889
  },
12970
12890
  resolver: zod.zodResolver(schema)
12971
12891
  });
@@ -12973,12 +12893,9 @@ const SalesChannelForm = ({ order }) => {
12973
12893
  const { handleSuccess } = useRouteModal();
12974
12894
  const onSubmit = form.handleSubmit(async (data) => {
12975
12895
  await mutateAsync(
12976
- {
12977
- sales_channel_id: data.sales_channel_id
12978
- },
12896
+ { billing_address: data },
12979
12897
  {
12980
12898
  onSuccess: () => {
12981
- ui.toast.success("Sales channel updated");
12982
12899
  handleSuccess();
12983
12900
  },
12984
12901
  onError: (error) => {
@@ -12993,7 +12910,132 @@ const SalesChannelForm = ({ order }) => {
12993
12910
  className: "flex flex-1 flex-col overflow-hidden",
12994
12911
  onSubmit,
12995
12912
  children: [
12996
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12913
+ /* @__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: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "country_code",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12927
+ /* @__PURE__ */ jsxRuntime.jsx(
12928
+ Form$2.Field,
12929
+ {
12930
+ control: form.control,
12931
+ name: "first_name",
12932
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12935
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12936
+ ] })
12937
+ }
12938
+ ),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(
12940
+ Form$2.Field,
12941
+ {
12942
+ control: form.control,
12943
+ name: "last_name",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12949
+ }
12950
+ )
12951
+ ] }),
12952
+ /* @__PURE__ */ jsxRuntime.jsx(
12953
+ Form$2.Field,
12954
+ {
12955
+ control: form.control,
12956
+ name: "company",
12957
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12960
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12961
+ ] })
12962
+ }
12963
+ ),
12964
+ /* @__PURE__ */ jsxRuntime.jsx(
12965
+ Form$2.Field,
12966
+ {
12967
+ control: form.control,
12968
+ name: "address_1",
12969
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12973
+ ] })
12974
+ }
12975
+ ),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "address_2",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12989
+ /* @__PURE__ */ jsxRuntime.jsx(
12990
+ Form$2.Field,
12991
+ {
12992
+ control: form.control,
12993
+ name: "postal_code",
12994
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12998
+ ] })
12999
+ }
13000
+ ),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13003
+ {
13004
+ control: form.control,
13005
+ name: "city",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13011
+ }
13012
+ )
13013
+ ] }),
13014
+ /* @__PURE__ */ jsxRuntime.jsx(
13015
+ Form$2.Field,
13016
+ {
13017
+ control: form.control,
13018
+ name: "province",
13019
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13022
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13023
+ ] })
13024
+ }
13025
+ ),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(
13027
+ Form$2.Field,
13028
+ {
13029
+ control: form.control,
13030
+ name: "phone",
13031
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13035
+ ] })
13036
+ }
13037
+ )
13038
+ ] }) }),
12997
13039
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12998
13040
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12999
13041
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13002,49 +13044,7 @@ const SalesChannelForm = ({ order }) => {
13002
13044
  }
13003
13045
  ) });
13004
13046
  };
13005
- const SalesChannelField = ({ control, order }) => {
13006
- const salesChannels = useComboboxData({
13007
- queryFn: async (params) => {
13008
- return await sdk.admin.salesChannel.list(params);
13009
- },
13010
- queryKey: ["sales-channels"],
13011
- getOptions: (data) => {
13012
- return data.sales_channels.map((salesChannel) => ({
13013
- label: salesChannel.name,
13014
- value: salesChannel.id
13015
- }));
13016
- },
13017
- defaultValue: order.sales_channel_id || void 0
13018
- });
13019
- return /* @__PURE__ */ jsxRuntime.jsx(
13020
- Form$2.Field,
13021
- {
13022
- control,
13023
- name: "sales_channel_id",
13024
- render: ({ field }) => {
13025
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13028
- Combobox,
13029
- {
13030
- options: salesChannels.options,
13031
- fetchNextPage: salesChannels.fetchNextPage,
13032
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13033
- searchValue: salesChannels.searchValue,
13034
- onSearchValueChange: salesChannels.onSearchValueChange,
13035
- placeholder: "Select sales channel",
13036
- ...field
13037
- }
13038
- ) }),
13039
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13040
- ] });
13041
- }
13042
- }
13043
- );
13044
- };
13045
- const schema = objectType({
13046
- sales_channel_id: stringType().min(1)
13047
- });
13047
+ const schema = addressSchema;
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13066,17 +13066,13 @@ const routeModule = {
13066
13066
  loader,
13067
13067
  children: [
13068
13068
  {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13069
+ Component: CustomItems,
13070
+ path: "/draft-orders/:id/custom-items"
13071
13071
  },
13072
13072
  {
13073
13073
  Component: Email,
13074
13074
  path: "/draft-orders/:id/email"
13075
13075
  },
13076
- {
13077
- Component: CustomItems,
13078
- path: "/draft-orders/:id/custom-items"
13079
- },
13080
13076
  {
13081
13077
  Component: Items,
13082
13078
  path: "/draft-orders/:id/items"
@@ -13090,20 +13086,24 @@ const routeModule = {
13090
13086
  path: "/draft-orders/:id/promotions"
13091
13087
  },
13092
13088
  {
13093
- Component: ShippingAddress,
13094
- path: "/draft-orders/:id/shipping-address"
13089
+ Component: SalesChannel,
13090
+ path: "/draft-orders/:id/sales-channel"
13095
13091
  },
13096
13092
  {
13097
- Component: Shipping,
13098
- path: "/draft-orders/:id/shipping"
13093
+ Component: ShippingAddress,
13094
+ path: "/draft-orders/:id/shipping-address"
13099
13095
  },
13100
13096
  {
13101
13097
  Component: TransferOwnership,
13102
13098
  path: "/draft-orders/:id/transfer-ownership"
13103
13099
  },
13104
13100
  {
13105
- Component: SalesChannel,
13106
- path: "/draft-orders/:id/sales-channel"
13101
+ Component: Shipping,
13102
+ path: "/draft-orders/:id/shipping"
13103
+ },
13104
+ {
13105
+ Component: BillingAddress,
13106
+ path: "/draft-orders/:id/billing-address"
13107
13107
  }
13108
13108
  ]
13109
13109
  }