@medusajs/draft-order 2.10.4-preview-20251005060154 → 2.10.4-preview-20251005120155

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.
@@ -9567,196 +9567,27 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const BillingAddress = () => {
9571
- const { id } = useParams();
9572
- const { order, isPending, isError, error } = useOrder(id, {
9573
- fields: "+billing_address"
9574
- });
9575
- if (isError) {
9576
- throw error;
9577
- }
9578
- const isReady = !isPending && !!order;
9570
+ const CustomItems = () => {
9579
9571
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
- ] }),
9584
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9572
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9573
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9585
9574
  ] });
9586
9575
  };
9587
- const BillingAddressForm = ({ order }) => {
9588
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9576
+ const CustomItemsForm = () => {
9589
9577
  const form = useForm({
9590
- defaultValues: {
9591
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
- },
9602
9578
  resolver: zodResolver(schema$5)
9603
9579
  });
9604
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
- const { handleSuccess } = useRouteModal();
9606
- const onSubmit = form.handleSubmit(async (data) => {
9607
- await mutateAsync(
9608
- { billing_address: data },
9609
- {
9610
- onSuccess: () => {
9611
- handleSuccess();
9612
- },
9613
- onError: (error) => {
9614
- toast.error(error.message);
9615
- }
9616
- }
9617
- );
9618
- });
9619
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
- KeyboundForm,
9621
- {
9622
- className: "flex flex-1 flex-col overflow-hidden",
9623
- onSubmit,
9624
- children: [
9625
- /* @__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: [
9626
- /* @__PURE__ */ jsx(
9627
- Form$2.Field,
9628
- {
9629
- control: form.control,
9630
- name: "country_code",
9631
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
- ] })
9636
- }
9637
- ),
9638
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
- /* @__PURE__ */ jsx(
9640
- Form$2.Field,
9641
- {
9642
- control: form.control,
9643
- name: "first_name",
9644
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
- ] })
9649
- }
9650
- ),
9651
- /* @__PURE__ */ jsx(
9652
- Form$2.Field,
9653
- {
9654
- control: form.control,
9655
- name: "last_name",
9656
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
- ] })
9661
- }
9662
- )
9663
- ] }),
9664
- /* @__PURE__ */ jsx(
9665
- Form$2.Field,
9666
- {
9667
- control: form.control,
9668
- name: "company",
9669
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
- ] })
9674
- }
9675
- ),
9676
- /* @__PURE__ */ jsx(
9677
- Form$2.Field,
9678
- {
9679
- control: form.control,
9680
- name: "address_1",
9681
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
- ] })
9686
- }
9687
- ),
9688
- /* @__PURE__ */ jsx(
9689
- Form$2.Field,
9690
- {
9691
- control: form.control,
9692
- name: "address_2",
9693
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
- ] })
9698
- }
9699
- ),
9700
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
- /* @__PURE__ */ jsx(
9702
- Form$2.Field,
9703
- {
9704
- control: form.control,
9705
- name: "postal_code",
9706
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
- ] })
9711
- }
9712
- ),
9713
- /* @__PURE__ */ jsx(
9714
- Form$2.Field,
9715
- {
9716
- control: form.control,
9717
- name: "city",
9718
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
- ] })
9723
- }
9724
- )
9725
- ] }),
9726
- /* @__PURE__ */ jsx(
9727
- Form$2.Field,
9728
- {
9729
- control: form.control,
9730
- name: "province",
9731
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
- ] })
9736
- }
9737
- ),
9738
- /* @__PURE__ */ jsx(
9739
- Form$2.Field,
9740
- {
9741
- control: form.control,
9742
- name: "phone",
9743
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
- ] })
9748
- }
9749
- )
9750
- ] }) }),
9751
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
- ] }) })
9755
- ]
9756
- }
9757
- ) });
9580
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9583
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9584
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9585
+ ] }) })
9586
+ ] }) });
9758
9587
  };
