@medusajs/draft-order 2.11.3-preview-20251031120214 → 2.11.3-preview-20251031180155

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.
@@ -13,9 +13,9 @@ import { FormProvider, Controller, useFormContext, useFormState, useForm, useWat
13
13
  import { Slot, Collapsible, Accordion } from "radix-ui";
14
14
  import { ComboboxProvider, Combobox as Combobox$1, ComboboxDisclosure, ComboboxPopover, ComboboxItem, ComboboxItemCheck, ComboboxItemValue, Separator } from "@ariakit/react";
15
15
  import { matchSorter } from "match-sorter";
16
- import debounce from "lodash/debounce";
16
+ import debounce from "lodash.debounce";
17
17
  import Primitive from "@uiw/react-json-view";
18
- import { isEqual } from "lodash";
18
+ import isEqual from "lodash.isequal";
19
19
  function useQueryParams(keys, prefix) {
20
20
  const [params] = useSearchParams();
21
21
  const result = {};
@@ -9565,6 +9565,196 @@ 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;
9568
9758
  const CustomItems = () => {
9569
9759
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9570
9760
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9573,7 +9763,7 @@ const CustomItems = () => {
9573
9763
  };
9574
9764
  const CustomItemsForm = () => {
9575
9765
  const form = useForm({
9576
- resolver: zodResolver(schema$5)
9766
+ resolver: zodResolver(schema$4)
9577
9767
  });
9578
9768
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9579
9769
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9583,45 +9773,113 @@ const CustomItemsForm = () => {
9583
9773
  ] }) })
9584
9774
  ] }) });
9585
9775
  };
9586
- const schema$5 = objectType({
9776
+ const schema$4 = objectType({
9587
9777
  email: stringType().email()
9588
9778
  });
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);
9605
- }
9606
- };
9607
- const handleIncrement = () => {
9608
- const newValue = value + step;
9609
- if (max === void 0 || newValue <= max) {
9610
- onChange(newValue);
9611
- }
9612
- };
9613
- const handleDecrement = () => {
9614
- const newValue = value - step;
9615
- if (min === void 0 || newValue >= min) {
9616
- onChange(newValue);
9617
- }
9618
- };
9619
- return /* @__PURE__ */ jsxs(
9620
- "div",
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 },
9621
9808
  {
9622
- className: clx(
9623
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9624
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
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);
9863
+ }
9864
+ };
9865
+ const handleIncrement = () => {
9866
+ const newValue = value + step;
9867
+ if (max === void 0 || newValue <= max) {
9868
+ onChange(newValue);
9869
+ }
9870
+ };
9871
+ const handleDecrement = () => {
9872
+ const newValue = value - step;
9873
+ if (min === void 0 || newValue >= min) {
9874
+ onChange(newValue);
9875
+ }
9876
+ };
9877
+ return /* @__PURE__ */ jsxs(
9878
+ "div",
9879
+ {
9880
+ className: clx(
9881
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9882
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9625
9883
  {
9626
9884
  "h-7": size === "small",
9627
9885
  "h-8": size === "base"
@@ -10560,116 +10818,466 @@ const customItemSchema = objectType({
10560
10818
  quantity: numberType(),
10561
10819
  unit_price: unionType([numberType(), stringType()])
10562
10820
  });
10563
- const PROMOTION_QUERY_KEY = "promotions";
10564
- const promotionsQueryKeys = {
10565
- list: (query2) => [
10566
- PROMOTION_QUERY_KEY,
10567
- query2 ? query2 : void 0
10568
- ],
10569
- detail: (id, query2) => [
10570
- PROMOTION_QUERY_KEY,
10571
- id,
10572
- query2 ? query2 : void 0
10573
- ]
10574
- };
10575
- const usePromotions = (query2, options) => {
10576
- const { data, ...rest } = useQuery({
10577
- queryKey: promotionsQueryKeys.list(query2),
10578
- queryFn: async () => sdk.admin.promotion.list(query2),
10579
- ...options
10580
- });
10581
- return { ...data, ...rest };
10582
- };
10583
- const Promotions = () => {
10821
+ const InlineTip = forwardRef(
10822
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10824
+ return /* @__PURE__ */ jsxs(
10825
+ "div",
10826
+ {
10827
+ ref,
10828
+ className: clx(
10829
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10830
+ className
10831
+ ),
10832
+ ...props,
10833
+ children: [
10834
+ /* @__PURE__ */ jsx(
10835
+ "div",
10836
+ {
10837
+ role: "presentation",
10838
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10839
+ "bg-ui-tag-orange-icon": variant === "warning"
10840
+ })
10841
+ }
10842
+ ),
10843
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10844
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10845
+ labelValue,
10846
+ ":"
10847
+ ] }),
10848
+ " ",
10849
+ children
10850
+ ] })
10851
+ ]
10852
+ }
10853
+ );
10854
+ }
10855
+ );
10856
+ InlineTip.displayName = "InlineTip";
10857
+ const MetadataFieldSchema = objectType({
10858
+ key: stringType(),
10859
+ disabled: booleanType().optional(),
10860
+ value: anyType()
10861
+ });
10862
+ const MetadataSchema = objectType({
10863
+ metadata: arrayType(MetadataFieldSchema)
10864
+ });
10865
+ const Metadata = () => {
10584
10866
  const { id } = useParams();
10585
- const {
10586
- order: preview,
10587
- isError: isPreviewError,
10588
- error: previewError
10589
- } = useOrderPreview(id, void 0);
10590
- useInitiateOrderEdit({ preview });
10591
- const { onCancel } = useCancelOrderEdit({ preview });
10592
- if (isPreviewError) {
10593
- throw previewError;
10867
+ const { order, isPending, isError, error } = useOrder(id, {
10868
+ fields: "metadata"
10869
+ });
10870
+ if (isError) {
10871
+ throw error;
10594
10872
  }
10595
- const isReady = !!preview;
10596
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10597
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10598
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10873
+ const isReady = !isPending && !!order;
10874
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10875
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10876
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10877
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10878
+ ] }),
10879
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10599
10880
  ] });
