@medusajs/draft-order 3.0.0-snapshot-20251216135612 → 3.0.0-snapshot-20260102125810

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.
@@ -8,6 +8,7 @@ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, Triangles
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
11
+ import { useTranslation } from "react-i18next";
11
12
  import { zodResolver } from "@hookform/resolvers/zod";
12
13
  import { FormProvider, useFormContext, useFormState, Controller, useForm, useWatch, useFieldArray } from "react-hook-form";
13
14
  import { Slot, Collapsible, Accordion } from "radix-ui";
@@ -937,6 +938,7 @@ const handle$1 = {
937
938
  breadcrumb: () => "Draft Orders"
938
939
  };
939
940
  const List = () => {
941
+ const { t } = useTranslation();
940
942
  const queryParams = useDraftOrderTableQuery({
941
943
  pageSize: PAGE_SIZE
942
944
  });
@@ -966,20 +968,20 @@ const List = () => {
966
968
  isLoading: isPending,
967
969
  pageSize: PAGE_SIZE,
968
970
  rowCount: count,
969
- heading: "Draft Orders",
971
+ heading: t("draftOrders.domain"),
970
972
  action: {
971
- label: "Create",
973
+ label: t("actions.create"),
972
974
  to: "create"
973
975
  },
974
976
  rowHref: (row) => `${row.id}`,
975
977
  emptyState: {
976
978
  empty: {
977
- heading: "No draft orders found",
978
- description: "Create a new draft order to get started."
979
+ heading: t("draftOrders.list.noRecordsMessage"),
980
+ description: t("draftOrders.list.description")
979
981
  },
980
982
  filtered: {
981
- heading: "No results found",
982
- description: "No draft orders match your filter criteria."
983
+ heading: t("draftOrders.list.filtered.heading"),
984
+ description: t("draftOrders.list.filtered.description")
983
985
  }
984
986
  }
985
987
  }
@@ -9565,196 +9567,6 @@ const ID = () => {
9565
9567
  /* @__PURE__ */ jsx(Outlet, {})
9566
9568
  ] });
9567
9569
  };
