@medusajs/draft-order 2.10.2-preview-20250901090155 → 2.10.2-preview-20250901150144

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.
@@ -9554,27 +9554,6 @@ const ID = () => {
9554
9554
  /* @__PURE__ */ jsx(Outlet, {})
9555
9555
  ] });
9556
9556
  };
9557
- const CustomItems = () => {
9558
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9559
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9560
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9561
- ] });
9562
- };
9563
- const CustomItemsForm = () => {
9564
- const form = useForm({
9565
- resolver: zodResolver(schema$5)
9566
- });
9567
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9568
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9569
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9570
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9571
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9572
- ] }) })
9573
- ] }) });
9574
- };
9575
- const schema$5 = objectType({
9576
- email: stringType().email()
9577
- });
9578
9557
  const Email = () => {
9579
9558
  const { id } = useParams();
9580
9559
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9597,7 +9576,7 @@ const EmailForm = ({ order }) => {
9597
9576
  defaultValues: {
9598
9577
  email: order.email ?? ""
9599
9578
  },
9600
- resolver: zodResolver(schema$4)
9579
+ resolver: zodResolver(schema$5)
9601
9580
  });
9602
9581
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9603
9582
  const { handleSuccess } = useRouteModal();
@@ -9640,7 +9619,7 @@ const EmailForm = ({ order }) => {
9640
9619
  }
9641
9620
  ) });
9642
9621
  };
9643
- const schema$4 = objectType({
9622
+ const schema$5 = objectType({
9644
9623
  email: stringType().email()
9645
9624
  });
9646
9625
  const NumberInput = forwardRef(
@@ -10617,196 +10596,27 @@ const customItemSchema = objectType({
10617
10596
  quantity: numberType(),
10618
10597
  unit_price: unionType([numberType(), stringType()])
10619
10598
  });
10620
- const BillingAddress = () => {
10621
- const { id } = useParams();
10622
- const { order, isPending, isError, error } = useOrder(id, {
10623
- fields: "+billing_address"
10624
- });
10625
- if (isError) {
10626
- throw error;
10627
- }
10628
- const isReady = !isPending && !!order;
10599
+ const CustomItems = () => {
10629
10600
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10630
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10631
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
10632
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
10633
- ] }),
10634
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
10601
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
10602
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
10635
10603
  ] });
10636
10604
  };
10637
- const BillingAddressForm = ({ order }) => {
10638
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10605
+ const CustomItemsForm = () => {
10639
10606
  const form = useForm({
10640
- defaultValues: {
10641
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
10642
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
10643
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
10644
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
10645
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
10646
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
10647
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
10648
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
10649
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
10650
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
10651
- },
10652
- resolver: zodResolver(schema$3)
10653
- });
10654
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10655
- const { handleSuccess } = useRouteModal();
10656
- const onSubmit = form.handleSubmit(async (data) => {
10657
- await mutateAsync(
10658
- { billing_address: data },
10659
- {
10660
- onSuccess: () => {
10661
- handleSuccess();
10662
- },
10663
- onError: (error) => {
10664
- toast.error(error.message);
10665
- }
10666
- }
10667
- );
10607
+ resolver: zodResolver(schema$4)
10668
10608
  });
10669
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10670
- KeyboundForm,
10671
- {
10672
- className: "flex flex-1 flex-col overflow-hidden",
10673
- onSubmit,
10674
- children: [
10675
- /* @__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: [
10676
- /* @__PURE__ */ jsx(
10677
- Form$2.Field,
10678
- {
10679
- control: form.control,
10680
- name: "country_code",
10681
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10682
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
10683
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
10684
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10685
- ] })
10686
- }
10687
- ),
10688
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10689
- /* @__PURE__ */ jsx(
10690
- Form$2.Field,
10691
- {
10692
- control: form.control,
10693
- name: "first_name",
10694
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10695
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
10696
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10697
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10698
- ] })
10699
- }
10700
- ),
10701
- /* @__PURE__ */ jsx(
10702
- Form$2.Field,
10703
- {
10704
- control: form.control,
10705
- name: "last_name",
10706
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10707
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
10708
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10709
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10710
- ] })
10711
- }
10712
- )
10713
- ] }),
10714
- /* @__PURE__ */ jsx(
10715
- Form$2.Field,
10716
- {
10717
- control: form.control,
10718
- name: "company",
10719
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10720
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
10721
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10722
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10723
- ] })
10724
- }
10725
- ),
10726
- /* @__PURE__ */ jsx(
10727
- Form$2.Field,
10728
- {
10729
- control: form.control,
10730
- name: "address_1",
10731
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10732
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
10733
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10734
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10735
- ] })
10736
- }
10737
- ),
10738
- /* @__PURE__ */ jsx(
10739
- Form$2.Field,
10740
- {
10741
- control: form.control,
10742
- name: "address_2",
10743
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10744
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10745
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10746
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10747
- ] })
10748
- }
10749
- ),
10750
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10751
- /* @__PURE__ */ jsx(
10752
- Form$2.Field,
10753
- {
10754
- control: form.control,
10755
- name: "postal_code",
10756
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10757
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
10758
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10759
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10760
- ] })
10761
- }
10762
- ),
10763
- /* @__PURE__ */ jsx(
10764
- Form$2.Field,
10765
- {
10766
- control: form.control,
10767
- name: "city",
10768
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10769
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
10770
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10771
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10772
- ] })
10773
- }
10774
- )
10775
- ] }),
10776
- /* @__PURE__ */ jsx(
10777
- Form$2.Field,
10778
- {
10779
- control: form.control,
10780
- name: "province",
10781
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10782
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10783
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10784
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10785
- ] })
10786
- }
10787
- ),
10788
- /* @__PURE__ */ jsx(
10789
- Form$2.Field,
10790
- {
10791
- control: form.control,
10792
- name: "phone",
10793
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10794
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
10795
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10796
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10797
- ] })
10798
- }
10799
- )
10800
- ] }) }),
10801
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10802
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10803
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10804
- ] }) })
10805
- ]
10806
- }
10807
- ) });
10609
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10610
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
10611
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10612
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10613
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
10614
+ ] }) })
10615
+ ] }) });
10808
10616
  };