10600
10881
  };
10601
- const PromotionForm = ({ preview }) => {
10602
- const { items, shipping_methods } = preview;
10603
- const [isSubmitting, setIsSubmitting] = useState(false);
10604
- const [comboboxValue, setComboboxValue] = useState("");
10882
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10883
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10884
+ const MetadataForm = ({ orderId, metadata }) => {
10605
10885
  const { handleSuccess } = useRouteModal();
10606
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10607
- const promoIds = getPromotionIds(items, shipping_methods);
10608
- const { promotions, isPending, isError, error } = usePromotions(
10609
- {
10610
- id: promoIds
10611
- },
10612
- {
10613
- enabled: !!promoIds.length
10614
- }
10615
- );
10616
- const comboboxData = useComboboxData({
10617
- queryKey: ["promotions", "combobox", promoIds],
10618
- queryFn: async (params) => {
10619
- return await sdk.admin.promotion.list({
10620
- ...params,
10621
- id: {
10622
- $nin: promoIds
10623
- }
10624
- });
10886
+ const hasUneditableRows = getHasUneditableRows(metadata);
10887
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10888
+ const form = useForm({
10889
+ defaultValues: {
10890
+ metadata: getDefaultValues(metadata)
10625
10891
  },
10626
- getOptions: (data) => {
10627
- return data.promotions.map((promotion) => ({
10628
- label: promotion.code,
10629
- value: promotion.code
10630
- }));
10631
- }
10892
+ resolver: zodResolver(MetadataSchema)
10632
10893
  });
10633
- const add = async (value) => {
10634
- if (!value) {
10635
- return;
10636
- }
10637
- addPromotions(
10894
+ const handleSubmit = form.handleSubmit(async (data) => {
10895
+ const parsedData = parseValues(data);
10896
+ await mutateAsync(
10638
10897
  {
10639
- promo_codes: [value]
10898
+ metadata: parsedData
10640
10899
  },
10641
10900
  {
10642
- onError: (e) => {
10643
- toast.error(e.message);
10644
- comboboxData.onSearchValueChange("");
10645
- setComboboxValue("");
10646
- },
10647
10901
  onSuccess: () => {
10648
- comboboxData.onSearchValueChange("");
10649
- setComboboxValue("");
10902
+ toast.success("Metadata updated");
10903
+ handleSuccess();
10904
+ },
10905
+ onError: (error) => {
10906
+ toast.error(error.message);
10650
10907
  }
10651
10908
  }
10652
10909
  );
10653
- };
10654
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10655
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10656
- const onSubmit = async () => {
10657
- setIsSubmitting(true);
10658
- let requestSucceeded = false;
10659
- await requestOrderEdit(void 0, {
10660
- onError: (e) => {
10661
- toast.error(e.message);
10662
- },
10663
- onSuccess: () => {
10664
- requestSucceeded = true;
10665
- }
10666
- });
10667
- if (!requestSucceeded) {
10668
- setIsSubmitting(false);
10669
- return;
10910
+ });
10911
+ const { fields, insert, remove } = useFieldArray({
10912
+ control: form.control,
10913
+ name: "metadata"
10914
+ });
10915
+ function deleteRow(index) {
10916
+ remove(index);
10917
+ if (fields.length === 1) {
10918
+ insert(0, {
10919
+ key: "",
10920
+ value: "",
10921
+ disabled: false
10922
+ });
10670
10923
  }
10671
- await confirmOrderEdit(void 0, {
10672
- onError: (e) => {
10924
+ }
10925
+ function insertRow(index, position) {
10926
+ insert(index + (position === "above" ? 0 : 1), {
10927
+ key: "",
10928
+ value: "",
10929
+ disabled: false
10930
+ });
10931
+ }
10932
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10933
+ KeyboundForm,
10934
+ {
10935
+ onSubmit: handleSubmit,
10936
+ className: "flex flex-1 flex-col overflow-hidden",
10937
+ children: [
10938
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10939
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10940
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10941
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10942
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10943
+ ] }),
10944
+ fields.map((field, index) => {
10945
+ const isDisabled = field.disabled || false;
10946
+ let placeholder = "-";
10947
+ if (typeof field.value === "object") {
10948
+ placeholder = "{ ... }";
10949
+ }
10950
+ if (Array.isArray(field.value)) {
10951
+ placeholder = "[ ... ]";
10952
+ }
10953
+ return /* @__PURE__ */ jsx(
10954
+ ConditionalTooltip,
10955
+ {
10956
+ showTooltip: isDisabled,
10957
+ content: "This row is disabled because it contains non-primitive data.",
10958
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10959
+ /* @__PURE__ */ jsxs(
10960
+ "div",
10961
+ {
10962
+ className: clx("grid grid-cols-2 divide-x", {
10963
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10964
+ }),
10965
+ children: [
10966
+ /* @__PURE__ */ jsx(
10967
+ Form$2.Field,
10968
+ {
10969
+ control: form.control,
10970
+ name: `metadata.${index}.key`,
10971
+ render: ({ field: field2 }) => {
10972
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10973
+ GridInput,
10974
+ {
10975
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10976
+ ...field2,
10977
+ disabled: isDisabled,
10978
+ placeholder: "Key"
10979
+ }
10980
+ ) }) });
10981
+ }
10982
+ }
10983
+ ),
10984
+ /* @__PURE__ */ jsx(
10985
+ Form$2.Field,
10986
+ {
10987
+ control: form.control,
10988
+ name: `metadata.${index}.value`,
10989
+ render: ({ field: { value, ...field2 } }) => {
10990
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10991
+ GridInput,
10992
+ {
10993
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10994
+ ...field2,
10995
+ value: isDisabled ? placeholder : value,
10996
+ disabled: isDisabled,
10997
+ placeholder: "Value"
10998
+ }
10999
+ ) }) });
11000
+ }
11001
+ }
11002
+ )
11003
+ ]
11004
+ }
11005
+ ),
11006
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11007
+ /* @__PURE__ */ jsx(
11008
+ DropdownMenu.Trigger,
11009
+ {
11010
+ className: clx(
11011
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11012
+ {
11013
+ hidden: isDisabled
11014
+ }
11015
+ ),
11016
+ disabled: isDisabled,
11017
+ asChild: true,
11018
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11019
+ }
11020
+ ),
11021
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11022
+ /* @__PURE__ */ jsxs(
11023
+ DropdownMenu.Item,
11024
+ {
11025
+ className: "gap-x-2",
11026
+ onClick: () => insertRow(index, "above"),
11027
+ children: [
11028
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11029
+ "Insert row above"
11030
+ ]
11031
+ }
11032
+ ),
11033
+ /* @__PURE__ */ jsxs(
11034
+ DropdownMenu.Item,
11035
+ {
11036
+ className: "gap-x-2",
11037
+ onClick: () => insertRow(index, "below"),
11038
+ children: [
11039
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11040
+ "Insert row below"
11041
+ ]
11042
+ }
11043
+ ),
11044
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11045
+ /* @__PURE__ */ jsxs(
11046
+ DropdownMenu.Item,
11047
+ {
11048
+ className: "gap-x-2",
11049
+ onClick: () => deleteRow(index),
11050
+ children: [
11051
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11052
+ "Delete row"
11053
+ ]
11054
+ }
11055
+ )
11056
+ ] })
11057
+ ] })
11058
+ ] })
11059
+ },
11060
+ field.id
11061
+ );
11062
+ })
11063
+ ] }),
11064
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11065
+ ] }),
11066
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11067
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11068
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11069
+ ] }) })
11070
+ ]
11071
+ }
11072
+ ) });
11073
+ };
11074
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11075
+ return /* @__PURE__ */ jsx(
11076
+ "input",
11077
+ {
11078
+ ref,
11079
+ ...props,
11080
+ autoComplete: "off",
11081
+ className: clx(
11082
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11083
+ className
11084
+ )
11085
+ }
11086
+ );
11087
+ });
11088
+ GridInput.displayName = "MetadataForm.GridInput";
11089
+ const PlaceholderInner = () => {
11090
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11091
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11092
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11093
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11094
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11095
+ ] }) })
11096
+ ] });
11097
+ };
11098
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11099
+ function getDefaultValues(metadata) {
11100
+ if (!metadata || !Object.keys(metadata).length) {
11101
+ return [
11102
+ {
11103
+ key: "",
11104
+ value: "",
11105
+ disabled: false
11106
+ }
11107
+ ];
11108
+ }
11109
+ return Object.entries(metadata).map(([key, value]) => {
11110
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11111
+ return {
11112
+ key,
11113
+ value,
11114
+ disabled: true
11115
+ };
11116
+ }
11117
+ let stringValue = value;
11118
+ if (typeof value !== "string") {
11119
+ stringValue = JSON.stringify(value);
11120
+ }
11121
+ return {
11122
+ key,
11123
+ value: stringValue,
11124
+ original_key: key
11125
+ };
11126
+ });
11127
+ }
11128
+ function parseValues(values) {
11129
+ const metadata = values.metadata;
11130
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11131
+ if (isEmpty) {
11132
+ return null;
11133
+ }
11134
+ const update = {};
11135
+ metadata.forEach((field) => {
11136
+ let key = field.key;
11137
+ let value = field.value;
11138
+ const disabled = field.disabled;
11139
+ if (!key || !value) {
11140
+ return;
11141
+ }
11142
+ if (disabled) {
11143
+ update[key] = value;
11144
+ return;
11145
+ }
11146
+ key = key.trim();
11147
+ value = value.trim();
11148
+ if (value === "true") {
11149
+ update[key] = true;
11150
+ } else if (value === "false") {
11151
+ update[key] = false;
11152
+ } else {
11153
+ const parsedNumber = parseFloat(value);
11154
+ if (!isNaN(parsedNumber)) {
11155
+ update[key] = parsedNumber;
11156
+ } else {
11157
+ update[key] = value;
11158
+ }
11159
+ }
11160
+ });
11161
+ return update;
11162
+ }
11163
+ function getHasUneditableRows(metadata) {
11164
+ if (!metadata) {
11165
+ return false;
11166
+ }
11167
+ return Object.values(metadata).some(
11168
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11169
+ );
11170
+ }
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) => {
10673
11281
  toast.error(e.message);
10674
11282
  },
