@medusajs/draft-order 2.10.4-snapshot-20250925183036 → 2.10.4-snapshot-20250925190227

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.
@@ -9588,6 +9588,196 @@ const CustomItemsForm = () => {
9588
9588
  const schema$5 = objectType({
9589
9589
  email: stringType().email()
9590
9590
  });
9591
+ const BillingAddress = () => {
9592
+ const { id } = useParams();
9593
+ const { order, isPending, isError, error } = useOrder(id, {
9594
+ fields: "+billing_address"
9595
+ });
9596
+ if (isError) {
9597
+ throw error;
9598
+ }
9599
+ const isReady = !isPending && !!order;
9600
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9601
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9602
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9603
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9604
+ ] }),
9605
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9606
+ ] });
9607
+ };
9608
+ const BillingAddressForm = ({ order }) => {
9609
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9610
+ const form = useForm({
9611
+ defaultValues: {
9612
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9613
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9614
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9615
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9616
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9617
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9618
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9619
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9620
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9621
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9622
+ },
9623
+ resolver: zodResolver(schema$4)
9624
+ });
9625
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9626
+ const { handleSuccess } = useRouteModal();
9627
+ const onSubmit = form.handleSubmit(async (data) => {
9628
+ await mutateAsync(
9629
+ { billing_address: data },
9630
+ {
9631
+ onSuccess: () => {
9632
+ handleSuccess();
9633
+ },
9634
+ onError: (error) => {
9635
+ toast.error(error.message);
9636
+ }
9637
+ }
9638
+ );
9639
+ });
9640
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9641
+ KeyboundForm,
9642
+ {
9643
+ className: "flex flex-1 flex-col overflow-hidden",
9644
+ onSubmit,
9645
+ children: [
9646
+ /* @__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: [
9647
+ /* @__PURE__ */ jsx(
9648
+ Form$2.Field,
9649
+ {
9650
+ control: form.control,
9651
+ name: "country_code",
9652
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9653
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9654
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9655
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9656
+ ] })
9657
+ }
9658
+ ),
9659
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9660
+ /* @__PURE__ */ jsx(
9661
+ Form$2.Field,
9662
+ {
9663
+ control: form.control,
9664
+ name: "first_name",
9665
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9666
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9667
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9668
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9669
+ ] })
9670
+ }
9671
+ ),
9672
+ /* @__PURE__ */ jsx(
9673
+ Form$2.Field,
9674
+ {
9675
+ control: form.control,
9676
+ name: "last_name",
9677
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9678
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9679
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9680
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9681
+ ] })
9682
+ }
9683
+ )
9684
+ ] }),
9685
+ /* @__PURE__ */ jsx(
9686
+ Form$2.Field,
9687
+ {
9688
+ control: form.control,
9689
+ name: "company",
9690
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9691
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9692
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9693
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9694
+ ] })
9695
+ }
9696
+ ),
9697
+ /* @__PURE__ */ jsx(
9698
+ Form$2.Field,
9699
+ {
9700
+ control: form.control,
9701
+ name: "address_1",
9702
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9703
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9704
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9705
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9706
+ ] })
9707
+ }
9708
+ ),
9709
+ /* @__PURE__ */ jsx(
9710
+ Form$2.Field,
9711
+ {
9712
+ control: form.control,
9713
+ name: "address_2",
9714
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9715
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9716
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9717
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9718
+ ] })
9719
+ }
9720
+ ),
9721
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9722
+ /* @__PURE__ */ jsx(
9723
+ Form$2.Field,
9724
+ {
9725
+ control: form.control,
9726
+ name: "postal_code",
9727
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9728
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9729
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9730
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9731
+ ] })
9732
+ }
9733
+ ),
9734
+ /* @__PURE__ */ jsx(
9735
+ Form$2.Field,
9736
+ {
9737
+ control: form.control,
9738
+ name: "city",
9739
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9740
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9741
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9742
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9743
+ ] })
9744
+ }
9745
+ )
9746
+ ] }),
9747
+ /* @__PURE__ */ jsx(
9748
+ Form$2.Field,
9749
+ {
9750
+ control: form.control,
9751
+ name: "province",
9752
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9753
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9754
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9755
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9756
+ ] })
9757
+ }
9758
+ ),
9759
+ /* @__PURE__ */ jsx(
9760
+ Form$2.Field,
9761
+ {
9762
+ control: form.control,
9763
+ name: "phone",
9764
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9765
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9766
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9767
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9768
+ ] })
9769
+ }
9770
+ )
9771
+ ] }) }),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9775
+ ] }) })
9776
+ ]
9777
+ }
9778
+ ) });
9779
+ };
9780
+ const schema$4 = addressSchema;
9591
9781
  const Email = () => {
9592
9782
  const { id } = useParams();
9593
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9610,7 +9800,7 @@ const EmailForm = ({ order }) => {
9610
9800
  defaultValues: {
9611
9801
  email: order.email ?? ""
9612
9802
  },
9613
- resolver: zodResolver(schema$4)
9803
+ resolver: zodResolver(schema$3)
9614
9804
  });
