@medusajs/draft-order 2.11.3-preview-20251031150158 → 2.11.3-preview-20251031210152

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.
@@ -13,9 +13,9 @@ import { FormProvider, Controller, useFormContext, useFormState, useForm, useWat
13
13
  import { Slot, Collapsible, Accordion } from "radix-ui";
14
14
  import { ComboboxProvider, Combobox as Combobox$1, ComboboxDisclosure, ComboboxPopover, ComboboxItem, ComboboxItemCheck, ComboboxItemValue, Separator } from "@ariakit/react";
15
15
  import { matchSorter } from "match-sorter";
16
- import debounce from "lodash/debounce";
16
+ import debounce from "lodash.debounce";
17
17
  import Primitive from "@uiw/react-json-view";
18
- import { isEqual } from "lodash";
18
+ import isEqual from "lodash.isequal";
19
19
  function useQueryParams(keys, prefix) {
20
20
  const [params] = useSearchParams();
21
21
  const result = {};
@@ -9586,6 +9586,196 @@ const CustomItemsForm = () => {
9586
9586
  const schema$5 = objectType({
9587
9587
  email: stringType().email()
9588
9588
  });
9589
+ const BillingAddress = () => {
9590
+ const { id } = useParams();
9591
+ const { order, isPending, isError, error } = useOrder(id, {
9592
+ fields: "+billing_address"
9593
+ });
9594
+ if (isError) {
9595
+ throw error;
9596
+ }
9597
+ const isReady = !isPending && !!order;
9598
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9599
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9600
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9601
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9602
+ ] }),
9603
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9604
+ ] });
9605
+ };
9606
+ const BillingAddressForm = ({ order }) => {
9607
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9608
+ const form = useForm({
9609
+ defaultValues: {
9610
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9611
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9612
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9613
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9614
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9615
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9616
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9617
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9618
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9619
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9620
+ },
9621
+ resolver: zodResolver(schema$4)
9622
+ });
9623
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9624
+ const { handleSuccess } = useRouteModal();
9625
+ const onSubmit = form.handleSubmit(async (data) => {
9626
+ await mutateAsync(
9627
+ { billing_address: data },
9628
+ {
9629
+ onSuccess: () => {
9630
+ handleSuccess();
9631
+ },
9632
+ onError: (error) => {
9633
+ toast.error(error.message);
9634
+ }
9635
+ }
9636
+ );
9637
+ });
9638
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9639
+ KeyboundForm,
9640
+ {
9641
+ className: "flex flex-1 flex-col overflow-hidden",
9642
+ onSubmit,
9643
+ children: [
9644
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9645
+ /* @__PURE__ */ jsx(
9646
+ Form$2.Field,
9647
+ {
9648
+ control: form.control,
9649
+ name: "country_code",
9650
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9651
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9652
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9653
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9654
+ ] })
9655
+ }
9656
+ ),
9657
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9658
+ /* @__PURE__ */ jsx(
9659
+ Form$2.Field,
9660
+ {
9661
+ control: form.control,
9662
+ name: "first_name",
9663
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9664
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9665
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9666
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9667
+ ] })
9668
+ }
9669
+ ),
9670
+ /* @__PURE__ */ jsx(
9671
+ Form$2.Field,
9672
+ {
9673
+ control: form.control,
9674
+ name: "last_name",
9675
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9676
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9677
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9678
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9679
+ ] })
9680
+ }
9681
+ )
9682
+ ] }),
9683
+ /* @__PURE__ */ jsx(
9684
+ Form$2.Field,
9685
+ {
9686
+ control: form.control,
9687
+ name: "company",
9688
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9689
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9690
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9691
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9692
+ ] })
9693
+ }
9694
+ ),
9695
+ /* @__PURE__ */ jsx(
9696
+ Form$2.Field,
9697
+ {
9698
+ control: form.control,
9699
+ name: "address_1",
9700
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9701
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9702
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9703
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9704
+ ] })
9705
+ }
9706
+ ),
9707
+ /* @__PURE__ */ jsx(
9708
+ Form$2.Field,
9709
+ {
9710
+ control: form.control,
9711
+ name: "address_2",
9712
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9713
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9714
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9715
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9716
+ ] })
9717
+ }
9718
+ ),
9719
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9720
+ /* @__PURE__ */ jsx(
9721
+ Form$2.Field,
9722
+ {
9723
+ control: form.control,
9724
+ name: "postal_code",
9725
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9726
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9727
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9728
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9729
+ ] })
9730
+ }
9731
+ ),
9732
+ /* @__PURE__ */ jsx(
9733
+ Form$2.Field,
9734
+ {
9735
+ control: form.control,
9736
+ name: "city",
9737
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9738
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9739
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9740
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9741
+ ] })
9742
+ }
9743
+ )
9744
+ ] }),
9745
+ /* @__PURE__ */ jsx(
9746
+ Form$2.Field,
9747
+ {
9748
+ control: form.control,
9749
+ name: "province",
9750
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9751
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9752
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9753
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9754
+ ] })
9755
+ }
9756
+ ),
9757
+ /* @__PURE__ */ jsx(
9758
+ Form$2.Field,
9759
+ {
9760
+ control: form.control,
9761
+ name: "phone",
9762
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9763
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9764
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9765
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9766
+ ] })
9767
+ }
9768
+ )
9769
+ ] }) }),
9770
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9772
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9773
+ ] }) })
9774
+ ]
9775
+ }
9776
+ ) });
9777
+ };
9778
+ const schema$4 = addressSchema;
9589
9779
  const Email = () => {
9590
9780
  const { id } = useParams();
9591
9781
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9608,7 +9798,7 @@ const EmailForm = ({ order }) => {
9608
9798
  defaultValues: {
9609
9799
  email: order.email ?? ""
9610
9800
  },
9611
- resolver: zodResolver(schema$4)
9801
+ resolver: zodResolver(schema$3)
9612
9802
  });
