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