9759
- const schema$5 = addressSchema;
9588
+ const schema$5 = objectType({
9589
+ email: stringType().email()
9590
+ });
9760
9591
  const Email = () => {
9761
9592
  const { id } = useParams();
9762
9593
  const { order, isPending, isError, error } = useOrder(id, {
@@ -11426,160 +11257,54 @@ function getPromotionIds(items, shippingMethods) {
11426
11257
  }
11427
11258
  return Array.from(promotionIds);
11428
11259
  }
11429
- const SalesChannel = () => {
11260
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11261
+ const Shipping = () => {
11262
+ var _a;
11430
11263
  const { id } = useParams();
11431
- const { draft_order, isPending, isError, error } = useDraftOrder(
11432
- id,
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(
11433
11302
  {
11434
- fields: "+sales_channel_id"
11303
+ id: appliedShippingOptionIds,
11304
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11435
11305
  },
11436
11306
  {
11437
- enabled: !!id
11438
- }
11439
- );
11440
- if (isError) {
11441
- throw error;
11442
- }
11443
- const ISrEADY = !!draft_order && !isPending;
11444
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11445
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11446
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11447
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11448
- ] }),
11449
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11450
- ] });
11451
- };
11452
- const SalesChannelForm = ({ order }) => {
11453
- const form = useForm({
11454
- defaultValues: {
11455
- sales_channel_id: order.sales_channel_id || ""
11456
- },
11457
- resolver: zodResolver(schema$3)
11458
- });
11459
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11460
- const { handleSuccess } = useRouteModal();
11461
- const onSubmit = form.handleSubmit(async (data) => {
11462
- await mutateAsync(
11463
- {
11464
- sales_channel_id: data.sales_channel_id
11465
- },
11466
- {
11467
- onSuccess: () => {
11468
- toast.success("Sales channel updated");
11469
- handleSuccess();
11470
- },
11471
- onError: (error) => {
11472
- toast.error(error.message);
11473
- }
11474
- }
11475
- );
11476
- });
11477
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11478
- KeyboundForm,
11479
- {
11480
- className: "flex flex-1 flex-col overflow-hidden",
11481
- onSubmit,
11482
- children: [
11483
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11484
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11485
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11486
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11487
- ] }) })
11488
- ]
11489
- }
11490
- ) });
11491
- };
11492
- const SalesChannelField = ({ control, order }) => {
11493
- const salesChannels = useComboboxData({
11494
- queryFn: async (params) => {
11495
- return await sdk.admin.salesChannel.list(params);
11496
- },
11497
- queryKey: ["sales-channels"],
11498
- getOptions: (data) => {
11499
- return data.sales_channels.map((salesChannel) => ({
11500
- label: salesChannel.name,
11501
- value: salesChannel.id
11502
- }));
11503
- },
11504
- defaultValue: order.sales_channel_id || void 0
11505
- });
11506
- return /* @__PURE__ */ jsx(
11507
- Form$2.Field,
11508
- {
11509
- control,
11510
- name: "sales_channel_id",
11511
- render: ({ field }) => {
11512
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11513
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11514
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11515
- Combobox,
11516
- {
11517
- options: salesChannels.options,
11518
- fetchNextPage: salesChannels.fetchNextPage,
11519
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11520
- searchValue: salesChannels.searchValue,
11521
- onSearchValueChange: salesChannels.onSearchValueChange,
11522
- placeholder: "Select sales channel",
11523
- ...field
11524
- }
11525
- ) }),
11526
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11527
- ] });
11528
- }
11529
- }
11530
- );
11531
- };
11532
- const schema$3 = objectType({
11533
- sales_channel_id: stringType().min(1)
11534
- });
11535
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11536
- const Shipping = () => {
11537
- var _a;
11538
- const { id } = useParams();
11539
- const { order, isPending, isError, error } = useOrder(id, {
11540
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11541
- });
11542
- const {
11543
- order: preview,
11544
- isPending: isPreviewPending,
11545
- isError: isPreviewError,
11546
- error: previewError
11547
- } = useOrderPreview(id);
11548
- useInitiateOrderEdit({ preview });
11549
- const { onCancel } = useCancelOrderEdit({ preview });
11550
- if (isError) {
11551
- throw error;
11552
- }
11553
- if (isPreviewError) {
11554
- throw previewError;
11555
- }
11556
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11557
- const isReady = preview && !isPreviewPending && order && !isPending;
11558
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11559
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11560
- /* @__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: [
11561
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11562
- /* @__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." }) })
11563
- ] }) }) }),
11564
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11565
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11566
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11567
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11568
- ] }) });
11569
- };
11570
- const ShippingForm = ({ preview, order }) => {
11571
- var _a;
11572
- const { setIsOpen } = useStackedModal();
11573
- const [isSubmitting, setIsSubmitting] = useState(false);
11574
- const [data, setData] = useState(null);
11575
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11576
- const { shipping_options } = useShippingOptions(
11577
- {
11578
- id: appliedShippingOptionIds,
11579
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11580
- },
11581
- {
11582
- enabled: appliedShippingOptionIds.length > 0
11307
+ enabled: appliedShippingOptionIds.length > 0
11583
11308
  }
11584
11309
  );
11585
11310
  const uniqueShippingProfiles = useMemo(() => {
@@ -12371,7 +12096,7 @@ const ShippingAddressForm = ({ order }) => {
12371
12096
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12372
12097
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12373
12098
  },
12374
- resolver: zodResolver(schema$2)
12099
+ resolver: zodResolver(schema$3)
12375
12100
  });
12376
12101
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12377
12102
  const { handleSuccess } = useRouteModal();
@@ -12541,7 +12266,7 @@ const ShippingAddressForm = ({ order }) => {
12541
12266
  }
12542
12267
  ) });
12543
12268
  };
12544
- const schema$2 = addressSchema;
12269
+ const schema$3 = addressSchema;
12545
12270
  const TransferOwnership = () => {
12546
12271
  const { id } = useParams();
12547
12272
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12565,7 +12290,7 @@ const TransferOwnershipForm = ({ order }) => {
12565
12290
  defaultValues: {
12566
12291
  customer_id: order.customer_id || ""
12567
12292
  },
12568
- resolver: zodResolver(schema$1)
12293
+ resolver: zodResolver(schema$2)
12569
12294
  });
12570
12295
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12571
12296
  const { handleSuccess } = useRouteModal();
@@ -13015,29 +12740,304 @@ const Illustration = () => {
13015
12740
  }
13016
12741
  );
13017
12742
  };
13018
- const schema$1 = objectType({
12743
+ const schema$2 = objectType({
13019
12744
  customer_id: stringType().min(1)
13020
12745
  });
13021
- const CustomItems = () => {
12746
+ const BillingAddress = () => {
12747
+ const { id } = useParams();
12748
+ const { order, isPending, isError, error } = useOrder(id, {
12749
+ fields: "+billing_address"
12750
+ });
12751
+ if (isError) {
12752
+ throw error;
12753
+ }
12754
+ const isReady = !isPending && !!order;
13022
12755
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
13023
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
13024
- /* @__PURE__ */ jsx(CustomItemsForm, {})
12756
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12757
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12758
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12759
+ ] }),
12760
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
13025
12761
  ] });