9613
9803
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9614
9804
  const { handleSuccess } = useRouteModal();
@@ -9651,7 +9841,7 @@ const EmailForm = ({ order }) => {
9651
9841
  }
9652
9842
  ) });
9653
9843
  };
9654
- const schema$4 = objectType({
9844
+ const schema$3 = objectType({
9655
9845
  email: stringType().email()
9656
9846
  });
9657
9847
  const NumberInput = forwardRef(
@@ -11255,360 +11445,51 @@ function getPromotionIds(items, shippingMethods) {
11255
11445
  }
11256
11446
  return Array.from(promotionIds);
11257
11447
  }
11258
- const SalesChannel = () => {
11448
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11449
+ const Shipping = () => {
11450
+ var _a;
11259
11451
  const { id } = useParams();
11260
- const { draft_order, isPending, isError, error } = useDraftOrder(
11261
- id,
11262
- {
11263
- fields: "+sales_channel_id"
11264
- },
11265
- {
11266
- enabled: !!id
11267
- }
11268
- );
11452
+ const { order, isPending, isError, error } = useOrder(id, {
11453
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11454
+ });
11455
+ const {
11456
+ order: preview,
11457
+ isPending: isPreviewPending,
11458
+ isError: isPreviewError,
11459
+ error: previewError
11460
+ } = useOrderPreview(id);
11461
+ useInitiateOrderEdit({ preview });
11462
+ const { onCancel } = useCancelOrderEdit({ preview });
11269
11463
  if (isError) {
11270
11464
  throw error;
11271
11465
  }
11272
- const ISrEADY = !!draft_order && !isPending;
11273
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11274
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11275
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11276
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11277
- ] }),
11278
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11279
- ] });
11466
+ if (isPreviewError) {
11467
+ throw previewError;
11468
+ }
11469
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11470
+ const isReady = preview && !isPreviewPending && order && !isPending;
11471
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11472
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11473
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11474
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11475
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11476
+ ] }) }) }),
11477
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11478
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11479
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11480
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11481
+ ] }) });
11280
11482
  };