10675
11283
  onSuccess: () => {
@@ -10699,493 +11307,143 @@ const PromotionForm = ({ preview }) => {
10699
11307
  fetchNextPage: comboboxData.fetchNextPage,
10700
11308
  options: comboboxData.options,
10701
11309
  onSearchValueChange: comboboxData.onSearchValueChange,
10702
- searchValue: comboboxData.searchValue,
10703
- disabled: comboboxData.disabled || isAddingPromotions,
10704
- onChange: add,
10705
- value: comboboxValue
10706
- }
10707
- )
10708
- ] }),
10709
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10710
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10711
- PromotionItem,
10712
- {
10713
- promotion,
10714
- orderId: preview.id,
10715
- isLoading: isPending
10716
- },
10717
- promotion.id
10718
- )) })
10719
- ] }) }),
10720
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10721
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10722
- /* @__PURE__ */ jsx(
10723
- Button,
10724
- {
10725
- size: "small",
10726
- type: "submit",
10727
- isLoading: isSubmitting || isAddingPromotions,
10728
- children: "Save"
10729
- }
10730
- )
10731
- ] }) })
10732
- ] });
10733
- };
10734
- const PromotionItem = ({
10735
- promotion,
10736
- orderId,
10737
- isLoading
10738
- }) => {
10739
- var _a;
10740
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10741
- const onRemove = async () => {
10742
- removePromotions(
10743
- {
10744
- promo_codes: [promotion.code]
10745
- },
10746
- {
10747
- onError: (e) => {
10748
- toast.error(e.message);
10749
- }
10750
- }
10751
- );
10752
- };
10753
- const displayValue = getDisplayValue(promotion);
10754
- return /* @__PURE__ */ jsxs(
10755
- "div",
10756
- {
10757
- className: clx(
10758
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10759
- {
10760
- "animate-pulse": isLoading
10761
- }
10762
- ),
10763
- children: [
10764
- /* @__PURE__ */ jsxs("div", { children: [
10765
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10766
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10767
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
10768
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
10769
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
10770
- ] }),
10771
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10772
- ] })
10773
- ] }),
10774
- /* @__PURE__ */ jsx(
10775
- IconButton,
10776
- {
10777
- size: "small",
10778
- type: "button",
10779
- variant: "transparent",
10780
- onClick: onRemove,
10781
- isLoading: isPending || isLoading,
10782
- children: /* @__PURE__ */ jsx(XMark, {})
10783
- }
10784
- )
10785
- ]
10786
- },
10787
- promotion.id
10788
- );
10789
- };
10790
- function getDisplayValue(promotion) {
10791
- var _a, _b, _c, _d;
10792
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10793
- if (!value) {
10794
- return null;
10795
- }
10796
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10797
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10798
- if (!currency) {
10799
- return null;
10800
- }
10801
- return getLocaleAmount(value, currency);
10802
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10803
- return formatPercentage(value);
10804
- }
10805
- return null;
10806
- }
10807
- const formatter = new Intl.NumberFormat([], {
10808
- style: "percent",
10809
- minimumFractionDigits: 2
10810
- });
10811
- const formatPercentage = (value, isPercentageValue = false) => {
10812
- let val = value || 0;
10813
- if (!isPercentageValue) {
10814
- val = val / 100;
10815
- }
10816
- return formatter.format(val);
10817
- };
10818
- function getPromotionIds(items, shippingMethods) {
10819
- const promotionIds = /* @__PURE__ */ new Set();
10820
- for (const item of items) {
10821
- if (item.adjustments) {
10822
- for (const adjustment of item.adjustments) {
10823
- if (adjustment.promotion_id) {
10824
- promotionIds.add(adjustment.promotion_id);
10825
- }
10826
- }
10827
- }
10828
- }
10829
- for (const shippingMethod of shippingMethods) {
10830
- if (shippingMethod.adjustments) {
10831
- for (const adjustment of shippingMethod.adjustments) {
10832
- if (adjustment.promotion_id) {
10833
- promotionIds.add(adjustment.promotion_id);
10834
- }
10835
- }
10836
- }
10837
- }
10838
- return Array.from(promotionIds);
10839
- }
10840
- const InlineTip = forwardRef(
10841
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10842
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10843
- return /* @__PURE__ */ jsxs(
10844
- "div",
10845
- {
10846
- ref,
10847
- className: clx(
10848
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10849
- className
10850
- ),
10851
- ...props,
10852
- children: [
10853
- /* @__PURE__ */ jsx(
10854
- "div",
10855
- {
10856
- role: "presentation",
10857
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10858
- "bg-ui-tag-orange-icon": variant === "warning"
10859
- })
10860
- }
10861
- ),
10862
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10863
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10864
- labelValue,
10865
- ":"
10866
- ] }),
10867
- " ",
10868
- children
10869
- ] })
10870
- ]
10871
- }
10872
- );
10873
- }
10874
- );
10875
- InlineTip.displayName = "InlineTip";
10876
- const MetadataFieldSchema = objectType({
10877
- key: stringType(),
10878
- disabled: booleanType().optional(),
10879
- value: anyType()
10880
- });
10881
- const MetadataSchema = objectType({
10882
- metadata: arrayType(MetadataFieldSchema)
10883
- });
10884
- const Metadata = () => {
10885
- const { id } = useParams();
10886
- const { order, isPending, isError, error } = useOrder(id, {
10887
- fields: "metadata"
10888
- });
10889
- if (isError) {
10890
- throw error;
10891
- }
10892
- const isReady = !isPending && !!order;
10893
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10894
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10895
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10896
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10897
- ] }),
10898
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
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
+ ] }) })
10899
11340
  ] });