10809
- const schema$3 = addressSchema;
10617
+ const schema$4 = objectType({
10618
+ email: stringType().email()
10619
+ });
10810
10620
  const InlineTip = forwardRef(
10811
10621
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10812
10622
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11434,33 +11244,342 @@ function getPromotionCodes(items, shippingMethods) {
11434
11244
  }
11435
11245
  return Array.from(codes);
11436
11246
  }
11437
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11438
- const Shipping = () => {
11439
- var _a;
11247
+ const SalesChannel = () => {
11440
11248
  const { id } = useParams();
11441
- const { order, isPending, isError, error } = useOrder(id, {
11442
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11443
- });
11444
- const {
11445
- order: preview,
11446
- isPending: isPreviewPending,
11447
- isError: isPreviewError,
11448
- error: previewError
11449
- } = useOrderPreview(id);
11450
- useInitiateOrderEdit({ preview });
11451
- const { onCancel } = useCancelOrderEdit({ preview });
11249
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11250
+ id,
11251
+ {
11252
+ fields: "+sales_channel_id"
11253
+ },
11254
+ {
11255
+ enabled: !!id
11256
+ }
11257
+ );
11452
11258
  if (isError) {
11453
11259
  throw error;
11454
11260
  }
11455
- if (isPreviewError) {
11456
- throw previewError;
11457
- }
11458
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11459
- const isReady = preview && !isPreviewPending && order && !isPending;
11460
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11461
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11462
- /* @__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: [
11463
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11261
+ const ISrEADY = !!draft_order && !isPending;
11262
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11263
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11264
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11265
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11266
+ ] }),
11267
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11268
+ ] });
11269
+ };
11270
+ const SalesChannelForm = ({ order }) => {
11271
+ const form = useForm({
11272
+ defaultValues: {
11273
+ sales_channel_id: order.sales_channel_id || ""
11274
+ },
11275
+ resolver: zodResolver(schema$3)
11276
+ });
11277
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11278
+ const { handleSuccess } = useRouteModal();
11279
+ const onSubmit = form.handleSubmit(async (data) => {
11280
+ await mutateAsync(
11281
+ {
11282
+ sales_channel_id: data.sales_channel_id
11283
+ },
11284
+ {
11285
+ onSuccess: () => {
11286
+ toast.success("Sales channel updated");
11287
+ handleSuccess();
11288
+ },
11289
+ onError: (error) => {
11290
+ toast.error(error.message);
11291
+ }
11292
+ }
11293
+ );
11294
+ });
11295
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11296
+ KeyboundForm,
11297
+ {
11298
+ className: "flex flex-1 flex-col overflow-hidden",
11299
+ onSubmit,
11300
+ children: [
11301
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11302
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11303
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11304
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11305
+ ] }) })
11306
+ ]
11307
+ }
11308
+ ) });
11309
+ };
11310
+ const SalesChannelField = ({ control, order }) => {
11311
+ const salesChannels = useComboboxData({
11312
+ queryFn: async (params) => {
11313
+ return await sdk.admin.salesChannel.list(params);
11314
+ },
11315
+ queryKey: ["sales-channels"],
11316
+ getOptions: (data) => {
11317
+ return data.sales_channels.map((salesChannel) => ({
11318
+ label: salesChannel.name,
11319
+ value: salesChannel.id
11320
+ }));
11321
+ },
11322
+ defaultValue: order.sales_channel_id || void 0
11323
+ });
11324
+ return /* @__PURE__ */ jsx(
11325
+ Form$2.Field,
11326
+ {
11327
+ control,
11328
+ name: "sales_channel_id",
11329
+ render: ({ field }) => {
11330
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11331
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11332
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11333
+ Combobox,
11334
+ {
11335
+ options: salesChannels.options,
11336
+ fetchNextPage: salesChannels.fetchNextPage,
11337
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11338
+ searchValue: salesChannels.searchValue,
11339
+ onSearchValueChange: salesChannels.onSearchValueChange,
11340
+ placeholder: "Select sales channel",
11341
+ ...field
11342
+ }
11343
+ ) }),
11344
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11345
+ ] });
11346
+ }
11347
+ }
11348
+ );
11349
+ };
11350
+ const schema$3 = objectType({
11351
+ sales_channel_id: stringType().min(1)
11352
+ });
11353
+ const ShippingAddress = () => {
11354
+ const { id } = useParams();
11355
+ const { order, isPending, isError, error } = useOrder(id, {
11356
+ fields: "+shipping_address"
11357
+ });
11358
+ if (isError) {
11359
+ throw error;
11360
+ }
11361
+ const isReady = !isPending && !!order;
11362
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11363
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11364
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11365
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11366
+ ] }),
11367
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11368
+ ] });
11369
+ };
11370
+ const ShippingAddressForm = ({ order }) => {
11371
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11372
+ const form = useForm({
11373
+ defaultValues: {
11374
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11375
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11376
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11377
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11378
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11379
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11380
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11381
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11382
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11383
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11384
+ },
11385
+ resolver: zodResolver(schema$2)
11386
+ });
11387
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11388
+ const { handleSuccess } = useRouteModal();
11389
+ const onSubmit = form.handleSubmit(async (data) => {
11390
+ await mutateAsync(
11391
+ {
11392
+ shipping_address: {
11393
+ first_name: data.first_name,
11394
+ last_name: data.last_name,
11395
+ company: data.company,
11396
+ address_1: data.address_1,
11397
+ address_2: data.address_2,
11398
+ city: data.city,
11399
+ province: data.province,
11400
+ country_code: data.country_code,
11401
+ postal_code: data.postal_code,
11402
+ phone: data.phone
11403
+ }
11404
+ },
11405
+ {
11406
+ onSuccess: () => {
11407
+ handleSuccess();
11408
+ },
11409
+ onError: (error) => {
11410
+ toast.error(error.message);
11411
+ }
11412
+ }
11413
+ );
11414
+ });
11415
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11416
+ KeyboundForm,
11417
+ {
11418
+ className: "flex flex-1 flex-col overflow-hidden",
11419
+ onSubmit,
11420
+ children: [
11421
+ /* @__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: [
11422
+ /* @__PURE__ */ jsx(
11423
+ Form$2.Field,
11424
+ {
11425
+ control: form.control,
11426
+ name: "country_code",
11427
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11428
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11429
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11430
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11431
+ ] })
11432
+ }
11433
+ ),
11434
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11435
+ /* @__PURE__ */ jsx(
11436
+ Form$2.Field,
11437
+ {
11438
+ control: form.control,
11439
+ name: "first_name",
11440
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11441
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11442
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11443
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11444
+ ] })
11445
+ }
11446
+ ),
11447
+ /* @__PURE__ */ jsx(
11448
+ Form$2.Field,
11449
+ {
11450
+ control: form.control,
11451
+ name: "last_name",
11452
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11453
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11454
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11455
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11456
+ ] })
11457
+ }
11458
+ )
11459
+ ] }),
11460
+ /* @__PURE__ */ jsx(
11461
+ Form$2.Field,
11462
+ {
11463
+ control: form.control,
11464
+ name: "company",
11465
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11466
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11467
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11468
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11469
+ ] })
11470
+ }
11471
+ ),
11472
+ /* @__PURE__ */ jsx(
11473
+ Form$2.Field,
11474
+ {
11475
+ control: form.control,
11476
+ name: "address_1",
11477
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11478
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11479
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11480
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11481
+ ] })
11482
+ }
11483
+ ),
11484
+ /* @__PURE__ */ jsx(
11485
+ Form$2.Field,
11486
+ {
11487
+ control: form.control,
11488
+ name: "address_2",
11489
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11490
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11491
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11492
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11493
+ ] })
11494
+ }
11495
+ ),
11496
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11497
+ /* @__PURE__ */ jsx(
11498
+ Form$2.Field,
11499
+ {
11500
+ control: form.control,
11501
+ name: "postal_code",
11502
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11503
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11504
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11505
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11506
+ ] })
11507
+ }
11508
+ ),
11509
+ /* @__PURE__ */ jsx(
11510
+ Form$2.Field,
11511
+ {
11512
+ control: form.control,
11513
+ name: "city",
11514
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11515
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11516
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11517
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11518
+ ] })
11519
+ }
11520
+ )
11521
+ ] }),
11522
+ /* @__PURE__ */ jsx(
11523
+ Form$2.Field,
11524
+ {
11525
+ control: form.control,
11526
+ name: "province",
11527
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11528
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11529
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11530
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11531
+ ] })
11532
+ }
11533
+ ),
11534
+ /* @__PURE__ */ jsx(
11535
+ Form$2.Field,
11536
+ {
11537
+ control: form.control,
11538
+ name: "phone",
11539
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11540
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11541
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11542
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11543
+ ] })
11544
+ }
11545
+ )
11546
+ ] }) }),
11547
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11548
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11549
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11550
+ ] }) })
11551
+ ]
11552
+ }
11553
+ ) });
11554
+ };
11555
+ const schema$2 = addressSchema;
11556
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
+ const Shipping = () => {
11558
+ var _a;
11559
+ const { id } = useParams();
11560
+ const { order, isPending, isError, error } = useOrder(id, {
11561
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11562
+ });
11563
+ const {
11564
+ order: preview,
11565
+ isPending: isPreviewPending,
11566
+ isError: isPreviewError,
11567
+ error: previewError
11568
+ } = useOrderPreview(id);
11569
+ useInitiateOrderEdit({ preview });
11570
+ const { onCancel } = useCancelOrderEdit({ preview });
11571
+ if (isError) {
11572
+ throw error;
11573
+ }
11574
+ if (isPreviewError) {
11575
+ throw previewError;
11576
+ }
11577
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
+ const isReady = preview && !isPreviewPending && order && !isPending;
11579
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11582
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11464
11583
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11465
11584
  ] }) }) }),