9615
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9616
9806
  const { handleSuccess } = useRouteModal();
@@ -9653,7 +9843,7 @@ const EmailForm = ({ order }) => {
9653
9843
  }
9654
9844
  ) });
9655
9845
  };
9656
- const schema$4 = objectType({
9846
+ const schema$3 = objectType({
9657
9847
  email: stringType().email()
9658
9848
  });
9659
9849
  const NumberInput = forwardRef(
@@ -11257,71 +11447,177 @@ function getPromotionIds(items, shippingMethods) {
11257
11447
  }
11258
11448
  return Array.from(promotionIds);
11259
11449
  }
11260
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11261
- const Shipping = () => {
11262
- var _a;
11450
+ const SalesChannel = () => {
11263
11451
  const { id } = useParams();
11264
- const { order, isPending, isError, error } = useOrder(id, {
11265
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11266
- });
11267
- const {
11268
- order: preview,
11269
- isPending: isPreviewPending,
11270
- isError: isPreviewError,
11271
- error: previewError
11272
- } = useOrderPreview(id);
11273
- useInitiateOrderEdit({ preview });
11274
- const { onCancel } = useCancelOrderEdit({ preview });
11275
- if (isError) {
11276
- throw error;
11277
- }
11278
- if (isPreviewError) {
11279
- throw previewError;
11280
- }
11281
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11282
- const isReady = preview && !isPreviewPending && order && !isPending;
11283
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11284
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11285
- /* @__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: [
11286
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11287
- /* @__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." }) })
11288
- ] }) }) }),
11289
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11290
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11291
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11292
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11293
- ] }) });
11294
- };
11295
- const ShippingForm = ({ preview, order }) => {
11296
- var _a;
11297
- const { setIsOpen } = useStackedModal();
11298
- const [isSubmitting, setIsSubmitting] = useState(false);
11299
- const [data, setData] = useState(null);
11300
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11301
- const { shipping_options } = useShippingOptions(
11452
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11453
+ id,
11302
11454
  {
11303
- id: appliedShippingOptionIds,
11304
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11455
+ fields: "+sales_channel_id"
11305
11456
  },
11306
11457
  {
11307
- enabled: appliedShippingOptionIds.length > 0
11458
+ enabled: !!id
11308
11459
  }
11309
11460
  );
11310
- const uniqueShippingProfiles = useMemo(() => {
11311
- const profiles = /* @__PURE__ */ new Map();
11312
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11313
- profiles.set(profile.id, profile);
11314
- });
11315
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11316
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11317
- });
11318
- return Array.from(profiles.values());
11319
- }, [order.items, shipping_options]);
11320
- const { handleSuccess } = useRouteModal();
11321
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11322
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11323
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11324
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11461
+ if (isError) {
11462
+ throw error;
11463
+ }
11464
+ const ISrEADY = !!draft_order && !isPending;
11465
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
+ ] }),
11470
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11471
+ ] });
11472
+ };
11473
+ const SalesChannelForm = ({ order }) => {
11474
+ const form = useForm({
11475
+ defaultValues: {
11476
+ sales_channel_id: order.sales_channel_id || ""
11477
+ },
11478
+ resolver: zodResolver(schema$2)
11479
+ });
11480
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
+ const { handleSuccess } = useRouteModal();
11482
+ const onSubmit = form.handleSubmit(async (data) => {
11483
+ await mutateAsync(
11484
+ {
11485
+ sales_channel_id: data.sales_channel_id
11486
+ },
11487
+ {
11488
+ onSuccess: () => {
11489
+ toast.success("Sales channel updated");
11490
+ handleSuccess();
11491
+ },
11492
+ onError: (error) => {
11493
+ toast.error(error.message);
11494
+ }
11495
+ }
11496
+ );
11497
+ });
11498
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11499
+ KeyboundForm,
11500
+ {
11501
+ className: "flex flex-1 flex-col overflow-hidden",
11502
+ onSubmit,
11503
+ children: [
11504
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11507
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
+ ] }) })
11509
+ ]
11510
+ }
11511
+ ) });
11512
+ };
11513
+ const SalesChannelField = ({ control, order }) => {
11514
+ const salesChannels = useComboboxData({
11515
+ queryFn: async (params) => {
11516
+ return await sdk.admin.salesChannel.list(params);
11517
+ },
11518
+ queryKey: ["sales-channels"],
11519
+ getOptions: (data) => {
11520
+ return data.sales_channels.map((salesChannel) => ({
11521
+ label: salesChannel.name,
11522
+ value: salesChannel.id
11523
+ }));
11524
+ },
11525
+ defaultValue: order.sales_channel_id || void 0
11526
+ });
11527
+ return /* @__PURE__ */ jsx(
11528
+ Form$2.Field,
11529
+ {
11530
+ control,
11531
+ name: "sales_channel_id",
11532
+ render: ({ field }) => {
11533
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
+ Combobox,
11537
+ {
11538
+ options: salesChannels.options,
11539
+ fetchNextPage: salesChannels.fetchNextPage,
11540
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
+ searchValue: salesChannels.searchValue,
11542
+ onSearchValueChange: salesChannels.onSearchValueChange,
11543
+ placeholder: "Select sales channel",
11544
+ ...field
11545
+ }
11546
+ ) }),
11547
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
+ ] });
11549
+ }
11550
+ }
11551
+ );
11552
+ };
11553
+ const schema$2 = objectType({
11554
+ sales_channel_id: stringType().min(1)
11555
+ });
11556
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
+ const Shipping = () => {
11558
+ var _a;
11559
+ const { id } = useParams();
11560
+ const { order, isPending, isError, error } = useOrder(id, {
11561
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11562
+ });
11563
+ const {
11564
+ order: preview,
11565
+ isPending: isPreviewPending,
11566
+ isError: isPreviewError,
11567
+ error: previewError
11568
+ } = useOrderPreview(id);
11569
+ useInitiateOrderEdit({ preview });
11570
+ const { onCancel } = useCancelOrderEdit({ preview });
11571
+ if (isError) {
11572
+ throw error;
11573
+ }
11574
+ if (isPreviewError) {
11575
+ throw previewError;
11576
+ }
11577
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
+ const isReady = preview && !isPreviewPending && order && !isPending;
11579
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11582
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
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." }) })
11584
+ ] }) }) }),
11585
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11586
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11587
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11588
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11589
+ ] }) });
11590
+ };
11591
+ const ShippingForm = ({ preview, order }) => {
11592
+ var _a;
11593
+ const { setIsOpen } = useStackedModal();
11594
+ const [isSubmitting, setIsSubmitting] = useState(false);
11595
+ const [data, setData] = useState(null);
11596
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11597
+ const { shipping_options } = useShippingOptions(
11598
+ {
11599
+ id: appliedShippingOptionIds,
11600
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11601
+ },
11602
+ {
11603
+ enabled: appliedShippingOptionIds.length > 0
11604
+ }
11605
+ );
11606
+ const uniqueShippingProfiles = useMemo(() => {
11607
+ const profiles = /* @__PURE__ */ new Map();
11608
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11609
+ profiles.set(profile.id, profile);
11610
+ });
11611
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11612
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11613
+ });
11614
+ return Array.from(profiles.values());
11615
+ }, [order.items, shipping_options]);
11616
+ const { handleSuccess } = useRouteModal();
11617
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11618
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11619
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11620
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11325
11621
  const onSubmit = async () => {
11326
11622
  setIsSubmitting(true);
11327
11623
  let requestSucceeded = false;
@@ -12064,46 +12360,60 @@ const CustomAmountField = ({
12064
12360
  }
12065
12361
  );
12066
12362
  };
