@medusajs/draft-order 2.10.3-preview-20250914090153 → 2.10.3-preview-20250914120159

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.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9567,6 +9567,217 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
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;
9579
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
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 })
9585
+ ] });
9586
+ };
9587
+ const BillingAddressForm = ({ order }) => {
9588
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
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
+ },
9602
+ resolver: zodResolver(schema$5)
9603
+ });
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
+ ) });
9758
+ };
9759
+ const schema$5 = addressSchema;
9760
+ const CustomItems = () => {
9761
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
+ ] });
9765
+ };
9766
+ const CustomItemsForm = () => {
9767
+ const form = useForm({
9768
+ resolver: zodResolver(schema$4)
9769
+ });
9770
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
+ ] }) })
9776
+ ] }) });
9777
+ };
9778
+ const schema$4 = objectType({
9779
+ email: stringType().email()
9780
+ });
9570
9781
  const Email = () => {
9571
9782
  const { id } = useParams();
9572
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9589,7 +9800,7 @@ const EmailForm = ({ order }) => {
9589
9800
  defaultValues: {
9590
9801
  email: order.email ?? ""
9591
9802
  },
9592
- resolver: zodResolver(schema$5)
9803
+ resolver: zodResolver(schema$3)
9593
9804
  });
9594
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9595
9806
  const { handleSuccess } = useRouteModal();
@@ -9632,592 +9843,242 @@ const EmailForm = ({ order }) => {
9632
9843
  }
9633
9844
  ) });
9634
9845
  };
9635
- const schema$5 = objectType({
9846
+ const schema$3 = objectType({
9636
9847
  email: stringType().email()
9637
9848
  });
9638
- const InlineTip = forwardRef(
9639
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9640
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9849
+ const NumberInput = forwardRef(
9850
+ ({
9851
+ value,
9852
+ onChange,
9853
+ size = "base",
9854
+ min = 0,
9855
+ max = 100,
9856
+ step = 1,
9857
+ className,
9858
+ disabled,
9859
+ ...props
9860
+ }, ref) => {
9861
+ const handleChange = (event) => {
9862
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9863
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9864
+ onChange(newValue);
9865
+ }
9866
+ };
9867
+ const handleIncrement = () => {
9868
+ const newValue = value + step;
9869
+ if (max === void 0 || newValue <= max) {
9870
+ onChange(newValue);
9871
+ }
9872
+ };
9873
+ const handleDecrement = () => {
9874
+ const newValue = value - step;
9875
+ if (min === void 0 || newValue >= min) {
9876
+ onChange(newValue);
9877
+ }
9878
+ };
9641
9879
  return /* @__PURE__ */ jsxs(
9642
9880
  "div",
9643
9881
  {
9644
- ref,
9645
9882
  className: clx(
9646
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9883
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9884
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9885
+ {
9886
+ "h-7": size === "small",
9887
+ "h-8": size === "base"
9888
+ },
9647
9889
  className
9648
9890
  ),
9649
- ...props,
9650
9891
  children: [
9651
9892
  /* @__PURE__ */ jsx(
9652
- "div",
9893
+ "input",
9653
9894
  {
9654
- role: "presentation",
9655
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9656
- "bg-ui-tag-orange-icon": variant === "warning"
9657
- })
9895
+ ref,
9896
+ type: "number",
9897
+ value,
9898
+ onChange: handleChange,
9899
+ min,
9900
+ max,
9901
+ step,
9902
+ className: clx(
9903
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9904
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9905
+ "placeholder:text-ui-fg-muted"
9906
+ ),
9907
+ ...props
9658
9908
  }
9659
9909
  ),
9660
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9661
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9662
- labelValue,
9663
- ":"
9664
- ] }),
9665
- " ",
9666
- children
9667
- ] })
9910
+ /* @__PURE__ */ jsxs(
9911
+ "button",
9912
+ {
9913
+ className: clx(
9914
+ "flex items-center justify-center outline-none transition-fg",
9915
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9916
+ "focus:bg-ui-bg-field-component-hover",
9917
+ "hover:bg-ui-bg-field-component-hover",
9918
+ {
9919
+ "size-7": size === "small",
9920
+ "size-8": size === "base"
9921
+ }
9922
+ ),
9923
+ type: "button",
9924
+ onClick: handleDecrement,
9925
+ disabled: min !== void 0 && value <= min || disabled,
9926
+ children: [
9927
+ /* @__PURE__ */ jsx(Minus, {}),
9928
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9929
+ ]
9930
+ }
9931
+ ),
9932
+ /* @__PURE__ */ jsxs(
9933
+ "button",
9934
+ {
9935
+ className: clx(
9936
+ "flex items-center justify-center outline-none transition-fg",
9937
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9938
+ "focus:bg-ui-bg-field-hover",
9939
+ "hover:bg-ui-bg-field-hover",
9940
+ {
9941
+ "size-7": size === "small",
9942
+ "size-8": size === "base"
9943
+ }
9944
+ ),
9945
+ type: "button",
9946
+ onClick: handleIncrement,
9947
+ disabled: max !== void 0 && value >= max || disabled,
9948
+ children: [
9949
+ /* @__PURE__ */ jsx(Plus, {}),
9950
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9951
+ ]
9952
+ }
9953
+ )
9668
9954
  ]
9669
9955
  }
9670
9956
  );
9671
9957
  }
9672
9958
  );
9673
- InlineTip.displayName = "InlineTip";
9674
- const MetadataFieldSchema = objectType({
9675
- key: stringType(),
9676
- disabled: booleanType().optional(),
9677
- value: anyType()
9678
- });
9679
- const MetadataSchema = objectType({
9680
- metadata: arrayType(MetadataFieldSchema)
9681
- });
9682
- const Metadata = () => {
9959
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9960
+ const productVariantsQueryKeys = {
9961
+ list: (query2) => [
9962
+ PRODUCT_VARIANTS_QUERY_KEY,
9963
+ query2 ? query2 : void 0
9964
+ ]
9965
+ };
9966
+ const useProductVariants = (query2, options) => {
9967
+ const { data, ...rest } = useQuery({
9968
+ queryKey: productVariantsQueryKeys.list(query2),
9969
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9970
+ ...options
9971
+ });
9972
+ return { ...data, ...rest };
9973
+ };
9974
+ const useCancelOrderEdit = ({ preview }) => {
9975
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9976
+ const onCancel = useCallback(async () => {
9977
+ if (!preview) {
9978
+ return true;
9979
+ }
9980
+ let res = false;
9981
+ await cancelOrderEdit(void 0, {
9982
+ onError: (e) => {
9983
+ toast.error(e.message);
9984
+ },
9985
+ onSuccess: () => {
9986
+ res = true;
9987
+ }
9988
+ });
9989
+ return res;
9990
+ }, [preview, cancelOrderEdit]);
9991
+ return { onCancel };
9992
+ };
9993
+ let IS_REQUEST_RUNNING = false;
9994
+ const useInitiateOrderEdit = ({
9995
+ preview
9996
+ }) => {
9997
+ const navigate = useNavigate();
9998
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9999
+ useEffect(() => {
10000
+ async function run() {
10001
+ if (IS_REQUEST_RUNNING || !preview) {
10002
+ return;
10003
+ }
10004
+ if (preview.order_change) {
10005
+ return;
10006
+ }
10007
+ IS_REQUEST_RUNNING = true;
10008
+ await mutateAsync(void 0, {
10009
+ onError: (e) => {
10010
+ toast.error(e.message);
10011
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10012
+ return;
10013
+ }
10014
+ });
10015
+ IS_REQUEST_RUNNING = false;
10016
+ }
10017
+ run();
10018
+ }, [preview, navigate, mutateAsync]);
10019
+ };
10020
+ function convertNumber(value) {
10021
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10022
+ }
10023
+ const STACKED_MODAL_ID = "items_stacked_modal";
10024
+ const Items = () => {
9683
10025
  const { id } = useParams();
9684
- const { order, isPending, isError, error } = useOrder(id, {
9685
- fields: "metadata"
10026
+ const {
10027
+ order: preview,
10028
+ isPending: isPreviewPending,
10029
+ isError: isPreviewError,
10030
+ error: previewError
10031
+ } = useOrderPreview(id, void 0, {
10032
+ placeholderData: keepPreviousData
9686
10033
  });
10034
+ useInitiateOrderEdit({ preview });
10035
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10036
+ id,
10037
+ {
10038
+ fields: "currency_code"
10039
+ },
10040
+ {
10041
+ enabled: !!id
10042
+ }
10043
+ );
10044
+ const { onCancel } = useCancelOrderEdit({ preview });
9687
10045
  if (isError) {
9688
10046
  throw error;
9689
10047
  }
9690
- const isReady = !isPending && !!order;
9691
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9692
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9693
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9694
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9695
- ] }),
9696
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9697
- ] });
10048
+ if (isPreviewError) {
10049
+ throw previewError;
10050
+ }
10051
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10052
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10053
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10054
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10055
+ ] }) });
9698
10056
  };