11466
11585
  /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
@@ -12140,416 +12259,107 @@ const LocationField = ({ control, setValue }) => {
12140
12259
  ] }) });
12141
12260
  }
12142
12261
  }
12143
- );
12144
- };
12145
- const ShippingOptionField = ({
12146
- shippingProfileId,
12147
- preview,
12148
- control
12149
- }) => {
12150
- var _a;
12151
- const locationId = useWatch({ control, name: "location_id" });
12152
- const shippingOptions = useComboboxData({
12153
- queryKey: ["shipping_options", locationId, shippingProfileId],
12154
- queryFn: async (params) => {
12155
- return await sdk.admin.shippingOption.list({
12156
- ...params,
12157
- stock_location_id: locationId,
12158
- shipping_profile_id: shippingProfileId
12159
- });
12160
- },
12161
- getOptions: (data) => {
12162
- return data.shipping_options.map((option) => {
12163
- var _a2;
12164
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12165
- (r) => r.attribute === "is_return" && r.value === "true"
12166
- )) {
12167
- return void 0;
12168
- }
12169
- return {
12170
- label: option.name,
12171
- value: option.id
12172
- };
12173
- }).filter(Boolean);
12174
- },
12175
- enabled: !!locationId && !!shippingProfileId,
12176
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12177
- });
12178
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12179
- return /* @__PURE__ */ jsx(
12180
- Form$2.Field,
12181
- {
12182
- control,
12183
- name: "shipping_option_id",
12184
- render: ({ field }) => {
12185
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12186
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12187
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12188
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12189
- ] }),
12190
- /* @__PURE__ */ jsx(
12191
- ConditionalTooltip,
12192
- {
12193
- content: tooltipContent,
12194
- showTooltip: !locationId || !shippingProfileId,
12195
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12196
- Combobox,
12197
- {
12198
- options: shippingOptions.options,
12199
- fetchNextPage: shippingOptions.fetchNextPage,
12200
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12201
- searchValue: shippingOptions.searchValue,
12202
- onSearchValueChange: shippingOptions.onSearchValueChange,
12203
- placeholder: "Select shipping option",
12204
- ...field,
12205
- disabled: !locationId || !shippingProfileId
12206
- }
12207
- ) }) })
12208
- }
12209
- )
12210
- ] }) });
12211
- }
12212
- }
12213
- );
12214
- };
12215
- const CustomAmountField = ({
12216
- control,
12217
- currencyCode
12218
- }) => {
12219
- return /* @__PURE__ */ jsx(
12220
- Form$2.Field,
12221
- {
12222
- control,
12223
- name: "custom_amount",
12224
- render: ({ field: { onChange, ...field } }) => {
12225
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12226
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12227
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12228
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12229
- ] }),
12230
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12231
- CurrencyInput,
12232
- {
12233
- ...field,
12234
- onValueChange: (value) => onChange(value),
12235
- symbol: getNativeSymbol(currencyCode),
12236
- code: currencyCode
12237
- }
12238
- ) })
12239
- ] });
12240
- }
12241
- }
12242
- );
12243
- };
12244
- const SalesChannel = () => {
12245
- const { id } = useParams();
12246
- const { draft_order, isPending, isError, error } = useDraftOrder(
12247
- id,
12248
- {
12249
- fields: "+sales_channel_id"
12250
- },
12251
- {
12252
- enabled: !!id
12253
- }
12254
- );
12255
- if (isError) {
12256
- throw error;
12257
- }
12258
- const ISrEADY = !!draft_order && !isPending;
12259
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12260
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12261
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12262
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12263
- ] }),
12264
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12265
- ] });
12266
- };
12267
- const SalesChannelForm = ({ order }) => {
12268
- const form = useForm({
12269
- defaultValues: {
12270
- sales_channel_id: order.sales_channel_id || ""
12271
- },
12272
- resolver: zodResolver(schema$2)
12273
- });
12274
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12275
- const { handleSuccess } = useRouteModal();
12276
- const onSubmit = form.handleSubmit(async (data) => {
12277
- await mutateAsync(
12278
- {
12279
- sales_channel_id: data.sales_channel_id
12280
- },
12281
- {
12282
- onSuccess: () => {
12283
- toast.success("Sales channel updated");
12284
- handleSuccess();
12285
- },
12286
- onError: (error) => {
12287
- toast.error(error.message);
12288
- }
12289
- }
12290
- );
12291
- });
12292
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12293
- KeyboundForm,
12294
- {
12295
- className: "flex flex-1 flex-col overflow-hidden",
12296
- onSubmit,
12297
- children: [
12298
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12299
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12300
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12301
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12302
- ] }) })
12303
- ]
12304
- }
12305
- ) });
12262
+ );
12306
12263
  };
