@medusajs/draft-order 2.11.2-preview-20251027180157 → 2.11.2-preview-20251028000318

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.
@@ -9571,196 +9571,6 @@ const ID = () => {
9571
9571
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9572
9572
  ] });
9573
9573
  };
9574
- const BillingAddress = () => {
9575
- const { id } = reactRouterDom.useParams();
9576
- const { order, isPending, isError, error } = useOrder(id, {
9577
- fields: "+billing_address"
9578
- });
9579
- if (isError) {
9580
- throw error;
9581
- }
9582
- const isReady = !isPending && !!order;
9583
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9584
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9585
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9587
- ] }),
9588
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9589
- ] });
9590
- };
9591
- const BillingAddressForm = ({ order }) => {
9592
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9593
- const form = reactHookForm.useForm({
9594
- defaultValues: {
9595
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9596
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9597
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9598
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9599
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9600
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9601
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9602
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9603
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9604
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9605
- },
9606
- resolver: zod.zodResolver(schema$5)
9607
- });
9608
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9609
- const { handleSuccess } = useRouteModal();
9610
- const onSubmit = form.handleSubmit(async (data) => {
9611
- await mutateAsync(
9612
- { billing_address: data },
9613
- {
9614
- onSuccess: () => {
9615
- handleSuccess();
9616
- },
9617
- onError: (error) => {
9618
- ui.toast.error(error.message);
9619
- }
9620
- }
9621
- );
9622
- });
9623
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9624
- KeyboundForm,
9625
- {
9626
- className: "flex flex-1 flex-col overflow-hidden",
9627
- onSubmit,
9628
- children: [
9629
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9630
- /* @__PURE__ */ jsxRuntime.jsx(
9631
- Form$2.Field,
9632
- {
9633
- control: form.control,
9634
- name: "country_code",
9635
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9636
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9639
- ] })
9640
- }
9641
- ),
9642
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9643
- /* @__PURE__ */ jsxRuntime.jsx(
9644
- Form$2.Field,
9645
- {
9646
- control: form.control,
9647
- name: "first_name",
9648
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9649
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9652
- ] })
9653
- }
9654
- ),
9655
- /* @__PURE__ */ jsxRuntime.jsx(
9656
- Form$2.Field,
9657
- {
9658
- control: form.control,
9659
- name: "last_name",
9660
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9661
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9664
- ] })
9665
- }
9666
- )
9667
- ] }),
9668
- /* @__PURE__ */ jsxRuntime.jsx(
9669
- Form$2.Field,
9670
- {
9671
- control: form.control,
9672
- name: "company",
9673
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9674
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9677
- ] })
9678
- }
9679
- ),
9680
- /* @__PURE__ */ jsxRuntime.jsx(
9681
- Form$2.Field,
9682
- {
9683
- control: form.control,
9684
- name: "address_1",
9685
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9686
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9689
- ] })
9690
- }
9691
- ),
9692
- /* @__PURE__ */ jsxRuntime.jsx(
9693
- Form$2.Field,
9694
- {
9695
- control: form.control,
9696
- name: "address_2",
9697
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9698
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9701
- ] })
9702
- }
9703
- ),
9704
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9705
- /* @__PURE__ */ jsxRuntime.jsx(
9706
- Form$2.Field,
9707
- {
9708
- control: form.control,
9709
- name: "postal_code",
9710
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9711
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9714
- ] })
9715
- }
9716
- ),
9717
- /* @__PURE__ */ jsxRuntime.jsx(
9718
- Form$2.Field,
9719
- {
9720
- control: form.control,
9721
- name: "city",
9722
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9723
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9726
- ] })
9727
- }
9728
- )
9729
- ] }),
9730
- /* @__PURE__ */ jsxRuntime.jsx(
9731
- Form$2.Field,
9732
- {
9733
- control: form.control,
9734
- name: "province",
9735
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9736
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9739
- ] })
9740
- }
9741
- ),
9742
- /* @__PURE__ */ jsxRuntime.jsx(
9743
- Form$2.Field,
9744
- {
9745
- control: form.control,
9746
- name: "phone",
9747
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9748
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9751
- ] })
9752
- }
9753
- )
9754
- ] }) }),
9755
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9758
- ] }) })
9759
- ]
9760
- }
9761
- ) });
9762
- };
9763
- const schema$5 = addressSchema;
9764
9574
  const CustomItems = () => {
9765
9575
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9766
9576
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9769,7 +9579,7 @@ const CustomItems = () => {
9769
9579
  };
9770
9580
  const CustomItemsForm = () => {
9771
9581
  const form = reactHookForm.useForm({
9772
- resolver: zod.zodResolver(schema$4)
9582
+ resolver: zod.zodResolver(schema$5)
9773
9583
  });
9774
9584
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9775
9585
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9779,93 +9589,25 @@ const CustomItemsForm = () => {
9779
9589
  ] }) })
