@medusajs/draft-order 2.10.4-preview-20250925060158 → 2.10.4-preview-20250925120212

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9567,27 +9567,196 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const CustomItems = () => {
9570
+ const BillingAddress = () => {
9571
+ const { id } = useParams();
9572
+ const { order, isPending, isError, error } = useOrder(id, {
9573
+ fields: "+billing_address"
9574
+ });
9575
+ if (isError) {
9576
+ throw error;
9577
+ }
9578
+ const isReady = !isPending && !!order;
9571
9579
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9573
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9580
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
+ ] }),
9584
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9574
9585
  ] });
9575
9586
  };
9576
- const CustomItemsForm = () => {
9587
+ const BillingAddressForm = ({ order }) => {
9588
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9577
9589
  const form = useForm({
9590
+ defaultValues: {
9591
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
+ },
9578
9602
  resolver: zodResolver(schema$5)
9579
9603
  });
9580
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9583
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9584
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9585
- ] }) })
9586
- ] }) });
9604
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
+ const { handleSuccess } = useRouteModal();
9606
+ const onSubmit = form.handleSubmit(async (data) => {
9607
+ await mutateAsync(
9608
+ { billing_address: data },
9609
+ {
9610
+ onSuccess: () => {
9611
+ handleSuccess();
9612
+ },
9613
+ onError: (error) => {
9614
+ toast.error(error.message);
9615
+ }
9616
+ }
9617
+ );
9618
+ });
9619
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
+ KeyboundForm,
9621
+ {
9622
+ className: "flex flex-1 flex-col overflow-hidden",
9623
+ onSubmit,
9624
+ children: [
9625
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9626
+ /* @__PURE__ */ jsx(
9627
+ Form$2.Field,
9628
+ {
9629
+ control: form.control,
9630
+ name: "country_code",
9631
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
+ ] })
9636
+ }
9637
+ ),
9638
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
+ /* @__PURE__ */ jsx(
9640
+ Form$2.Field,
9641
+ {
9642
+ control: form.control,
9643
+ name: "first_name",
9644
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
+ ] })
9649
+ }
9650
+ ),
9651
+ /* @__PURE__ */ jsx(
9652
+ Form$2.Field,
9653
+ {
9654
+ control: form.control,
9655
+ name: "last_name",
9656
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
+ ] })
9661
+ }
9662
+ )
9663
+ ] }),
9664
+ /* @__PURE__ */ jsx(
9665
+ Form$2.Field,
9666
+ {
9667
+ control: form.control,
9668
+ name: "company",
9669
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
+ ] })
9674
+ }
9675
+ ),
9676
+ /* @__PURE__ */ jsx(
9677
+ Form$2.Field,
9678
+ {
9679
+ control: form.control,
9680
+ name: "address_1",
9681
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
+ ] })
9686
+ }
9687
+ ),
9688
+ /* @__PURE__ */ jsx(
9689
+ Form$2.Field,
9690
+ {
9691
+ control: form.control,
9692
+ name: "address_2",
9693
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
+ ] })
9698
+ }
9699
+ ),
9700
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
+ /* @__PURE__ */ jsx(
9702
+ Form$2.Field,
9703
+ {
9704
+ control: form.control,
9705
+ name: "postal_code",
9706
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
+ ] })
9711
+ }
9712
+ ),
9713
+ /* @__PURE__ */ jsx(
9714
+ Form$2.Field,
9715
+ {
9716
+ control: form.control,
9717
+ name: "city",
9718
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
+ ] })
9723
+ }
9724
+ )
9725
+ ] }),
9726
+ /* @__PURE__ */ jsx(
9727
+ Form$2.Field,
9728
+ {
9729
+ control: form.control,
9730
+ name: "province",
9731
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
+ ] })
9736
+ }
9737
+ ),
9738
+ /* @__PURE__ */ jsx(
9739
+ Form$2.Field,
9740
+ {
9741
+ control: form.control,
9742
+ name: "phone",
9743
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
+ ] })
9748
+ }
9749
+ )
9750
+ ] }) }),
9751
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
+ ] }) })
9755
+ ]
9756
+ }
9757
+ ) });
9587
9758
  };
