@medusajs/draft-order 2.10.2-preview-20250904180154 → 2.10.2-preview-20250905000310

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,217 +9554,6 @@ const ID = () => {
9554
9554
  /* @__PURE__ */ jsx(Outlet, {})
9555
9555
  ] });
9556
9556
  };
9557
- const BillingAddress = () => {
9558
- const { id } = useParams();
9559
- const { order, isPending, isError, error } = useOrder(id, {
9560
- fields: "+billing_address"
9561
- });
9562
- if (isError) {
9563
- throw error;
9564
- }
9565
- const isReady = !isPending && !!order;
9566
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9567
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9568
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9569
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9570
- ] }),
9571
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9572
- ] });
9573
- };
9574
- const BillingAddressForm = ({ order }) => {
9575
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9576
- const form = useForm({
9577
- defaultValues: {
9578
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9579
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9580
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9581
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9582
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9583
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9584
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9585
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9586
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9587
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9588
- },
9589
- resolver: zodResolver(schema$5)
9590
- });
9591
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9592
- const { handleSuccess } = useRouteModal();
9593
- const onSubmit = form.handleSubmit(async (data) => {
9594
- await mutateAsync(
9595
- { billing_address: data },
9596
- {
9597
- onSuccess: () => {
9598
- handleSuccess();
9599
- },
9600
- onError: (error) => {
9601
- toast.error(error.message);
9602
- }
9603
- }
9604
- );
9605
- });
9606
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9607
- KeyboundForm,
9608
- {
9609
- className: "flex flex-1 flex-col overflow-hidden",
9610
- onSubmit,
9611
- children: [
9612
- /* @__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: [
9613
- /* @__PURE__ */ jsx(
9614
- Form$2.Field,
9615
- {
9616
- control: form.control,
9617
- name: "country_code",
9618
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9619
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9620
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9621
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9622
- ] })
9623
- }
9624
- ),
9625
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9626
- /* @__PURE__ */ jsx(
9627
- Form$2.Field,
9628
- {
9629
- control: form.control,
9630
- name: "first_name",
9631
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9633
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9634
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
- ] })
9636
- }
9637
- ),
9638
- /* @__PURE__ */ jsx(
9639
- Form$2.Field,
9640
- {
9641
- control: form.control,
9642
- name: "last_name",
9643
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9644
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9645
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9646
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9647
- ] })
9648
- }
9649
- )
9650
- ] }),
9651
- /* @__PURE__ */ jsx(
9652
- Form$2.Field,
9653
- {
9654
- control: form.control,
9655
- name: "company",
9656
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9658
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
- ] })
9661
- }
9662
- ),
9663
- /* @__PURE__ */ jsx(
9664
- Form$2.Field,
9665
- {
9666
- control: form.control,
9667
- name: "address_1",
9668
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9669
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9670
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9671
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9672
- ] })
9673
- }
9674
- ),
9675
- /* @__PURE__ */ jsx(
9676
- Form$2.Field,
9677
- {
9678
- control: form.control,
9679
- name: "address_2",
9680
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9681
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9682
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9683
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9684
- ] })
9685
- }
9686
- ),
9687
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9688
- /* @__PURE__ */ jsx(
9689
- Form$2.Field,
9690
- {
9691
- control: form.control,
9692
- name: "postal_code",
9693
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9695
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
- ] })
9698
- }
9699
- ),
9700
- /* @__PURE__ */ jsx(
9701
- Form$2.Field,
9702
- {
9703
- control: form.control,
9704
- name: "city",
9705
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9706
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9707
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9708
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9709
- ] })
9710
- }
9711
- )
9712
- ] }),
9713
- /* @__PURE__ */ jsx(
9714
- Form$2.Field,
9715
- {
9716
- control: form.control,
9717
- name: "province",
9718
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9720
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
- ] })
9723
- }
9724
- ),
9725
- /* @__PURE__ */ jsx(
9726
- Form$2.Field,
9727
- {
9728
- control: form.control,
9729
- name: "phone",
9730
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9731
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9732
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9733
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9734
- ] })
9735
- }
9736
- )
9737
- ] }) }),
9738
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9739
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9740
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9741
- ] }) })
9742
- ]
9743
- }
9744
- ) });
9745
- };
9746
- const schema$5 = addressSchema;
9747
- const CustomItems = () => {
9748
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9749
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9750
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9751
- ] });
9752
- };
9753
- const CustomItemsForm = () => {
9754
- const form = useForm({
9755
- resolver: zodResolver(schema$4)
9756
- });
9757
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9758
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9759
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9760
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9761
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9762
- ] }) })
9763
- ] }) });
9764
- };
9765
- const schema$4 = objectType({
9766
- email: stringType().email()
9767
- });
9768
9557
  const Email = () => {
9769
9558
  const { id } = useParams();
9770
9559
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9787,7 +9576,7 @@ const EmailForm = ({ order }) => {
9787
9576
  defaultValues: {
9788
9577
  email: order.email ?? ""
9789
9578
  },
9790
- resolver: zodResolver(schema$3)
9579
+ resolver: zodResolver(schema$5)
9791
9580
  });