9780
9590
  ] }) });
9781
9591
  };
9782
- const schema$4 = objectType({
9592
+ const schema$5 = objectType({
9783
9593
  email: stringType().email()
9784
9594
  });
9785
- const Email = () => {
9786
- const { id } = reactRouterDom.useParams();
9787
- const { order, isPending, isError, error } = useOrder(id, {
9788
- fields: "+email"
9789
- });
9790
- if (isError) {
9791
- throw error;
9792
- }
9793
- const isReady = !isPending && !!order;
9794
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9795
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9796
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9797
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9798
- ] }),
9799
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9800
- ] });
9801
- };
9802
- const EmailForm = ({ order }) => {
9803
- const form = reactHookForm.useForm({
9804
- defaultValues: {
9805
- email: order.email ?? ""
9806
- },
9807
- resolver: zod.zodResolver(schema$3)
9808
- });
9809
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9810
- const { handleSuccess } = useRouteModal();
9811
- const onSubmit = form.handleSubmit(async (data) => {
9812
- await mutateAsync(
9813
- { email: data.email },
9814
- {
9815
- onSuccess: () => {
9816
- handleSuccess();
9817
- },
9818
- onError: (error) => {
9819
- ui.toast.error(error.message);
9820
- }
9821
- }
9822
- );
9823
- });
9824
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9825
- KeyboundForm,
9826
- {
9827
- className: "flex flex-1 flex-col overflow-hidden",
9828
- onSubmit,
9829
- children: [
9830
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9831
- Form$2.Field,
9832
- {
9833
- control: form.control,
9834
- name: "email",
9835
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9836
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9837
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9839
- ] })
9840
- }
9841
- ) }),
9842
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9843
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9845
- ] }) })
9846
- ]
9847
- }
9848
- ) });
9849
- };
9850
- const schema$3 = objectType({
9851
- email: stringType().email()
9852
- });
9853
- const NumberInput = React.forwardRef(
9854
- ({
9855
- value,
9856
- onChange,
9857
- size = "base",
9858
- min = 0,
9859
- max = 100,
9860
- step = 1,
9861
- className,
9862
- disabled,
9863
- ...props
9864
- }, ref) => {
9865
- const handleChange = (event) => {
9866
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9867
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9868
- onChange(newValue);
9595
+ const NumberInput = React.forwardRef(
9596
+ ({
9597
+ value,
9598
+ onChange,
9599
+ size = "base",
9600
+ min = 0,
9601
+ max = 100,
9602
+ step = 1,
9603
+ className,
9604
+ disabled,
9605
+ ...props
9606
+ }, ref) => {
9607
+ const handleChange = (event) => {
9608
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9609
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9610
+ onChange(newValue);
9869
9611
  }
9870
9612
  };
9871
9613
  const handleIncrement = () => {
@@ -10824,6 +10566,74 @@ const customItemSchema = objectType({
10824
10566
  quantity: numberType(),
10825
10567
  unit_price: unionType([numberType(), stringType()])
10826
10568
  });
10569
+ const Email = () => {
10570
+ const { id } = reactRouterDom.useParams();
10571
+ const { order, isPending, isError, error } = useOrder(id, {
10572
+ fields: "+email"
10573
+ });
10574
+ if (isError) {
10575
+ throw error;
10576
+ }
10577
+ const isReady = !isPending && !!order;
10578
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10579
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10580
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10581
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10582
+ ] }),
10583
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10584
+ ] });
10585
+ };
10586
+ const EmailForm = ({ order }) => {
10587
+ const form = reactHookForm.useForm({
10588
+ defaultValues: {
10589
+ email: order.email ?? ""
10590
+ },
10591
+ resolver: zod.zodResolver(schema$4)
10592
+ });
10593
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10594
+ const { handleSuccess } = useRouteModal();
10595
+ const onSubmit = form.handleSubmit(async (data) => {
10596
+ await mutateAsync(
10597
+ { email: data.email },
10598
+ {
10599
+ onSuccess: () => {
10600
+ handleSuccess();
10601
+ },
10602
+ onError: (error) => {
10603
+ ui.toast.error(error.message);
10604
+ }
10605
+ }
10606
+ );
10607
+ });
10608
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10609
+ KeyboundForm,
10610
+ {
10611
+ className: "flex flex-1 flex-col overflow-hidden",
10612
+ onSubmit,
10613
+ children: [
10614
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10615
+ Form$2.Field,
10616
+ {
10617
+ control: form.control,
10618
+ name: "email",
10619
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10620
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10621
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10622
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10623
+ ] })
10624
+ }
10625
+ ) }),
10626
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10627
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10628
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10629
+ ] }) })
10630
+ ]
10631
+ }
10632
+ ) });
10633
+ };
10634
+ const schema$4 = objectType({
10635
+ email: stringType().email()
10636
+ });
10827
10637
  const InlineTip = React.forwardRef(
10828
10638
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10829
10639
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11163,16 +10973,483 @@ function parseValues(values) {
11163
10973
  update[key] = value;
11164
10974
  }
11165
10975
  }