12307
- const SalesChannelField = ({ control, order }) => {
12308
- const salesChannels = useComboboxData({
12264
+ const ShippingOptionField = ({
12265
+ shippingProfileId,
12266
+ preview,
12267
+ control
12268
+ }) => {
12269
+ var _a;
12270
+ const locationId = useWatch({ control, name: "location_id" });
12271
+ const shippingOptions = useComboboxData({
12272
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12309
12273
  queryFn: async (params) => {
12310
- return await sdk.admin.salesChannel.list(params);
12274
+ return await sdk.admin.shippingOption.list({
12275
+ ...params,
12276
+ stock_location_id: locationId,
12277
+ shipping_profile_id: shippingProfileId
12278
+ });
12311
12279
  },
12312
- queryKey: ["sales-channels"],
12313
12280
  getOptions: (data) => {
12314
- return data.sales_channels.map((salesChannel) => ({
12315
- label: salesChannel.name,
12316
- value: salesChannel.id
12317
- }));
12281
+ return data.shipping_options.map((option) => {
12282
+ var _a2;
12283
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12284
+ (r) => r.attribute === "is_return" && r.value === "true"
12285
+ )) {
12286
+ return void 0;
12287
+ }
12288
+ return {
12289
+ label: option.name,
12290
+ value: option.id
12291
+ };
12292
+ }).filter(Boolean);
12318
12293
  },
12319
- defaultValue: order.sales_channel_id || void 0
12294
+ enabled: !!locationId && !!shippingProfileId,
12295
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12320
12296
  });
12297
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12321
12298
  return /* @__PURE__ */ jsx(
12322
12299
  Form$2.Field,
12323
12300
  {
12324
12301
  control,
12325
- name: "sales_channel_id",
12302
+ name: "shipping_option_id",
12326
12303
  render: ({ field }) => {
12327
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12328
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12329
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12330
- Combobox,
12304
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12305
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12306
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12307
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12308
+ ] }),
12309
+ /* @__PURE__ */ jsx(
12310
+ ConditionalTooltip,
12331
12311
  {
12332
- options: salesChannels.options,
12333
- fetchNextPage: salesChannels.fetchNextPage,
12334
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12335
- searchValue: salesChannels.searchValue,
12336
- onSearchValueChange: salesChannels.onSearchValueChange,
12337
- placeholder: "Select sales channel",
12338
- ...field
12312
+ content: tooltipContent,
12313
+ showTooltip: !locationId || !shippingProfileId,
12314
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12315
+ Combobox,
12316
+ {
12317
+ options: shippingOptions.options,
12318
+ fetchNextPage: shippingOptions.fetchNextPage,
12319
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12320
+ searchValue: shippingOptions.searchValue,
12321
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12322
+ placeholder: "Select shipping option",
12323
+ ...field,
12324
+ disabled: !locationId || !shippingProfileId
12325
+ }
12326
+ ) }) })
12339
12327
  }