9699
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9700
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9701
- const MetadataForm = ({ orderId, metadata }) => {
10057
+ const ItemsForm = ({ preview, currencyCode }) => {
10058
+ var _a;
10059
+ const [isSubmitting, setIsSubmitting] = useState(false);
10060
+ const [modalContent, setModalContent] = useState(
10061
+ null
10062
+ );
9702
10063
  const { handleSuccess } = useRouteModal();
9703
- const hasUneditableRows = getHasUneditableRows(metadata);
9704
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9705
- const form = useForm({
9706
- defaultValues: {
9707
- metadata: getDefaultValues(metadata)
9708
- },
9709
- resolver: zodResolver(MetadataSchema)
9710
- });
9711
- const handleSubmit = form.handleSubmit(async (data) => {
9712
- const parsedData = parseValues(data);
9713
- await mutateAsync(
9714
- {
9715
- metadata: parsedData
10064
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10065
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10066
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10067
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10068
+ const matches = useMemo(() => {
10069
+ return matchSorter(preview.items, query2, {
10070
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10071
+ });
10072
+ }, [preview.items, query2]);
10073
+ const onSubmit = async () => {
10074
+ setIsSubmitting(true);
10075
+ let requestSucceeded = false;
10076
+ await requestOrderEdit(void 0, {
10077
+ onError: (e) => {
10078
+ toast.error(`Failed to request order edit: ${e.message}`);
9716
10079
  },
9717
- {
9718
- onSuccess: () => {
9719
- toast.success("Metadata updated");
9720
- handleSuccess();
9721
- },
9722
- onError: (error) => {
9723
- toast.error(error.message);
9724
- }
9725
- }
9726
- );
9727
- });
9728
- const { fields, insert, remove } = useFieldArray({
9729
- control: form.control,
9730
- name: "metadata"
9731
- });
9732
- function deleteRow(index) {
9733
- remove(index);
9734
- if (fields.length === 1) {
9735
- insert(0, {
9736
- key: "",
9737
- value: "",
9738
- disabled: false
9739
- });
9740
- }
9741
- }
9742
- function insertRow(index, position) {
9743
- insert(index + (position === "above" ? 0 : 1), {
9744
- key: "",
9745
- value: "",
9746
- disabled: false
9747
- });
9748
- }
9749
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9750
- KeyboundForm,
9751
- {
9752
- onSubmit: handleSubmit,
9753
- className: "flex flex-1 flex-col overflow-hidden",
9754
- children: [
9755
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9756
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9757
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9758
- /* @__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" }) }),
9759
- /* @__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" }) })
9760
- ] }),
9761
- fields.map((field, index) => {
9762
- const isDisabled = field.disabled || false;
9763
- let placeholder = "-";
9764
- if (typeof field.value === "object") {
9765
- placeholder = "{ ... }";
9766
- }
9767
- if (Array.isArray(field.value)) {
9768
- placeholder = "[ ... ]";
9769
- }
9770
- return /* @__PURE__ */ jsx(
9771
- ConditionalTooltip,
9772
- {
9773
- showTooltip: isDisabled,
9774
- content: "This row is disabled because it contains non-primitive data.",
9775
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9776
- /* @__PURE__ */ jsxs(
9777
- "div",
9778
- {
9779
- className: clx("grid grid-cols-2 divide-x", {
9780
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9781
- }),
9782
- children: [
9783
- /* @__PURE__ */ jsx(
9784
- Form$2.Field,
9785
- {
9786
- control: form.control,
9787
- name: `metadata.${index}.key`,
9788
- render: ({ field: field2 }) => {
9789
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9790
- GridInput,
9791
- {
9792
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9793
- ...field2,
9794
- disabled: isDisabled,
9795
- placeholder: "Key"
9796
- }
9797
- ) }) });
9798
- }
9799
- }
9800
- ),
9801
- /* @__PURE__ */ jsx(
9802
- Form$2.Field,
9803
- {
9804
- control: form.control,
9805
- name: `metadata.${index}.value`,
9806
- render: ({ field: { value, ...field2 } }) => {
9807
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9808
- GridInput,
9809
- {
9810
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9811
- ...field2,
9812
- value: isDisabled ? placeholder : value,
9813
- disabled: isDisabled,
9814
- placeholder: "Value"
9815
- }
9816
- ) }) });
9817
- }
9818
- }
9819
- )
9820
- ]
9821
- }
9822
- ),
9823
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
9824
- /* @__PURE__ */ jsx(
9825
- DropdownMenu.Trigger,
9826
- {
9827
- className: clx(
9828
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9829
- {
9830
- hidden: isDisabled
9831
- }
9832
- ),
9833
- disabled: isDisabled,
9834
- asChild: true,
9835
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
9836
- }
9837
- ),
9838
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9839
- /* @__PURE__ */ jsxs(
9840
- DropdownMenu.Item,
9841
- {
9842
- className: "gap-x-2",
9843
- onClick: () => insertRow(index, "above"),
9844
- children: [
9845
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
9846
- "Insert row above"
9847
- ]
9848
- }
9849
- ),
9850
- /* @__PURE__ */ jsxs(
9851
- DropdownMenu.Item,
9852
- {
9853
- className: "gap-x-2",
9854
- onClick: () => insertRow(index, "below"),
9855
- children: [
9856
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
9857
- "Insert row below"
9858
- ]
9859
- }
9860
- ),
9861
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
9862
- /* @__PURE__ */ jsxs(
9863
- DropdownMenu.Item,
9864
- {
9865
- className: "gap-x-2",
9866
- onClick: () => deleteRow(index),
9867
- children: [
9868
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
9869
- "Delete row"
9870
- ]
9871
- }
9872
- )
9873
- ] })
9874
- ] })
9875
- ] })
9876
- },
9877
- field.id
9878
- );
9879
- })
9880
- ] }),
9881
- 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." })
9882
- ] }),
9883
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9884
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9885
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9886
- ] }) })
9887
- ]
9888
- }
9889
- ) });
9890
- };
9891
- const GridInput = forwardRef(({ className, ...props }, ref) => {
9892
- return /* @__PURE__ */ jsx(
9893
- "input",
9894
- {
9895
- ref,
9896
- ...props,
9897
- autoComplete: "off",
9898
- className: clx(
9899
- "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",
9900
- className
9901
- )
9902
- }
9903
- );
9904
- });
9905
- GridInput.displayName = "MetadataForm.GridInput";
9906
- const PlaceholderInner = () => {
9907
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9908
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9909
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9910
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
9911
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
9912
- ] }) })
9913
- ] });
9914
- };
9915
- const EDITABLE_TYPES = ["string", "number", "boolean"];
9916
- function getDefaultValues(metadata) {
9917
- if (!metadata || !Object.keys(metadata).length) {
9918
- return [
9919
- {
9920
- key: "",
9921
- value: "",
9922
- disabled: false
9923
- }
9924
- ];
9925
- }
9926
- return Object.entries(metadata).map(([key, value]) => {
9927
- if (!EDITABLE_TYPES.includes(typeof value)) {
9928
- return {
9929
- key,
9930
- value,
9931
- disabled: true
9932
- };
9933
- }
9934
- let stringValue = value;
9935
- if (typeof value !== "string") {
9936
- stringValue = JSON.stringify(value);
9937
- }
9938
- return {
9939
- key,
9940
- value: stringValue,
9941
- original_key: key
9942
- };
9943
- });
9944
- }
9945
- function parseValues(values) {
9946
- const metadata = values.metadata;
9947
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9948
- if (isEmpty) {
9949
- return null;
9950
- }
9951
- const update = {};
9952
- metadata.forEach((field) => {
9953
- let key = field.key;
9954
- let value = field.value;
9955
- const disabled = field.disabled;
9956
- if (!key || !value) {
9957
- return;
9958
- }
9959
- if (disabled) {
9960
- update[key] = value;
9961
- return;
9962
- }
9963
- key = key.trim();
9964
- value = value.trim();
9965
- if (value === "true") {
9966
- update[key] = true;
9967
- } else if (value === "false") {
9968
- update[key] = false;
9969
- } else {
9970
- const parsedNumber = parseFloat(value);
9971
- if (!isNaN(parsedNumber)) {
9972
- update[key] = parsedNumber;
9973
- } else {
9974
- update[key] = value;
9975
- }
9976
- }
9977
- });
9978
- return update;
9979
- }
9980
- function getHasUneditableRows(metadata) {
9981
- if (!metadata) {
9982
- return false;
9983
- }
9984
- return Object.values(metadata).some(
9985
- (value) => !EDITABLE_TYPES.includes(typeof value)
9986
- );
9987
- }
9988
- const NumberInput = forwardRef(
9989
- ({
9990
- value,
9991
- onChange,
9992
- size = "base",
9993
- min = 0,
9994
- max = 100,
9995
- step = 1,
9996
- className,
9997
- disabled,
9998
- ...props
9999
- }, ref) => {
10000
- const handleChange = (event) => {
10001
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10002
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10003
- onChange(newValue);
10004
- }
10005
- };
10006
- const handleIncrement = () => {
10007
- const newValue = value + step;
10008
- if (max === void 0 || newValue <= max) {
10009
- onChange(newValue);
10010
- }
10011
- };
10012
- const handleDecrement = () => {
10013
- const newValue = value - step;
10014
- if (min === void 0 || newValue >= min) {
10015
- onChange(newValue);
10016
- }
10017
- };
10018
- return /* @__PURE__ */ jsxs(
10019
- "div",
10020
- {
10021
- className: clx(
10022
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10023
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10024
- {
10025
- "h-7": size === "small",
10026
- "h-8": size === "base"
10027
- },
10028
- className
10029
- ),
10030
- children: [
10031
- /* @__PURE__ */ jsx(
10032
- "input",
10033
- {
10034
- ref,
10035
- type: "number",
10036
- value,
10037
- onChange: handleChange,
10038
- min,
10039
- max,
10040
- step,
10041
- className: clx(
10042
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10043
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10044
- "placeholder:text-ui-fg-muted"
10045
- ),
10046
- ...props
10047
- }
10048
- ),
10049
- /* @__PURE__ */ jsxs(
10050
- "button",
10051
- {
10052
- className: clx(
10053
- "flex items-center justify-center outline-none transition-fg",
10054
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10055
- "focus:bg-ui-bg-field-component-hover",
10056
- "hover:bg-ui-bg-field-component-hover",
10057
- {
10058
- "size-7": size === "small",
10059
- "size-8": size === "base"
10060
- }
10061
- ),
10062
- type: "button",
10063
- onClick: handleDecrement,
10064
- disabled: min !== void 0 && value <= min || disabled,
10065
- children: [
10066
- /* @__PURE__ */ jsx(Minus, {}),
10067
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10068
- ]
10069
- }
10070
- ),
10071
- /* @__PURE__ */ jsxs(
10072
- "button",
10073
- {
10074
- className: clx(
10075
- "flex items-center justify-center outline-none transition-fg",
10076
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10077
- "focus:bg-ui-bg-field-hover",
10078
- "hover:bg-ui-bg-field-hover",
10079
- {
10080
- "size-7": size === "small",
10081
- "size-8": size === "base"
10082
- }
10083
- ),
10084
- type: "button",
10085
- onClick: handleIncrement,
10086
- disabled: max !== void 0 && value >= max || disabled,
10087
- children: [
10088
- /* @__PURE__ */ jsx(Plus, {}),
10089
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10090
- ]
10091
- }
10092
- )
10093
- ]
10094
- }
10095
- );
10096
- }
10097
- );
10098
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10099
- const productVariantsQueryKeys = {
10100
- list: (query2) => [
10101
- PRODUCT_VARIANTS_QUERY_KEY,
10102
- query2 ? query2 : void 0
10103
- ]
10104
- };
10105
- const useProductVariants = (query2, options) => {
10106
- const { data, ...rest } = useQuery({
10107
- queryKey: productVariantsQueryKeys.list(query2),
10108
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10109
- ...options
10110
- });
10111
- return { ...data, ...rest };
10112
- };
10113
- const useCancelOrderEdit = ({ preview }) => {
10114
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10115
- const onCancel = useCallback(async () => {
10116
- if (!preview) {
10117
- return true;
10118
- }
10119
- let res = false;
10120
- await cancelOrderEdit(void 0, {
10121
- onError: (e) => {
10122
- toast.error(e.message);
10123
- },
10124
- onSuccess: () => {
10125
- res = true;
10126
- }
10127
- });
10128
- return res;
10129
- }, [preview, cancelOrderEdit]);
10130
- return { onCancel };
10131
- };
10132
- let IS_REQUEST_RUNNING = false;
10133
- const useInitiateOrderEdit = ({
10134
- preview
10135
- }) => {
10136
- const navigate = useNavigate();
10137
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10138
- useEffect(() => {
10139
- async function run() {
10140
- if (IS_REQUEST_RUNNING || !preview) {
10141
- return;
10142
- }
10143
- if (preview.order_change) {
10144
- return;
10145
- }
10146
- IS_REQUEST_RUNNING = true;
10147
- await mutateAsync(void 0, {
10148
- onError: (e) => {
10149
- toast.error(e.message);
10150
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10151
- return;
10152
- }
10153
- });
10154
- IS_REQUEST_RUNNING = false;
10155
- }
10156
- run();
10157
- }, [preview, navigate, mutateAsync]);
10158
- };
10159
- function convertNumber(value) {
10160
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10161
- }
10162
- const STACKED_MODAL_ID = "items_stacked_modal";
10163
- const Items = () => {
10164
- const { id } = useParams();
10165
- const {
10166
- order: preview,
10167
- isPending: isPreviewPending,
10168
- isError: isPreviewError,
10169
- error: previewError
10170
- } = useOrderPreview(id, void 0, {
10171
- placeholderData: keepPreviousData
10172
- });
10173
- useInitiateOrderEdit({ preview });
10174
- const { draft_order, isPending, isError, error } = useDraftOrder(
10175
- id,
10176
- {
10177
- fields: "currency_code"
10178
- },
10179
- {
10180
- enabled: !!id
10181
- }
10182
- );
10183
- const { onCancel } = useCancelOrderEdit({ preview });
10184
- if (isError) {
10185
- throw error;
10186
- }
10187
- if (isPreviewError) {
10188
- throw previewError;
10189
- }
10190
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10191
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10192
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10193
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10194
- ] }) });
10195
- };
10196
- const ItemsForm = ({ preview, currencyCode }) => {
10197
- var _a;
10198
- const [isSubmitting, setIsSubmitting] = useState(false);
10199
- const [modalContent, setModalContent] = useState(
10200
- null
10201
- );
10202
- const { handleSuccess } = useRouteModal();
10203
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10204
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10205
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10206
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10207
- const matches = useMemo(() => {
10208
- return matchSorter(preview.items, query2, {
10209
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10210
- });
10211
- }, [preview.items, query2]);
10212
- const onSubmit = async () => {
10213
- setIsSubmitting(true);
10214
- let requestSucceeded = false;
10215
- await requestOrderEdit(void 0, {
10216
- onError: (e) => {
10217
- toast.error(`Failed to request order edit: ${e.message}`);
10218
- },
10219
- onSuccess: () => {
10220
- requestSucceeded = true;
10080
+ onSuccess: () => {
10081
+ requestSucceeded = true;
10221
10082
  }
10222
10083
  });
10223
10084
  if (!requestSucceeded) {
@@ -10422,7 +10283,166 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10422
10283
  toast.error(e.message);
10423
10284
  }
10424
10285
  }
10425
- );
10286
+ );
10287
+ return;
10288
+ }
10289
+ await updateActionItem(
10290
+ {
10291
+ action_id: actionId,
10292
+ quantity: data.quantity,
10293
+ unit_price: convertNumber(data.unit_price)
10294
+ },
10295
+ {
10296
+ onSuccess: () => {
10297
+ setEditing(false);
10298
+ },
10299
+ onError: (e) => {
10300
+ toast.error(e.message);
10301
+ }
10302
+ }
10303
+ );
10304
+ });
10305
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10306
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10307
+ /* @__PURE__ */ jsx(
10308
+ Thumbnail,
10309
+ {
10310
+ thumbnail: item.thumbnail,
10311
+ alt: item.product_title ?? void 0
10312
+ }
10313
+ ),
10314
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10315
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10316
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10317
+ /* @__PURE__ */ jsxs(
10318
+ Text,
10319
+ {
10320
+ size: "small",
10321
+ leading: "compact",
10322
+ className: "text-ui-fg-subtle",
10323
+ children: [
10324
+ "(",
10325
+ item.variant_title,
10326
+ ")"
10327
+ ]
10328
+ }
10329
+ )
10330
+ ] }),
10331
+ /* @__PURE__ */ jsx(
10332
+ Text,
10333
+ {
10334
+ size: "small",
10335
+ leading: "compact",
10336
+ className: "text-ui-fg-subtle",
10337
+ children: item.variant_sku
10338
+ }
10339
+ )
10340
+ ] })
10341
+ ] }),
10342
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10343
+ Form$2.Field,
10344
+ {
10345
+ control: form.control,
10346
+ name: "quantity",
10347
+ render: ({ field }) => {
10348
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10349
+ }
10350
+ }
10351
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10352
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10353
+ Form$2.Field,
10354
+ {
10355
+ control: form.control,
10356
+ name: "unit_price",
10357
+ render: ({ field: { onChange, ...field } }) => {
10358
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10359
+ CurrencyInput,
10360
+ {
10361
+ ...field,
10362
+ symbol: getNativeSymbol(currencyCode),
10363
+ code: currencyCode,
10364
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10365
+ }
10366
+ ) }) });
10367
+ }
10368
+ }
10369
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10370
+ /* @__PURE__ */ jsx(
10371
+ IconButton,
10372
+ {
10373
+ type: "button",
10374
+ size: "small",
10375
+ onClick: editing ? onSubmit : () => {
10376
+ setEditing(true);
10377
+ },
10378
+ disabled: isPending,
10379
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10380
+ }
10381
+ )
10382
+ ] }) }) });
10383
+ };
10384
+ const variantItemSchema = objectType({
10385
+ quantity: numberType(),
10386
+ unit_price: unionType([numberType(), stringType()])
10387
+ });
10388
+ const CustomItem = ({ item, preview, currencyCode }) => {
10389
+ const [editing, setEditing] = useState(false);
10390
+ const { quantity, unit_price, title } = item;
10391
+ const form = useForm({
10392
+ defaultValues: {
10393
+ title,
10394
+ quantity,
10395
+ unit_price
10396
+ },
10397
+ resolver: zodResolver(customItemSchema)
10398
+ });
10399
+ useEffect(() => {
10400
+ form.reset({
10401
+ title,
10402
+ quantity,
10403
+ unit_price
10404
+ });
10405
+ }, [form, title, quantity, unit_price]);
10406
+ const actionId = useMemo(() => {
10407
+ var _a, _b;
10408
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10409
+ }, [item]);
10410
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10411
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10412
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10413
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10414
+ const onSubmit = form.handleSubmit(async (data) => {
10415
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10416
+ setEditing(false);
10417
+ return;
10418
+ }
10419
+ if (!actionId) {
10420
+ await updateOriginalItem(
10421
+ {
10422
+ item_id: item.id,
10423
+ quantity: data.quantity,
10424
+ unit_price: convertNumber(data.unit_price)
10425
+ },
10426
+ {
10427
+ onSuccess: () => {
10428
+ setEditing(false);
10429
+ },
10430
+ onError: (e) => {
10431
+ toast.error(e.message);
10432
+ }
10433
+ }
10434
+ );
10435
+ return;
10436
+ }
10437
+ if (data.quantity === 0) {
10438
+ await removeActionItem(actionId, {
10439
+ onSuccess: () => {
10440
+ setEditing(false);
10441
+ },
10442
+ onError: (e) => {
10443
+ toast.error(e.message);
10444
+ }
10445
+ });
10426
10446
  return;
10427
10447
  }
10428
10448
  await updateActionItem(
@@ -10442,43 +10462,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10442
10462
  );
10443
10463
  });