9568
- const BillingAddress = () => {
9569
- const { id } = useParams();
9570
- const { order, isPending, isError, error } = useOrder(id, {
9571
- fields: "+billing_address"
9572
- });
9573
- if (isError) {
9574
- throw error;
9575
- }
9576
- const isReady = !isPending && !!order;
9577
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9578
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9579
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9580
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9581
- ] }),
9582
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9583
- ] });
9584
- };
9585
- const BillingAddressForm = ({ order }) => {
9586
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9587
- const form = useForm({
9588
- defaultValues: {
9589
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9590
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9591
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9592
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9593
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9594
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9595
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9596
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9597
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9598
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9599
- },
9600
- resolver: zodResolver(schema$5)
9601
- });
9602
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9603
- const { handleSuccess } = useRouteModal();
9604
- const onSubmit = form.handleSubmit(async (data) => {
9605
- await mutateAsync(
9606
- { billing_address: data },
9607
- {
9608
- onSuccess: () => {
9609
- handleSuccess();
9610
- },
9611
- onError: (error) => {
9612
- toast.error(error.message);
9613
- }
9614
- }
9615
- );
9616
- });
9617
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9618
- KeyboundForm,
9619
- {
9620
- className: "flex flex-1 flex-col overflow-hidden",
9621
- onSubmit,
9622
- children: [
9623
- /* @__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: [
9624
- /* @__PURE__ */ jsx(
9625
- Form$2.Field,
9626
- {
9627
- control: form.control,
9628
- name: "country_code",
9629
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9630
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9631
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9632
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9633
- ] })
9634
- }
9635
- ),
9636
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9637
- /* @__PURE__ */ jsx(
9638
- Form$2.Field,
9639
- {
9640
- control: form.control,
9641
- name: "first_name",
9642
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9643
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9644
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9645
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9646
- ] })
9647
- }
9648
- ),
9649
- /* @__PURE__ */ jsx(
9650
- Form$2.Field,
9651
- {
9652
- control: form.control,
9653
- name: "last_name",
9654
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9655
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9656
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9657
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9658
- ] })
9659
- }
9660
- )
9661
- ] }),
9662
- /* @__PURE__ */ jsx(
9663
- Form$2.Field,
9664
- {
9665
- control: form.control,
9666
- name: "company",
9667
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9668
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9669
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9670
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9671
- ] })
9672
- }
9673
- ),
9674
- /* @__PURE__ */ jsx(
9675
- Form$2.Field,
9676
- {
9677
- control: form.control,
9678
- name: "address_1",
9679
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9680
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9681
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9682
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9683
- ] })
9684
- }
9685
- ),
9686
- /* @__PURE__ */ jsx(
9687
- Form$2.Field,
9688
- {
9689
- control: form.control,
9690
- name: "address_2",
9691
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9692
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9693
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9694
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9695
- ] })
9696
- }
9697
- ),
9698
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9699
- /* @__PURE__ */ jsx(
9700
- Form$2.Field,
9701
- {
9702
- control: form.control,
9703
- name: "postal_code",
9704
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9705
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9706
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9707
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9708
- ] })
9709
- }
9710
- ),
9711
- /* @__PURE__ */ jsx(
9712
- Form$2.Field,
9713
- {
9714
- control: form.control,
9715
- name: "city",
9716
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9717
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9718
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9719
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9720
- ] })
9721
- }
9722
- )
9723
- ] }),
9724
- /* @__PURE__ */ jsx(
9725
- Form$2.Field,
9726
- {
9727
- control: form.control,
9728
- name: "province",
9729
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9730
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9731
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9732
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9733
- ] })
9734
- }
9735
- ),
9736
- /* @__PURE__ */ jsx(
9737
- Form$2.Field,
9738
- {
9739
- control: form.control,
9740
- name: "phone",
9741
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9742
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9743
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9744
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9745
- ] })
9746
- }
9747
- )
9748
- ] }) }),
9749
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9750
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9751
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9752
- ] }) })
9753
- ]
9754
- }
9755
- ) });
9756
- };
9757
- const schema$5 = addressSchema;
9758
9570
  const CustomItems = () => {
9759
9571
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9760
9572
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9763,7 +9575,7 @@ const CustomItems = () => {
9763
9575
  };
9764
9576
  const CustomItemsForm = () => {
9765
9577
  const form = useForm({
9766
- resolver: zodResolver(schema$4)
9578
+ resolver: zodResolver(schema$5)
9767
9579
  });
9768
9580
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9769
9581
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9773,75 +9585,7 @@ const CustomItemsForm = () => {
9773
9585
  ] }) })
9774
9586
  ] }) });
9775
9587
  };