9588
- const schema$5 = objectType({
9589
- email: stringType().email()
9590
- });
9759
+ const schema$5 = addressSchema;
9591
9760
  const Email = () => {
9592
9761
  const { id } = useParams();
9593
9762
  const { order, isPending, isError, error } = useOrder(id, {
@@ -10630,10 +10799,54 @@ const customItemSchema = objectType({
10630
10799
  quantity: numberType(),
10631
10800
  unit_price: unionType([numberType(), stringType()])
10632
10801
  });
10633
- const BillingAddress = () => {
10802
+ const InlineTip = forwardRef(
10803
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10804
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10805
+ return /* @__PURE__ */ jsxs(
10806
+ "div",
10807
+ {
10808
+ ref,
10809
+ className: clx(
10810
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10811
+ className
10812
+ ),
10813
+ ...props,
10814
+ children: [
10815
+ /* @__PURE__ */ jsx(
10816
+ "div",
10817
+ {
10818
+ role: "presentation",
10819
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10820
+ "bg-ui-tag-orange-icon": variant === "warning"
10821
+ })
10822
+ }
10823
+ ),
10824
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10825
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10826
+ labelValue,
10827
+ ":"
10828
+ ] }),
10829
+ " ",
10830
+ children
10831
+ ] })
10832
+ ]
10833
+ }
10834
+ );
10835
+ }
10836
+ );
10837
+ InlineTip.displayName = "InlineTip";
10838
+ const MetadataFieldSchema = objectType({
10839
+ key: stringType(),
10840
+ disabled: booleanType().optional(),
10841
+ value: anyType()
10842
+ });
10843
+ const MetadataSchema = objectType({
10844
+ metadata: arrayType(MetadataFieldSchema)
10845
+ });
10846
+ const Metadata = () => {
10634
10847
  const { id } = useParams();
10635
10848
  const { order, isPending, isError, error } = useOrder(id, {
10636
- fields: "+billing_address"
10849
+ fields: "metadata"
10637
10850
  });
10638
10851
  if (isError) {
10639
10852
  throw error;
@@ -10641,244 +10854,10 @@ const BillingAddress = () => {
10641
10854
  const isReady = !isPending && !!order;
10642
10855
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10643
10856
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10644
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
10645
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
10857
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10858
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10646
10859
  ] }),