11281
- const SalesChannelForm = ({ order }) => {
11282
- const form = useForm({
11283
- defaultValues: {
11284
- sales_channel_id: order.sales_channel_id || ""
11285
- },
11286
- resolver: zodResolver(schema$3)
11287
- });
11288
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11289
- const { handleSuccess } = useRouteModal();
11290
- const onSubmit = form.handleSubmit(async (data) => {
11291
- await mutateAsync(
11292
- {
11293
- sales_channel_id: data.sales_channel_id
11294
- },
11295
- {
11296
- onSuccess: () => {
11297
- toast.success("Sales channel updated");
11298
- handleSuccess();
11299
- },
11300
- onError: (error) => {
11301
- toast.error(error.message);
11302
- }
11303
- }
11304
- );
11305
- });
11306
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11307
- KeyboundForm,
11308
- {
11309
- className: "flex flex-1 flex-col overflow-hidden",
11310
- onSubmit,
11311
- children: [
11312
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11313
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11314
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11315
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11316
- ] }) })
11317
- ]
11318
- }
11319
- ) });
11320
- };
11321
- const SalesChannelField = ({ control, order }) => {
11322
- const salesChannels = useComboboxData({
11323
- queryFn: async (params) => {
11324
- return await sdk.admin.salesChannel.list(params);
11325
- },
11326
- queryKey: ["sales-channels"],
11327
- getOptions: (data) => {
11328
- return data.sales_channels.map((salesChannel) => ({
11329
- label: salesChannel.name,
11330
- value: salesChannel.id
11331
- }));
11332
- },
11333
- defaultValue: order.sales_channel_id || void 0
11334
- });
11335
- return /* @__PURE__ */ jsx(
11336
- Form$2.Field,
11337
- {
11338
- control,
11339
- name: "sales_channel_id",
11340
- render: ({ field }) => {
11341
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11342
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11343
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11344
- Combobox,
11345
- {
11346
- options: salesChannels.options,
11347
- fetchNextPage: salesChannels.fetchNextPage,
11348
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11349
- searchValue: salesChannels.searchValue,
11350
- onSearchValueChange: salesChannels.onSearchValueChange,
11351
- placeholder: "Select sales channel",
11352
- ...field
11353
- }
11354
- ) }),
11355
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11356
- ] });
11357
- }
11358
- }
11359
- );
11360
- };
11361
- const schema$3 = objectType({
11362
- sales_channel_id: stringType().min(1)
11363
- });
11364
- const ShippingAddress = () => {
11365
- const { id } = useParams();
11366
- const { order, isPending, isError, error } = useOrder(id, {
11367
- fields: "+shipping_address"
11368
- });
11369
- if (isError) {
11370
- throw error;
11371
- }
11372
- const isReady = !isPending && !!order;
11373
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11374
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11375
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11376
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11377
- ] }),
11378
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11379
- ] });
11380
- };
11381
- const ShippingAddressForm = ({ order }) => {
11382
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11383
- const form = useForm({
11384
- defaultValues: {
11385
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11386
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11387
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11388
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11389
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11390
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11391
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11392
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11393
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11394
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11395
- },
11396
- resolver: zodResolver(schema$2)
11397
- });
11398
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11399
- const { handleSuccess } = useRouteModal();
11400
- const onSubmit = form.handleSubmit(async (data) => {
11401
- await mutateAsync(
11402
- {
11403
- shipping_address: {
11404
- first_name: data.first_name,
11405
- last_name: data.last_name,
11406
- company: data.company,
11407
- address_1: data.address_1,
11408
- address_2: data.address_2,
11409
- city: data.city,
11410
- province: data.province,
11411
- country_code: data.country_code,
11412
- postal_code: data.postal_code,
11413
- phone: data.phone
11414
- }
11415
- },
11416
- {
11417
- onSuccess: () => {
11418
- handleSuccess();
11419
- },
11420
- onError: (error) => {
11421
- toast.error(error.message);
11422
- }
11423
- }
11424
- );
11425
- });
11426
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11427
- KeyboundForm,
11428
- {
11429
- className: "flex flex-1 flex-col overflow-hidden",
11430
- onSubmit,
11431
- children: [
11432
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11433
- /* @__PURE__ */ jsx(
11434
- Form$2.Field,
11435
- {
11436
- control: form.control,
11437
- name: "country_code",
11438
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11439
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11440
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11441
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11442
- ] })
11443
- }
11444
- ),
11445
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11446
- /* @__PURE__ */ jsx(
11447
- Form$2.Field,
11448
- {
11449
- control: form.control,
11450
- name: "first_name",
11451
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11452
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11453
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11454
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11455
- ] })
11456
- }
11457
- ),
11458
- /* @__PURE__ */ jsx(
11459
- Form$2.Field,
11460
- {
11461
- control: form.control,
11462
- name: "last_name",
11463
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11464
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11465
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11466
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11467
- ] })
11468
- }
11469
- )
11470
- ] }),
11471
- /* @__PURE__ */ jsx(
11472
- Form$2.Field,
11473
- {
11474
- control: form.control,
11475
- name: "company",
11476
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11477
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11478
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11479
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11480
- ] })
11481
- }
11482
- ),
11483
- /* @__PURE__ */ jsx(
11484
- Form$2.Field,
11485
- {
11486
- control: form.control,
11487
- name: "address_1",
11488
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11489
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11490
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11491
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11492
- ] })
11493
- }
11494
- ),
11495
- /* @__PURE__ */ jsx(
11496
- Form$2.Field,
11497
- {
11498
- control: form.control,
11499
- name: "address_2",
11500
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11501
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11502
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11503
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11504
- ] })
11505
- }
11506
- ),
11507
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11508
- /* @__PURE__ */ jsx(
11509
- Form$2.Field,
11510
- {
11511
- control: form.control,
11512
- name: "postal_code",
11513
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11514
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11515
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11516
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11517
- ] })
11518
- }
11519
- ),
11520
- /* @__PURE__ */ jsx(
11521
- Form$2.Field,
11522
- {
11523
- control: form.control,
11524
- name: "city",
11525
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11526
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11527
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11528
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11529
- ] })
11530
- }
11531
- )
11532
- ] }),
11533
- /* @__PURE__ */ jsx(
11534
- Form$2.Field,
11535
- {
11536
- control: form.control,
11537
- name: "province",
11538
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11539
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11540
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11541
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11542
- ] })
11543
- }
11544
- ),
11545
- /* @__PURE__ */ jsx(
11546
- Form$2.Field,
11547
- {
11548
- control: form.control,
11549
- name: "phone",
11550
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11551
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11552
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11553
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11554
- ] })
11555
- }
11556
- )
11557
- ] }) }),
11558
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11559
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11560
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11561
- ] }) })
11562
- ]
11563
- }
11564
- ) });
11565
- };
11566
- const schema$2 = addressSchema;
11567
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11568
- const Shipping = () => {
11569
- var _a;
11570
- const { id } = useParams();
11571
- const { order, isPending, isError, error } = useOrder(id, {
11572
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11573
- });
11574
- const {
11575
- order: preview,
11576
- isPending: isPreviewPending,
11577
- isError: isPreviewError,
11578
- error: previewError
11579
- } = useOrderPreview(id);
11580
- useInitiateOrderEdit({ preview });
11581
- const { onCancel } = useCancelOrderEdit({ preview });
11582
- if (isError) {
11583
- throw error;
11584
- }
11585
- if (isPreviewError) {
11586
- throw previewError;
11587
- }
11588
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11589
- const isReady = preview && !isPreviewPending && order && !isPending;
11590
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11591
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11592
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11593
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11594
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11595
- ] }) }) }),
11596
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11597
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11598
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11599
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11600
- ] }) });
11601
- };
11602
- const ShippingForm = ({ preview, order }) => {
11603
- var _a;
11604
- const { setIsOpen } = useStackedModal();
11605
- const [isSubmitting, setIsSubmitting] = useState(false);
11606
- const [data, setData] = useState(null);
11607
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11608
- const { shipping_options } = useShippingOptions(
11609
- {
11610
- id: appliedShippingOptionIds,
11611
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11483
+ const ShippingForm = ({ preview, order }) => {
11484
+ var _a;
11485
+ const { setIsOpen } = useStackedModal();
11486
+ const [isSubmitting, setIsSubmitting] = useState(false);
11487
+ const [data, setData] = useState(null);
11488
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11489
+ const { shipping_options } = useShippingOptions(
11490
+ {
11491
+ id: appliedShippingOptionIds,
11492
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11612
11493
  },
11613
11494
  {
11614
11495
  enabled: appliedShippingOptionIds.length > 0
@@ -11676,14 +11557,14 @@ const ShippingForm = ({ preview, order }) => {
11676
11557
  return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11677
11558
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11678
11559
  /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11679
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11560
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11680
11561
  /* @__PURE__ */ jsxs("div", { children: [
11681
11562
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11682
11563
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11683
11564
  ] }),
11684
11565
  /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11685
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11686
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11566
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11567
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11687
11568
  /* @__PURE__ */ jsx(
11688
11569
  Text,
11689
11570
  {
@@ -11725,8 +11606,8 @@ const ShippingForm = ({ preview, order }) => {
11725
11606
  value: profile.id,
11726
11607
  className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11727
11608
  children: [
11728
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11729
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11609
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11610
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11730
11611
  /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11731
11612
  IconButton,
11732
11613
  {
@@ -11734,12 +11615,12 @@ const ShippingForm = ({ preview, order }) => {
11734
11615
  variant: "transparent",
11735
11616
  className: "group/trigger",
11736
11617
  disabled: !hasItems,
11737
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11618
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11738
11619
  }
11739
11620
  ) }),
11740
11621
  !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11741
- /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11742
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11622
+ /* @__PURE__ */ jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11623
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col", children: [
11743
11624
  /* @__PURE__ */ jsx(
11744
11625
  Text,
11745
11626
  {
@@ -11763,7 +11644,7 @@ const ShippingForm = ({ preview, order }) => {
11763
11644
  }
11764
11645
  )
11765
11646
  ] })
11766
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11647
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11767
11648
  /* @__PURE__ */ jsx(
11768
11649
  Tooltip,
11769
11650
  {
@@ -11780,7 +11661,7 @@ const ShippingForm = ({ preview, order }) => {
11780
11661
  children: /* @__PURE__ */ jsxs(
11781
11662
  Badge,
11782
11663
  {
11783
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11664
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11784
11665
  size: "xsmall",
11785
11666
  children: [
11786
11667
  /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
@@ -11805,7 +11686,7 @@ const ShippingForm = ({ preview, order }) => {
11805
11686
  children: /* @__PURE__ */ jsxs(
11806
11687
  Badge,
11807
11688
  {
11808
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11689
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11809
11690
  size: "xsmall",
11810
11691
  children: [
11811
11692
  /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
@@ -11818,7 +11699,7 @@ const ShippingForm = ({ preview, order }) => {
11818
11699
  /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11819
11700
  Badge,
11820
11701
  {
11821
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11702
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11822
11703
  size: "xsmall",
11823
11704
  children: [
11824
11705
  /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
@@ -11889,17 +11770,17 @@ const ShippingForm = ({ preview, order }) => {
11889
11770
  /* @__PURE__ */ jsxs(
11890
11771
  "div",
11891
11772
  {
11892
- className: "px-3 flex items-center gap-x-3",
11773
+ className: "flex items-center gap-x-3 px-3",
11893
11774
  children: [
11894
- /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11775
+ /* @__PURE__ */ jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsx(
11895
11776
  Divider,
11896
11777
  {
11897
11778
  variant: "dashed",
11898
11779
  orientation: "vertical"
11899
11780
  }
11900
11781
  ) }),
11901
- /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11902
- /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11782
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
11783
+ /* @__PURE__ */ jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11903
11784
  Text,
11904
11785
  {
11905
11786
  size: "small",
@@ -12080,7 +11961,7 @@ const ShippingProfileForm = ({
12080
11961
  onSubmit,
12081
11962
  children: [
12082
11963
  /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12083
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11964
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12084
11965
  /* @__PURE__ */ jsxs("div", { children: [
12085
11966
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12086
11967
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(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." }) })
@@ -12153,14 +12034,14 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12153
12034
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12154
12035
  ] }) }),
12155
12036
  /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12156
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12037
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12157
12038
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12158
12039
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12159
12040
  ] }),
12160
12041
  /* @__PURE__ */ 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__ */ jsxs(
12161
12042
  "div",
12162
12043
  {
12163
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12044
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12164
12045
  children: [
12165
12046
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12166
12047
  /* @__PURE__ */ jsx(
@@ -12213,7 +12094,7 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12213
12094
  ]
12214
12095
  },
12215
12096
  item.id
12216
- )) : /* @__PURE__ */ 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: [
12097
+ )) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12217
12098
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12218
12099
  /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12219
12100
  'No items found for "',
@@ -12371,6 +12252,112 @@ const CustomAmountField = ({
12371
12252
  }
12372
12253
  );
12373
12254
  };
12255
+ const SalesChannel = () => {
12256
+ const { id } = useParams();
12257
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12258
+ id,
12259
+ {
12260
+ fields: "+sales_channel_id"
12261
+ },
12262
+ {
12263
+ enabled: !!id
12264
+ }
12265
+ );
12266
+ if (isError) {
12267
+ throw error;
12268
+ }
12269
+ const ISrEADY = !!draft_order && !isPending;
12270
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12271
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12272
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12273
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12274
+ ] }),
12275
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12276
+ ] });
12277
+ };
12278
+ const SalesChannelForm = ({ order }) => {
12279
+ const form = useForm({
12280
+ defaultValues: {
12281
+ sales_channel_id: order.sales_channel_id || ""
12282
+ },
12283
+ resolver: zodResolver(schema$2)
12284
+ });
12285
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12286
+ const { handleSuccess } = useRouteModal();
12287
+ const onSubmit = form.handleSubmit(async (data) => {
12288
+ await mutateAsync(
12289
+ {
12290
+ sales_channel_id: data.sales_channel_id
12291
+ },
12292
+ {
12293
+ onSuccess: () => {
12294
+ toast.success("Sales channel updated");
12295
+ handleSuccess();
12296
+ },
12297
+ onError: (error) => {
12298
+ toast.error(error.message);
12299
+ }
12300
+ }
12301
+ );
12302
+ });
12303
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12304
+ KeyboundForm,
12305
+ {
12306
+ className: "flex flex-1 flex-col overflow-hidden",
12307
+ onSubmit,
12308
+ children: [
12309
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12310
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12311
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12312
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12313
+ ] }) })
12314
+ ]
12315
+ }
12316
+ ) });
12317
+ };
12318
+ const SalesChannelField = ({ control, order }) => {
12319
+ const salesChannels = useComboboxData({
12320
+ queryFn: async (params) => {
12321
+ return await sdk.admin.salesChannel.list(params);
12322
+ },
12323
+ queryKey: ["sales-channels"],
12324
+ getOptions: (data) => {
12325
+ return data.sales_channels.map((salesChannel) => ({
12326
+ label: salesChannel.name,
12327
+ value: salesChannel.id
12328
+ }));
12329
+ },
12330
+ defaultValue: order.sales_channel_id || void 0
12331
+ });
12332
+ return /* @__PURE__ */ jsx(
12333
+ Form$2.Field,
12334
+ {
12335
+ control,
12336
+ name: "sales_channel_id",
12337
+ render: ({ field }) => {
12338
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12339
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12340
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12341
+ Combobox,
12342
+ {
12343
+ options: salesChannels.options,
12344
+ fetchNextPage: salesChannels.fetchNextPage,
12345
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12346
+ searchValue: salesChannels.searchValue,
12347
+ onSearchValueChange: salesChannels.onSearchValueChange,
12348
+ placeholder: "Select sales channel",
12349
+ ...field
12350
+ }
12351
+ ) }),
12352
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12353
+ ] });
12354
+ }
12355
+ }
12356
+ );
12357
+ };
12358
+ const schema$2 = objectType({
12359
+ sales_channel_id: stringType().min(1)
12360
+ });
12374
12361
  const TransferOwnership = () => {
12375
12362
  const { id } = useParams();
12376
12363
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12847,10 +12834,10 @@ const Illustration = () => {
12847
12834
  const schema$1 = objectType({
12848
12835
  customer_id: stringType().min(1)
12849
12836
  });
12850
- const BillingAddress = () => {
12837
+ const ShippingAddress = () => {
12851
12838
  const { id } = useParams();
12852
12839
  const { order, isPending, isError, error } = useOrder(id, {
12853
- fields: "+billing_address"
12840
+ fields: "+shipping_address"
12854
12841
  });
12855
12842
  if (isError) {
12856
12843
  throw error;
@@ -12858,26 +12845,26 @@ const BillingAddress = () => {
12858
12845
  const isReady = !isPending && !!order;
12859
12846
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12860
12847
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12861
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12862
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12848
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12849
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12863
12850
  ] }),
12864
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12851
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12865
12852
  ] });