10444
10464
  return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10445
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10465
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10446
10466
  /* @__PURE__ */ jsx(
10447
10467
  Thumbnail,
10448
10468
  {
10449
10469
  thumbnail: item.thumbnail,
10450
- alt: item.product_title ?? void 0
10470
+ alt: item.title ?? void 0
10451
10471
  }
10452
10472
  ),
10453
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10454
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10455
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10456
- /* @__PURE__ */ jsxs(
10457
- Text,
10458
- {
10459
- size: "small",
10460
- leading: "compact",
10461
- className: "text-ui-fg-subtle",
10462
- children: [
10463
- "(",
10464
- item.variant_title,
10465
- ")"
10466
- ]
10467
- }
10468
- )
10469
- ] }),
10470
- /* @__PURE__ */ jsx(
10471
- Text,
10472
- {
10473
- size: "small",
10474
- leading: "compact",
10475
- className: "text-ui-fg-subtle",
10476
- children: item.variant_sku
10473
+ editing ? /* @__PURE__ */ jsx(
10474
+ Form$2.Field,
10475
+ {
10476
+ control: form.control,
10477
+ name: "title",
10478
+ render: ({ field }) => {
10479
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10477
10480
  }
10478
- )
10479
- ] })
10481
+ }
10482
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10480
10483
  ] }),