11166
- });
11167
- return update;
11168
- }
11169
- function getHasUneditableRows(metadata) {
11170
- if (!metadata) {
11171
- return false;
10976
+ });
10977
+ return update;
10978
+ }
10979
+ function getHasUneditableRows(metadata) {
10980
+ if (!metadata) {
10981
+ return false;
10982
+ }
10983
+ return Object.values(metadata).some(
10984
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10985
+ );
10986
+ }
10987
+ const BillingAddress = () => {
10988
+ const { id } = reactRouterDom.useParams();
10989
+ const { order, isPending, isError, error } = useOrder(id, {
10990
+ fields: "+billing_address"
10991
+ });
10992
+ if (isError) {
10993
+ throw error;
10994
+ }
10995
+ const isReady = !isPending && !!order;
10996
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10997
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10998
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
10999
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
11000
+ ] }),
11001
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
11002
+ ] });
11003
+ };
11004
+ const BillingAddressForm = ({ order }) => {
11005
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11006
+ const form = reactHookForm.useForm({
11007
+ defaultValues: {
11008
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
11009
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
11010
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
11011
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
11012
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
11013
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
11014
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
11015
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
11016
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11017
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11018
+ },
11019
+ resolver: zod.zodResolver(schema$3)
11020
+ });
11021
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11022
+ const { handleSuccess } = useRouteModal();
11023
+ const onSubmit = form.handleSubmit(async (data) => {
11024
+ await mutateAsync(
11025
+ { billing_address: data },
11026
+ {
11027
+ onSuccess: () => {
11028
+ handleSuccess();
11029
+ },
11030
+ onError: (error) => {
11031
+ ui.toast.error(error.message);
11032
+ }
11033
+ }
11034
+ );
11035
+ });
11036
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11037
+ KeyboundForm,
11038
+ {
11039
+ className: "flex flex-1 flex-col overflow-hidden",
11040
+ onSubmit,
11041
+ children: [
11042
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11043
+ /* @__PURE__ */ jsxRuntime.jsx(
11044
+ Form$2.Field,
11045
+ {
11046
+ control: form.control,
11047
+ name: "country_code",
11048
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11049
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11050
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11051
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11052
+ ] })
11053
+ }
11054
+ ),
11055
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11056
+ /* @__PURE__ */ jsxRuntime.jsx(
11057
+ Form$2.Field,
11058
+ {
11059
+ control: form.control,
11060
+ name: "first_name",
11061
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11062
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11063
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11064
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11065
+ ] })
11066
+ }
11067
+ ),
11068
+ /* @__PURE__ */ jsxRuntime.jsx(
11069
+ Form$2.Field,
11070
+ {
11071
+ control: form.control,
11072
+ name: "last_name",
11073
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11074
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11075
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11076
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11077
+ ] })
11078
+ }
11079
+ )
11080
+ ] }),
11081
+ /* @__PURE__ */ jsxRuntime.jsx(
11082
+ Form$2.Field,
11083
+ {
11084
+ control: form.control,
11085
+ name: "company",
11086
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11087
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11088
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11089
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11090
+ ] })
11091
+ }
11092
+ ),
11093
+ /* @__PURE__ */ jsxRuntime.jsx(
11094
+ Form$2.Field,
11095
+ {
11096
+ control: form.control,
11097
+ name: "address_1",
11098
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11099
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11100
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11101
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11102
+ ] })
11103
+ }
11104
+ ),
11105
+ /* @__PURE__ */ jsxRuntime.jsx(
11106
+ Form$2.Field,
11107
+ {
11108
+ control: form.control,
11109
+ name: "address_2",
11110
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11111
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11112
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11113
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11114
+ ] })
11115
+ }
11116
+ ),
11117
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11118
+ /* @__PURE__ */ jsxRuntime.jsx(
11119
+ Form$2.Field,
11120
+ {
11121
+ control: form.control,
11122
+ name: "postal_code",
11123
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11124
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11125
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11126
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11127
+ ] })
11128
+ }
11129
+ ),
11130
+ /* @__PURE__ */ jsxRuntime.jsx(
11131
+ Form$2.Field,
11132
+ {
11133
+ control: form.control,
11134
+ name: "city",
11135
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11136
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11137
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11138
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11139
+ ] })
11140
+ }
11141
+ )
11142
+ ] }),
11143
+ /* @__PURE__ */ jsxRuntime.jsx(
11144
+ Form$2.Field,
11145
+ {
11146
+ control: form.control,
11147
+ name: "province",
11148
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11149
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11150
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11151
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11152
+ ] })
11153
+ }
11154
+ ),
11155
+ /* @__PURE__ */ jsxRuntime.jsx(
11156
+ Form$2.Field,
11157
+ {
11158
+ control: form.control,
11159
+ name: "phone",
11160
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11161
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11162
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11163
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11164
+ ] })
11165
+ }
11166
+ )
11167
+ ] }) }),
11168
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11169
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11170
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11171
+ ] }) })
11172
+ ]
11173
+ }
11174
+ ) });
11175
+ };
11176
+ const schema$3 = addressSchema;
11177
+ const PROMOTION_QUERY_KEY = "promotions";
11178
+ const promotionsQueryKeys = {
11179
+ list: (query2) => [
11180
+ PROMOTION_QUERY_KEY,
11181
+ query2 ? query2 : void 0
11182
+ ],
11183
+ detail: (id, query2) => [
11184
+ PROMOTION_QUERY_KEY,
11185
+ id,
11186
+ query2 ? query2 : void 0
11187
+ ]
11188
+ };
11189
+ const usePromotions = (query2, options) => {
11190
+ const { data, ...rest } = reactQuery.useQuery({
11191
+ queryKey: promotionsQueryKeys.list(query2),
11192
+ queryFn: async () => sdk.admin.promotion.list(query2),
11193
+ ...options
11194
+ });
11195
+ return { ...data, ...rest };
11196
+ };
11197
+ const Promotions = () => {
11198
+ const { id } = reactRouterDom.useParams();
11199
+ const {
11200
+ order: preview,
11201
+ isError: isPreviewError,
11202
+ error: previewError
11203
+ } = useOrderPreview(id, void 0);
11204
+ useInitiateOrderEdit({ preview });
11205
+ const { onCancel } = useCancelOrderEdit({ preview });
11206
+ if (isPreviewError) {
11207
+ throw previewError;
11208
+ }
11209
+ const isReady = !!preview;
11210
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11211
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11212
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11213
+ ] });
11214
+ };
11215
+ const PromotionForm = ({ preview }) => {
11216
+ const { items, shipping_methods } = preview;
11217
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11218
+ const [comboboxValue, setComboboxValue] = React.useState("");
11219
+ const { handleSuccess } = useRouteModal();
11220
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11221
+ const promoIds = getPromotionIds(items, shipping_methods);
11222
+ const { promotions, isPending, isError, error } = usePromotions(
11223
+ {
11224
+ id: promoIds
11225
+ },
11226
+ {
11227
+ enabled: !!promoIds.length
11228
+ }
11229
+ );
11230
+ const comboboxData = useComboboxData({
11231
+ queryKey: ["promotions", "combobox", promoIds],
11232
+ queryFn: async (params) => {
11233
+ return await sdk.admin.promotion.list({
11234
+ ...params,
11235
+ id: {
11236
+ $nin: promoIds
11237
+ }
11238
+ });
11239
+ },
11240
+ getOptions: (data) => {
11241
+ return data.promotions.map((promotion) => ({
11242
+ label: promotion.code,
11243
+ value: promotion.code
11244
+ }));
11245
+ }
11246
+ });
11247
+ const add = async (value) => {
11248
+ if (!value) {
11249
+ return;
11250
+ }
11251
+ addPromotions(
11252
+ {
11253
+ promo_codes: [value]
11254
+ },
11255
+ {
11256
+ onError: (e) => {
11257
+ ui.toast.error(e.message);
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
11260
+ },
11261
+ onSuccess: () => {
11262
+ comboboxData.onSearchValueChange("");
11263
+ setComboboxValue("");
11264
+ }
11265
+ }
11266
+ );
11267
+ };
11268
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11269
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11270
+ const onSubmit = async () => {
11271
+ setIsSubmitting(true);
11272
+ let requestSucceeded = false;
11273
+ await requestOrderEdit(void 0, {
11274
+ onError: (e) => {
11275
+ ui.toast.error(e.message);
11276
+ },
11277
+ onSuccess: () => {
11278
+ requestSucceeded = true;
11279
+ }
11280
+ });
11281
+ if (!requestSucceeded) {
11282
+ setIsSubmitting(false);
11283
+ return;
11284
+ }
11285
+ await confirmOrderEdit(void 0, {
11286
+ onError: (e) => {
11287
+ ui.toast.error(e.message);
11288
+ },
11289
+ onSuccess: () => {
11290
+ handleSuccess();
11291
+ },
11292
+ onSettled: () => {
11293
+ setIsSubmitting(false);
11294
+ }
11295
+ });
11296
+ };
11297
+ if (isError) {
11298
+ throw error;
11299
+ }
11300
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11301
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11302
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11305
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11306
+ ] }),
11307
+ /* @__PURE__ */ jsxRuntime.jsx(
11308
+ Combobox,
11309
+ {
11310
+ id: "promotion-combobox",
11311
+ "aria-describedby": "promotion-combobox-hint",
11312
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11313
+ fetchNextPage: comboboxData.fetchNextPage,
11314
+ options: comboboxData.options,
11315
+ onSearchValueChange: comboboxData.onSearchValueChange,
11316
+ searchValue: comboboxData.searchValue,
11317
+ disabled: comboboxData.disabled || isAddingPromotions,
11318
+ onChange: add,
11319
+ value: comboboxValue
11320
+ }
11321
+ )
11322
+ ] }),
11323
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11324
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11325
+ PromotionItem,
11326
+ {
11327
+ promotion,
11328
+ orderId: preview.id,
11329
+ isLoading: isPending
11330
+ },
11331
+ promotion.id
11332
+ )) })
11333
+ ] }) }),
11334
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11335
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11336
+ /* @__PURE__ */ jsxRuntime.jsx(
11337
+ ui.Button,
11338
+ {
11339
+ size: "small",
11340
+ type: "submit",
11341
+ isLoading: isSubmitting || isAddingPromotions,
11342
+ children: "Save"
11343
+ }
11344
+ )
11345
+ ] }) })
11346
+ ] });
11347
+ };
11348
+ const PromotionItem = ({
11349
+ promotion,
11350
+ orderId,
11351
+ isLoading
11352
+ }) => {
11353
+ var _a;
11354
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11355
+ const onRemove = async () => {
11356
+ removePromotions(
11357
+ {
11358
+ promo_codes: [promotion.code]
11359
+ },
11360
+ {
11361
+ onError: (e) => {
11362
+ ui.toast.error(e.message);
11363
+ }
11364
+ }
11365
+ );
11366
+ };
11367
+ const displayValue = getDisplayValue(promotion);
11368
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11369
+ "div",
11370
+ {
11371
+ className: ui.clx(
11372
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11373
+ {
11374
+ "animate-pulse": isLoading
11375
+ }
11376
+ ),
11377
+ children: [
11378
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11379
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11380
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11381
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11382
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11383
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11384
+ ] }),
11385
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11386
+ ] })
11387
+ ] }),
11388
+ /* @__PURE__ */ jsxRuntime.jsx(
11389
+ ui.IconButton,
11390
+ {
11391
+ size: "small",
11392
+ type: "button",
11393
+ variant: "transparent",
11394
+ onClick: onRemove,
11395
+ isLoading: isPending || isLoading,
11396
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11397
+ }
11398
+ )
11399
+ ]
11400
+ },
11401
+ promotion.id
11402
+ );
11403
+ };
11404
+ function getDisplayValue(promotion) {
11405
+ var _a, _b, _c, _d;
11406
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11407
+ if (!value) {
11408
+ return null;
11409
+ }
11410
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11411
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11412
+ if (!currency) {
11413
+ return null;
11414
+ }
11415
+ return getLocaleAmount(value, currency);
11416
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11417
+ return formatPercentage(value);
11418
+ }
11419
+ return null;
11420
+ }
11421
+ const formatter = new Intl.NumberFormat([], {
11422
+ style: "percent",
11423
+ minimumFractionDigits: 2
11424
+ });
11425
+ const formatPercentage = (value, isPercentageValue = false) => {
11426
+ let val = value || 0;
11427
+ if (!isPercentageValue) {
11428
+ val = val / 100;
11429
+ }
11430
+ return formatter.format(val);
11431
+ };
11432
+ function getPromotionIds(items, shippingMethods) {
11433
+ const promotionIds = /* @__PURE__ */ new Set();
11434
+ for (const item of items) {
11435
+ if (item.adjustments) {
11436
+ for (const adjustment of item.adjustments) {
11437
+ if (adjustment.promotion_id) {
11438
+ promotionIds.add(adjustment.promotion_id);
11439
+ }
11440
+ }
11441
+ }
11172
11442
  }
11173
- return Object.values(metadata).some(
11174
- (value) => !EDITABLE_TYPES.includes(typeof value)
11175
- );
11443
+ for (const shippingMethod of shippingMethods) {
11444
+ if (shippingMethod.adjustments) {
11445
+ for (const adjustment of shippingMethod.adjustments) {
11446
+ if (adjustment.promotion_id) {
11447
+ promotionIds.add(adjustment.promotion_id);
11448
+ }
11449
+ }
11450
+ }
11451
+ }
11452
+ return Array.from(promotionIds);
11176
11453
  }