9792
9581
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
9582
  const { handleSuccess } = useRouteModal();
@@ -9830,7 +9619,7 @@ const EmailForm = ({ order }) => {
9830
9619
  }
9831
9620
  ) });
9832
9621
  };
9833
- const schema$3 = objectType({
9622
+ const schema$5 = objectType({
9834
9623
  email: stringType().email()
9835
9624
  });
9836
9625
  const NumberInput = forwardRef(
@@ -11434,44 +11223,150 @@ function getPromotionCodes(items, shippingMethods) {
11434
11223
  }
11435
11224
  return Array.from(codes);
11436
11225
  }
11437
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11438
- const Shipping = () => {
11439
- var _a;
11226
+ const SalesChannel = () => {
11440
11227
  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 });
11228
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11229
+ id,
11230
+ {
11231
+ fields: "+sales_channel_id"
11232
+ },
11233
+ {
11234
+ enabled: !!id
11235
+ }
11236
+ );
11452
11237
  if (isError) {
11453
11238
  throw error;
11454
11239
  }
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" }) }),
11464
- /* @__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
- ] }) }) }),
11466
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11467
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11468
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11469
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11470
- ] }) });
11471
- };
11472
- const ShippingForm = ({ preview, order }) => {
11473
- var _a;
11474
- const { setIsOpen } = useStackedModal();
11240
+ const ISrEADY = !!draft_order && !isPending;
11241
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11242
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11243
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11244
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11245
+ ] }),
11246
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11247
+ ] });
11248
+ };
11249
+ const SalesChannelForm = ({ order }) => {
11250
+ const form = useForm({
11251
+ defaultValues: {
11252
+ sales_channel_id: order.sales_channel_id || ""
11253
+ },
11254
+ resolver: zodResolver(schema$4)
11255
+ });
11256
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11257
+ const { handleSuccess } = useRouteModal();
11258
+ const onSubmit = form.handleSubmit(async (data) => {
11259
+ await mutateAsync(
11260
+ {
11261
+ sales_channel_id: data.sales_channel_id
11262
+ },
11263
+ {
11264
+ onSuccess: () => {
11265
+ toast.success("Sales channel updated");
11266
+ handleSuccess();
11267
+ },
11268
+ onError: (error) => {
11269
+ toast.error(error.message);
11270
+ }
11271
+ }
11272
+ );
11273
+ });
11274
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11275
+ KeyboundForm,
11276
+ {
11277
+ className: "flex flex-1 flex-col overflow-hidden",
11278
+ onSubmit,
11279
+ children: [
11280
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11281
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11282
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11283
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11284
+ ] }) })
11285
+ ]
11286
+ }
11287
+ ) });
11288
+ };
11289
+ const SalesChannelField = ({ control, order }) => {
11290
+ const salesChannels = useComboboxData({
11291
+ queryFn: async (params) => {
11292
+ return await sdk.admin.salesChannel.list(params);
11293
+ },
11294
+ queryKey: ["sales-channels"],
11295
+ getOptions: (data) => {
11296
+ return data.sales_channels.map((salesChannel) => ({
11297
+ label: salesChannel.name,
11298
+ value: salesChannel.id
11299
+ }));
11300
+ },
11301
+ defaultValue: order.sales_channel_id || void 0
11302
+ });
11303
+ return /* @__PURE__ */ jsx(
11304
+ Form$2.Field,
11305
+ {
11306
+ control,
11307
+ name: "sales_channel_id",
11308
+ render: ({ field }) => {
11309
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11310
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11311
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11312
+ Combobox,
11313
+ {
11314
+ options: salesChannels.options,
11315
+ fetchNextPage: salesChannels.fetchNextPage,
11316
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11317
+ searchValue: salesChannels.searchValue,
11318
+ onSearchValueChange: salesChannels.onSearchValueChange,
11319
+ placeholder: "Select sales channel",
11320
+ ...field
11321
+ }
11322
+ ) }),
11323
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11324
+ ] });
11325
+ }
11326
+ }
11327
+ );
11328
+ };
11329
+ const schema$4 = objectType({
11330
+ sales_channel_id: stringType().min(1)
11331
+ });
11332
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11333
+ const Shipping = () => {
11334
+ var _a;
11335
+ const { id } = useParams();
11336
+ const { order, isPending, isError, error } = useOrder(id, {
11337
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11338
+ });
11339
+ const {
11340
+ order: preview,
11341
+ isPending: isPreviewPending,
11342
+ isError: isPreviewError,
11343
+ error: previewError
11344
+ } = useOrderPreview(id);
11345
+ useInitiateOrderEdit({ preview });
11346
+ const { onCancel } = useCancelOrderEdit({ preview });
11347
+ if (isError) {
11348
+ throw error;
11349
+ }
11350
+ if (isPreviewError) {
11351
+ throw previewError;
11352
+ }
11353
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11354
+ const isReady = preview && !isPreviewPending && order && !isPending;
11355
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11356
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11357
+ /* @__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: [
11358
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11359
+ /* @__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." }) })
11360
+ ] }) }) }),
11361
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11362
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11363
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11364
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11365
+ ] }) });
11366
+ };
11367
+ const ShippingForm = ({ preview, order }) => {
11368
+ var _a;
11369
+ const { setIsOpen } = useStackedModal();
11475
11370
  const [isSubmitting, setIsSubmitting] = useState(false);
11476
11371
  const [data, setData] = useState(null);
11477
11372
  const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
@@ -12273,7 +12168,7 @@ const ShippingAddressForm = ({ order }) => {
12273
12168
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12274
12169
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12275
12170
  },
12276
- resolver: zodResolver(schema$2)
12171
+ resolver: zodResolver(schema$3)
12277
12172
  });
12278
12173
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12279
12174
  const { handleSuccess } = useRouteModal();
@@ -12443,7 +12338,7 @@ const ShippingAddressForm = ({ order }) => {
12443
12338
  }
12444
12339
  ) });
12445
12340
  };
12446
- const schema$2 = addressSchema;
12341
+ const schema$3 = addressSchema;
12447
12342
  const TransferOwnership = () => {
12448
12343
  const { id } = useParams();
12449
12344
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12467,7 +12362,7 @@ const TransferOwnershipForm = ({ order }) => {
12467
12362
  defaultValues: {
12468
12363
  customer_id: order.customer_id || ""
12469
12364
  },
12470
- resolver: zodResolver(schema$1)
12365
+ resolver: zodResolver(schema$2)
12471
12366
  });
12472
12367
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12473
12368
  const { handleSuccess } = useRouteModal();
@@ -12917,36 +12812,61 @@ const Illustration = () => {
12917
12812
  }
12918
12813
  );
12919
12814
  };
12920
- const schema$1 = objectType({
12815
+ const schema$2 = objectType({
12921
12816
  customer_id: stringType().min(1)
12922
12817
  });
12923
- const SalesChannel = () => {
12818
+ const CustomItems = () => {
12819
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12820
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
12821
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
12822
+ ] });
12823
+ };
12824
+ const CustomItemsForm = () => {
12825
+ const form = useForm({
12826
+ resolver: zodResolver(schema$1)
12827
+ });
12828
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
12829
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
12830
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12831
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12832
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
12833
+ ] }) })
12834
+ ] }) });
12835
+ };
12836
+ const schema$1 = objectType({
12837
+ email: stringType().email()
12838
+ });
12839
+ const BillingAddress = () => {
12924
12840
  const { id } = useParams();
12925
- const { draft_order, isPending, isError, error } = useDraftOrder(
12926
- id,
12927
- {
12928
- fields: "+sales_channel_id"
12929
- },
12930
- {
12931
- enabled: !!id
12932
- }
12933
- );
12841
+ const { order, isPending, isError, error } = useOrder(id, {
12842
+ fields: "+billing_address"
12843
+ });
12934
12844
  if (isError) {
12935
12845
  throw error;
12936
12846
  }
12937
- const ISrEADY = !!draft_order && !isPending;
12847
+ const isReady = !isPending && !!order;
12938
12848
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12939
12849
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12940
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12941
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
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" }) })
12942
12852
  ] }),
12943
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12853
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12944
12854
  ] });
12945
12855
  };
12946
- const SalesChannelForm = ({ order }) => {
12856
+ const BillingAddressForm = ({ order }) => {
12857
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12947
12858
  const form = useForm({
12948
12859
  defaultValues: {
12949
- sales_channel_id: order.sales_channel_id || ""
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) ?? ""
12950
12870
  },
12951
12871
  resolver: zodResolver(schema)
12952
12872
  });
@@ -12954,12 +12874,9 @@ const SalesChannelForm = ({ order }) => {
12954
12874
  const { handleSuccess } = useRouteModal();
12955
12875
  const onSubmit = form.handleSubmit(async (data) => {
12956
12876
  await mutateAsync(
12957
- {
12958
- sales_channel_id: data.sales_channel_id
12959
- },
12877
+ { billing_address: data },
12960
12878
  {
12961
12879
  onSuccess: () => {
12962
- toast.success("Sales channel updated");
12963
12880
  handleSuccess();
12964
12881
  },
12965
12882
  onError: (error) => {
@@ -12974,7 +12891,132 @@ const SalesChannelForm = ({ order }) => {
12974
12891
  className: "flex flex-1 flex-col overflow-hidden",
12975
12892
  onSubmit,
12976
12893
  children: [
12977
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
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
+ ] }) }),
12978
13020
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12979
13021
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12980
13022
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -12983,49 +13025,7 @@ const SalesChannelForm = ({ order }) => {
12983
13025
  }
12984
13026
  ) });
12985
13027
  };
12986
- const SalesChannelField = ({ control, order }) => {
12987
- const salesChannels = useComboboxData({
12988
- queryFn: async (params) => {
12989
- return await sdk.admin.salesChannel.list(params);
12990
- },
12991
- queryKey: ["sales-channels"],
12992
- getOptions: (data) => {
12993
- return data.sales_channels.map((salesChannel) => ({
12994
- label: salesChannel.name,
12995
- value: salesChannel.id
12996
- }));
12997
- },
12998
- defaultValue: order.sales_channel_id || void 0
12999
- });
13000
- return /* @__PURE__ */ jsx(
13001
- Form$2.Field,
13002
- {
13003
- control,
13004
- name: "sales_channel_id",
13005
- render: ({ field }) => {
13006
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13007
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13008
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13009
- Combobox,
13010
- {
13011
- options: salesChannels.options,
13012
- fetchNextPage: salesChannels.fetchNextPage,
13013
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13014
- searchValue: salesChannels.searchValue,
13015
- onSearchValueChange: salesChannels.onSearchValueChange,
13016
- placeholder: "Select sales channel",
13017
- ...field
13018
- }
13019
- ) }),
13020
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13021
- ] });
13022
- }
13023
- }
13024
- );
13025
- };
13026
- const schema = objectType({
13027
- sales_channel_id: stringType().min(1)
13028
- });
13028
+ const schema = addressSchema;
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
13031
13031
  routes: [
@@ -13046,14 +13046,6 @@ const routeModule = {
13046
13046
  handle,
13047
13047
  loader,
13048
13048
  children: [
13049
- {
13050
- Component: BillingAddress,
13051
- path: "/draft-orders/:id/billing-address"
13052
- },
13053
- {
13054
- Component: CustomItems,
13055
- path: "/draft-orders/:id/custom-items"
13056
- },
13057
13049
  {
13058
13050
  Component: Email,
13059
13051
  path: "/draft-orders/:id/email"
@@ -13070,6 +13062,10 @@ const routeModule = {
13070
13062
  Component: Promotions,
13071
13063
  path: "/draft-orders/:id/promotions"
13072
13064
  },
13065
+ {
13066
+ Component: SalesChannel,
13067
+ path: "/draft-orders/:id/sales-channel"
13068
+ },
13073
13069
  {
13074
13070
  Component: Shipping,
13075
13071
  path: "/draft-orders/:id/shipping"
@@ -13083,8 +13079,12 @@ const routeModule = {
13083
13079
  path: "/draft-orders/:id/transfer-ownership"
13084
13080
  },
13085
13081
  {
13086
- Component: SalesChannel,
13087
- path: "/draft-orders/:id/sales-channel"
13082
+ Component: CustomItems,
13083
+ path: "/draft-orders/:id/custom-items"
13084
+ },
13085
+ {
13086
+ Component: BillingAddress,
13087
+ path: "/draft-orders/:id/billing-address"
13088
13088
  }
13089
13089
  ]
13090
13090
  }