12340
- ) }),
12341
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12342
- ] });
12328
+ )
12329
+ ] }) });
12343
12330
  }
12344
12331
  }
12345
12332
  );
12346
12333
  };
12347
- const schema$2 = objectType({
12348
- sales_channel_id: stringType().min(1)
12349
- });
12350
- const ShippingAddress = () => {
12351
- const { id } = useParams();
12352
- const { order, isPending, isError, error } = useOrder(id, {
12353
- fields: "+shipping_address"
12354
- });
12355
- if (isError) {
12356
- throw error;
12357
- }
12358
- const isReady = !isPending && !!order;
12359
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12360
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12361
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12362
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12363
- ] }),
12364
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12365
- ] });
12366
- };
12367
- const ShippingAddressForm = ({ order }) => {
12368
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12369
- const form = useForm({
12370
- defaultValues: {
12371
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12372
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12373
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12374
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12375
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12376
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12377
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12378
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12379
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12380
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12381
- },
12382
- resolver: zodResolver(schema$1)
12383
- });
12384
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12385
- const { handleSuccess } = useRouteModal();
12386
- const onSubmit = form.handleSubmit(async (data) => {
12387
- await mutateAsync(
12388
- {
12389
- shipping_address: {
12390
- first_name: data.first_name,
12391
- last_name: data.last_name,
12392
- company: data.company,
12393
- address_1: data.address_1,
12394
- address_2: data.address_2,
12395
- city: data.city,
12396
- province: data.province,
12397
- country_code: data.country_code,
12398
- postal_code: data.postal_code,
12399
- phone: data.phone
12400
- }
12401
- },
12402
- {
12403
- onSuccess: () => {
12404
- handleSuccess();
12405
- },
12406
- onError: (error) => {
12407
- toast.error(error.message);
12408
- }
12409
- }
12410
- );
12411
- });
12412
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12413
- KeyboundForm,
12334
+ const CustomAmountField = ({
12335
+ control,
12336
+ currencyCode
12337
+ }) => {
12338
+ return /* @__PURE__ */ jsx(
12339
+ Form$2.Field,
12414
12340
  {
12415
- className: "flex flex-1 flex-col overflow-hidden",
12416
- onSubmit,
12417
- children: [
12418
- /* @__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: [
12419
- /* @__PURE__ */ jsx(
12420
- Form$2.Field,
12421
- {
12422
- control: form.control,
12423
- name: "country_code",
12424
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12425
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12426
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12427
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12428
- ] })
12429
- }
12430
- ),
12431
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12432
- /* @__PURE__ */ jsx(
12433
- Form$2.Field,
12434
- {
12435
- control: form.control,
12436
- name: "first_name",
12437
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12439
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12440
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
- ] })
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsx(
12445
- Form$2.Field,
12446
- {
12447
- control: form.control,
12448
- name: "last_name",
12449
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12450
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12451
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12452
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12453
- ] })
12454
- }
12455
- )
12456
- ] }),
12457
- /* @__PURE__ */ jsx(
12458
- Form$2.Field,
12459
- {
12460
- control: form.control,
12461
- name: "company",
12462
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12464
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
- ] })
12467
- }
12468
- ),
12469
- /* @__PURE__ */ jsx(
12470
- Form$2.Field,
12471
- {
12472
- control: form.control,
12473
- name: "address_1",
12474
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12475
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12476
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12477
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12478
- ] })
12479
- }
12480
- ),
12481
- /* @__PURE__ */ jsx(
12482
- Form$2.Field,
12483
- {
12484
- control: form.control,
12485
- name: "address_2",
12486
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12487
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12488
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12489
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12490
- ] })
12491
- }
12492
- ),
12493
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12494
- /* @__PURE__ */ jsx(
12495
- Form$2.Field,
12496
- {
12497
- control: form.control,
12498
- name: "postal_code",
12499
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12501
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
- ] })
12504
- }
12505
- ),
12506
- /* @__PURE__ */ jsx(
12507
- Form$2.Field,
12508
- {
12509
- control: form.control,
12510
- name: "city",
12511
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12512
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12513
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12514
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12515
- ] })
12516
- }
12517
- )
12341
+ control,
12342
+ name: "custom_amount",
12343
+ render: ({ field: { onChange, ...field } }) => {
12344
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12345
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12346
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12518
12348
  ] }),