11177
11454
  const SalesChannel = () => {
11178
11455
  const { id } = reactRouterDom.useParams();
@@ -12663,386 +12940,109 @@ const Illustration = () => {
12663
12940
  strokeLinejoin: "round"
12664
12941
  }
12665
12942
  ) }),
12666
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12667
- "path",
12668
- {
12669
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12670
- stroke: "#A1A1AA",
12671
- strokeWidth: "1.5",
12672
- strokeLinecap: "round",
12673
- strokeLinejoin: "round"
12674
- }
12675
- ) }),
12676
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12677
- "path",
12678
- {
12679
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12680
- stroke: "#A1A1AA",
12681
- strokeWidth: "1.5",
12682
- strokeLinecap: "round",
12683
- strokeLinejoin: "round"
12684
- }
12685
- ) }),
12686
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12687
- "path",
12688
- {
12689
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12690
- stroke: "#A1A1AA",
12691
- strokeWidth: "1.5",
12692
- strokeLinecap: "round",
12693
- strokeLinejoin: "round"
12694
- }
12695
- ) }),
12696
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12697
- "path",
12698
- {
12699
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12700
- stroke: "#A1A1AA",
12701
- strokeWidth: "1.5",
12702
- strokeLinecap: "round",
12703
- strokeLinejoin: "round"
12704
- }
12705
- ) }),
12706
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12707
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12708
- "rect",
12709
- {
12710
- width: "12",
12711
- height: "12",
12712
- fill: "white",
12713
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12714
- }
12715
- ) }),
12716
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12717
- "rect",
12718
- {
12719
- width: "12",
12720
- height: "12",
12721
- fill: "white",
12722
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12723
- }
12724
- ) }),
12725
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12726
- "rect",
12727
- {
12728
- width: "12",
12729
- height: "12",
12730
- fill: "white",
12731
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12732
- }
12733
- ) }),
12734
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12735
- "rect",
12736
- {
12737
- width: "12",
12738
- height: "12",
12739
- fill: "white",
12740
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12741
- }
12742
- ) }),
12743
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12744
- "rect",
12745
- {
12746
- width: "12",
12747
- height: "12",
12748
- fill: "white",
12749
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12750
- }
12751
- ) }),
12752
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12753
- "rect",
12754
- {
12755
- width: "12",
12756
- height: "12",
12757
- fill: "white",
12758
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12759
- }
12760
- ) })
12761
- ] })
12762
- ]
12763
- }
12764
- );
12765
- };
12766
- const schema = objectType({
12767
- customer_id: stringType().min(1)
12768
- });
12769
- const PROMOTION_QUERY_KEY = "promotions";
12770
- const promotionsQueryKeys = {
12771
- list: (query2) => [
12772
- PROMOTION_QUERY_KEY,
12773
- query2 ? query2 : void 0
12774
- ],
12775
- detail: (id, query2) => [
12776
- PROMOTION_QUERY_KEY,
12777
- id,
12778
- query2 ? query2 : void 0
12779
- ]
12780
- };
12781
- const usePromotions = (query2, options) => {
12782
- const { data, ...rest } = reactQuery.useQuery({
12783
- queryKey: promotionsQueryKeys.list(query2),
12784
- queryFn: async () => sdk.admin.promotion.list(query2),
12785
- ...options
12786
- });
12787
- return { ...data, ...rest };
12788
- };
12789
- const Promotions = () => {
12790
- const { id } = reactRouterDom.useParams();
12791
- const {
12792
- order: preview,
12793
- isError: isPreviewError,
12794
- error: previewError
12795
- } = useOrderPreview(id, void 0);
12796
- useInitiateOrderEdit({ preview });
12797
- const { onCancel } = useCancelOrderEdit({ preview });
12798
- if (isPreviewError) {
12799
- throw previewError;
12800
- }
12801
- const isReady = !!preview;
12802
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12803
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12804
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12805
- ] });
12806
- };
12807
- const PromotionForm = ({ preview }) => {
12808
- const { items, shipping_methods } = preview;
12809
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12810
- const [comboboxValue, setComboboxValue] = React.useState("");
12811
- const { handleSuccess } = useRouteModal();
12812
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12813
- const promoIds = getPromotionIds(items, shipping_methods);
12814
- const { promotions, isPending, isError, error } = usePromotions(
12815
- {
12816
- id: promoIds
12817
- },
12818
- {
12819
- enabled: !!promoIds.length
12820
- }
12821
- );
12822
- const comboboxData = useComboboxData({
12823
- queryKey: ["promotions", "combobox", promoIds],
12824
- queryFn: async (params) => {
12825
- return await sdk.admin.promotion.list({
12826
- ...params,
12827
- id: {
12828
- $nin: promoIds
12829
- }
12830
- });
12831
- },
12832
- getOptions: (data) => {
12833
- return data.promotions.map((promotion) => ({
12834
- label: promotion.code,
12835
- value: promotion.code
12836
- }));
12837
- }
12838
- });
12839
- const add = async (value) => {
12840
- if (!value) {
12841
- return;
12842
- }
12843
- addPromotions(
12844
- {
12845
- promo_codes: [value]
12846
- },
12847
- {
12848
- onError: (e) => {
12849
- ui.toast.error(e.message);
12850
- comboboxData.onSearchValueChange("");
12851
- setComboboxValue("");
12852
- },
12853
- onSuccess: () => {
12854
- comboboxData.onSearchValueChange("");
12855
- setComboboxValue("");
12856
- }
12857
- }
12858
- );
12859
- };
12860
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12861
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12862
- const onSubmit = async () => {
12863
- setIsSubmitting(true);
12864
- let requestSucceeded = false;
12865
- await requestOrderEdit(void 0, {
12866
- onError: (e) => {
12867
- ui.toast.error(e.message);
12868
- },
12869
- onSuccess: () => {
12870
- requestSucceeded = true;
12871
- }
12872
- });
12873
- if (!requestSucceeded) {
12874
- setIsSubmitting(false);
12875
- return;
12876
- }
12877
- await confirmOrderEdit(void 0, {
12878
- onError: (e) => {
12879
- ui.toast.error(e.message);
12880
- },
12881
- onSuccess: () => {
12882
- handleSuccess();
12883
- },
12884
- onSettled: () => {
12885
- setIsSubmitting(false);
12886
- }
12887
- });
12888
- };
12889
- if (isError) {
12890
- throw error;
12891
- }
12892
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12893
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12894
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12895
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12896
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12897
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12898
- ] }),
12899
- /* @__PURE__ */ jsxRuntime.jsx(
12900
- Combobox,
12943
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12944
+ "path",
12901
12945
  {
12902
- id: "promotion-combobox",
12903
- "aria-describedby": "promotion-combobox-hint",
12904
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12905
- fetchNextPage: comboboxData.fetchNextPage,
12906
- options: comboboxData.options,
12907
- onSearchValueChange: comboboxData.onSearchValueChange,
12908
- searchValue: comboboxData.searchValue,
12909
- disabled: comboboxData.disabled || isAddingPromotions,
12910
- onChange: add,
12911
- value: comboboxValue
12946
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12947
+ stroke: "#A1A1AA",
12948
+ strokeWidth: "1.5",
12949
+ strokeLinecap: "round",
12950
+ strokeLinejoin: "round"
12912
12951
  }
12913
- )
12914
- ] }),
12915
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12916
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12917
- PromotionItem,
12918
- {
12919
- promotion,
12920
- orderId: preview.id,
12921
- isLoading: isPending
12922
- },
12923
- promotion.id
12924
- )) })
12925
- ] }) }),
12926
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12927
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12928
- /* @__PURE__ */ jsxRuntime.jsx(
12929
- ui.Button,
12930
- {
12931
- size: "small",
12932
- type: "submit",
12933
- isLoading: isSubmitting || isAddingPromotions,
12934
- children: "Save"
12935
- }
12936
- )
12937
- ] }) })
12938
- ] });
12939
- };
12940
- const PromotionItem = ({
12941
- promotion,
12942
- orderId,
12943
- isLoading
12944
- }) => {
12945
- var _a;
12946
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12947
- const onRemove = async () => {
12948
- removePromotions(
12949
- {
12950
- promo_codes: [promotion.code]
12951
- },
12952
- {
12953
- onError: (e) => {
12954
- ui.toast.error(e.message);
12955
- }
12956
- }
12957
- );
12958
- };
12959
- const displayValue = getDisplayValue(promotion);
12960
- return /* @__PURE__ */ jsxRuntime.jsxs(
12961
- "div",
12962
- {
12963
- className: ui.clx(
12964
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12965
- {
12966
- "animate-pulse": isLoading
12967
- }
12968
- ),
12969
- children: [
12970
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12971
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12973
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12974
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12975
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12976
- ] }),
12977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12978
- ] })
12979
- ] }),
12980
- /* @__PURE__ */ jsxRuntime.jsx(
12981
- ui.IconButton,
12952
+ ) }),
12953
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12954
+ "path",
12982
12955
  {
12983
- size: "small",
12984
- type: "button",
12985
- variant: "transparent",
12986
- onClick: onRemove,
12987
- isLoading: isPending || isLoading,
12988
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12956
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12957
+ stroke: "#A1A1AA",
12958
+ strokeWidth: "1.5",
12959
+ strokeLinecap: "round",
12960
+ strokeLinejoin: "round"
12989
12961
  }