9776
- const schema$4 = objectType({
9777
- email: stringType().email()
9778
- });
9779
- const Email = () => {
9780
- const { id } = useParams();
9781
- const { order, isPending, isError, error } = useOrder(id, {
9782
- fields: "+email"
9783
- });
9784
- if (isError) {
9785
- throw error;
9786
- }
9787
- const isReady = !isPending && !!order;
9788
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9789
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9790
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9791
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9792
- ] }),
9793
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9794
- ] });
9795
- };
9796
- const EmailForm = ({ order }) => {
9797
- const form = useForm({
9798
- defaultValues: {
9799
- email: order.email ?? ""
9800
- },
9801
- resolver: zodResolver(schema$3)
9802
- });
9803
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9804
- const { handleSuccess } = useRouteModal();
9805
- const onSubmit = form.handleSubmit(async (data) => {
9806
- await mutateAsync(
9807
- { email: data.email },
9808
- {
9809
- onSuccess: () => {
9810
- handleSuccess();
9811
- },
9812
- onError: (error) => {
9813
- toast.error(error.message);
9814
- }
9815
- }
9816
- );
9817
- });
9818
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9819
- KeyboundForm,
9820
- {
9821
- className: "flex flex-1 flex-col overflow-hidden",
9822
- onSubmit,
9823
- children: [
9824
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9825
- Form$2.Field,
9826
- {
9827
- control: form.control,
9828
- name: "email",
9829
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9830
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9831
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9832
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9833
- ] })
9834
- }
9835
- ) }),
9836
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9837
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9838
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9839
- ] }) })
9840
- ]
9841
- }
9842
- ) });
9843
- };
9844
- const schema$3 = objectType({
9588
+ const schema$5 = objectType({
9845
9589
  email: stringType().email()
9846
9590
  });
9847
9591
  const NumberInput = forwardRef(
@@ -10714,110 +10458,368 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10714
10458
  quantity: 1,
10715
10459
  unit_price: ""
10716
10460
  },
10717
- resolver: zodResolver(customItemSchema)
10461
+ resolver: zodResolver(customItemSchema)
10462
+ });
10463
+ const onSubmit = form.handleSubmit(async (data) => {
10464
+ await addItems(
10465
+ {
10466
+ items: [
10467
+ {
10468
+ title: data.title,
10469
+ quantity: data.quantity,
10470
+ unit_price: convertNumber(data.unit_price)
10471
+ }
10472
+ ]
10473
+ },
10474
+ {
10475
+ onSuccess: () => {
10476
+ setIsOpen(STACKED_MODAL_ID, false);
10477
+ },
10478
+ onError: (e) => {
10479
+ toast.error(e.message);
10480
+ }
10481
+ }
10482
+ );
10483
+ });
10484
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10485
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10486
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10487
+ /* @__PURE__ */ jsxs("div", { children: [
10488
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10489
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10490
+ ] }),
10491
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10492
+ /* @__PURE__ */ jsx(
10493
+ Form$2.Field,
10494
+ {
10495
+ control: form.control,
10496
+ name: "title",
10497
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10498
+ /* @__PURE__ */ jsxs("div", { children: [
10499
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10500
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10501
+ ] }),
10502
+ /* @__PURE__ */ jsxs("div", { children: [
10503
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10504
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10505
+ ] })
10506
+ ] }) })
10507
+ }
10508
+ ),
10509
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10510
+ /* @__PURE__ */ jsx(
10511
+ Form$2.Field,
10512
+ {
10513
+ control: form.control,
10514
+ name: "unit_price",
10515
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10516
+ /* @__PURE__ */ jsxs("div", { children: [
10517
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10518
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10519
+ ] }),
10520
+ /* @__PURE__ */ jsxs("div", { children: [
10521
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10522
+ CurrencyInput,
10523
+ {
10524
+ symbol: getNativeSymbol(currencyCode),
10525
+ code: currencyCode,
10526
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10527
+ ...field
10528
+ }
10529
+ ) }),
10530
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10531
+ ] })
10532
+ ] }) })
10533
+ }
10534
+ ),
10535
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10536
+ /* @__PURE__ */ jsx(
10537
+ Form$2.Field,
10538
+ {
10539
+ control: form.control,
10540
+ name: "quantity",
10541
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10542
+ /* @__PURE__ */ jsxs("div", { children: [
10543
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10544
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10545
+ ] }),
10546
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10547
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10548
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10549
+ ] })
10550
+ ] }) })
10551
+ }
10552
+ )
10553
+ ] }) }) }),
10554
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10555
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10556
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10557
+ ] }) })
10558
+ ] }) }) });
10559
+ };
10560
+ const customItemSchema = objectType({
10561
+ title: stringType().min(1),
10562
+ quantity: numberType(),
10563
+ unit_price: unionType([numberType(), stringType()])
10564
+ });
10565
+ const Email = () => {
10566
+ const { id } = useParams();
10567
+ const { order, isPending, isError, error } = useOrder(id, {
10568
+ fields: "+email"
10569
+ });
10570
+ if (isError) {
10571
+ throw error;
10572
+ }
10573
+ const isReady = !isPending && !!order;
10574
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10575
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10576
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10577
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10578
+ ] }),
10579
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10580
+ ] });
10581
+ };
10582
+ const EmailForm = ({ order }) => {
10583
+ const form = useForm({
10584
+ defaultValues: {
10585
+ email: order.email ?? ""
10586
+ },
10587
+ resolver: zodResolver(schema$4)
10588
+ });
10589
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10590
+ const { handleSuccess } = useRouteModal();
10591
+ const onSubmit = form.handleSubmit(async (data) => {
10592
+ await mutateAsync(
10593
+ { email: data.email },
10594
+ {
10595
+ onSuccess: () => {
10596
+ handleSuccess();
10597
+ },
10598
+ onError: (error) => {
10599
+ toast.error(error.message);
10600
+ }
10601
+ }
10602
+ );
10603
+ });
10604
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10605
+ KeyboundForm,
10606
+ {
10607
+ className: "flex flex-1 flex-col overflow-hidden",
10608
+ onSubmit,
10609
+ children: [
10610
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10611
+ Form$2.Field,
10612
+ {
10613
+ control: form.control,
10614
+ name: "email",
10615
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10616
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10617
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10618
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10619
+ ] })
10620
+ }
10621
+ ) }),
10622
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10623
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10624
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10625
+ ] }) })
10626
+ ]
10627
+ }
10628
+ ) });
10629
+ };
10630
+ const schema$4 = objectType({
10631
+ email: stringType().email()
10632
+ });
10633
+ const BillingAddress = () => {
10634
+ const { id } = useParams();
10635
+ const { order, isPending, isError, error } = useOrder(id, {
10636
+ fields: "+billing_address"
10637
+ });
10638
+ if (isError) {
10639
+ throw error;
10640
+ }
10641
+ const isReady = !isPending && !!order;
10642
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10643
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10644
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
10645
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
10646
+ ] }),
10647
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
10648
+ ] });
10649
+ };
10650
+ const BillingAddressForm = ({ order }) => {
10651
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10652
+ const form = useForm({
10653
+ defaultValues: {
10654
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
10655
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
10656
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
10657
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
10658
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
10659
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
10660
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
10661
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
10662
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
10663
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
10664
+ },
10665
+ resolver: zodResolver(schema$3)
10718
10666
  });
10667
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10668
+ const { handleSuccess } = useRouteModal();
10719
10669
  const onSubmit = form.handleSubmit(async (data) => {
10720
- await addItems(
10721
- {
10722
- items: [
10723
- {
10724
- title: data.title,
10725
- quantity: data.quantity,
10726
- unit_price: convertNumber(data.unit_price)
10727
- }
10728
- ]
10729
- },
10670
+ await mutateAsync(
10671
+ { billing_address: data },
10730
10672
  {
10731
10673
  onSuccess: () => {
10732
- setIsOpen(STACKED_MODAL_ID, false);
10674
+ handleSuccess();
10733
10675
  },
10734
- onError: (e) => {
10735
- toast.error(e.message);
10676
+ onError: (error) => {
10677
+ toast.error(error.message);
10736
10678
  }
10737
10679
  }
10738
10680
  );
10739
10681
  });
10740
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10741
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10742
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10743
- /* @__PURE__ */ jsxs("div", { children: [
10744
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10745
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10746
- ] }),
10747
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10748
- /* @__PURE__ */ jsx(
10749
- Form$2.Field,
10750
- {
10751
- control: form.control,
10752
- name: "title",
10753
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10754
- /* @__PURE__ */ jsxs("div", { children: [
10755
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10756
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10757
- ] }),
10758
- /* @__PURE__ */ jsxs("div", { children: [
10759
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10760
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10761
- ] })
10762
- ] }) })
10763
- }
10764
- ),
10765
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10766
- /* @__PURE__ */ jsx(
10767
- Form$2.Field,
10768
- {
10769
- control: form.control,
10770
- name: "unit_price",
10771
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10772
- /* @__PURE__ */ jsxs("div", { children: [
10773
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10774
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10775
- ] }),
10776
- /* @__PURE__ */ jsxs("div", { children: [
10777
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10778
- CurrencyInput,
10779
- {
10780
- symbol: getNativeSymbol(currencyCode),
10781
- code: currencyCode,
10782
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10783
- ...field
10784
- }
10785
- ) }),
10786
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10787
- ] })
10788
- ] }) })
10789
- }
10790
- ),
10791
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10792
- /* @__PURE__ */ jsx(
10793
- Form$2.Field,
10794
- {
10795
- control: form.control,
10796
- name: "quantity",
10797
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10798
- /* @__PURE__ */ jsxs("div", { children: [
10799
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10800
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10801
- ] }),
10802
- /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10803
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10804
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10805
- ] })
10806
- ] }) })
10807
- }
10808
- )
10809
- ] }) }) }),
10810
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10811
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10812
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10813
- ] }) })
10814
- ] }) }) });
10682
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10683
+ KeyboundForm,
10684
+ {
10685
+ className: "flex flex-1 flex-col overflow-hidden",
10686
+ onSubmit,
10687
+ children: [
10688
+ /* @__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: [
10689
+ /* @__PURE__ */ jsx(
10690
+ Form$2.Field,
10691
+ {
10692
+ control: form.control,
10693
+ name: "country_code",
10694
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10695
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
10696
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
10697
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10698
+ ] })
10699
+ }
10700
+ ),
10701
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10702
+ /* @__PURE__ */ jsx(
10703
+ Form$2.Field,
10704
+ {
10705
+ control: form.control,
10706
+ name: "first_name",
10707
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10708
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
10709
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10710
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10711
+ ] })
10712
+ }
10713
+ ),
10714
+ /* @__PURE__ */ jsx(
10715
+ Form$2.Field,
10716
+ {
10717
+ control: form.control,
10718
+ name: "last_name",
10719
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10720
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
10721
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10722
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10723
+ ] })
10724
+ }
10725
+ )
10726
+ ] }),
10727
+ /* @__PURE__ */ jsx(
10728
+ Form$2.Field,
10729
+ {
10730
+ control: form.control,
10731
+ name: "company",
10732
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10733
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
10734
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10735
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10736
+ ] })
10737
+ }
10738
+ ),
10739
+ /* @__PURE__ */ jsx(
10740
+ Form$2.Field,
10741
+ {
10742
+ control: form.control,
10743
+ name: "address_1",
10744
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10745
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
10746
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10747
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10748
+ ] })
10749
+ }
10750
+ ),
10751
+ /* @__PURE__ */ jsx(
10752
+ Form$2.Field,
10753
+ {
10754
+ control: form.control,
10755
+ name: "address_2",
10756
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10757
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10758
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10759
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10760
+ ] })
10761
+ }
10762
+ ),
10763
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10764
+ /* @__PURE__ */ jsx(
10765
+ Form$2.Field,
10766
+ {
10767
+ control: form.control,
10768
+ name: "postal_code",
10769
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10770
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
10771
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10772
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10773
+ ] })
10774
+ }
10775
+ ),
10776
+ /* @__PURE__ */ jsx(
10777
+ Form$2.Field,
10778
+ {
10779
+ control: form.control,
10780
+ name: "city",
10781
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10782
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
10783
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10784
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10785
+ ] })
10786
+ }
10787
+ )
10788
+ ] }),
10789
+ /* @__PURE__ */ jsx(
10790
+ Form$2.Field,
10791
+ {
10792
+ control: form.control,
10793
+ name: "province",
10794
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10795
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10796
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10797
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10798
+ ] })
10799
+ }
10800
+ ),
10801
+ /* @__PURE__ */ jsx(
10802
+ Form$2.Field,
10803
+ {
10804
+ control: form.control,
10805
+ name: "phone",
10806
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10807
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
10808
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10809
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10810
+ ] })
10811
+ }
10812
+ )
10813
+ ] }) }),
10814
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10815
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10816
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10817
+ ] }) })
10818
+ ]
10819
+ }
10820
+ ) });
10815
10821
  };
10816
- const customItemSchema = objectType({
10817
- title: stringType().min(1),
10818
- quantity: numberType(),
10819
- unit_price: unionType([numberType(), stringType()])
10820
- });
10822
+ const schema$3 = addressSchema;
10821
10823
  const InlineTip = forwardRef(
10822
10824
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
10825
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -13057,21 +13059,21 @@ const routeModule = {
13057
13059
  handle,
13058
13060
  loader,
13059
13061
  children: [
13060
- {
13061
- Component: BillingAddress,
13062
- path: "/draft-orders/:id/billing-address"
13063
- },
13064
13062
  {
13065
13063
  Component: CustomItems,
13066
13064
  path: "/draft-orders/:id/custom-items"
13067
13065
  },
13066
+ {
13067
+ Component: Items,
13068
+ path: "/draft-orders/:id/items"
13069
+ },
13068
13070
  {
13069
13071
  Component: Email,
13070
13072
  path: "/draft-orders/:id/email"
13071
13073
  },
13072
13074
  {
13073
- Component: Items,
13074
- path: "/draft-orders/:id/items"
13075
+ Component: BillingAddress,
13076
+ path: "/draft-orders/:id/billing-address"
13075
13077
  },
13076
13078
  {
13077
13079
  Component: Metadata,