10900
11341
  };
10901
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10902
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10903
- const MetadataForm = ({ orderId, metadata }) => {
10904
- const { handleSuccess } = useRouteModal();
10905
- const hasUneditableRows = getHasUneditableRows(metadata);
10906
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10907
- const form = useForm({
10908
- defaultValues: {
10909
- metadata: getDefaultValues(metadata)
10910
- },
10911
- resolver: zodResolver(MetadataSchema)
10912
- });
10913
- const handleSubmit = form.handleSubmit(async (data) => {
10914
- const parsedData = parseValues(data);
10915
- await mutateAsync(
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(
10916
11351
  {
10917
- metadata: parsedData
11352
+ promo_codes: [promotion.code]
10918
11353
  },
10919
11354
  {
10920
- onSuccess: () => {
10921
- toast.success("Metadata updated");
10922
- handleSuccess();
10923
- },
10924
- onError: (error) => {
10925
- toast.error(error.message);
11355
+ onError: (e) => {
11356
+ toast.error(e.message);
10926
11357
  }
10927
11358
  }
10928
11359
  );
10929
- });
10930
- const { fields, insert, remove } = useFieldArray({
10931
- control: form.control,
10932
- name: "metadata"
10933
- });
10934
- function deleteRow(index) {
10935
- remove(index);
10936
- if (fields.length === 1) {
10937
- insert(0, {
10938
- key: "",
10939
- value: "",
10940
- disabled: false
10941
- });
10942
- }
10943
- }
10944
- function insertRow(index, position) {
10945
- insert(index + (position === "above" ? 0 : 1), {
10946
- key: "",
10947
- value: "",
10948
- disabled: false
10949
- });
10950
- }
10951
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10952
- KeyboundForm,
11360
+ };
11361
+ const displayValue = getDisplayValue(promotion);
11362
+ return /* @__PURE__ */ jsxs(
11363
+ "div",
10953
11364
  {
10954
- onSubmit: handleSubmit,
10955
- className: "flex flex-1 flex-col overflow-hidden",
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
+ ),
10956
11371
  children: [
10957
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10958
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10959
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10960
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10961
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
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: "·" })
10962
11378
  ] }),