12990
- )
12962
+ ) }),
12963
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12964
+ "path",
12965
+ {
12966
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12967
+ stroke: "#A1A1AA",
12968
+ strokeWidth: "1.5",
12969
+ strokeLinecap: "round",
12970
+ strokeLinejoin: "round"
12971
+ }
12972
+ ) }),
12973
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12974
+ "path",
12975
+ {
12976
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12977
+ stroke: "#A1A1AA",
12978
+ strokeWidth: "1.5",
12979
+ strokeLinecap: "round",
12980
+ strokeLinejoin: "round"
12981
+ }
12982
+ ) }),
12983
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12984
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12985
+ "rect",
12986
+ {
12987
+ width: "12",
12988
+ height: "12",
12989
+ fill: "white",
12990
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12991
+ }
12992
+ ) }),
12993
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12994
+ "rect",
12995
+ {
12996
+ width: "12",
12997
+ height: "12",
12998
+ fill: "white",
12999
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13000
+ }
13001
+ ) }),
13002
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13003
+ "rect",
13004
+ {
13005
+ width: "12",
13006
+ height: "12",
13007
+ fill: "white",
13008
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13009
+ }
13010
+ ) }),
13011
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13012
+ "rect",
13013
+ {
13014
+ width: "12",
13015
+ height: "12",
13016
+ fill: "white",
13017
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13018
+ }
13019
+ ) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13021
+ "rect",
13022
+ {
13023
+ width: "12",
13024
+ height: "12",
13025
+ fill: "white",
13026
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13027
+ }
13028
+ ) }),
13029
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13030
+ "rect",
13031
+ {
13032
+ width: "12",
13033
+ height: "12",
13034
+ fill: "white",
13035
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13036
+ }
13037
+ ) })
13038
+ ] })
12991
13039
  ]