12866
12853
  };
12867
- const BillingAddressForm = ({ order }) => {
12854
+ const ShippingAddressForm = ({ order }) => {
12868
12855
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12869
12856
  const form = useForm({
12870
12857
  defaultValues: {
12871
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12872
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12873
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12874
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12875
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12876
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12877
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12878
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12879
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12880
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12858
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12859
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12860
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12861
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12862
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12863
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12864
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12865
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12866
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12867
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12881
12868
  },
12882
12869
  resolver: zodResolver(schema)
12883
12870
  });
@@ -12885,7 +12872,20 @@ const BillingAddressForm = ({ order }) => {
12885
12872
  const { handleSuccess } = useRouteModal();
12886
12873
  const onSubmit = form.handleSubmit(async (data) => {
12887
12874
  await mutateAsync(
12888
- { billing_address: data },
12875
+ {
12876
+ shipping_address: {
12877
+ first_name: data.first_name,
12878
+ last_name: data.last_name,
12879
+ company: data.company,
12880
+ address_1: data.address_1,
12881
+ address_2: data.address_2,
12882
+ city: data.city,
12883
+ province: data.province,
12884
+ country_code: data.country_code,
12885
+ postal_code: data.postal_code,
12886
+ phone: data.phone
12887
+ }
12888
+ },
12889
12889
  {
12890
12890
  onSuccess: () => {
12891
12891
  handleSuccess();
@@ -13061,6 +13061,10 @@ const routeModule = {
13061
13061
  Component: CustomItems,
13062
13062
  path: "/draft-orders/:id/custom-items"
13063
13063
  },
13064
+ {
13065
+ Component: BillingAddress,
13066
+ path: "/draft-orders/:id/billing-address"
13067
+ },
13064
13068
  {
13065
13069
  Component: Email,
13066
13070
  path: "/draft-orders/:id/email"
@@ -13077,25 +13081,21 @@ const routeModule = {
13077
13081
  Component: Promotions,
13078
13082
  path: "/draft-orders/:id/promotions"
13079
13083
  },
13080
- {
13081
- Component: SalesChannel,
13082
- path: "/draft-orders/:id/sales-channel"
13083
- },
13084
- {
13085
- Component: ShippingAddress,
13086
- path: "/draft-orders/:id/shipping-address"
13087
- },
13088
13084
  {
13089
13085
  Component: Shipping,
13090
13086
  path: "/draft-orders/:id/shipping"
13091
13087
  },
13088
+ {
13089
+ Component: SalesChannel,
13090
+ path: "/draft-orders/:id/sales-channel"
13091
+ },
13092
13092
  {
13093
13093
  Component: TransferOwnership,
13094
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
13095
  },
13096
13096
  {
13097
- Component: BillingAddress,
13098
- path: "/draft-orders/:id/billing-address"
13097
+ Component: ShippingAddress,
13098
+ path: "/draft-orders/:id/shipping-address"
13099
13099
  }
13100
13100
  ]
13101
13101
  }