12067
- const SalesChannel = () => {
12363
+ const ShippingAddress = () => {
12068
12364
  const { id } = useParams();
12069
- const { draft_order, isPending, isError, error } = useDraftOrder(
12070
- id,
12071
- {
12072
- fields: "+sales_channel_id"
12073
- },
12074
- {
12075
- enabled: !!id
12076
- }
12077
- );
12365
+ const { order, isPending, isError, error } = useOrder(id, {
12366
+ fields: "+shipping_address"
12367
+ });
12078
12368
  if (isError) {
12079
12369
  throw error;
12080
12370
  }
12081
- const ISrEADY = !!draft_order && !isPending;
12371
+ const isReady = !isPending && !!order;
12082
12372
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12083
12373
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12084
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12085
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12374
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12086
12376
  ] }),
12087
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12377
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12088
12378
  ] });
12089
12379
  };
12090
- const SalesChannelForm = ({ order }) => {
12380
+ const ShippingAddressForm = ({ order }) => {
12381
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12091
12382
  const form = useForm({
12092
12383
  defaultValues: {
12093
- sales_channel_id: order.sales_channel_id || ""
12384
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12094
12394
  },
12095
- resolver: zodResolver(schema$3)
12395
+ resolver: zodResolver(schema$1)
12096
12396
  });
12097
12397
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12098
12398
  const { handleSuccess } = useRouteModal();
12099
12399
  const onSubmit = form.handleSubmit(async (data) => {
12100
12400
  await mutateAsync(
12101
12401
  {
12102
- sales_channel_id: data.sales_channel_id
12402
+ shipping_address: {
12403
+ first_name: data.first_name,
12404
+ last_name: data.last_name,
12405
+ company: data.company,
12406
+ address_1: data.address_1,
12407
+ address_2: data.address_2,
12408
+ city: data.city,
12409
+ province: data.province,
12410
+ country_code: data.country_code,
12411
+ postal_code: data.postal_code,
12412
+ phone: data.phone
12413
+ }
12103
12414
  },
12104
12415
  {
12105
12416
  onSuccess: () => {
12106
- toast.success("Sales channel updated");
12107
12417
  handleSuccess();
12108
12418
  },
12109
12419
  onError: (error) => {
@@ -12118,58 +12428,141 @@ const SalesChannelForm = ({ order }) => {
12118
12428
  className: "flex flex-1 flex-col overflow-hidden",
12119
12429
  onSubmit,
12120
12430
  children: [
12121
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12122
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12123
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12124
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12125
- ] }) })
12126
- ]
12127
- }
12128
- ) });
12129
- };
12130
- const SalesChannelField = ({ control, order }) => {
12131
- const salesChannels = useComboboxData({
12132
- queryFn: async (params) => {
12133
- return await sdk.admin.salesChannel.list(params);
12134
- },
12135
- queryKey: ["sales-channels"],
12136
- getOptions: (data) => {
12137
- return data.sales_channels.map((salesChannel) => ({
12138
- label: salesChannel.name,
12139
- value: salesChannel.id
12140
- }));
12141
- },
12142
- defaultValue: order.sales_channel_id || void 0
12143
- });
12144
- return /* @__PURE__ */ jsx(
12145
- Form$2.Field,
12146
- {
12147
- control,
12148
- name: "sales_channel_id",
12149
- render: ({ field }) => {
12150
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12151
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12152
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12153
- Combobox,
12431
+ /* @__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: [
12432
+ /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12154
12434
  {
12155
- options: salesChannels.options,
12156
- fetchNextPage: salesChannels.fetchNextPage,
12157
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12158
- searchValue: salesChannels.searchValue,
12159
- onSearchValueChange: salesChannels.onSearchValueChange,
12160
- placeholder: "Select sales channel",
12161
- ...field
12162
- }
12163
- ) }),
12164
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12165
- ] });
12166
- }
12435
+ control: form.control,
12436
+ name: "country_code",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
+ ] })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
+ /* @__PURE__ */ jsx(
12446
+ Form$2.Field,
12447
+ {
12448
+ control: form.control,
12449
+ name: "first_name",
12450
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
+ ] })
12455
+ }
12456
+ ),
12457
+ /* @__PURE__ */ jsx(
12458
+ Form$2.Field,
12459
+ {
12460
+ control: form.control,
12461
+ name: "last_name",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
+ ] })
12467
+ }
12468
+ )
12469
+ ] }),
12470
+ /* @__PURE__ */ jsx(
12471
+ Form$2.Field,
12472
+ {
12473
+ control: form.control,
12474
+ name: "company",
12475
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
+ ] })
12480
+ }
12481
+ ),
12482
+ /* @__PURE__ */ jsx(
12483
+ Form$2.Field,
12484
+ {
12485
+ control: form.control,
12486
+ name: "address_1",
12487
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
+ ] })
12492
+ }
12493
+ ),
12494
+ /* @__PURE__ */ jsx(
12495
+ Form$2.Field,
12496
+ {
12497
+ control: form.control,
12498
+ name: "address_2",
12499
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
+ ] })
12504
+ }
12505
+ ),
12506
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
+ /* @__PURE__ */ jsx(
12508
+ Form$2.Field,
12509
+ {
12510
+ control: form.control,
12511
+ name: "postal_code",
12512
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
+ ] })
12517
+ }
12518
+ ),
12519
+ /* @__PURE__ */ jsx(
12520
+ Form$2.Field,
12521
+ {
12522
+ control: form.control,
12523
+ name: "city",
12524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
+ ] })
12529
+ }
12530
+ )
12531
+ ] }),
12532
+ /* @__PURE__ */ jsx(
12533
+ Form$2.Field,
12534
+ {
12535
+ control: form.control,
12536
+ name: "province",
12537
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
+ ] })
12542
+ }
12543
+ ),
12544
+ /* @__PURE__ */ jsx(
12545
+ Form$2.Field,
12546
+ {
12547
+ control: form.control,
12548
+ name: "phone",
12549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
+ ] })
12554
+ }
12555
+ )
12556
+ ] }) }),
12557
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
+ ] }) })
12561
+ ]
12167
12562
  }