13026
12762
  };
13027
- const CustomItemsForm = () => {
12763
+ const BillingAddressForm = ({ order }) => {
12764
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12765
+ const form = useForm({
12766
+ defaultValues: {
12767
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12768
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12769
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12770
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12771
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12772
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12773
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12774
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12775
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12776
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12777
+ },
12778
+ resolver: zodResolver(schema$1)
12779
+ });
12780
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12781
+ const { handleSuccess } = useRouteModal();
12782
+ const onSubmit = form.handleSubmit(async (data) => {
12783
+ await mutateAsync(
12784
+ { billing_address: data },
12785
+ {
12786
+ onSuccess: () => {
12787
+ handleSuccess();
12788
+ },
12789
+ onError: (error) => {
12790
+ toast.error(error.message);
12791
+ }
12792
+ }
12793
+ );
12794
+ });
12795
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12796
+ KeyboundForm,
12797
+ {
12798
+ className: "flex flex-1 flex-col overflow-hidden",
12799
+ onSubmit,
12800
+ children: [
12801
+ /* @__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: [
12802
+ /* @__PURE__ */ jsx(
12803
+ Form$2.Field,
12804
+ {
12805
+ control: form.control,
12806
+ name: "country_code",
12807
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12808
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12809
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12810
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12811
+ ] })
12812
+ }
12813
+ ),
12814
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12815
+ /* @__PURE__ */ jsx(
12816
+ Form$2.Field,
12817
+ {
12818
+ control: form.control,
12819
+ name: "first_name",
12820
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12821
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12822
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12823
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12824
+ ] })
12825
+ }
12826
+ ),
12827
+ /* @__PURE__ */ jsx(
12828
+ Form$2.Field,
12829
+ {
12830
+ control: form.control,
12831
+ name: "last_name",
12832
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12833
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12834
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12835
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12836
+ ] })
12837
+ }
12838
+ )
12839
+ ] }),
12840
+ /* @__PURE__ */ jsx(
12841
+ Form$2.Field,
12842
+ {
12843
+ control: form.control,
12844
+ name: "company",
12845
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12846
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12847
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12848
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12849
+ ] })
12850
+ }
12851
+ ),
12852
+ /* @__PURE__ */ jsx(
12853
+ Form$2.Field,
12854
+ {
12855
+ control: form.control,
12856
+ name: "address_1",
12857
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12858
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12859
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12860
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12861
+ ] })
12862
+ }
12863
+ ),
12864
+ /* @__PURE__ */ jsx(
12865
+ Form$2.Field,
12866
+ {
12867
+ control: form.control,
12868
+ name: "address_2",
12869
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12870
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12871
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12872
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12873
+ ] })
12874
+ }
12875
+ ),
12876
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12877
+ /* @__PURE__ */ jsx(
12878
+ Form$2.Field,
12879
+ {
12880
+ control: form.control,
12881
+ name: "postal_code",
12882
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12883
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12884
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12885
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12886
+ ] })
12887
+ }
12888
+ ),
12889
+ /* @__PURE__ */ jsx(
12890
+ Form$2.Field,
12891
+ {
12892
+ control: form.control,
12893
+ name: "city",
12894
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12895
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12896
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12897
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12898
+ ] })
12899
+ }
12900
+ )
12901
+ ] }),
12902
+ /* @__PURE__ */ jsx(
12903
+ Form$2.Field,
12904
+ {
12905
+ control: form.control,
12906
+ name: "province",
12907
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12908
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12909
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12910
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12911
+ ] })
12912
+ }
12913
+ ),
12914
+ /* @__PURE__ */ jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "phone",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12921
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12922
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ )
12926
+ ] }) }),
12927
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12928
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12929
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12930
+ ] }) })
12931
+ ]
12932
+ }
12933
+ ) });
12934
+ };
12935
+ const schema$1 = addressSchema;
12936
+ const SalesChannel = () => {
12937
+ const { id } = useParams();
12938
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12939
+ id,
12940
+ {
12941
+ fields: "+sales_channel_id"
12942
+ },
12943
+ {
12944
+ enabled: !!id
12945
+ }
12946
+ );
12947
+ if (isError) {
12948
+ throw error;
12949
+ }
12950
+ const ISrEADY = !!draft_order && !isPending;
12951
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12952
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12953
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12954
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12955
+ ] }),
12956
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12957
+ ] });
12958
+ };
12959
+ const SalesChannelForm = ({ order }) => {
13028
12960
  const form = useForm({
12961
+ defaultValues: {
12962
+ sales_channel_id: order.sales_channel_id || ""
12963
+ },
13029
12964
  resolver: zodResolver(schema)
13030
12965
  });
13031
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13032
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
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", children: "Save" })
13036
- ] }) })
13037
- ] }) });
12966
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12967
+ const { handleSuccess } = useRouteModal();
12968
+ const onSubmit = form.handleSubmit(async (data) => {
12969
+ await mutateAsync(
12970
+ {
12971
+ sales_channel_id: data.sales_channel_id
12972
+ },
12973
+ {
12974
+ onSuccess: () => {
12975
+ toast.success("Sales channel updated");
12976
+ handleSuccess();
12977
+ },
12978
+ onError: (error) => {
12979
+ toast.error(error.message);
12980
+ }
12981
+ }
12982
+ );
12983
+ });
12984
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12985
+ KeyboundForm,
12986
+ {
12987
+ className: "flex flex-1 flex-col overflow-hidden",
12988
+ onSubmit,
12989
+ children: [
12990
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12991
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12992
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12993
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12994
+ ] }) })
12995
+ ]
12996
+ }
12997
+ ) });
12998
+ };
12999
+ const SalesChannelField = ({ control, order }) => {
13000
+ const salesChannels = useComboboxData({
13001
+ queryFn: async (params) => {
13002
+ return await sdk.admin.salesChannel.list(params);
13003
+ },
13004
+ queryKey: ["sales-channels"],
13005
+ getOptions: (data) => {
13006
+ return data.sales_channels.map((salesChannel) => ({
13007
+ label: salesChannel.name,
13008
+ value: salesChannel.id
13009
+ }));
13010
+ },
13011
+ defaultValue: order.sales_channel_id || void 0
13012
+ });
13013
+ return /* @__PURE__ */ jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control,
13017
+ name: "sales_channel_id",
13018
+ render: ({ field }) => {
13019
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13021
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13022
+ Combobox,
13023
+ {
13024
+ options: salesChannels.options,
13025
+ fetchNextPage: salesChannels.fetchNextPage,
13026
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13027
+ searchValue: salesChannels.searchValue,
13028
+ onSearchValueChange: salesChannels.onSearchValueChange,
13029
+ placeholder: "Select sales channel",
13030
+ ...field
13031
+ }
13032
+ ) }),
13033
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13034
+ ] });
13035
+ }
13036
+ }
13037
+ );
13038
13038
  };