10481
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10484
+ editing ? /* @__PURE__ */ jsx(
10482
10485
  Form$2.Field,
10483
10486
  {
10484
10487
  control: form.control,
@@ -10487,8 +10490,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10487
10490
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10488
10491
  }
10489
10492
  }
10490
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10491
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10493
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10494
+ editing ? /* @__PURE__ */ jsx(
10492
10495
  Form$2.Field,
10493
10496
  {
10494
10497
  control: form.control,
@@ -10505,7 +10508,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10505
10508
  ) }) });
10506
10509
  }
10507
10510
  }
10508
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10511
+ ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10509
10512
  /* @__PURE__ */ jsx(
10510
10513
  IconButton,
10511
10514
  {
@@ -10520,79 +10523,215 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10520
10523
  )
10521
10524
  ] }) }) });
10522
10525
  };
10523
- const variantItemSchema = objectType({
10524
- quantity: numberType(),
10525
- unit_price: unionType([numberType(), stringType()])
10526
- });
10527
- const CustomItem = ({ item, preview, currencyCode }) => {
10528
- const [editing, setEditing] = useState(false);
10529
- const { quantity, unit_price, title } = item;
10526
+ const StackedModalTrigger$1 = ({
10527
+ type,
10528
+ setModalContent
10529
+ }) => {
10530
+ const { setIsOpen } = useStackedModal();
10531
+ const onClick = useCallback(() => {
10532
+ setModalContent(type);
10533
+ setIsOpen(STACKED_MODAL_ID, true);
10534
+ }, [setModalContent, setIsOpen, type]);
10535
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10536
+ };
10537
+ const VARIANT_PREFIX = "items";
10538
+ const LIMIT = 50;
10539
+ const ExistingItemsForm = ({ orderId, items }) => {
10540
+ const { setIsOpen } = useStackedModal();
10541
+ const [rowSelection, setRowSelection] = useState(
10542
+ items.reduce((acc, item) => {
10543
+ acc[item.variant_id] = true;
10544
+ return acc;
10545
+ }, {})
10546
+ );
10547
+ useEffect(() => {
10548
+ setRowSelection(
10549
+ items.reduce((acc, item) => {
10550
+ if (item.variant_id) {
10551
+ acc[item.variant_id] = true;
10552
+ }
10553
+ return acc;
10554
+ }, {})
10555
+ );
10556
+ }, [items]);
10557
+ const { q, order, offset } = useQueryParams(
10558
+ ["q", "order", "offset"],
10559
+ VARIANT_PREFIX
10560
+ );
10561
+ const { variants, count, isPending, isError, error } = useProductVariants(
10562
+ {
10563
+ q,
10564
+ order,
10565
+ offset: offset ? parseInt(offset) : void 0,
10566
+ limit: LIMIT
10567
+ },
10568
+ {
10569
+ placeholderData: keepPreviousData
10570
+ }
10571
+ );
10572
+ const columns = useColumns();
10573
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10574
+ const onSubmit = async () => {
10575
+ const ids = Object.keys(rowSelection).filter(
10576
+ (id) => !items.find((i) => i.variant_id === id)
10577
+ );
10578
+ await mutateAsync(
10579
+ {
10580
+ items: ids.map((id) => ({
10581
+ variant_id: id,
10582
+ quantity: 1
10583
+ }))
10584
+ },
10585
+ {
10586
+ onSuccess: () => {
10587
+ setRowSelection({});
10588
+ setIsOpen(STACKED_MODAL_ID, false);
10589
+ },
10590
+ onError: (e) => {
10591
+ toast.error(e.message);
10592
+ }
10593
+ }
10594
+ );
10595
+ };
10596
+ if (isError) {
10597
+ throw error;
10598
+ }
10599
+ return /* @__PURE__ */ jsxs(
10600
+ StackedFocusModal.Content,
10601
+ {
10602
+ onOpenAutoFocus: (e) => {
10603
+ e.preventDefault();
10604
+ const searchInput = document.querySelector(
10605
+ "[data-modal-id='modal-search-input']"
10606
+ );
10607
+ if (searchInput) {
10608
+ searchInput.focus();
10609
+ }
10610
+ },
10611
+ children: [
10612
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10613
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10614
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10615
+ ] }),
10616
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10617
+ DataTable,
10618
+ {
10619
+ data: variants,
10620
+ columns,
10621
+ isLoading: isPending,
10622
+ getRowId: (row) => row.id,
10623
+ rowCount: count,
10624
+ prefix: VARIANT_PREFIX,
10625
+ layout: "fill",
10626
+ rowSelection: {
10627
+ state: rowSelection,
10628
+ onRowSelectionChange: setRowSelection,
10629
+ enableRowSelection: (row) => {
10630
+ return !items.find((i) => i.variant_id === row.original.id);
10631
+ }
10632
+ },
10633
+ autoFocusSearch: true
10634
+ }
10635
+ ) }),
10636
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10637
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10638
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10639
+ ] }) })
10640
+ ]
10641
+ }
10642
+ );
10643
+ };
10644
+ const columnHelper = createDataTableColumnHelper();
10645
+ const useColumns = () => {
10646
+ return useMemo(() => {
10647
+ return [
10648
+ columnHelper.select(),
10649
+ columnHelper.accessor("product.title", {
10650
+ header: "Product",
10651
+ cell: ({ row }) => {
10652
+ var _a, _b, _c;
10653
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10654
+ /* @__PURE__ */ jsx(
10655
+ Thumbnail,
10656
+ {
10657
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10658
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10659
+ }
10660
+ ),
10661
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10662
+ ] });
10663
+ },
10664
+ enableSorting: true
10665
+ }),
10666
+ columnHelper.accessor("title", {
10667
+ header: "Variant",
10668
+ enableSorting: true
10669
+ }),
10670
+ columnHelper.accessor("sku", {
10671
+ header: "SKU",
10672
+ cell: ({ getValue }) => {
10673
+ return getValue() ?? "-";
10674
+ },
10675
+ enableSorting: true
10676
+ }),
10677
+ columnHelper.accessor("updated_at", {
10678
+ header: "Updated",
10679
+ cell: ({ getValue }) => {
10680
+ return /* @__PURE__ */ jsx(
10681
+ Tooltip,
10682
+ {
10683
+ content: getFullDate({ date: getValue(), includeTime: true }),
10684
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10685
+ }
10686
+ );
10687
+ },
10688
+ enableSorting: true,
10689
+ sortAscLabel: "Oldest first",
10690
+ sortDescLabel: "Newest first"
10691
+ }),
10692
+ columnHelper.accessor("created_at", {
10693
+ header: "Created",
10694
+ cell: ({ getValue }) => {
10695
+ return /* @__PURE__ */ jsx(
10696
+ Tooltip,
10697
+ {
10698
+ content: getFullDate({ date: getValue(), includeTime: true }),
10699
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10700
+ }
10701
+ );
10702
+ },
10703
+ enableSorting: true,
10704
+ sortAscLabel: "Oldest first",
10705
+ sortDescLabel: "Newest first"
10706
+ })
10707
+ ];
10708
+ }, []);
10709
+ };
10710
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10711
+ const { setIsOpen } = useStackedModal();
10712
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10530
10713
  const form = useForm({
10531
10714
  defaultValues: {
10532
- title,
10533
- quantity,
10534
- unit_price
10715
+ title: "",
10716
+ quantity: 1,
10717
+ unit_price: ""
10535
10718
  },
10536
10719
  resolver: zodResolver(customItemSchema)
10537
10720
  });