10963
- fields.map((field, index) => {
10964
- const isDisabled = field.disabled || false;
10965
- let placeholder = "-";
10966
- if (typeof field.value === "object") {
10967
- placeholder = "{ ... }";
10968
- }
10969
- if (Array.isArray(field.value)) {
10970
- placeholder = "[ ... ]";
10971
- }
10972
- return /* @__PURE__ */ jsx(
10973
- ConditionalTooltip,
10974
- {
10975
- showTooltip: isDisabled,
10976
- content: "This row is disabled because it contains non-primitive data.",
10977
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10978
- /* @__PURE__ */ jsxs(
10979
- "div",
10980
- {
10981
- className: clx("grid grid-cols-2 divide-x", {
10982
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10983
- }),
10984
- children: [
10985
- /* @__PURE__ */ jsx(
10986
- Form$2.Field,
10987
- {
10988
- control: form.control,
10989
- name: `metadata.${index}.key`,
10990
- render: ({ field: field2 }) => {
10991
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10992
- GridInput,
10993
- {
10994
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10995
- ...field2,
10996
- disabled: isDisabled,
10997
- placeholder: "Key"
10998
- }
10999
- ) }) });
11000
- }
11001
- }
11002
- ),
11003
- /* @__PURE__ */ jsx(
11004
- Form$2.Field,
11005
- {
11006
- control: form.control,
11007
- name: `metadata.${index}.value`,
11008
- render: ({ field: { value, ...field2 } }) => {
11009
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11010
- GridInput,
11011
- {
11012
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11013
- ...field2,
11014
- value: isDisabled ? placeholder : value,
11015
- disabled: isDisabled,
11016
- placeholder: "Value"
11017
- }
11018
- ) }) });
11019
- }
11020
- }
11021
- )
11022
- ]
11023
- }
11024
- ),
11025
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11026
- /* @__PURE__ */ jsx(
11027
- DropdownMenu.Trigger,
11028
- {
11029
- className: clx(
11030
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11031
- {
11032
- hidden: isDisabled
11033
- }
11034
- ),
11035
- disabled: isDisabled,
11036
- asChild: true,
11037
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11038
- }
11039
- ),
11040
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11041
- /* @__PURE__ */ jsxs(
11042
- DropdownMenu.Item,
11043
- {
11044
- className: "gap-x-2",
11045
- onClick: () => insertRow(index, "above"),
11046
- children: [
11047
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11048
- "Insert row above"
11049
- ]
11050
- }
11051
- ),
11052
- /* @__PURE__ */ jsxs(
11053
- DropdownMenu.Item,
11054
- {
11055
- className: "gap-x-2",
11056
- onClick: () => insertRow(index, "below"),
11057
- children: [
11058
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11059
- "Insert row below"
11060
- ]
11061
- }
11062
- ),
11063
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11064
- /* @__PURE__ */ jsxs(
11065
- DropdownMenu.Item,
11066
- {
11067
- className: "gap-x-2",
11068
- onClick: () => deleteRow(index),
11069
- children: [
11070
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11071
- "Delete row"
11072
- ]
11073
- }
11074
- )
11075
- ] })
11076
- ] })
11077
- ] })
11078
- },
11079
- field.id
11080
- );
11081
- })
11082
- ] }),
11083
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11379
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11380
+ ] })
11084
11381
  ] }),
11085
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11086
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11087
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11088
- ] }) })
11089
- ]
11090
- }
11091
- ) });
11092
- };
11093
- const GridInput = forwardRef(({ className, ...props }, ref) => {
11094
- return /* @__PURE__ */ jsx(
11095
- "input",
11096
- {
11097
- ref,
11098
- ...props,
11099
- autoComplete: "off",
11100
- className: clx(
11101
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11102
- className
11103
- )
11104
- }
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
11105
11396
  );
11106
- });
11107
- GridInput.displayName = "MetadataForm.GridInput";
11108
- const PlaceholderInner = () => {
11109
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11110
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11111
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11112
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11113
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11114
- ] }) })
11115
- ] });
11116
11397
  };
11117
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11118
- function getDefaultValues(metadata) {
11119
- if (!metadata || !Object.keys(metadata).length) {
11120
- return [
11121
- {
11122
- key: "",
11123
- value: "",
11124
- disabled: false
11125
- }
11126
- ];
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;
11127
11403
  }
11128
- return Object.entries(metadata).map(([key, value]) => {
11129
- if (!EDITABLE_TYPES.includes(typeof value)) {
11130
- return {
11131
- key,
11132
- value,
11133
- disabled: true
11134
- };
11135
- }
11136
- let stringValue = value;
11137
- if (typeof value !== "string") {
11138
- stringValue = JSON.stringify(value);
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;
11139
11408
  }
11140
- return {
11141
- key,
11142
- value: stringValue,
11143
- original_key: key
11144
- };
11145
- });
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;
11146
11414
  }