12168
- );
12563
+ ) });
12169
12564
  };
12170
- const schema$3 = objectType({
12171
- sales_channel_id: stringType().min(1)
12172
- });
12565
+ const schema$1 = addressSchema;
12173
12566
  const TransferOwnership = () => {
12174
12567
  const { id } = useParams();
12175
12568
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12193,7 +12586,7 @@ const TransferOwnershipForm = ({ order }) => {
12193
12586
  defaultValues: {
12194
12587
  customer_id: order.customer_id || ""
12195
12588
  },
12196
- resolver: zodResolver(schema$2)
12589
+ resolver: zodResolver(schema)
12197
12590
  });
12198
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12199
12592
  const { handleSuccess } = useRouteModal();
@@ -12643,426 +13036,37 @@ const Illustration = () => {
12643
13036
  }
12644
13037
  );
12645
13038
  };
12646
- const schema$2 = objectType({
13039
+ const schema = objectType({
12647
13040
  customer_id: stringType().min(1)
12648
13041
  });
12649
- const ShippingAddress = () => {
12650
- const { id } = useParams();
12651
- const { order, isPending, isError, error } = useOrder(id, {
12652
- fields: "+shipping_address"
12653
- });
12654
- if (isError) {
12655
- throw error;
12656
- }
12657
- const isReady = !isPending && !!order;
12658
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12659
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12660
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12661
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12662
- ] }),
12663
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12664
- ] });
12665
- };
12666
- const ShippingAddressForm = ({ order }) => {
12667
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12668
- const form = useForm({
12669
- defaultValues: {
12670
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12671
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12672
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12673
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12674
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12675
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12676
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12677
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12678
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12679
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12680
- },
12681
- resolver: zodResolver(schema$1)
12682
- });
12683
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12684
- const { handleSuccess } = useRouteModal();
12685
- const onSubmit = form.handleSubmit(async (data) => {
12686
- await mutateAsync(
12687
- {
12688
- shipping_address: {
12689
- first_name: data.first_name,
12690
- last_name: data.last_name,
12691
- company: data.company,
12692
- address_1: data.address_1,
12693
- address_2: data.address_2,
12694
- city: data.city,
12695
- province: data.province,
12696
- country_code: data.country_code,
12697
- postal_code: data.postal_code,
12698
- phone: data.phone
12699
- }
12700
- },
12701
- {
12702
- onSuccess: () => {
12703
- handleSuccess();
12704
- },
12705
- onError: (error) => {
12706
- toast.error(error.message);
13042
+ const widgetModule = { widgets: [] };
13043
+ const routeModule = {
13044
+ routes: [
13045
+ {
13046
+ Component: List,
13047
+ path: "/draft-orders",
13048
+ handle: handle$1,
13049
+ children: [
13050
+ {
13051
+ Component: Create,
13052
+ path: "/draft-orders/create"
12707
13053
  }
12708
- }
12709
- );
12710
- });
12711
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12712
- KeyboundForm,
13054
+ ]
13055
+ },
12713
13056
  {
12714
- className: "flex flex-1 flex-col overflow-hidden",
12715
- onSubmit,
12716
- children: [
12717
- /* @__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: [
12718
- /* @__PURE__ */ jsx(
12719
- Form$2.Field,
12720
- {
12721
- control: form.control,
12722
- name: "country_code",
12723
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12724
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12725
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12726
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12727
- ] })
12728
- }
12729
- ),
12730
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12731
- /* @__PURE__ */ jsx(
12732
- Form$2.Field,
12733
- {
12734
- control: form.control,
12735
- name: "first_name",
12736
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12737
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12738
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12739
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12740
- ] })
12741
- }
12742
- ),
12743
- /* @__PURE__ */ jsx(
12744
- Form$2.Field,
12745
- {
12746
- control: form.control,
12747
- name: "last_name",
12748
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12749
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12750
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12751
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12752
- ] })
12753
- }
12754
- )
12755
- ] }),
12756
- /* @__PURE__ */ jsx(
12757
- Form$2.Field,
12758
- {
12759
- control: form.control,
12760
- name: "company",
12761
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12762
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12763
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12764
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12765
- ] })
12766
- }
12767
- ),
12768
- /* @__PURE__ */ jsx(
12769
- Form$2.Field,
12770
- {
12771
- control: form.control,
12772
- name: "address_1",
12773
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12774
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12775
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12776
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12777
- ] })
12778
- }
12779
- ),
12780
- /* @__PURE__ */ jsx(
12781
- Form$2.Field,
12782
- {
12783
- control: form.control,
12784
- name: "address_2",
12785
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12786
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12787
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12788
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12789
- ] })
12790
- }
12791
- ),
12792
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12793
- /* @__PURE__ */ jsx(
12794
- Form$2.Field,
12795
- {
12796
- control: form.control,
12797
- name: "postal_code",
12798
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12799
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12800
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12801
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12802
- ] })
12803
- }
12804
- ),
12805
- /* @__PURE__ */ jsx(
12806
- Form$2.Field,
12807
- {
12808
- control: form.control,
12809
- name: "city",
12810
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12811
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12812
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12813
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12814
- ] })
12815
- }
12816
- )
12817
- ] }),
12818
- /* @__PURE__ */ jsx(
12819
- Form$2.Field,
12820
- {
12821
- control: form.control,
12822
- name: "province",
12823
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12824
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12825
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12826
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12827
- ] })
12828
- }
12829
- ),
12830
- /* @__PURE__ */ jsx(
12831
- Form$2.Field,
12832
- {
12833
- control: form.control,
12834
- name: "phone",
12835
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12836
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12837
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12838
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12839
- ] })
12840
- }
12841
- )
12842
- ] }) }),
12843
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12844
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12845
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12846
- ] }) })
12847
- ]
12848
- }
12849
- ) });
12850
- };
12851
- const schema$1 = addressSchema;
12852
- const BillingAddress = () => {
12853
- const { id } = useParams();
12854
- const { order, isPending, isError, error } = useOrder(id, {
12855
- fields: "+billing_address"
12856
- });
12857
- if (isError) {
12858
- throw error;
12859
- }
12860
- const isReady = !isPending && !!order;
12861
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12863
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12865
- ] }),
12866
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12867
- ] });
12868
- };
12869
- const BillingAddressForm = ({ order }) => {
12870
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12871
- const form = useForm({
12872
- defaultValues: {
12873
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12883
- },
12884
- resolver: zodResolver(schema)
12885
- });
12886
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
- const { handleSuccess } = useRouteModal();
12888
- const onSubmit = form.handleSubmit(async (data) => {
12889
- await mutateAsync(
12890
- { billing_address: data },
12891
- {
12892
- onSuccess: () => {
12893
- handleSuccess();
12894
- },
12895
- onError: (error) => {
12896
- toast.error(error.message);
12897
- }
12898
- }
12899
- );
12900
- });
12901
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
- KeyboundForm,
12903
- {
12904
- className: "flex flex-1 flex-col overflow-hidden",
12905
- onSubmit,
12906
- children: [
12907
- /* @__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: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12910
- {
12911
- control: form.control,
12912
- name: "country_code",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12918
- }
12919
- ),
12920
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
- /* @__PURE__ */ jsx(
12922
- Form$2.Field,
12923
- {
12924
- control: form.control,
12925
- name: "first_name",
12926
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
- ] })
12931
- }
12932
- ),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "last_name",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- )
12945
- ] }),
12946
- /* @__PURE__ */ jsx(
12947
- Form$2.Field,
12948
- {
12949
- control: form.control,
12950
- name: "company",
12951
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
- ] })
12956
- }
12957
- ),
12958
- /* @__PURE__ */ jsx(
12959
- Form$2.Field,
12960
- {
12961
- control: form.control,
12962
- name: "address_1",
12963
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
- ] })
12968
- }
12969
- ),
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
12972
- {
12973
- control: form.control,
12974
- name: "address_2",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
12980
- }
12981
- ),
12982
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
- /* @__PURE__ */ jsx(
12984
- Form$2.Field,
12985
- {
12986
- control: form.control,
12987
- name: "postal_code",
12988
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
- ] })
12993
- }
12994
- ),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "city",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- )
13007
- ] }),
13008
- /* @__PURE__ */ jsx(
13009
- Form$2.Field,
13010
- {
13011
- control: form.control,
13012
- name: "province",
13013
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
- ] })
13018
- }
13019
- ),
13020
- /* @__PURE__ */ jsx(
13021
- Form$2.Field,
13022
- {
13023
- control: form.control,
13024
- name: "phone",
13025
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
- ] })
13030
- }
13031
- )
13032
- ] }) }),
13033
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13036
- ] }) })
13037
- ]
13038
- }
13039
- ) });
13040
- };
13041
- const schema = addressSchema;
13042
- const widgetModule = { widgets: [] };
13043
- const routeModule = {
13044
- routes: [
13045
- {
13046
- Component: List,
13047
- path: "/draft-orders",
13048
- handle: handle$1,
13049
- children: [
13050
- {
13051
- Component: Create,
13052
- path: "/draft-orders/create"
13053
- }
13054
- ]
13055
- },
13056
- {
13057
- Component: ID,
13058
- path: "/draft-orders/:id",
13059
- handle,
13060
- loader,
13057
+ Component: ID,
13058
+ path: "/draft-orders/:id",
13059
+ handle,
13060
+ loader,
13061
13061
  children: [
13062
13062
  {
13063
13063
  Component: CustomItems,
13064
13064
  path: "/draft-orders/:id/custom-items"
13065
13065
  },
13066
+ {
13067
+ Component: BillingAddress,
13068
+ path: "/draft-orders/:id/billing-address"
13069
+ },
13066
13070
  {
13067
13071
  Component: Email,
13068
13072
  path: "/draft-orders/:id/email"
@@ -13079,25 +13083,21 @@ const routeModule = {
13079
13083
  Component: Promotions,
13080
13084
  path: "/draft-orders/:id/promotions"
13081
13085
  },
13082
- {
13083
- Component: Shipping,
13084
- path: "/draft-orders/:id/shipping"
13085
- },
13086
13086
  {
13087
13087
  Component: SalesChannel,
13088
13088
  path: "/draft-orders/:id/sales-channel"
13089
13089
  },
13090
13090
  {
13091
- Component: TransferOwnership,
13092
- path: "/draft-orders/:id/transfer-ownership"
13091
+ Component: Shipping,
13092
+ path: "/draft-orders/:id/shipping"
13093
13093
  },
13094
13094
  {
13095
13095
  Component: ShippingAddress,
13096
13096
  path: "/draft-orders/:id/shipping-address"
13097
13097
  },
13098
13098
  {
13099
- Component: BillingAddress,
13100
- path: "/draft-orders/:id/billing-address"
13099
+ Component: TransferOwnership,
13100
+ path: "/draft-orders/:id/transfer-ownership"
13101
13101
  }
13102
13102
  ]
13103
13103
  }