10538
- useEffect(() => {
10539
- form.reset({
10540
- title,
10541
- quantity,
10542
- unit_price
10543
- });
10544
- }, [form, title, quantity, unit_price]);
10545
- const actionId = useMemo(() => {
10546
- var _a, _b;
10547
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10548
- }, [item]);
10549
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10550
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10551
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10552
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10553
10721
  const onSubmit = form.handleSubmit(async (data) => {
10554
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10555
- setEditing(false);
10556
- return;
10557
- }
10558
- if (!actionId) {
10559
- await updateOriginalItem(
10560
- {
10561
- item_id: item.id,
10562
- quantity: data.quantity,
10563
- unit_price: convertNumber(data.unit_price)
10564
- },
10565
- {
10566
- onSuccess: () => {
10567
- setEditing(false);
10568
- },
10569
- onError: (e) => {
10570
- toast.error(e.message);
10571
- }
10572
- }
10573
- );
10574
- return;
10575
- }
10576
- if (data.quantity === 0) {
10577
- await removeActionItem(actionId, {
10578
- onSuccess: () => {
10579
- setEditing(false);
10580
- },
10581
- onError: (e) => {
10582
- toast.error(e.message);
10583
- }
10584
- });
10585
- return;
10586
- }
10587
- await updateActionItem(
10722
+ await addItems(
10588
10723
  {
10589
- action_id: actionId,
10590
- quantity: data.quantity,
10591
- unit_price: convertNumber(data.unit_price)
10724
+ items: [
10725
+ {
10726
+ title: data.title,
10727
+ quantity: data.quantity,
10728
+ unit_price: convertNumber(data.unit_price)
10729
+ }
10730
+ ]
10592
10731
  },
10593
10732
  {
10594
10733
  onSuccess: () => {
10595
- setEditing(false);
10734
+ setIsOpen(STACKED_MODAL_ID, false);
10596
10735
  },
10597
10736
  onError: (e) => {
10598
10737
  toast.error(e.message);
@@ -10600,365 +10739,437 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10600
10739
  }
10601
10740
  );
10602
10741
  });
10603
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10604
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10742
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10743
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10744
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10745
+ /* @__PURE__ */ jsxs("div", { children: [
10746
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10747
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10748
+ ] }),
10749
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10605
10750
  /* @__PURE__ */ jsx(
10606
- Thumbnail,
10751
+ Form$2.Field,
10607
10752
  {
10608
- thumbnail: item.thumbnail,
10609
- alt: item.title ?? void 0
10753
+ control: form.control,
10754
+ name: "title",
10755
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10756
+ /* @__PURE__ */ jsxs("div", { children: [
10757
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10758
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10759
+ ] }),
10760
+ /* @__PURE__ */ jsxs("div", { children: [
10761
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10762
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10763
+ ] })
10764
+ ] }) })
10610
10765
  }
10611
10766
  ),
10612
- editing ? /* @__PURE__ */ jsx(
10767
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10768
+ /* @__PURE__ */ jsx(
10613
10769
  Form$2.Field,
10614
10770
  {
10615
10771
  control: form.control,
10616
- name: "title",
10617
- render: ({ field }) => {
10618
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10619
- }
10772
+ name: "unit_price",
10773
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10774
+ /* @__PURE__ */ jsxs("div", { children: [
10775
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10776
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10777
+ ] }),
10778
+ /* @__PURE__ */ jsxs("div", { children: [
10779
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10780
+ CurrencyInput,
10781
+ {
10782
+ symbol: getNativeSymbol(currencyCode),
10783
+ code: currencyCode,
10784
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10785
+ ...field
10786
+ }
10787
+ ) }),
10788
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10789
+ ] })
10790
+ ] }) })
10620
10791
  }
10621
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10622
- ] }),
10623
- editing ? /* @__PURE__ */ jsx(
10624
- Form$2.Field,
10625
- {
10626
- control: form.control,
10627
- name: "quantity",
10628
- render: ({ field }) => {
10629
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10792
+ ),
10793
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10794
+ /* @__PURE__ */ jsx(
10795
+ Form$2.Field,
10796
+ {
10797
+ control: form.control,
10798
+ name: "quantity",
10799
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10800
+ /* @__PURE__ */ jsxs("div", { children: [
10801
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10802
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10803
+ ] }),
10804
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10805
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10806
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10807
+ ] })
10808
+ ] }) })
10630
10809
  }