10647
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
10648
- ] });
10649
- };
10650
- const BillingAddressForm = ({ order }) => {
10651
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10652
- const form = useForm({
10653
- defaultValues: {
10654
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
10655
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
10656
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
10657
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
10658
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
10659
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
10660
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
10661
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
10662
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
10663
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
10664
- },
10665
- resolver: zodResolver(schema$3)
10666
- });
10667
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10668
- const { handleSuccess } = useRouteModal();
10669
- const onSubmit = form.handleSubmit(async (data) => {
10670
- await mutateAsync(
10671
- { billing_address: data },
10672
- {
10673
- onSuccess: () => {
10674
- handleSuccess();
10675
- },
10676
- onError: (error) => {
10677
- toast.error(error.message);
10678
- }
10679
- }
10680
- );
10681
- });
10682
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10683
- KeyboundForm,
10684
- {
10685
- className: "flex flex-1 flex-col overflow-hidden",
10686
- onSubmit,
10687
- children: [
10688
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
10689
- /* @__PURE__ */ jsx(
10690
- Form$2.Field,
10691
- {
10692
- control: form.control,
10693
- name: "country_code",
10694
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10695
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
10696
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
10697
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10698
- ] })
10699
- }
10700
- ),
10701
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10702
- /* @__PURE__ */ jsx(
10703
- Form$2.Field,
10704
- {
10705
- control: form.control,
10706
- name: "first_name",
10707
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10708
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
10709
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10710
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10711
- ] })
10712
- }
10713
- ),
10714
- /* @__PURE__ */ jsx(
10715
- Form$2.Field,
10716
- {
10717
- control: form.control,
10718
- name: "last_name",
10719
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10720
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
10721
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10722
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10723
- ] })
10724
- }
10725
- )
10726
- ] }),
10727
- /* @__PURE__ */ jsx(
10728
- Form$2.Field,
10729
- {
10730
- control: form.control,
10731
- name: "company",
10732
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10733
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
10734
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10735
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10736
- ] })
10737
- }
10738
- ),
10739
- /* @__PURE__ */ jsx(
10740
- Form$2.Field,
10741
- {
10742
- control: form.control,
10743
- name: "address_1",
10744
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10745
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
10746
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10747
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10748
- ] })
10749
- }
10750
- ),
10751
- /* @__PURE__ */ jsx(
10752
- Form$2.Field,
10753
- {
10754
- control: form.control,
10755
- name: "address_2",
10756
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10757
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10758
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10759
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10760
- ] })
10761
- }
10762
- ),
10763
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10764
- /* @__PURE__ */ jsx(
10765
- Form$2.Field,
10766
- {
10767
- control: form.control,
10768
- name: "postal_code",
10769
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10770
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
10771
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10772
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10773
- ] })
10774
- }
10775
- ),
10776
- /* @__PURE__ */ jsx(
10777
- Form$2.Field,
10778
- {
10779
- control: form.control,
10780
- name: "city",
10781
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10782
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
10783
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10784
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10785
- ] })
10786
- }
10787
- )
10788
- ] }),
10789
- /* @__PURE__ */ jsx(
10790
- Form$2.Field,
10791
- {
10792
- control: form.control,
10793
- name: "province",
10794
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10795
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10796
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10797
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10798
- ] })
10799
- }
10800
- ),
10801
- /* @__PURE__ */ jsx(
10802
- Form$2.Field,
10803
- {
10804
- control: form.control,
10805
- name: "phone",
10806
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10807
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
10808
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10809
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10810
- ] })
10811
- }
10812
- )
10813
- ] }) }),
10814
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10815
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10816
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10817
- ] }) })
10818
- ]
10819
- }
10820
- ) });
10821
- };
10822
- const schema$3 = addressSchema;
10823
- const InlineTip = forwardRef(
10824
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10825
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10826
- return /* @__PURE__ */ jsxs(
10827
- "div",
10828
- {
10829
- ref,
10830
- className: clx(
10831
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10832
- className
10833
- ),
10834
- ...props,
10835
- children: [
10836
- /* @__PURE__ */ jsx(
10837
- "div",
10838
- {
10839
- role: "presentation",
10840
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10841
- "bg-ui-tag-orange-icon": variant === "warning"
10842
- })
10843
- }
10844
- ),
10845
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10846
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10847
- labelValue,
10848
- ":"
10849
- ] }),
10850
- " ",
10851
- children
10852
- ] })
10853
- ]
10854
- }
10855
- );
10856
- }
10857
- );
10858
- InlineTip.displayName = "InlineTip";
10859
- const MetadataFieldSchema = objectType({
10860
- key: stringType(),
10861
- disabled: booleanType().optional(),
10862
- value: anyType()
10863
- });
10864
- const MetadataSchema = objectType({
10865
- metadata: arrayType(MetadataFieldSchema)
10866
- });
10867
- const Metadata = () => {
10868
- const { id } = useParams();
10869
- const { order, isPending, isError, error } = useOrder(id, {
10870
- fields: "metadata"
10871
- });
10872
- if (isError) {
10873
- throw error;
10874
- }
10875
- const isReady = !isPending && !!order;
10876
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10877
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10878
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10879
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10880
- ] }),
10881
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10860
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10882
10861
  ] });
10883
10862
  };
10884
10863
  const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