11147
- function parseValues(values) {
11148
- const metadata = values.metadata;
11149
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11150
- if (isEmpty) {
11151
- return null;
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;
11152
11423
  }
11153
- const update = {};
11154
- metadata.forEach((field) => {
11155
- let key = field.key;
11156
- let value = field.value;
11157
- const disabled = field.disabled;
11158
- if (!key || !value) {
11159
- return;
11160
- }
11161
- if (disabled) {
11162
- update[key] = value;
11163
- return;
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
+ }
11164
11435
  }
11165
- key = key.trim();
11166
- value = value.trim();
11167
- if (value === "true") {
11168
- update[key] = true;
11169
- } else if (value === "false") {
11170
- update[key] = false;
11171
- } else {
11172
- const parsedNumber = parseFloat(value);
11173
- if (!isNaN(parsedNumber)) {
11174
- update[key] = parsedNumber;
11175
- } else {
11176
- update[key] = value;
11436
+ }
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
+ }
11177
11443
  }
11178
11444
  }
11179
- });
11180
- return update;
11181
- }
11182
- function getHasUneditableRows(metadata) {
11183
- if (!metadata) {
11184
- return false;
11185
11445
  }
11186
- return Object.values(metadata).some(
11187
- (value) => !EDITABLE_TYPES.includes(typeof value)
11188
- );
11446
+ return Array.from(promotionIds);
11189
11447
  }
11190
11448
  const SalesChannel = () => {
11191
11449
  const { id } = useParams();
@@ -11215,7 +11473,7 @@ const SalesChannelForm = ({ order }) => {
11215
11473
  defaultValues: {
11216
11474
  sales_channel_id: order.sales_channel_id || ""
11217
11475
  },
11218
- resolver: zodResolver(schema$4)
11476
+ resolver: zodResolver(schema$2)
11219
11477
  });
11220
11478
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11221
11479
  const { handleSuccess } = useRouteModal();
@@ -11290,7 +11548,7 @@ const SalesChannelField = ({ control, order }) => {
11290
11548
  }
11291
11549
  );
11292
11550
  };
11293
- const schema$4 = objectType({
11551
+ const schema$2 = objectType({
11294
11552
  sales_channel_id: stringType().min(1)
11295
11553
  });
11296
11554
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -11318,7 +11576,7 @@ const Shipping = () => {
11318
11576
  const isReady = preview && !isPreviewPending && order && !isPending;
11319
11577
  return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11320
11578
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11321
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11579
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11322
11580
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11323
11581
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11324
11582
  ] }) }) }),