12519
- /* @__PURE__ */ jsx(
12520
- Form$2.Field,
12521
- {
12522
- control: form.control,
12523
- name: "province",
12524
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12526
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
- ] })
12529
- }
12530
- ),
12531
- /* @__PURE__ */ jsx(
12532
- Form$2.Field,
12349
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
+ CurrencyInput,
12533
12351
  {
12534
- control: form.control,
12535
- name: "phone",
12536
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12537
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12538
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12539
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12540
- ] })
12352
+ ...field,
12353
+ onValueChange: (value) => onChange(value),
12354
+ symbol: getNativeSymbol(currencyCode),
12355
+ code: currencyCode
12541
12356
  }
12542
- )
12543
- ] }) }),
12544
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12545
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12546
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12547
- ] }) })
12548
- ]
12357
+ ) })
12358
+ ] });
12359
+ }
12549
12360
  }
12550
- ) });
12361
+ );
12551
12362
  };
12552
- const schema$1 = addressSchema;
12553
12363
  const TransferOwnership = () => {
12554
12364
  const { id } = useParams();
12555
12365
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12573,7 +12383,7 @@ const TransferOwnershipForm = ({ order }) => {
12573
12383
  defaultValues: {
12574
12384
  customer_id: order.customer_id || ""
12575
12385
  },
12576
- resolver: zodResolver(schema)
12386
+ resolver: zodResolver(schema$1)
12577
12387
  });