10631
- }
10632
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10633
- editing ? /* @__PURE__ */ jsx(
10634
- Form$2.Field,
10810
+ )
10811
+ ] }) }) }),
10812
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10813
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10814
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10815
+ ] }) })
10816
+ ] }) }) });
10817
+ };
10818
+ const customItemSchema = objectType({
10819
+ title: stringType().min(1),
10820
+ quantity: numberType(),
10821
+ unit_price: unionType([numberType(), stringType()])
10822
+ });
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",
10635
10828
  {
10636
- control: form.control,
10637
- name: "unit_price",
10638
- render: ({ field: { onChange, ...field } }) => {
10639
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10640
- CurrencyInput,
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",
10641
10838
  {
10642
- ...field,
10643
- symbol: getNativeSymbol(currencyCode),
10644
- code: currencyCode,
10645
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
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
+ })
10646
10843
  }
10647
- ) }) });
10648
- }
10649
- }
10650
- ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10651
- /* @__PURE__ */ jsx(
10652
- IconButton,
10653
- {
10654
- type: "button",
10655
- size: "small",
10656
- onClick: editing ? onSubmit : () => {
10657
- setEditing(true);
10658
- },
10659
- disabled: isPending,
10660
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10661
- }
10662
- )
10663
- ] }) }) });
10664
- };
10665
- const StackedModalTrigger$1 = ({
10666
- type,
10667
- setModalContent
10668
- }) => {
10669
- const { setIsOpen } = useStackedModal();
10670
- const onClick = useCallback(() => {
10671
- setModalContent(type);
10672
- setIsOpen(STACKED_MODAL_ID, true);
10673
- }, [setModalContent, setIsOpen, type]);
10674
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10675
- };
10676
- const VARIANT_PREFIX = "items";
10677
- const LIMIT = 50;
10678
- const ExistingItemsForm = ({ orderId, items }) => {
10679
- const { setIsOpen } = useStackedModal();
10680
- const [rowSelection, setRowSelection] = useState(
10681
- items.reduce((acc, item) => {
10682
- acc[item.variant_id] = true;
10683
- return acc;
10684
- }, {})
10685
- );
10686
- useEffect(() => {
10687
- setRowSelection(
10688
- items.reduce((acc, item) => {
10689
- if (item.variant_id) {
10690
- acc[item.variant_id] = true;
10691
- }
10692
- return acc;
10693
- }, {})
10694
- );
10695
- }, [items]);
10696
- const { q, order, offset } = useQueryParams(
10697
- ["q", "order", "offset"],
10698
- VARIANT_PREFIX
10699
- );
10700
- const { variants, count, isPending, isError, error } = useProductVariants(
10701
- {
10702
- q,
10703
- order,
10704
- offset: offset ? parseInt(offset) : void 0,
10705
- limit: LIMIT
10706
- },
10707
- {
10708
- placeholderData: keepPreviousData
10709
- }
10710
- );
10711
- const columns = useColumns();
10712
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10713
- const onSubmit = async () => {
10714
- const ids = Object.keys(rowSelection).filter(
10715
- (id) => !items.find((i) => i.variant_id === id)
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
+ }
10716
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 })
10882
+ ] });
10883
+ };
10884
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10885
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10886
+ const MetadataForm = ({ orderId, metadata }) => {
10887
+ const { handleSuccess } = useRouteModal();
10888
+ const hasUneditableRows = getHasUneditableRows(metadata);
10889
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10890
+ const form = useForm({
10891
+ defaultValues: {
10892
+ metadata: getDefaultValues(metadata)
10893
+ },
10894
+ resolver: zodResolver(MetadataSchema)
10895
+ });
10896
+ const handleSubmit = form.handleSubmit(async (data) => {
10897
+ const parsedData = parseValues(data);
10717
10898
  await mutateAsync(
10718
10899
  {
10719
- items: ids.map((id) => ({
10720
- variant_id: id,
10721
- quantity: 1
10722
- }))
10900
+ metadata: parsedData
10723
10901
  },
10724
10902
  {
10725
10903
  onSuccess: () => {
10726
- setRowSelection({});
10727
- setIsOpen(STACKED_MODAL_ID, false);
10904
+ toast.success("Metadata updated");
10905
+ handleSuccess();
10728
10906
  },
10729
- onError: (e) => {
10730
- toast.error(e.message);
10907
+ onError: (error) => {
10908
+ toast.error(error.message);
10731
10909
  }
10732
10910
  }
10733
10911
  );
10734
- };
10735
- if (isError) {
10736
- throw error;
10912
+ });
10913
+ const { fields, insert, remove } = useFieldArray({
10914
+ control: form.control,
10915
+ name: "metadata"
10916
+ });
10917
+ function deleteRow(index) {
10918
+ remove(index);
10919
+ if (fields.length === 1) {
10920
+ insert(0, {
10921
+ key: "",
10922
+ value: "",
10923
+ disabled: false
10924
+ });
10925
+ }
10737
10926
  }
10738
- return /* @__PURE__ */ jsxs(
10739
- StackedFocusModal.Content,
10927
+ function insertRow(index, position) {
10928
+ insert(index + (position === "above" ? 0 : 1), {
10929
+ key: "",
10930
+ value: "",
10931
+ disabled: false
10932
+ });
10933
+ }
10934
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10935
+ KeyboundForm,
10740
10936
  {
10741
- onOpenAutoFocus: (e) => {
10742
- e.preventDefault();
10743
- const searchInput = document.querySelector(
10744
- "[data-modal-id='modal-search-input']"
10745
- );
10746
- if (searchInput) {
10747
- searchInput.focus();
10748
- }
10749
- },
10937
+ onSubmit: handleSubmit,
10938
+ className: "flex flex-1 flex-col overflow-hidden",
10750
10939
  children: [
10751
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10752
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10753
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10754
- ] }),
10755
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10756
- DataTable,
10757
- {
10758
- data: variants,
10759
- columns,
10760
- isLoading: isPending,
10761
- getRowId: (row) => row.id,
10762
- rowCount: count,
10763
- prefix: VARIANT_PREFIX,
10764
- layout: "fill",
10765
- rowSelection: {
10766
- state: rowSelection,
10767
- onRowSelectionChange: setRowSelection,
10768
- enableRowSelection: (row) => {
10769
- return !items.find((i) => i.variant_id === row.original.id);
10940
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10941
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10942
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10943
+ /* @__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" }) }),
10944
+ /* @__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" }) })
10945
+ ] }),
10946
+ fields.map((field, index) => {
10947
+ const isDisabled = field.disabled || false;
10948
+ let placeholder = "-";
10949
+ if (typeof field.value === "object") {
10950
+ placeholder = "{ ... }";
10770
10951
  }
10771
- },
10772
- autoFocusSearch: true
10773
- }
10774
- ) }),
10775
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10776
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10777
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10952
+ if (Array.isArray(field.value)) {
10953
+ placeholder = "[ ... ]";
10954
+ }
10955
+ return /* @__PURE__ */ jsx(
10956
+ ConditionalTooltip,
10957
+ {
10958
+ showTooltip: isDisabled,
10959
+ content: "This row is disabled because it contains non-primitive data.",
10960
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10961
+ /* @__PURE__ */ jsxs(
10962
+ "div",
10963
+ {
10964
+ className: clx("grid grid-cols-2 divide-x", {
10965
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10966
+ }),
10967
+ children: [
10968
+ /* @__PURE__ */ jsx(
10969
+ Form$2.Field,
10970
+ {
10971
+ control: form.control,
10972
+ name: `metadata.${index}.key`,
10973
+ render: ({ field: field2 }) => {
10974
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10975
+ GridInput,
10976
+ {
10977
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10978
+ ...field2,
10979
+ disabled: isDisabled,
10980
+ placeholder: "Key"
10981
+ }
10982
+ ) }) });
10983
+ }
10984
+ }
10985
+ ),
10986
+ /* @__PURE__ */ jsx(
10987
+ Form$2.Field,
10988
+ {
10989
+ control: form.control,
10990
+ name: `metadata.${index}.value`,
10991
+ render: ({ field: { value, ...field2 } }) => {
10992
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10993
+ GridInput,
10994
+ {
10995
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10996
+ ...field2,
10997
+ value: isDisabled ? placeholder : value,
10998
+ disabled: isDisabled,
10999
+ placeholder: "Value"
11000
+ }
11001
+ ) }) });
11002
+ }
11003
+ }
11004
+ )
11005
+ ]
11006
+ }
11007
+ ),
11008
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11009
+ /* @__PURE__ */ jsx(
11010
+ DropdownMenu.Trigger,
11011
+ {
11012
+ className: clx(
11013
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11014
+ {
11015
+ hidden: isDisabled
11016
+ }
11017
+ ),
11018
+ disabled: isDisabled,
11019
+ asChild: true,
11020
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11021
+ }
11022
+ ),
11023
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11024
+ /* @__PURE__ */ jsxs(
11025
+ DropdownMenu.Item,
11026
+ {
11027
+ className: "gap-x-2",
11028
+ onClick: () => insertRow(index, "above"),
11029
+ children: [
11030
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11031
+ "Insert row above"
11032
+ ]
11033
+ }
11034
+ ),
11035
+ /* @__PURE__ */ jsxs(
11036
+ DropdownMenu.Item,
11037
+ {
11038
+ className: "gap-x-2",
11039
+ onClick: () => insertRow(index, "below"),
11040
+ children: [
11041
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11042
+ "Insert row below"
11043
+ ]
11044
+ }
11045
+ ),
11046
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11047
+ /* @__PURE__ */ jsxs(
11048
+ DropdownMenu.Item,
11049
+ {
11050
+ className: "gap-x-2",
11051
+ onClick: () => deleteRow(index),
11052
+ children: [
11053
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11054
+ "Delete row"
11055
+ ]
11056
+ }
11057
+ )
11058
+ ] })
11059
+ ] })
11060
+ ] })
11061
+ },
11062
+ field.id
11063
+ );
11064
+ })
11065
+ ] }),
11066
+ 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." })
11067
+ ] }),
11068
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11069
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11070
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10778
11071
  ] }) })