@@ -11170,283 +11149,27 @@ function getHasUneditableRows(metadata) {
11170
11149
  (value) => !EDITABLE_TYPES.includes(typeof value)
11171
11150
  );
11172
11151
  }
11173
- const PROMOTION_QUERY_KEY = "promotions";
11174
- const promotionsQueryKeys = {
11175
- list: (query2) => [
11176
- PROMOTION_QUERY_KEY,
11177
- query2 ? query2 : void 0
11178
- ],
11179
- detail: (id, query2) => [
11180
- PROMOTION_QUERY_KEY,
11181
- id,
11182
- query2 ? query2 : void 0
11183
- ]
11152
+ const CustomItems = () => {
11153
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11154
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
11155
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
11156
+ ] });
11184
11157
  };
11185
- const usePromotions = (query2, options) => {
11186
- const { data, ...rest } = useQuery({
11187
- queryKey: promotionsQueryKeys.list(query2),
11188
- queryFn: async () => sdk.admin.promotion.list(query2),
11189
- ...options
11158
+ const CustomItemsForm = () => {
11159
+ const form = useForm({
11160
+ resolver: zodResolver(schema$3)
11190
11161
  });
11191
- return { ...data, ...rest };
11192
- };
11193
- const Promotions = () => {
11194
- const { id } = useParams();
11195
- const {
11196
- order: preview,
11197
- isError: isPreviewError,
11198
- error: previewError
11199
- } = useOrderPreview(id, void 0);
11200
- useInitiateOrderEdit({ preview });
11201
- const { onCancel } = useCancelOrderEdit({ preview });
11202
- if (isPreviewError) {
11203
- throw previewError;
11204
- }
11205
- const isReady = !!preview;
11206
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11207
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11208
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11209
- ] });
11210
- };
11211
- const PromotionForm = ({ preview }) => {
11212
- const { items, shipping_methods } = preview;
11213
- const [isSubmitting, setIsSubmitting] = useState(false);
11214
- const [comboboxValue, setComboboxValue] = useState("");
11215
- const { handleSuccess } = useRouteModal();
11216
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11217
- const promoIds = getPromotionIds(items, shipping_methods);
11218
- const { promotions, isPending, isError, error } = usePromotions(
11219
- {
11220
- id: promoIds
11221
- },
11222
- {
11223
- enabled: !!promoIds.length
11224
- }
11225
- );
11226
- const comboboxData = useComboboxData({
11227
- queryKey: ["promotions", "combobox", promoIds],
11228
- queryFn: async (params) => {
11229
- return await sdk.admin.promotion.list({
11230
- ...params,
11231
- id: {
11232
- $nin: promoIds
11233
- }
11234
- });
11235
- },
11236
- getOptions: (data) => {
11237
- return data.promotions.map((promotion) => ({
11238
- label: promotion.code,
11239
- value: promotion.code
11240
- }));
11241
- }
11242
- });
11243
- const add = async (value) => {
11244
- if (!value) {
11245
- return;
11246
- }
11247
- addPromotions(
11248
- {
11249
- promo_codes: [value]
11250
- },
11251
- {
11252
- onError: (e) => {
11253
- toast.error(e.message);
11254
- comboboxData.onSearchValueChange("");
11255
- setComboboxValue("");
11256
- },
11257
- onSuccess: () => {
11258
- comboboxData.onSearchValueChange("");
11259
- setComboboxValue("");
11260
- }
11261
- }
11262
- );
11263
- };
11264
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11265
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11266
- const onSubmit = async () => {
11267
- setIsSubmitting(true);
11268
- let requestSucceeded = false;
11269
- await requestOrderEdit(void 0, {
11270
- onError: (e) => {
11271
- toast.error(e.message);
11272
- },
11273
- onSuccess: () => {
11274
- requestSucceeded = true;
11275
- }
11276
- });
11277
- if (!requestSucceeded) {
11278
- setIsSubmitting(false);
11279
- return;
11280
- }
11281
- await confirmOrderEdit(void 0, {
11282
- onError: (e) => {
11283
- toast.error(e.message);
11284
- },
11285
- onSuccess: () => {
11286
- handleSuccess();
11287
- },
11288
- onSettled: () => {
11289
- setIsSubmitting(false);
11290
- }
11291
- });
11292
- };
11293
- if (isError) {
11294
- throw error;
11295
- }
11296
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11297
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11298
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11299
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11300
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11301
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11302
- ] }),
11303
- /* @__PURE__ */ jsx(
11304
- Combobox,
11305
- {
11306
- id: "promotion-combobox",
11307
- "aria-describedby": "promotion-combobox-hint",
11308
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11309
- fetchNextPage: comboboxData.fetchNextPage,
11310
- options: comboboxData.options,
11311
- onSearchValueChange: comboboxData.onSearchValueChange,
11312
- searchValue: comboboxData.searchValue,
11313
- disabled: comboboxData.disabled || isAddingPromotions,
11314
- onChange: add,
11315
- value: comboboxValue
11316
- }
11317
- )
11318
- ] }),
11319
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11320
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11321
- PromotionItem,
11322
- {
11323
- promotion,
11324
- orderId: preview.id,
11325
- isLoading: isPending
11326
- },
11327
- promotion.id
11328
- )) })
11329
- ] }) }),
11162
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11163
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
11330
11164
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11331
11165
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11332
- /* @__PURE__ */ jsx(
11333
- Button,
11334
- {
11335
- size: "small",
11336
- type: "submit",
11337
- isLoading: isSubmitting || isAddingPromotions,
11338
- children: "Save"
11339
- }
11340
- )
11166
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
11341
11167
  ] }) })