13039
13039
  const schema = objectType({
13040
- email: stringType().email()
13040
+ sales_channel_id: stringType().min(1)
13041
13041
  });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
@@ -13060,8 +13060,8 @@ const routeModule = {
13060
13060
  loader,
13061
13061
  children: [
13062
13062
  {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13063
+ Component: CustomItems,
13064
+ path: "/draft-orders/:id/custom-items"
13065
13065
  },
13066
13066
  {
13067
13067
  Component: Email,
@@ -13079,10 +13079,6 @@ const routeModule = {
13079
13079
  Component: Promotions,
13080
13080
  path: "/draft-orders/:id/promotions"
13081
13081
  },
13082
- {
13083
- Component: SalesChannel,
13084
- path: "/draft-orders/:id/sales-channel"
13085
- },
13086
13082
  {
13087
13083
  Component: Shipping,
13088
13084
  path: "/draft-orders/:id/shipping"
@@ -13096,8 +13092,12 @@ const routeModule = {
13096
13092
  path: "/draft-orders/:id/transfer-ownership"
13097
13093
  },
13098
13094
  {
13099
- Component: CustomItems,
13100
- path: "/draft-orders/:id/custom-items"
13095
+ Component: BillingAddress,
13096
+ path: "/draft-orders/:id/billing-address"
13097
+ },
13098
+ {
13099
+ Component: SalesChannel,
13100
+ path: "/draft-orders/:id/sales-channel"
13101
13101
  }
13102
13102
  ]
13103
13103
  }