10779
11072
  ]
10780
11073
  }
11074
+ ) });
11075
+ };
11076
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11077
+ return /* @__PURE__ */ jsx(
11078
+ "input",
11079
+ {
11080
+ ref,
11081
+ ...props,
11082
+ autoComplete: "off",
11083
+ className: clx(
11084
+ "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",
11085
+ className
11086
+ )
11087
+ }
10781
11088
  );
11089
+ });
11090
+ GridInput.displayName = "MetadataForm.GridInput";
11091
+ const PlaceholderInner = () => {
11092
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11093
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11094
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11095
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11096
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11097
+ ] }) })
11098
+ ] });
10782
11099
  };
10783
- const columnHelper = createDataTableColumnHelper();
10784
- const useColumns = () => {
10785
- return useMemo(() => {
11100
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11101
+ function getDefaultValues(metadata) {
11102
+ if (!metadata || !Object.keys(metadata).length) {
10786
11103
  return [
10787
- columnHelper.select(),
10788
- columnHelper.accessor("product.title", {
10789
- header: "Product",
10790
- cell: ({ row }) => {
10791
- var _a, _b, _c;
10792
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10793
- /* @__PURE__ */ jsx(
10794
- Thumbnail,
10795
- {
10796
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10797
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10798
- }
10799
- ),
10800
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10801
- ] });
10802
- },
10803
- enableSorting: true
10804
- }),
10805
- columnHelper.accessor("title", {
10806
- header: "Variant",
10807
- enableSorting: true
10808
- }),
10809
- columnHelper.accessor("sku", {
10810
- header: "SKU",
10811
- cell: ({ getValue }) => {
10812
- return getValue() ?? "-";
10813
- },
10814
- enableSorting: true
10815
- }),
10816
- columnHelper.accessor("updated_at", {
10817
- header: "Updated",
10818
- cell: ({ getValue }) => {
10819
- return /* @__PURE__ */ jsx(
10820
- Tooltip,
10821
- {
10822
- content: getFullDate({ date: getValue(), includeTime: true }),
10823
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10824
- }
10825
- );
10826
- },
10827
- enableSorting: true,
10828
- sortAscLabel: "Oldest first",
10829
- sortDescLabel: "Newest first"
10830
- }),
10831
- columnHelper.accessor("created_at", {
10832
- header: "Created",
10833
- cell: ({ getValue }) => {
10834
- return /* @__PURE__ */ jsx(
10835
- Tooltip,
10836
- {
10837
- content: getFullDate({ date: getValue(), includeTime: true }),
10838
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10839
- }
10840
- );
10841
- },
10842
- enableSorting: true,
10843
- sortAscLabel: "Oldest first",
10844
- sortDescLabel: "Newest first"
10845
- })
10846
- ];
10847
- }, []);
10848
- };
10849
- const CustomItemForm = ({ orderId, currencyCode }) => {
10850
- const { setIsOpen } = useStackedModal();
10851
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10852
- const form = useForm({
10853
- defaultValues: {
10854
- title: "",
10855
- quantity: 1,
10856
- unit_price: ""
10857
- },
10858
- resolver: zodResolver(customItemSchema)
10859
- });
10860
- const onSubmit = form.handleSubmit(async (data) => {
10861
- await addItems(
10862
- {
10863
- items: [
10864
- {
10865
- title: data.title,
10866
- quantity: data.quantity,
10867
- unit_price: convertNumber(data.unit_price)
10868
- }
10869
- ]
10870
- },
10871
11104
  {
10872
- onSuccess: () => {
10873
- setIsOpen(STACKED_MODAL_ID, false);
10874
- },
10875
- onError: (e) => {
10876
- toast.error(e.message);
10877
- }
11105
+ key: "",
11106
+ value: "",
11107
+ disabled: false
10878
11108
  }
10879
- );
11109
+ ];
11110
+ }
11111
+ return Object.entries(metadata).map(([key, value]) => {
11112
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11113
+ return {
11114
+ key,
11115
+ value,
11116
+ disabled: true
11117
+ };
11118
+ }
11119
+ let stringValue = value;
11120
+ if (typeof value !== "string") {
11121
+ stringValue = JSON.stringify(value);
11122
+ }
11123
+ return {
11124
+ key,
11125
+ value: stringValue,
11126
+ original_key: key
11127
+ };
10880
11128
  });
10881
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10882
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10883
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10884
- /* @__PURE__ */ jsxs("div", { children: [
10885
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10886
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10887
- ] }),
10888
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10889
- /* @__PURE__ */ jsx(
10890
- Form$2.Field,
10891
- {
10892
- control: form.control,
10893
- name: "title",
10894
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10895
- /* @__PURE__ */ jsxs("div", { children: [
10896
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10897
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10898
- ] }),
10899
- /* @__PURE__ */ jsxs("div", { children: [
10900
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10901
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10902
- ] })
10903
- ] }) })
10904
- }
10905
- ),
10906
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10907
- /* @__PURE__ */ jsx(
10908
- Form$2.Field,
10909
- {
10910
- control: form.control,
10911
- name: "unit_price",
10912
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10913
- /* @__PURE__ */ jsxs("div", { children: [
10914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10915
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10916
- ] }),
10917
- /* @__PURE__ */ jsxs("div", { children: [
10918
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10919
- CurrencyInput,
10920
- {
10921
- symbol: getNativeSymbol(currencyCode),
10922
- code: currencyCode,
10923
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10924
- ...field
10925
- }
10926
- ) }),
10927
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10928
- ] })
10929
- ] }) })
10930
- }
10931
- ),
10932
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10933
- /* @__PURE__ */ jsx(
10934
- Form$2.Field,
10935
- {
10936
- control: form.control,
10937
- name: "quantity",
10938
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10939
- /* @__PURE__ */ jsxs("div", { children: [
10940
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10941
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10942
- ] }),
10943
- /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10944
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10945
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10946
- ] })
10947
- ] }) })
10948
- }
10949
- )
10950
- ] }) }) }),
10951
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10952
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10953
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10954
- ] }) })
10955
- ] }) }) });
10956
- };
10957
- const customItemSchema = objectType({
10958
- title: stringType().min(1),
10959
- quantity: numberType(),
10960
- unit_price: unionType([numberType(), stringType()])
10961
- });
11129
+ }
11130
+ function parseValues(values) {
11131
+ const metadata = values.metadata;
11132
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11133
+ if (isEmpty) {
11134
+ return null;
11135
+ }
11136
+ const update = {};
11137
+ metadata.forEach((field) => {
11138
+ let key = field.key;
11139
+ let value = field.value;
11140
+ const disabled = field.disabled;
11141
+ if (!key || !value) {
11142
+ return;
11143
+ }
11144
+ if (disabled) {
11145
+ update[key] = value;
11146
+ return;
11147
+ }
11148
+ key = key.trim();
11149
+ value = value.trim();
11150
+ if (value === "true") {
11151
+ update[key] = true;
11152
+ } else if (value === "false") {
11153
+ update[key] = false;
11154
+ } else {
11155
+ const parsedNumber = parseFloat(value);
11156
+ if (!isNaN(parsedNumber)) {
11157
+ update[key] = parsedNumber;
11158
+ } else {
11159
+ update[key] = value;
11160
+ }
11161
+ }
11162
+ });
11163
+ return update;
11164
+ }
11165
+ function getHasUneditableRows(metadata) {
11166
+ if (!metadata) {
11167
+ return false;
11168
+ }
11169
+ return Object.values(metadata).some(
11170
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11171
+ );
11172
+ }
10962
11173
  const PROMOTION_QUERY_KEY = "promotions";