11342
- ] });
11343
- };
11344
- const PromotionItem = ({
11345
- promotion,
11346
- orderId,
11347
- isLoading
11348
- }) => {
11349
- var _a;
11350
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11351
- const onRemove = async () => {
11352
- removePromotions(
11353
- {
11354
- promo_codes: [promotion.code]
11355
- },
11356
- {
11357
- onError: (e) => {
11358
- toast.error(e.message);
11359
- }
11360
- }
11361
- );
11362
- };
11363
- const displayValue = getDisplayValue(promotion);
11364
- return /* @__PURE__ */ jsxs(
11365
- "div",
11366
- {
11367
- className: clx(
11368
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11369
- {
11370
- "animate-pulse": isLoading
11371
- }
11372
- ),
11373
- children: [
11374
- /* @__PURE__ */ jsxs("div", { children: [
11375
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11376
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11377
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11378
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11379
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11380
- ] }),
11381
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11382
- ] })
11383
- ] }),
11384
- /* @__PURE__ */ jsx(
11385
- IconButton,
11386
- {
11387
- size: "small",
11388
- type: "button",
11389
- variant: "transparent",
11390
- onClick: onRemove,
11391
- isLoading: isPending || isLoading,
11392
- children: /* @__PURE__ */ jsx(XMark, {})
11393
- }
11394
- )
11395
- ]
11396
- },
11397
- promotion.id
11398
- );
11168
+ ] }) });
11399
11169
  };