@@ -11405,14 +11663,14 @@ const ShippingForm = ({ preview, order }) => {
11405
11663
  return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11406
11664
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11407
11665
  /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11408
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11666
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11409
11667
  /* @__PURE__ */ jsxs("div", { children: [
11410
11668
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11411
11669
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11412
11670
  ] }),
11413
11671
  /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11414
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11415
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11672
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11673
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11416
11674
  /* @__PURE__ */ jsx(
11417
11675
  Text,
11418
11676
  {
@@ -11454,8 +11712,8 @@ const ShippingForm = ({ preview, order }) => {
11454
11712
  value: profile.id,
11455
11713
  className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11456
11714
  children: [
11457
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11458
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11715
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11716
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11459
11717
  /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11460
11718
  IconButton,
11461
11719
  {
@@ -11463,12 +11721,12 @@ const ShippingForm = ({ preview, order }) => {
11463
11721
  variant: "transparent",
11464
11722
  className: "group/trigger",
11465
11723
  disabled: !hasItems,
11466
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11724
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11467
11725
  }
11468
11726
  ) }),
11469
11727
  !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11470
- /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11471
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11728
+ /* @__PURE__ */ jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11729
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col", children: [
11472
11730
  /* @__PURE__ */ jsx(
11473
11731
  Text,
11474
11732
  {
@@ -11492,7 +11750,7 @@ const ShippingForm = ({ preview, order }) => {
11492
11750
  }
11493
11751
  )
11494
11752
  ] })
11495
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11753
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11496
11754
  /* @__PURE__ */ jsx(
11497
11755
  Tooltip,
11498
11756
  {
@@ -11509,7 +11767,7 @@ const ShippingForm = ({ preview, order }) => {
11509
11767
  children: /* @__PURE__ */ jsxs(
11510
11768
  Badge,
11511
11769
  {
11512
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11770
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11513
11771
  size: "xsmall",
11514
11772
  children: [
11515
11773
  /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
@@ -11534,7 +11792,7 @@ const ShippingForm = ({ preview, order }) => {
11534
11792
  children: /* @__PURE__ */ jsxs(
11535
11793
  Badge,
11536
11794
  {
11537
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11795
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11538
11796
  size: "xsmall",
11539
11797
  children: [
11540
11798
  /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
@@ -11547,7 +11805,7 @@ const ShippingForm = ({ preview, order }) => {
11547
11805
  /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11548
11806
  Badge,
11549
11807
  {
11550
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11808
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11551
11809
  size: "xsmall",
11552
11810
  children: [
11553
11811
  /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
@@ -11618,17 +11876,17 @@ const ShippingForm = ({ preview, order }) => {
11618
11876
  /* @__PURE__ */ jsxs(
11619
11877
  "div",
11620
11878
  {
11621
- className: "px-3 flex items-center gap-x-3",
11879
+ className: "flex items-center gap-x-3 px-3",
11622
11880
  children: [
11623
- /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11881
+ /* @__PURE__ */ jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsx(
11624
11882
  Divider,
11625
11883
  {
11626
11884
  variant: "dashed",
11627
11885
  orientation: "vertical"
11628
11886
  }
11629
11887
  ) }),
11630
- /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11631
- /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11888
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
11889
+ /* @__PURE__ */ jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11632
11890
  Text,
11633
11891
  {
11634
11892
  size: "small",
@@ -11809,7 +12067,7 @@ const ShippingProfileForm = ({
11809
12067
  onSubmit,
11810
12068
  children: [
11811
12069
  /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11812
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12070
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11813
12071
  /* @__PURE__ */ jsxs("div", { children: [
11814
12072
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11815
12073
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
@@ -11882,14 +12140,14 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
11882
12140
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11883
12141
  ] }) }),
11884
12142
  /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11885
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12143
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
11886
12144
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
11887
12145
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
11888
12146
  ] }),
11889
12147
  /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
11890
12148
  "div",
11891
12149
  {
11892
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12150
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
11893
12151
  children: [
11894
12152
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11895
12153
  /* @__PURE__ */ jsx(
@@ -11942,7 +12200,7 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
11942
12200
  ]
11943
12201
  },
11944
12202
  item.id
11945
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12203
+ )) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
11946
12204
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11947
12205
  /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
11948
12206
  'No items found for "',
@@ -12132,7 +12390,7 @@ const ShippingAddressForm = ({ order }) => {
12132
12390
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12133
12391
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12134
12392
  },
12135
- resolver: zodResolver(schema$3)
12393
+ resolver: zodResolver(schema$1)
12136
12394
  });
12137
12395
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12138
12396
  const { handleSuccess } = useRouteModal();
@@ -12302,7 +12560,7 @@ const ShippingAddressForm = ({ order }) => {
12302
12560
  }
12303
12561
  ) });
12304
12562
  };
12305
- const schema$3 = addressSchema;
12563
+ const schema$1 = addressSchema;
12306
12564
  const TransferOwnership = () => {
12307
12565
  const { id } = useParams();
12308
12566
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12326,7 +12584,7 @@ const TransferOwnershipForm = ({ order }) => {
12326
12584
  defaultValues: {
12327
12585
  customer_id: order.customer_id || ""
12328
12586
  },
12329
- resolver: zodResolver(schema$2)
12587
+ resolver: zodResolver(schema)
12330
12588
  });
12331
12589
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12332
12590
  const { handleSuccess } = useRouteModal();
@@ -12713,330 +12971,72 @@ const Illustration = () => {
12713
12971
  stroke: "#A1A1AA",
12714
12972
  strokeWidth: "1.5",
12715
12973
  strokeLinecap: "round",
12716
- strokeLinejoin: "round"
12717
- }
12718
- ) }),
12719
- /* @__PURE__ */ jsxs("defs", { children: [
12720
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12721
- "rect",
12722
- {
12723
- width: "12",
12724
- height: "12",
12725
- fill: "white",
12726
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12727
- }
12728
- ) }),
12729
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12730
- "rect",
12731
- {
12732
- width: "12",
12733
- height: "12",
12734
- fill: "white",
12735
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12736
- }
12737
- ) }),
12738
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12739
- "rect",
12740
- {
12741
- width: "12",
12742
- height: "12",
12743
- fill: "white",
12744
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12745
- }
12746
- ) }),
12747
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12748
- "rect",
12749
- {
12750
- width: "12",
12751
- height: "12",
12752
- fill: "white",
12753
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12754
- }
12755
- ) }),
12756
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12757
- "rect",
12758
- {
12759
- width: "12",
12760
- height: "12",
12761
- fill: "white",
12762
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12763
- }
12764
- ) }),
12765
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12766
- "rect",
12767
- {
12768
- width: "12",
12769
- height: "12",
12770
- fill: "white",
12771
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12772
- }
12773
- ) })
12774
- ] })
12775
- ]
12776
- }
12777
- );
12778
- };
12779
- const schema$2 = objectType({
12780
- customer_id: stringType().min(1)
12781
- });
12782
- const Email = () => {
12783
- const { id } = useParams();
12784
- const { order, isPending, isError, error } = useOrder(id, {
12785
- fields: "+email"
12786
- });
12787
- if (isError) {
12788
- throw error;
12789
- }
12790
- const isReady = !isPending && !!order;
12791
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12792
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12793
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12794
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12795
- ] }),
12796
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12797
- ] });
12798
- };
12799
- const EmailForm = ({ order }) => {
12800
- const form = useForm({
12801
- defaultValues: {
12802
- email: order.email ?? ""
12803
- },
12804
- resolver: zodResolver(schema$1)
12805
- });
12806
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12807
- const { handleSuccess } = useRouteModal();
12808
- const onSubmit = form.handleSubmit(async (data) => {
12809
- await mutateAsync(
12810
- { email: data.email },
12811
- {
12812
- onSuccess: () => {
12813
- handleSuccess();
12814
- },
12815
- onError: (error) => {
12816
- toast.error(error.message);
12817
- }
12818
- }
12819
- );
12820
- });
12821
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12822
- KeyboundForm,
12823
- {
12824
- className: "flex flex-1 flex-col overflow-hidden",
12825
- onSubmit,
12826
- children: [
12827
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
12828
- Form$2.Field,
12829
- {
12830
- control: form.control,
12831
- name: "email",
12832
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12833
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
12834
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12835
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12836
- ] })
12974
+ strokeLinejoin: "round"
12837
12975
  }
12838
12976
  ) }),