10963
11174
  const promotionsQueryKeys = {
10964
11175
  list: (query2) => [
@@ -11236,27 +11447,6 @@ function getPromotionIds(items, shippingMethods) {
11236
11447
  }
11237
11448
  return Array.from(promotionIds);
11238
11449
  }
11239
- const CustomItems = () => {
11240
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11241
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
11242
- /* @__PURE__ */ jsx(CustomItemsForm, {})
11243
- ] });
11244
- };
11245
- const CustomItemsForm = () => {
11246
- const form = useForm({
11247
- resolver: zodResolver(schema$4)
11248
- });
11249
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11250
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
11251
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11252
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11253
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
11254
- ] }) })
11255
- ] }) });
11256
- };
11257
- const schema$4 = objectType({
11258
- email: stringType().email()
11259
- });
11260
11450
  const SalesChannel = () => {
11261
11451
  const { id } = useParams();
11262
11452
  const { draft_order, isPending, isError, error } = useDraftOrder(
@@ -11285,7 +11475,7 @@ const SalesChannelForm = ({ order }) => {
11285
11475
  defaultValues: {
11286
11476
  sales_channel_id: order.sales_channel_id || ""
11287
11477
  },
11288
- resolver: zodResolver(schema$3)
11478
+ resolver: zodResolver(schema$2)
11289
11479
  });
11290
11480
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11291
11481
  const { handleSuccess } = useRouteModal();
@@ -11360,7 +11550,7 @@ const SalesChannelField = ({ control, order }) => {
11360
11550
  }
11361
11551
  );
11362
11552
  };
11363
- const schema$3 = objectType({
11553
+ const schema$2 = objectType({
11364
11554
  sales_channel_id: stringType().min(1)
11365
11555
  });
11366
11556
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12202,7 +12392,7 @@ const ShippingAddressForm = ({ order }) => {
12202
12392
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12203
12393
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12204
12394
  },
12205
- resolver: zodResolver(schema$2)
12395
+ resolver: zodResolver(schema$1)
12206
12396
  });
12207
12397
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12208
12398
  const { handleSuccess } = useRouteModal();
@@ -12372,7 +12562,7 @@ const ShippingAddressForm = ({ order }) => {
12372
12562
  }
12373
12563
  ) });
12374
12564
  };
12375
- const schema$2 = addressSchema;
12565
+ const schema$1 = addressSchema;
12376
12566
  const TransferOwnership = () => {
12377
12567
  const { id } = useParams();
12378
12568
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12396,7 +12586,7 @@ const TransferOwnershipForm = ({ order }) => {
12396
12586
  defaultValues: {
12397
12587
  customer_id: order.customer_id || ""
12398
12588
  },
12399
- resolver: zodResolver(schema$1)
12589
+ resolver: zodResolver(schema)
12400
12590
  });
12401
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12402
12592
  const { handleSuccess } = useRouteModal();
@@ -12846,199 +13036,9 @@ const Illustration = () => {
12846
13036
  }
12847
13037
  );
12848
13038
  };
12849
- const schema$1 = objectType({
13039
+ const schema = objectType({
12850
13040
  customer_id: stringType().min(1)
12851
13041
  });
12852
- const BillingAddress = () => {
12853
- const { id } = useParams();
12854
- const { order, isPending, isError, error } = useOrder(id, {
12855
- fields: "+billing_address"
12856
- });
12857
- if (isError) {
12858
- throw error;
12859
- }
12860
- const isReady = !isPending && !!order;
12861
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12863
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12865
- ] }),
12866
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12867
- ] });
12868
- };
12869
- const BillingAddressForm = ({ order }) => {
12870
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12871
- const form = useForm({
12872
- defaultValues: {
12873
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12883
- },
12884
- resolver: zodResolver(schema)
12885
- });
12886
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
- const { handleSuccess } = useRouteModal();
12888
- const onSubmit = form.handleSubmit(async (data) => {
12889
- await mutateAsync(
12890
- { billing_address: data },
12891
- {
12892
- onSuccess: () => {
12893
- handleSuccess();
12894
- },
12895
- onError: (error) => {
12896
- toast.error(error.message);
12897
- }
12898
- }
12899
- );
12900
- });
12901
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
- KeyboundForm,
12903
- {
12904
- className: "flex flex-1 flex-col overflow-hidden",
12905
- onSubmit,
12906
- children: [
12907
- /* @__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: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12910
- {
12911
- control: form.control,
12912
- name: "country_code",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12918
- }
12919
- ),
12920
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
- /* @__PURE__ */ jsx(
12922
- Form$2.Field,
12923
- {
12924
- control: form.control,
12925
- name: "first_name",
12926
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
- ] })
12931
- }
12932
- ),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "last_name",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- )
12945
- ] }),
12946
- /* @__PURE__ */ jsx(
12947
- Form$2.Field,
12948
- {
12949
- control: form.control,
12950
- name: "company",
12951
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
- ] })
12956
- }
12957
- ),
12958
- /* @__PURE__ */ jsx(
12959
- Form$2.Field,
12960
- {
12961
- control: form.control,
12962
- name: "address_1",
12963
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
- ] })
12968
- }
12969
- ),
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
12972
- {
12973
- control: form.control,
12974
- name: "address_2",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
12980
- }
12981
- ),
12982
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
- /* @__PURE__ */ jsx(
12984
- Form$2.Field,
12985
- {
12986
- control: form.control,
12987
- name: "postal_code",
12988
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
- ] })
12993
- }
12994
- ),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "city",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- )
13007
- ] }),
13008
- /* @__PURE__ */ jsx(
13009
- Form$2.Field,
13010
- {
13011
- control: form.control,
13012
- name: "province",
13013
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
- ] })
13018
- }
13019
- ),
13020
- /* @__PURE__ */ jsx(
13021
- Form$2.Field,
13022
- {
13023
- control: form.control,
13024
- name: "phone",
13025
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
- ] })
13030
- }
13031
- )
13032
- ] }) }),
13033
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13036
- ] }) })
13037
- ]
13038
- }
13039
- ) });
13040
- };
13041
- const schema = addressSchema;
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13060,24 +13060,28 @@ const routeModule = {
13060
13060
  loader,
13061
13061
  children: [
13062
13062
  {
13063
- Component: Email,
13064
- path: "/draft-orders/:id/email"
13063
+ Component: BillingAddress,
13064
+ path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
13066
  {
13067
- Component: Metadata,
13068
- path: "/draft-orders/:id/metadata"
13067
+ Component: CustomItems,
13068
+ path: "/draft-orders/:id/custom-items"
13069
+ },
13070
+ {
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13069
13073
  },
13070
13074
  {
13071
13075
  Component: Items,
13072
13076
  path: "/draft-orders/:id/items"
13073
13077
  },
13074
13078
  {
13075
- Component: Promotions,
13076
- path: "/draft-orders/:id/promotions"
13079
+ Component: Metadata,
13080
+ path: "/draft-orders/:id/metadata"
13077
13081
  },
13078
13082
  {
13079
- Component: CustomItems,
13080
- path: "/draft-orders/:id/custom-items"
13083
+ Component: Promotions,
13084
+ path: "/draft-orders/:id/promotions"
13081
13085
  },
13082
13086
  {
13083
13087
  Component: SalesChannel,
@@ -13094,10 +13098,6 @@ const routeModule = {
13094
13098
  {
13095
13099
  Component: TransferOwnership,
13096
13100
  path: "/draft-orders/:id/transfer-ownership"
13097
- },
13098
- {
13099
- Component: BillingAddress,
13100
- path: "/draft-orders/:id/billing-address"
13101
13101
  }
13102
13102
  ]
13103
13103
  }