11400
- function getDisplayValue(promotion) {
11401
- var _a, _b, _c, _d;
11402
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11403
- if (!value) {
11404
- return null;
11405
- }
11406
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11407
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11408
- if (!currency) {
11409
- return null;
11410
- }
11411
- return getLocaleAmount(value, currency);
11412
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11413
- return formatPercentage(value);
11414
- }
11415
- return null;
11416
- }
11417
- const formatter = new Intl.NumberFormat([], {
11418
- style: "percent",
11419
- minimumFractionDigits: 2
11170
+ const schema$3 = objectType({
11171
+ email: stringType().email()
11420
11172
  });
11421
- const formatPercentage = (value, isPercentageValue = false) => {
11422
- let val = value || 0;
11423
- if (!isPercentageValue) {
11424
- val = val / 100;
11425
- }
11426
- return formatter.format(val);
11427
- };
11428
- function getPromotionIds(items, shippingMethods) {
11429
- const promotionIds = /* @__PURE__ */ new Set();
11430
- for (const item of items) {
11431
- if (item.adjustments) {
11432
- for (const adjustment of item.adjustments) {
11433
- if (adjustment.promotion_id) {
11434
- promotionIds.add(adjustment.promotion_id);
11435
- }
11436
- }
11437
- }
11438
- }
11439
- for (const shippingMethod of shippingMethods) {
11440
- if (shippingMethod.adjustments) {
11441
- for (const adjustment of shippingMethod.adjustments) {
11442
- if (adjustment.promotion_id) {
11443
- promotionIds.add(adjustment.promotion_id);
11444
- }
11445
- }
11446
- }
11447
- }
11448
- return Array.from(promotionIds);
11449
- }
11450
11173
  const SalesChannel = () => {
11451
11174
  const { id } = useParams();
11452
11175
  const { draft_order, isPending, isError, error } = useDraftOrder(
@@ -13039,9 +12762,286 @@ const Illustration = () => {
13039
12762
  const schema = objectType({
13040
12763
  customer_id: stringType().min(1)
13041
12764
  });
13042
- const widgetModule = { widgets: [] };
13043
- const routeModule = {
13044
- routes: [
12765
+ const PROMOTION_QUERY_KEY = "promotions";
12766
+ const promotionsQueryKeys = {
12767
+ list: (query2) => [
12768
+ PROMOTION_QUERY_KEY,
12769
+ query2 ? query2 : void 0
12770
+ ],
12771
+ detail: (id, query2) => [
12772
+ PROMOTION_QUERY_KEY,
12773
+ id,
12774
+ query2 ? query2 : void 0
12775
+ ]
12776
+ };
12777
+ const usePromotions = (query2, options) => {
12778
+ const { data, ...rest } = useQuery({
12779
+ queryKey: promotionsQueryKeys.list(query2),
12780
+ queryFn: async () => sdk.admin.promotion.list(query2),
12781
+ ...options
12782
+ });
12783
+ return { ...data, ...rest };
12784
+ };
12785
+ const Promotions = () => {
12786
+ const { id } = useParams();
12787
+ const {
12788
+ order: preview,
12789
+ isError: isPreviewError,
12790
+ error: previewError
12791
+ } = useOrderPreview(id, void 0);
12792
+ useInitiateOrderEdit({ preview });
12793
+ const { onCancel } = useCancelOrderEdit({ preview });
12794
+ if (isPreviewError) {
12795
+ throw previewError;
12796
+ }
12797
+ const isReady = !!preview;
12798
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12799
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12800
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12801
+ ] });
12802
+ };
12803
+ const PromotionForm = ({ preview }) => {
12804
+ const { items, shipping_methods } = preview;
12805
+ const [isSubmitting, setIsSubmitting] = useState(false);
12806
+ const [comboboxValue, setComboboxValue] = useState("");
12807
+ const { handleSuccess } = useRouteModal();
12808
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12809
+ const promoIds = getPromotionIds(items, shipping_methods);
12810
+ const { promotions, isPending, isError, error } = usePromotions(
12811
+ {
12812
+ id: promoIds
12813
+ },
12814
+ {
12815
+ enabled: !!promoIds.length
12816
+ }
12817
+ );
12818
+ const comboboxData = useComboboxData({
12819
+ queryKey: ["promotions", "combobox", promoIds],
12820
+ queryFn: async (params) => {
12821
+ return await sdk.admin.promotion.list({
12822
+ ...params,
12823
+ id: {
12824
+ $nin: promoIds
12825
+ }
12826
+ });
12827
+ },
12828
+ getOptions: (data) => {
12829
+ return data.promotions.map((promotion) => ({
12830
+ label: promotion.code,
12831
+ value: promotion.code
12832
+ }));
12833
+ }
12834
+ });
12835
+ const add = async (value) => {
12836
+ if (!value) {
12837
+ return;
12838
+ }
12839
+ addPromotions(
12840
+ {
12841
+ promo_codes: [value]
12842
+ },
12843
+ {
12844
+ onError: (e) => {
12845
+ toast.error(e.message);
12846
+ comboboxData.onSearchValueChange("");
12847
+ setComboboxValue("");
12848
+ },
12849
+ onSuccess: () => {
12850
+ comboboxData.onSearchValueChange("");
12851
+ setComboboxValue("");
12852
+ }
12853
+ }
12854
+ );
12855
+ };
12856
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12857
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12858
+ const onSubmit = async () => {
12859
+ setIsSubmitting(true);
12860
+ let requestSucceeded = false;
12861
+ await requestOrderEdit(void 0, {
12862
+ onError: (e) => {
12863
+ toast.error(e.message);
12864
+ },
12865
+ onSuccess: () => {
12866
+ requestSucceeded = true;
12867
+ }
12868
+ });
12869
+ if (!requestSucceeded) {
12870
+ setIsSubmitting(false);
12871
+ return;
12872
+ }
12873
+ await confirmOrderEdit(void 0, {
12874
+ onError: (e) => {
12875
+ toast.error(e.message);
12876
+ },
12877
+ onSuccess: () => {
12878
+ handleSuccess();
12879
+ },
12880
+ onSettled: () => {
12881
+ setIsSubmitting(false);
12882
+ }
12883
+ });
12884
+ };
12885
+ if (isError) {
12886
+ throw error;
12887
+ }
12888
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12889
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12890
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12891
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12892
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12893
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12894
+ ] }),
12895
+ /* @__PURE__ */ jsx(
12896
+ Combobox,
12897
+ {
12898
+ id: "promotion-combobox",
12899
+ "aria-describedby": "promotion-combobox-hint",
12900
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12901
+ fetchNextPage: comboboxData.fetchNextPage,
12902
+ options: comboboxData.options,
12903
+ onSearchValueChange: comboboxData.onSearchValueChange,
12904
+ searchValue: comboboxData.searchValue,
12905
+ disabled: comboboxData.disabled || isAddingPromotions,
12906
+ onChange: add,
12907
+ value: comboboxValue
12908
+ }
12909
+ )
12910
+ ] }),
12911
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12912
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12913
+ PromotionItem,
12914
+ {
12915
+ promotion,
12916
+ orderId: preview.id,
12917
+ isLoading: isPending
12918
+ },
12919
+ promotion.id
12920
+ )) })
12921
+ ] }) }),
12922
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12923
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12924
+ /* @__PURE__ */ jsx(
12925
+ Button,
12926
+ {
12927
+ size: "small",
12928
+ type: "submit",
12929
+ isLoading: isSubmitting || isAddingPromotions,
12930
+ children: "Save"
12931
+ }
12932
+ )
12933
+ ] }) })
12934
+ ] });
12935
+ };
12936
+ const PromotionItem = ({
12937
+ promotion,
12938
+ orderId,
12939
+ isLoading
12940
+ }) => {
12941
+ var _a;
12942
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12943
+ const onRemove = async () => {
12944
+ removePromotions(
12945
+ {
12946
+ promo_codes: [promotion.code]
12947
+ },
12948
+ {
12949
+ onError: (e) => {
12950
+ toast.error(e.message);
12951
+ }
12952
+ }
12953
+ );
12954
+ };
12955
+ const displayValue = getDisplayValue(promotion);
12956
+ return /* @__PURE__ */ jsxs(
12957
+ "div",
12958
+ {
12959
+ className: clx(
12960
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12961
+ {
12962
+ "animate-pulse": isLoading
12963
+ }
12964
+ ),
12965
+ children: [
12966
+ /* @__PURE__ */ jsxs("div", { children: [
12967
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12968
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12969
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12970
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12971
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12972
+ ] }),
12973
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12974
+ ] })
12975
+ ] }),
12976
+ /* @__PURE__ */ jsx(
12977
+ IconButton,
12978
+ {
12979
+ size: "small",
12980
+ type: "button",
12981
+ variant: "transparent",
12982
+ onClick: onRemove,
12983
+ isLoading: isPending || isLoading,
12984
+ children: /* @__PURE__ */ jsx(XMark, {})
12985
+ }
12986
+ )
12987
+ ]
12988
+ },
12989
+ promotion.id
12990
+ );
12991
+ };
12992
+ function getDisplayValue(promotion) {
12993
+ var _a, _b, _c, _d;
12994
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12995
+ if (!value) {
12996
+ return null;
12997
+ }
12998
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12999
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13000
+ if (!currency) {
13001
+ return null;
13002
+ }
13003
+ return getLocaleAmount(value, currency);
13004
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13005
+ return formatPercentage(value);
13006
+ }
13007
+ return null;
13008
+ }
13009
+ const formatter = new Intl.NumberFormat([], {
13010
+ style: "percent",
13011
+ minimumFractionDigits: 2
13012
+ });
13013
+ const formatPercentage = (value, isPercentageValue = false) => {
13014
+ let val = value || 0;
13015
+ if (!isPercentageValue) {
13016
+ val = val / 100;
13017
+ }
13018
+ return formatter.format(val);
13019
+ };
13020
+ function getPromotionIds(items, shippingMethods) {
13021
+ const promotionIds = /* @__PURE__ */ new Set();
13022
+ for (const item of items) {
13023
+ if (item.adjustments) {
13024
+ for (const adjustment of item.adjustments) {
13025
+ if (adjustment.promotion_id) {
13026
+ promotionIds.add(adjustment.promotion_id);
13027
+ }
13028
+ }
13029
+ }
13030
+ }
13031
+ for (const shippingMethod of shippingMethods) {
13032
+ if (shippingMethod.adjustments) {
13033
+ for (const adjustment of shippingMethod.adjustments) {
13034
+ if (adjustment.promotion_id) {
13035
+ promotionIds.add(adjustment.promotion_id);
13036
+ }
13037
+ }
13038
+ }
13039
+ }
13040
+ return Array.from(promotionIds);
13041
+ }
13042
+ const widgetModule = { widgets: [] };
13043
+ const routeModule = {
13044
+ routes: [
13045
13045
  {
13046
13046
  Component: List,
13047
13047
  path: "/draft-orders",
@@ -13060,8 +13060,8 @@ const routeModule = {
13060
13060
  loader,
13061
13061
  children: [
13062
13062
  {
13063
- Component: CustomItems,
13064
- path: "/draft-orders/:id/custom-items"
13063
+ Component: BillingAddress,
13064
+ path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
13066
  {
13067
13067
  Component: Email,
@@ -13071,17 +13071,13 @@ const routeModule = {
13071
13071
  Component: Items,
13072
13072
  path: "/draft-orders/:id/items"
13073
13073
  },
13074
- {
13075
- Component: BillingAddress,
13076
- path: "/draft-orders/:id/billing-address"
13077
- },
13078
13074
  {
13079
13075
  Component: Metadata,
13080
13076
  path: "/draft-orders/:id/metadata"
13081
13077
  },
13082
13078
  {
13083
- Component: Promotions,
13084
- path: "/draft-orders/:id/promotions"
13079
+ Component: CustomItems,
13080
+ path: "/draft-orders/:id/custom-items"
13085
13081
  },
13086
13082
  {
13087
13083
  Component: SalesChannel,
@@ -13098,6 +13094,10 @@ const routeModule = {
13098
13094
  {
13099
13095
  Component: TransferOwnership,
13100
13096
  path: "/draft-orders/:id/transfer-ownership"
13097
+ },
13098
+ {
13099
+ Component: Promotions,
13100
+ path: "/draft-orders/:id/promotions"
13101
13101
  }
13102
13102
  ]
13103
13103
  }