12578
12388
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12579
12389
  const { handleSuccess } = useRouteModal();
@@ -13023,9 +12833,199 @@ const Illustration = () => {
13023
12833
  }
13024
12834
  );
13025
12835
  };
13026
- const schema = objectType({
12836
+ const schema$1 = objectType({
13027
12837
  customer_id: stringType().min(1)
13028
12838
  });
12839
+ const BillingAddress = () => {
12840
+ const { id } = useParams();
12841
+ const { order, isPending, isError, error } = useOrder(id, {
12842
+ fields: "+billing_address"
12843
+ });
12844
+ if (isError) {
12845
+ throw error;
12846
+ }
12847
+ const isReady = !isPending && !!order;
12848
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12849
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12850
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12851
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12852
+ ] }),
12853
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12854
+ ] });
12855
+ };
12856
+ const BillingAddressForm = ({ order }) => {
12857
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12858
+ const form = useForm({
12859
+ defaultValues: {
12860
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12861
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12862
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12863
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12864
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12865
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12866
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12867
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12868
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12869
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12870
+ },
12871
+ resolver: zodResolver(schema)
12872
+ });
12873
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12874
+ const { handleSuccess } = useRouteModal();
12875
+ const onSubmit = form.handleSubmit(async (data) => {
12876
+ await mutateAsync(
12877
+ { billing_address: data },
12878
+ {
12879
+ onSuccess: () => {
12880
+ handleSuccess();
12881
+ },
12882
+ onError: (error) => {
12883
+ toast.error(error.message);
12884
+ }
12885
+ }
12886
+ );
12887
+ });
12888
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12889
+ KeyboundForm,
12890
+ {
12891
+ className: "flex flex-1 flex-col overflow-hidden",
12892
+ onSubmit,
12893
+ children: [
12894
+ /* @__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: [
12895
+ /* @__PURE__ */ jsx(
12896
+ Form$2.Field,
12897
+ {
12898
+ control: form.control,
12899
+ name: "country_code",
12900
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12901
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12902
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12903
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12904
+ ] })
12905
+ }
12906
+ ),
12907
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12908
+ /* @__PURE__ */ jsx(
12909
+ Form$2.Field,
12910
+ {
12911
+ control: form.control,
12912
+ name: "first_name",
12913
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12915
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12916
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
+ ] })
12918
+ }
12919
+ ),
12920
+ /* @__PURE__ */ jsx(
12921
+ Form$2.Field,
12922
+ {
12923
+ control: form.control,
12924
+ name: "last_name",
12925
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12926
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12927
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12928
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12929
+ ] })
12930
+ }
12931
+ )
12932
+ ] }),
12933
+ /* @__PURE__ */ jsx(
12934
+ Form$2.Field,
12935
+ {
12936
+ control: form.control,
12937
+ name: "company",
12938
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12940
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
+ ] })
12943
+ }
12944
+ ),
12945
+ /* @__PURE__ */ jsx(
12946
+ Form$2.Field,
12947
+ {
12948
+ control: form.control,
12949
+ name: "address_1",
12950
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12951
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12952
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12953
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12954
+ ] })
12955
+ }
12956
+ ),
12957
+ /* @__PURE__ */ jsx(
12958
+ Form$2.Field,
12959
+ {
12960
+ control: form.control,
12961
+ name: "address_2",
12962
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12963
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12964
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12965
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12966
+ ] })
12967
+ }
12968
+ ),
12969
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12970
+ /* @__PURE__ */ jsx(
12971
+ Form$2.Field,
12972
+ {
12973
+ control: form.control,
12974
+ name: "postal_code",
12975
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12977
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
+ ] })
12980
+ }
12981
+ ),
12982
+ /* @__PURE__ */ jsx(
12983
+ Form$2.Field,
12984
+ {
12985
+ control: form.control,
12986
+ name: "city",
12987
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12988
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12989
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12990
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12991
+ ] })
12992
+ }
12993
+ )
12994
+ ] }),
12995
+ /* @__PURE__ */ jsx(
12996
+ Form$2.Field,
12997
+ {
12998
+ control: form.control,
12999
+ name: "province",
13000
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13002
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
+ ] })
13005
+ }
13006
+ ),
13007
+ /* @__PURE__ */ jsx(
13008
+ Form$2.Field,
13009
+ {
13010
+ control: form.control,
13011
+ name: "phone",
13012
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13013
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13014
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13015
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13016
+ ] })
13017
+ }
13018
+ )
13019
+ ] }) }),
13020
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13021
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13022
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13023
+ ] }) })
13024
+ ]
13025
+ }
13026
+ ) });
13027
+ };
13028
+ const schema = addressSchema;
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
13031
13031
  routes: [
@@ -13046,10 +13046,6 @@ const routeModule = {
13046
13046
  handle,
13047
13047
  loader,
13048
13048
  children: [
13049
- {
13050
- Component: CustomItems,
13051
- path: "/draft-orders/:id/custom-items"
13052
- },
13053
13049
  {
13054
13050
  Component: Email,
13055
13051
  path: "/draft-orders/:id/email"
@@ -13059,8 +13055,8 @@ const routeModule = {
13059
13055
  path: "/draft-orders/:id/items"
13060
13056
  },
13061
13057
  {
13062
- Component: BillingAddress,
13063
- path: "/draft-orders/:id/billing-address"
13058
+ Component: CustomItems,
13059
+ path: "/draft-orders/:id/custom-items"
13064
13060
  },
13065
13061
  {
13066
13062
  Component: Metadata,
@@ -13070,10 +13066,6 @@ const routeModule = {
13070
13066
  Component: Promotions,
13071
13067
  path: "/draft-orders/:id/promotions"
13072
13068
  },
13073
- {
13074
- Component: Shipping,
13075
- path: "/draft-orders/:id/shipping"
13076
- },
13077
13069
  {
13078
13070
  Component: SalesChannel,
13079
13071
  path: "/draft-orders/:id/sales-channel"
@@ -13082,9 +13074,17 @@ const routeModule = {
13082
13074
  Component: ShippingAddress,
13083
13075
  path: "/draft-orders/:id/shipping-address"
13084
13076
  },
13077
+ {
13078
+ Component: Shipping,
13079
+ path: "/draft-orders/:id/shipping"
13080
+ },
13085
13081
  {
13086
13082
  Component: TransferOwnership,
13087
13083
  path: "/draft-orders/:id/transfer-ownership"
13084
+ },
13085
+ {
13086
+ Component: BillingAddress,
13087
+ path: "/draft-orders/:id/billing-address"
13088
13088
  }
13089
13089
  ]
13090
13090
  }