12992
- },
12993
- promotion.id
13040
+ }
12994
13041
  );
12995
13042
  };
12996
- function getDisplayValue(promotion) {
12997
- var _a, _b, _c, _d;
12998
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12999
- if (!value) {
13000
- return null;
13001
- }
13002
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
13003
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13004
- if (!currency) {
13005
- return null;
13006
- }
13007
- return getLocaleAmount(value, currency);
13008
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13009
- return formatPercentage(value);
13010
- }
13011
- return null;
13012
- }
13013
- const formatter = new Intl.NumberFormat([], {
13014
- style: "percent",
13015
- minimumFractionDigits: 2
13043
+ const schema = objectType({
13044
+ customer_id: stringType().min(1)
13016
13045
  });
13017
- const formatPercentage = (value, isPercentageValue = false) => {
13018
- let val = value || 0;
13019
- if (!isPercentageValue) {
13020
- val = val / 100;
13021
- }
13022
- return formatter.format(val);
13023
- };
13024
- function getPromotionIds(items, shippingMethods) {
13025
- const promotionIds = /* @__PURE__ */ new Set();
13026
- for (const item of items) {
13027
- if (item.adjustments) {
13028
- for (const adjustment of item.adjustments) {
13029
- if (adjustment.promotion_id) {
13030
- promotionIds.add(adjustment.promotion_id);
13031
- }
13032
- }
13033
- }
13034
- }
13035
- for (const shippingMethod of shippingMethods) {
13036
- if (shippingMethod.adjustments) {
13037
- for (const adjustment of shippingMethod.adjustments) {
13038
- if (adjustment.promotion_id) {
13039
- promotionIds.add(adjustment.promotion_id);
13040
- }
13041
- }
13042
- }
13043
- }
13044
- return Array.from(promotionIds);
13045
- }
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13063,26 +13063,30 @@ const routeModule = {
13063
13063
  handle,
13064
13064
  loader,
13065
13065
  children: [
13066
- {
13067
- Component: BillingAddress,
13068
- path: "/draft-orders/:id/billing-address"
13069
- },
13070
13066
  {
13071
13067
  Component: CustomItems,
13072
13068
  path: "/draft-orders/:id/custom-items"
13073
13069
  },
13074
- {
13075
- Component: Email,
13076
- path: "/draft-orders/:id/email"
13077
- },
13078
13070
  {
13079
13071
  Component: Items,
13080
13072
  path: "/draft-orders/:id/items"
13081
13073
  },
13074
+ {
13075
+ Component: Email,
13076
+ path: "/draft-orders/:id/email"
13077
+ },
13082
13078
  {
13083
13079
  Component: Metadata,
13084
13080
  path: "/draft-orders/:id/metadata"
13085
13081
  },
13082
+ {
13083
+ Component: BillingAddress,
13084
+ path: "/draft-orders/:id/billing-address"
13085
+ },
13086
+ {
13087
+ Component: Promotions,
13088
+ path: "/draft-orders/:id/promotions"
13089
+ },
13086
13090
  {
13087
13091
  Component: SalesChannel,
13088
13092
  path: "/draft-orders/:id/sales-channel"
@@ -13098,10 +13102,6 @@ const routeModule = {
13098
13102
  {
13099
13103
  Component: TransferOwnership,
13100
13104
  path: "/draft-orders/:id/transfer-ownership"
13101
- },
13102
- {
13103
- Component: Promotions,
13104
- path: "/draft-orders/:id/promotions"
13105
13105
  }
13106
13106
  ]
13107
13107
  }