12839
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12840
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12841
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12842
- ] }) })
12843
- ]
12844
- }
12845
- ) });
12846
- };
12847
- const schema$1 = objectType({
12848
- email: stringType().email()
12849
- });
12850
- const BillingAddress = () => {
12851
- const { id } = useParams();
12852
- const { order, isPending, isError, error } = useOrder(id, {
12853
- fields: "+billing_address"
12854
- });
12855
- if (isError) {
12856
- throw error;
12857
- }
12858
- const isReady = !isPending && !!order;
12859
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12860
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12861
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12862
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12863
- ] }),
12864
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12865
- ] });
12866
- };
12867
- const BillingAddressForm = ({ order }) => {
12868
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12869
- const form = useForm({
12870
- defaultValues: {
12871
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12872
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12873
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12874
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12875
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12876
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12877
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12878
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12879
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12880
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12881
- },
12882
- resolver: zodResolver(schema)
12883
- });
12884
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12885
- const { handleSuccess } = useRouteModal();
12886
- const onSubmit = form.handleSubmit(async (data) => {
12887
- await mutateAsync(
12888
- { billing_address: data },
12889
- {
12890
- onSuccess: () => {
12891
- handleSuccess();
12892
- },
12893
- onError: (error) => {
12894
- toast.error(error.message);
12895
- }
12896
- }
12897
- );
12898
- });
12899
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12900
- KeyboundForm,
12901
- {
12902
- className: "flex flex-1 flex-col overflow-hidden",
12903
- onSubmit,
12904
- children: [
12905
- /* @__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: [
12906
- /* @__PURE__ */ jsx(
12907
- Form$2.Field,
12977
+ /* @__PURE__ */ jsxs("defs", { children: [
12978
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12979
+ "rect",
12908
12980
  {
12909
- control: form.control,
12910
- name: "country_code",
12911
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12912
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12913
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12914
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12915
- ] })
12981
+ width: "12",
12982
+ height: "12",
12983
+ fill: "white",
12984
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12916
12985
  }
12917
- ),
12918
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12919
- /* @__PURE__ */ jsx(
12920
- Form$2.Field,
12921
- {
12922
- control: form.control,
12923
- name: "first_name",
12924
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12925
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12926
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12927
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12928
- ] })
12929
- }
12930
- ),
12931
- /* @__PURE__ */ jsx(
12932
- Form$2.Field,
12933
- {
12934
- control: form.control,
12935
- name: "last_name",
12936
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12937
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12938
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12939
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12940
- ] })
12941
- }
12942
- )
12943
- ] }),
12944
- /* @__PURE__ */ jsx(
12945
- Form$2.Field,
12986
+ ) }),
12987
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12988
+ "rect",
12946
12989
  {
12947
- control: form.control,
12948
- name: "company",
12949
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12950
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12951
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12952
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
- ] })
12990
+ width: "12",
12991
+ height: "12",
12992
+ fill: "white",
12993
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12954
12994
  }
12955
- ),
12956
- /* @__PURE__ */ jsx(
12957
- Form$2.Field,
12995
+ ) }),
12996
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12997
+ "rect",
12958
12998
  {
12959
- control: form.control,
12960
- name: "address_1",
12961
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12962
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12963
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12964
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12965
- ] })
12999
+ width: "12",
13000
+ height: "12",
13001
+ fill: "white",
13002
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12966
13003
  }
12967
- ),
12968
- /* @__PURE__ */ jsx(
12969
- Form$2.Field,
13004
+ ) }),
13005
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13006
+ "rect",
12970
13007
  {
12971
- control: form.control,
12972
- name: "address_2",
12973
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12974
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12975
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12976
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12977
- ] })
13008
+ width: "12",
13009
+ height: "12",
13010
+ fill: "white",
13011
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12978
13012
  }
12979
- ),
12980
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12981
- /* @__PURE__ */ jsx(
12982
- Form$2.Field,
12983
- {
12984
- control: form.control,
12985
- name: "postal_code",
12986
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12987
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12988
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12989
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12990
- ] })
12991
- }
12992
- ),
12993
- /* @__PURE__ */ jsx(
12994
- Form$2.Field,
12995
- {
12996
- control: form.control,
12997
- name: "city",
12998
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12999
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13000
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13001
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13002
- ] })
13003
- }
13004
- )
13005
- ] }),
13006
- /* @__PURE__ */ jsx(
13007
- Form$2.Field,
13013
+ ) }),
13014
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13015
+ "rect",
13008
13016
  {
13009
- control: form.control,
13010
- name: "province",
13011
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13013
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
- ] })
13017
+ width: "12",
13018
+ height: "12",
13019
+ fill: "white",
13020
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13016
13021
  }
13017
- ),
13018
- /* @__PURE__ */ jsx(
13019
- Form$2.Field,
13022
+ ) }),
13023
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13024
+ "rect",
13020
13025
  {
13021
- control: form.control,
13022
- name: "phone",
13023
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13024
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13025
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13026
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13027
- ] })
13026
+ width: "12",
13027
+ height: "12",
13028
+ fill: "white",
13029
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13028
13030
  }
13029
- )
13030
- ] }) }),
13031
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13033
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13034
- ] }) })
13031
+ ) })
13032
+ ] })
13035
13033
  ]
13036
13034
  }
13037
- ) });
13035
+ );
13038
13036
  };
13039
- const schema = addressSchema;
13037
+ const schema = objectType({
13038
+ customer_id: stringType().min(1)
13039
+ });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13057,22 +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
+ },
13060
13064
  {
13061
13065
  Component: CustomItems,
13062
13066
  path: "/draft-orders/:id/custom-items"
13063
13067
  },
13064
13068
  {
13065
- Component: Items,
13066
- path: "/draft-orders/:id/items"
13069
+ Component: Email,
13070
+ path: "/draft-orders/:id/email"
13067
13071
  },
13068
13072
  {
13069
- Component: Promotions,
13070
- path: "/draft-orders/:id/promotions"
13073
+ Component: Items,
13074
+ path: "/draft-orders/:id/items"
13071
13075
  },
13072
13076
  {
13073
13077
  Component: Metadata,
13074
13078
  path: "/draft-orders/:id/metadata"
13075
13079
  },
13080
+ {
13081
+ Component: Promotions,
13082
+ path: "/draft-orders/:id/promotions"
13083
+ },
13076
13084
  {
13077
13085
  Component: SalesChannel,
13078
13086
  path: "/draft-orders/:id/sales-channel"
@@ -13088,14 +13096,6 @@ const routeModule = {
13088
13096
  {
13089
13097
  Component: TransferOwnership,
13090
13098
  path: "/draft-orders/:id/transfer-ownership"
13091
- },
13092
- {
13093
- Component: Email,
13094
- path: "/draft-orders/:id/email"
13095
- },
13096
- {
13097
- Component: BillingAddress,
13098
- path: "/draft-orders/:id/billing-address"
13099
13099
  }
13100
13100
  ]
13101
13101
  }