@medusajs/draft-order 2.10.2-preview-20250902000306 → 2.10.2-preview-20250902031730

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, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } 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, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } 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";
@@ -9744,27 +9744,6 @@ const BillingAddressForm = ({ order }) => {
9744
9744
  ) });
9745
9745
  };
9746
9746
  const schema$5 = addressSchema;
9747
- const CustomItems = () => {
9748
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9749
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9750
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9751
- ] });
9752
- };
9753
- const CustomItemsForm = () => {
9754
- const form = useForm({
9755
- resolver: zodResolver(schema$4)
9756
- });
9757
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9758
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9759
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9760
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9761
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9762
- ] }) })
9763
- ] }) });
9764
- };
9765
- const schema$4 = objectType({
9766
- email: stringType().email()
9767
- });
9768
9747
  const Email = () => {
9769
9748
  const { id } = useParams();
9770
9749
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9787,7 +9766,7 @@ const EmailForm = ({ order }) => {
9787
9766
  defaultValues: {
9788
9767
  email: order.email ?? ""
9789
9768
  },
9790
- resolver: zodResolver(schema$3)
9769
+ resolver: zodResolver(schema$4)
9791
9770
  });
9792
9771
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
9772
  const { handleSuccess } = useRouteModal();
@@ -9830,1069 +9809,95 @@ const EmailForm = ({ order }) => {
9830
9809
  }
9831
9810
  ) });
9832
9811
  };
9833
- const schema$3 = objectType({
9812
+ const schema$4 = objectType({
9834
9813
  email: stringType().email()
9835
9814
  });
9836
- const NumberInput = forwardRef(
9837
- ({
9838
- value,
9839
- onChange,
9840
- size = "base",
9841
- min = 0,
9842
- max = 100,
9843
- step = 1,
9844
- className,
9845
- disabled,
9846
- ...props
9847
- }, ref) => {
9848
- const handleChange = (event) => {
9849
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9850
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9851
- onChange(newValue);
9852
- }
9853
- };
9854
- const handleIncrement = () => {
9855
- const newValue = value + step;
9856
- if (max === void 0 || newValue <= max) {
9857
- onChange(newValue);
9858
- }
9859
- };
9860
- const handleDecrement = () => {
9861
- const newValue = value - step;
9862
- if (min === void 0 || newValue >= min) {
9863
- onChange(newValue);
9864
- }
9865
- };
9815
+ const InlineTip = forwardRef(
9816
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9817
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9866
9818
  return /* @__PURE__ */ jsxs(
9867
9819
  "div",
9868
9820
  {
9821
+ ref,
9869
9822
  className: clx(
9870
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9871
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9872
- {
9873
- "h-7": size === "small",
9874
- "h-8": size === "base"
9875
- },
9823
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9876
9824
  className
9877
9825
  ),
9826
+ ...props,
9878
9827
  children: [
9879
9828
  /* @__PURE__ */ jsx(
9880
- "input",
9881
- {
9882
- ref,
9883
- type: "number",
9884
- value,
9885
- onChange: handleChange,
9886
- min,
9887
- max,
9888
- step,
9889
- className: clx(
9890
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9891
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9892
- "placeholder:text-ui-fg-muted"
9893
- ),
9894
- ...props
9895
- }
9896
- ),
9897
- /* @__PURE__ */ jsxs(
9898
- "button",
9829
+ "div",
9899
9830
  {
9900
- className: clx(
9901
- "flex items-center justify-center outline-none transition-fg",
9902
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9903
- "focus:bg-ui-bg-field-component-hover",
9904
- "hover:bg-ui-bg-field-component-hover",
9905
- {
9906
- "size-7": size === "small",
9907
- "size-8": size === "base"
9908
- }
9909
- ),
9910
- type: "button",
9911
- onClick: handleDecrement,
9912
- disabled: min !== void 0 && value <= min || disabled,
9913
- children: [
9914
- /* @__PURE__ */ jsx(Minus, {}),
9915
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9916
- ]
9831
+ role: "presentation",
9832
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9833
+ "bg-ui-tag-orange-icon": variant === "warning"
9834
+ })
9917
9835
  }
9918
9836
  ),
9919
- /* @__PURE__ */ jsxs(
9920
- "button",
9921
- {
9922
- className: clx(
9923
- "flex items-center justify-center outline-none transition-fg",
9924
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9925
- "focus:bg-ui-bg-field-hover",
9926
- "hover:bg-ui-bg-field-hover",
9927
- {
9928
- "size-7": size === "small",
9929
- "size-8": size === "base"
9930
- }
9931
- ),
9932
- type: "button",
9933
- onClick: handleIncrement,
9934
- disabled: max !== void 0 && value >= max || disabled,
9935
- children: [
9936
- /* @__PURE__ */ jsx(Plus, {}),
9937
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9938
- ]
9939
- }
9940
- )
9837
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9838
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9839
+ labelValue,
9840
+ ":"
9841
+ ] }),
9842
+ " ",
9843
+ children
9844
+ ] })
9941
9845
  ]
9942
9846
  }
9943
9847
  );
9944
9848
  }
9945
9849
  );
9946
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9947
- const productVariantsQueryKeys = {
9948
- list: (query2) => [
9949
- PRODUCT_VARIANTS_QUERY_KEY,
9950
- query2 ? query2 : void 0
9951
- ]
9952
- };
9953
- const useProductVariants = (query2, options) => {
9954
- const { data, ...rest } = useQuery({
9955
- queryKey: productVariantsQueryKeys.list(query2),
9956
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9957
- ...options
9958
- });
9959
- return { ...data, ...rest };
9960
- };
9961
- const useCancelOrderEdit = ({ preview }) => {
9962
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9963
- const onCancel = useCallback(async () => {
9964
- if (!preview) {
9965
- return true;
9966
- }
9967
- let res = false;
9968
- await cancelOrderEdit(void 0, {
9969
- onError: (e) => {
9970
- toast.error(e.message);
9971
- },
9972
- onSuccess: () => {
9973
- res = true;
9974
- }
9975
- });
9976
- return res;
9977
- }, [preview, cancelOrderEdit]);
9978
- return { onCancel };
9979
- };
9980
- let IS_REQUEST_RUNNING = false;
9981
- const useInitiateOrderEdit = ({
9982
- preview
9983
- }) => {
9984
- const navigate = useNavigate();
9985
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9986
- useEffect(() => {
9987
- async function run() {
9988
- if (IS_REQUEST_RUNNING || !preview) {
9989
- return;
9990
- }
9991
- if (preview.order_change) {
9992
- return;
9993
- }
9994
- IS_REQUEST_RUNNING = true;
9995
- await mutateAsync(void 0, {
9996
- onError: (e) => {
9997
- toast.error(e.message);
9998
- navigate(`/draft-orders/${preview.id}`, { replace: true });
9999
- return;
10000
- }
10001
- });
10002
- IS_REQUEST_RUNNING = false;
10003
- }
10004
- run();
10005
- }, [preview, navigate, mutateAsync]);
10006
- };
10007
- function convertNumber(value) {
10008
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10009
- }
10010
- const STACKED_MODAL_ID = "items_stacked_modal";
10011
- const Items = () => {
9850
+ InlineTip.displayName = "InlineTip";
9851
+ const MetadataFieldSchema = objectType({
9852
+ key: stringType(),
9853
+ disabled: booleanType().optional(),
9854
+ value: anyType()
9855
+ });
9856
+ const MetadataSchema = objectType({
9857
+ metadata: arrayType(MetadataFieldSchema)
9858
+ });
9859
+ const Metadata = () => {
10012
9860
  const { id } = useParams();
10013
- const {
10014
- order: preview,
10015
- isPending: isPreviewPending,
10016
- isError: isPreviewError,
10017
- error: previewError
10018
- } = useOrderPreview(id, void 0, {
10019
- placeholderData: keepPreviousData
9861
+ const { order, isPending, isError, error } = useOrder(id, {
9862
+ fields: "metadata"
10020
9863
  });
10021
- useInitiateOrderEdit({ preview });
10022
- const { draft_order, isPending, isError, error } = useDraftOrder(
10023
- id,
10024
- {
10025
- fields: "currency_code"
10026
- },
10027
- {
10028
- enabled: !!id
10029
- }
10030
- );
10031
- const { onCancel } = useCancelOrderEdit({ preview });
10032
9864
  if (isError) {
10033
9865
  throw error;
10034
9866
  }
10035
- if (isPreviewError) {
10036
- throw previewError;
10037
- }
10038
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10039
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10040
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10041
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10042
- ] }) });
9867
+ const isReady = !isPending && !!order;
9868
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9869
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9870
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9871
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9872
+ ] }),
9873
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9874
+ ] });
10043
9875
  };
10044
- const ItemsForm = ({ preview, currencyCode }) => {
10045
- var _a;
10046
- const [isSubmitting, setIsSubmitting] = useState(false);
10047
- const [modalContent, setModalContent] = useState(
10048
- null
10049
- );
9876
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9877
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9878
+ const MetadataForm = ({ orderId, metadata }) => {
10050
9879
  const { handleSuccess } = useRouteModal();
10051
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10052
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10053
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10054
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10055
- const matches = useMemo(() => {
10056
- return matchSorter(preview.items, query2, {
10057
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10058
- });
10059
- }, [preview.items, query2]);
10060
- const onSubmit = async () => {
10061
- setIsSubmitting(true);
10062
- let requestSucceeded = false;
10063
- await requestOrderEdit(void 0, {
10064
- onError: (e) => {
10065
- toast.error(`Failed to request order edit: ${e.message}`);
10066
- },
10067
- onSuccess: () => {
10068
- requestSucceeded = true;
10069
- }
10070
- });
10071
- if (!requestSucceeded) {
10072
- setIsSubmitting(false);
10073
- return;
10074
- }
10075
- await confirmOrderEdit(void 0, {
10076
- onError: (e) => {
10077
- toast.error(`Failed to confirm order edit: ${e.message}`);
10078
- },
10079
- onSuccess: () => {
10080
- handleSuccess();
10081
- },
10082
- onSettled: () => {
10083
- setIsSubmitting(false);
10084
- }
10085
- });
10086
- };
10087
- const onKeyDown = useCallback(
10088
- (e) => {
10089
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10090
- if (modalContent || isSubmitting) {
10091
- return;
10092
- }
10093
- onSubmit();
10094
- }
10095
- },
10096
- [modalContent, isSubmitting, onSubmit]
10097
- );
10098
- useEffect(() => {
10099
- document.addEventListener("keydown", onKeyDown);
10100
- return () => {
10101
- document.removeEventListener("keydown", onKeyDown);
10102
- };
10103
- }, [onKeyDown]);
10104
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10105
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10106
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10107
- StackedFocusModal,
10108
- {
10109
- id: STACKED_MODAL_ID,
10110
- onOpenChangeCallback: (open) => {
10111
- if (!open) {
10112
- setModalContent(null);
10113
- }
10114
- },
10115
- children: [
10116
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10117
- /* @__PURE__ */ jsxs("div", { children: [
10118
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10119
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
10120
- ] }),
10121
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10122
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10123
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10124
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10125
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10126
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10127
- ] }),
10128
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10129
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10130
- Input,
10131
- {
10132
- type: "search",
10133
- placeholder: "Search items",
10134
- value: searchValue,
10135
- onChange: (e) => onSearchValueChange(e.target.value)
10136
- }
10137
- ) }),
10138
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10139
- /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10140
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10141
- /* @__PURE__ */ jsx(
10142
- StackedModalTrigger$1,
10143
- {
10144
- type: "add-items",
10145
- setModalContent
10146
- }
10147
- ),
10148
- /* @__PURE__ */ jsx(
10149
- StackedModalTrigger$1,
10150
- {
10151
- type: "add-custom-item",
10152
- setModalContent
10153
- }
10154
- )
10155
- ] })
10156
- ] })
10157
- ] })
10158
- ] }),
10159
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10160
- /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
10161
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10162
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10163
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10164
- /* @__PURE__ */ jsx("div", {})
10165
- ] }) }),
10166
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10167
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10168
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10169
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10170
- Item,
10171
- {
10172
- item,
10173
- preview,
10174
- currencyCode
10175
- },
10176
- item.id
10177
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10178
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10179
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10180
- 'No items found for "',
10181
- query2,
10182
- '".'
10183
- ] })
10184
- ] }) })
10185
- ] })
10186
- ] }),
10187
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10188
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10189
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10190
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10191
- Text,
10192
- {
10193
- size: "small",
10194
- leading: "compact",
10195
- className: "text-ui-fg-subtle",
10196
- children: [
10197
- itemCount,
10198
- " ",
10199
- itemCount === 1 ? "item" : "items"
10200
- ]
10201
- }
10202
- ) }),
10203
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10204
- ] })
10205
- ] }) }),
10206
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10207
- CustomItemForm,
10208
- {
10209
- orderId: preview.id,
10210
- currencyCode
10211
- }
10212
- ) : null)
10213
- ]
10214
- }
10215
- ) }),
10216
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10217
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10218
- /* @__PURE__ */ jsx(
10219
- Button,
10220
- {
10221
- size: "small",
10222
- type: "button",
10223
- onClick: onSubmit,
10224
- isLoading: isSubmitting,
10225
- children: "Save"
10226
- }
10227
- )
10228
- ] }) })
10229
- ] });
10230
- };
10231
- const Item = ({ item, preview, currencyCode }) => {
10232
- if (item.variant_id) {
10233
- return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10234
- }
10235
- return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10236
- };
10237
- const VariantItem = ({ item, preview, currencyCode }) => {
10238
- const [editing, setEditing] = useState(false);
9880
+ const hasUneditableRows = getHasUneditableRows(metadata);
9881
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10239
9882
  const form = useForm({
10240
9883
  defaultValues: {
10241
- quantity: item.quantity,
10242
- unit_price: item.unit_price
9884
+ metadata: getDefaultValues(metadata)
10243
9885
  },
10244
- resolver: zodResolver(variantItemSchema)
9886
+ resolver: zodResolver(MetadataSchema)
10245
9887
  });
10246
- const actionId = useMemo(() => {
10247
- var _a, _b;
10248
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10249
- }, [item]);
10250
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10251
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10252
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10253
- const onSubmit = form.handleSubmit(async (data) => {
10254
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10255
- setEditing(false);
10256
- return;
10257
- }
10258
- if (!actionId) {
10259
- await updateOriginalItem(
10260
- {
10261
- item_id: item.id,
10262
- quantity: data.quantity,
10263
- unit_price: convertNumber(data.unit_price)
10264
- },
10265
- {
10266
- onSuccess: () => {
10267
- setEditing(false);
10268
- },
10269
- onError: (e) => {
10270
- toast.error(e.message);
10271
- }
10272
- }
10273
- );
10274
- return;
10275
- }
10276
- await updateActionItem(
9888
+ const handleSubmit = form.handleSubmit(async (data) => {
9889
+ const parsedData = parseValues(data);
9890
+ await mutateAsync(
10277
9891
  {
10278
- action_id: actionId,
10279
- quantity: data.quantity,
10280
- unit_price: convertNumber(data.unit_price)
9892
+ metadata: parsedData
10281
9893
  },
10282
9894
  {
10283
9895
  onSuccess: () => {
10284
- setEditing(false);
9896
+ toast.success("Metadata updated");
9897
+ handleSuccess();
10285
9898
  },
10286
- onError: (e) => {
10287
- toast.error(e.message);
10288
- }
10289
- }
10290
- );
10291
- });
10292
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10293
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
10294
- /* @__PURE__ */ jsx(
10295
- Thumbnail,
10296
- {
10297
- thumbnail: item.thumbnail,
10298
- alt: item.product_title ?? void 0
10299
- }
10300
- ),
10301
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10302
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10303
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10304
- /* @__PURE__ */ jsxs(
10305
- Text,
10306
- {
10307
- size: "small",
10308
- leading: "compact",
10309
- className: "text-ui-fg-subtle",
10310
- children: [
10311
- "(",
10312
- item.variant_title,
10313
- ")"
10314
- ]
10315
- }
10316
- )
10317
- ] }),
10318
- /* @__PURE__ */ jsx(
10319
- Text,
10320
- {
10321
- size: "small",
10322
- leading: "compact",
10323
- className: "text-ui-fg-subtle",
10324
- children: item.variant_sku
10325
- }
10326
- )
10327
- ] })
10328
- ] }),
10329
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10330
- Form$2.Field,
10331
- {
10332
- control: form.control,
10333
- name: "quantity",
10334
- render: ({ field }) => {
10335
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10336
- }
10337
- }
10338
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10339
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10340
- Form$2.Field,
10341
- {
10342
- control: form.control,
10343
- name: "unit_price",
10344
- render: ({ field: { onChange, ...field } }) => {
10345
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10346
- CurrencyInput,
10347
- {
10348
- ...field,
10349
- symbol: getNativeSymbol(currencyCode),
10350
- code: currencyCode,
10351
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10352
- }
10353
- ) }) });
10354
- }
10355
- }
10356
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10357
- /* @__PURE__ */ jsx(
10358
- IconButton,
10359
- {
10360
- type: "button",
10361
- size: "small",
10362
- onClick: editing ? onSubmit : () => {
10363
- setEditing(true);
10364
- },
10365
- disabled: isPending,
10366
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10367
- }
10368
- )
10369
- ] }) }) });
10370
- };
10371
- const variantItemSchema = objectType({
10372
- quantity: numberType(),
10373
- unit_price: unionType([numberType(), stringType()])
10374
- });
10375
- const CustomItem = ({ item, preview, currencyCode }) => {
10376
- const [editing, setEditing] = useState(false);
10377
- const { quantity, unit_price, title } = item;
10378
- const form = useForm({
10379
- defaultValues: {
10380
- title,
10381
- quantity,
10382
- unit_price
10383
- },
10384
- resolver: zodResolver(customItemSchema)
10385
- });
10386
- useEffect(() => {
10387
- form.reset({
10388
- title,
10389
- quantity,
10390
- unit_price
10391
- });
10392
- }, [form, title, quantity, unit_price]);
10393
- const actionId = useMemo(() => {
10394
- var _a, _b;
10395
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10396
- }, [item]);
10397
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10398
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10399
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10400
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10401
- const onSubmit = form.handleSubmit(async (data) => {
10402
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10403
- setEditing(false);
10404
- return;
10405
- }
10406
- if (!actionId) {
10407
- await updateOriginalItem(
10408
- {
10409
- item_id: item.id,
10410
- quantity: data.quantity,
10411
- unit_price: convertNumber(data.unit_price)
10412
- },
10413
- {
10414
- onSuccess: () => {
10415
- setEditing(false);
10416
- },
10417
- onError: (e) => {
10418
- toast.error(e.message);
10419
- }
10420
- }
10421
- );
10422
- return;
10423
- }
10424
- if (data.quantity === 0) {
10425
- await removeActionItem(actionId, {
10426
- onSuccess: () => {
10427
- setEditing(false);
10428
- },
10429
- onError: (e) => {
10430
- toast.error(e.message);
10431
- }
10432
- });
10433
- return;
10434
- }
10435
- await updateActionItem(
10436
- {
10437
- action_id: actionId,
10438
- quantity: data.quantity,
10439
- unit_price: convertNumber(data.unit_price)
10440
- },
10441
- {
10442
- onSuccess: () => {
10443
- setEditing(false);
10444
- },
10445
- onError: (e) => {
10446
- toast.error(e.message);
10447
- }
10448
- }
10449
- );
10450
- });
10451
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10452
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10453
- /* @__PURE__ */ jsx(
10454
- Thumbnail,
10455
- {
10456
- thumbnail: item.thumbnail,
10457
- alt: item.title ?? void 0
10458
- }
10459
- ),
10460
- editing ? /* @__PURE__ */ jsx(
10461
- Form$2.Field,
10462
- {
10463
- control: form.control,
10464
- name: "title",
10465
- render: ({ field }) => {
10466
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10467
- }
10468
- }
10469
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10470
- ] }),
10471
- editing ? /* @__PURE__ */ jsx(
10472
- Form$2.Field,
10473
- {
10474
- control: form.control,
10475
- name: "quantity",
10476
- render: ({ field }) => {
10477
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10478
- }
10479
- }
10480
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10481
- editing ? /* @__PURE__ */ jsx(
10482
- Form$2.Field,
10483
- {
10484
- control: form.control,
10485
- name: "unit_price",
10486
- render: ({ field: { onChange, ...field } }) => {
10487
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10488
- CurrencyInput,
10489
- {
10490
- ...field,
10491
- symbol: getNativeSymbol(currencyCode),
10492
- code: currencyCode,
10493
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10494
- }
10495
- ) }) });
10496
- }
10497
- }
10498
- ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10499
- /* @__PURE__ */ jsx(
10500
- IconButton,
10501
- {
10502
- type: "button",
10503
- size: "small",
10504
- onClick: editing ? onSubmit : () => {
10505
- setEditing(true);
10506
- },
10507
- disabled: isPending,
10508
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10509
- }
10510
- )
10511
- ] }) }) });
10512
- };
10513
- const StackedModalTrigger$1 = ({
10514
- type,
10515
- setModalContent
10516
- }) => {
10517
- const { setIsOpen } = useStackedModal();
10518
- const onClick = useCallback(() => {
10519
- setModalContent(type);
10520
- setIsOpen(STACKED_MODAL_ID, true);
10521
- }, [setModalContent, setIsOpen, type]);
10522
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10523
- };
10524
- const VARIANT_PREFIX = "items";
10525
- const LIMIT = 50;
10526
- const ExistingItemsForm = ({ orderId, items }) => {
10527
- const { setIsOpen } = useStackedModal();
10528
- const [rowSelection, setRowSelection] = useState(
10529
- items.reduce((acc, item) => {
10530
- acc[item.variant_id] = true;
10531
- return acc;
10532
- }, {})
10533
- );
10534
- useEffect(() => {
10535
- setRowSelection(
10536
- items.reduce((acc, item) => {
10537
- if (item.variant_id) {
10538
- acc[item.variant_id] = true;
10539
- }
10540
- return acc;
10541
- }, {})
10542
- );
10543
- }, [items]);
10544
- const { q, order, offset } = useQueryParams(
10545
- ["q", "order", "offset"],
10546
- VARIANT_PREFIX
10547
- );
10548
- const { variants, count, isPending, isError, error } = useProductVariants(
10549
- {
10550
- q,
10551
- order,
10552
- offset: offset ? parseInt(offset) : void 0,
10553
- limit: LIMIT
10554
- },
10555
- {
10556
- placeholderData: keepPreviousData
10557
- }
10558
- );
10559
- const columns = useColumns();
10560
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10561
- const onSubmit = async () => {
10562
- const ids = Object.keys(rowSelection).filter(
10563
- (id) => !items.find((i) => i.variant_id === id)
10564
- );
10565
- await mutateAsync(
10566
- {
10567
- items: ids.map((id) => ({
10568
- variant_id: id,
10569
- quantity: 1
10570
- }))
10571
- },
10572
- {
10573
- onSuccess: () => {
10574
- setRowSelection({});
10575
- setIsOpen(STACKED_MODAL_ID, false);
10576
- },
10577
- onError: (e) => {
10578
- toast.error(e.message);
10579
- }
10580
- }
10581
- );
10582
- };
10583
- if (isError) {
10584
- throw error;
10585
- }
10586
- return /* @__PURE__ */ jsxs(
10587
- StackedFocusModal.Content,
10588
- {
10589
- onOpenAutoFocus: (e) => {
10590
- e.preventDefault();
10591
- const searchInput = document.querySelector(
10592
- "[data-modal-id='modal-search-input']"
10593
- );
10594
- if (searchInput) {
10595
- searchInput.focus();
10596
- }
10597
- },
10598
- children: [
10599
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10600
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10601
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10602
- ] }),
10603
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10604
- DataTable,
10605
- {
10606
- data: variants,
10607
- columns,
10608
- isLoading: isPending,
10609
- getRowId: (row) => row.id,
10610
- rowCount: count,
10611
- prefix: VARIANT_PREFIX,
10612
- layout: "fill",
10613
- rowSelection: {
10614
- state: rowSelection,
10615
- onRowSelectionChange: setRowSelection,
10616
- enableRowSelection: (row) => {
10617
- return !items.find((i) => i.variant_id === row.original.id);
10618
- }
10619
- },
10620
- autoFocusSearch: true
10621
- }
10622
- ) }),
10623
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10624
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10625
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10626
- ] }) })
10627
- ]
10628
- }
10629
- );
10630
- };
10631
- const columnHelper = createDataTableColumnHelper();
10632
- const useColumns = () => {
10633
- return useMemo(() => {
10634
- return [
10635
- columnHelper.select(),
10636
- columnHelper.accessor("product.title", {
10637
- header: "Product",
10638
- cell: ({ row }) => {
10639
- var _a, _b, _c;
10640
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10641
- /* @__PURE__ */ jsx(
10642
- Thumbnail,
10643
- {
10644
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10645
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10646
- }
10647
- ),
10648
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10649
- ] });
10650
- },
10651
- enableSorting: true
10652
- }),
10653
- columnHelper.accessor("title", {
10654
- header: "Variant",
10655
- enableSorting: true
10656
- }),
10657
- columnHelper.accessor("sku", {
10658
- header: "SKU",
10659
- cell: ({ getValue }) => {
10660
- return getValue() ?? "-";
10661
- },
10662
- enableSorting: true
10663
- }),
10664
- columnHelper.accessor("updated_at", {
10665
- header: "Updated",
10666
- cell: ({ getValue }) => {
10667
- return /* @__PURE__ */ jsx(
10668
- Tooltip,
10669
- {
10670
- content: getFullDate({ date: getValue(), includeTime: true }),
10671
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10672
- }
10673
- );
10674
- },
10675
- enableSorting: true,
10676
- sortAscLabel: "Oldest first",
10677
- sortDescLabel: "Newest first"
10678
- }),
10679
- columnHelper.accessor("created_at", {
10680
- header: "Created",
10681
- cell: ({ getValue }) => {
10682
- return /* @__PURE__ */ jsx(
10683
- Tooltip,
10684
- {
10685
- content: getFullDate({ date: getValue(), includeTime: true }),
10686
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10687
- }
10688
- );
10689
- },
10690
- enableSorting: true,
10691
- sortAscLabel: "Oldest first",
10692
- sortDescLabel: "Newest first"
10693
- })
10694
- ];
10695
- }, []);
10696
- };
10697
- const CustomItemForm = ({ orderId, currencyCode }) => {
10698
- const { setIsOpen } = useStackedModal();
10699
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10700
- const form = useForm({
10701
- defaultValues: {
10702
- title: "",
10703
- quantity: 1,
10704
- unit_price: ""
10705
- },
10706
- resolver: zodResolver(customItemSchema)
10707
- });
10708
- const onSubmit = form.handleSubmit(async (data) => {
10709
- await addItems(
10710
- {
10711
- items: [
10712
- {
10713
- title: data.title,
10714
- quantity: data.quantity,
10715
- unit_price: convertNumber(data.unit_price)
10716
- }
10717
- ]
10718
- },
10719
- {
10720
- onSuccess: () => {
10721
- setIsOpen(STACKED_MODAL_ID, false);
10722
- },
10723
- onError: (e) => {
10724
- toast.error(e.message);
10725
- }
10726
- }
10727
- );
10728
- });
10729
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10730
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10731
- /* @__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: [
10732
- /* @__PURE__ */ jsxs("div", { children: [
10733
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10734
- /* @__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." }) })
10735
- ] }),
10736
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10737
- /* @__PURE__ */ jsx(
10738
- Form$2.Field,
10739
- {
10740
- control: form.control,
10741
- name: "title",
10742
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10743
- /* @__PURE__ */ jsxs("div", { children: [
10744
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10745
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10746
- ] }),
10747
- /* @__PURE__ */ jsxs("div", { children: [
10748
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10749
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10750
- ] })
10751
- ] }) })
10752
- }
10753
- ),
10754
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10755
- /* @__PURE__ */ jsx(
10756
- Form$2.Field,
10757
- {
10758
- control: form.control,
10759
- name: "unit_price",
10760
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10761
- /* @__PURE__ */ jsxs("div", { children: [
10762
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10763
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10764
- ] }),
10765
- /* @__PURE__ */ jsxs("div", { children: [
10766
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10767
- CurrencyInput,
10768
- {
10769
- symbol: getNativeSymbol(currencyCode),
10770
- code: currencyCode,
10771
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10772
- ...field
10773
- }
10774
- ) }),
10775
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10776
- ] })
10777
- ] }) })
10778
- }
10779
- ),
10780
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10781
- /* @__PURE__ */ jsx(
10782
- Form$2.Field,
10783
- {
10784
- control: form.control,
10785
- name: "quantity",
10786
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10787
- /* @__PURE__ */ jsxs("div", { children: [
10788
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10789
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10790
- ] }),
10791
- /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
10792
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10793
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10794
- ] })
10795
- ] }) })
10796
- }
10797
- )
10798
- ] }) }) }),
10799
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10800
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10801
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10802
- ] }) })
10803
- ] }) }) });
10804
- };
10805
- const customItemSchema = objectType({
10806
- title: stringType().min(1),
10807
- quantity: numberType(),
10808
- unit_price: unionType([numberType(), stringType()])
10809
- });
10810
- const InlineTip = forwardRef(
10811
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10812
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10813
- return /* @__PURE__ */ jsxs(
10814
- "div",
10815
- {
10816
- ref,
10817
- className: clx(
10818
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10819
- className
10820
- ),
10821
- ...props,
10822
- children: [
10823
- /* @__PURE__ */ jsx(
10824
- "div",
10825
- {
10826
- role: "presentation",
10827
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10828
- "bg-ui-tag-orange-icon": variant === "warning"
10829
- })
10830
- }
10831
- ),
10832
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10833
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10834
- labelValue,
10835
- ":"
10836
- ] }),
10837
- " ",
10838
- children
10839
- ] })
10840
- ]
10841
- }
10842
- );
10843
- }
10844
- );
10845
- InlineTip.displayName = "InlineTip";
10846
- const MetadataFieldSchema = objectType({
10847
- key: stringType(),
10848
- disabled: booleanType().optional(),
10849
- value: anyType()
10850
- });
10851
- const MetadataSchema = objectType({
10852
- metadata: arrayType(MetadataFieldSchema)
10853
- });
10854
- const Metadata = () => {
10855
- const { id } = useParams();
10856
- const { order, isPending, isError, error } = useOrder(id, {
10857
- fields: "metadata"
10858
- });
10859
- if (isError) {
10860
- throw error;
10861
- }
10862
- const isReady = !isPending && !!order;
10863
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10864
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10865
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10866
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10867
- ] }),
10868
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10869
- ] });
10870
- };
10871
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10872
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10873
- const MetadataForm = ({ orderId, metadata }) => {
10874
- const { handleSuccess } = useRouteModal();
10875
- const hasUneditableRows = getHasUneditableRows(metadata);
10876
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10877
- const form = useForm({
10878
- defaultValues: {
10879
- metadata: getDefaultValues(metadata)
10880
- },
10881
- resolver: zodResolver(MetadataSchema)
10882
- });
10883
- const handleSubmit = form.handleSubmit(async (data) => {
10884
- const parsedData = parseValues(data);
10885
- await mutateAsync(
10886
- {
10887
- metadata: parsedData
10888
- },
10889
- {
10890
- onSuccess: () => {
10891
- toast.success("Metadata updated");
10892
- handleSuccess();
10893
- },
10894
- onError: (error) => {
10895
- toast.error(error.message);
9899
+ onError: (error) => {
9900
+ toast.error(error.message);
10896
9901
  }
10897
9902
  }
10898
9903
  );
@@ -11169,13 +10174,59 @@ const promotionsQueryKeys = {
11169
10174
  query2 ? query2 : void 0
11170
10175
  ]
11171
10176
  };
11172
- const usePromotions = (query2, options) => {
11173
- const { data, ...rest } = useQuery({
11174
- queryKey: promotionsQueryKeys.list(query2),
11175
- queryFn: async () => sdk.admin.promotion.list(query2),
11176
- ...options
11177
- });
11178
- return { ...data, ...rest };
10177
+ const usePromotions = (query2, options) => {
10178
+ const { data, ...rest } = useQuery({
10179
+ queryKey: promotionsQueryKeys.list(query2),
10180
+ queryFn: async () => sdk.admin.promotion.list(query2),
10181
+ ...options
10182
+ });
10183
+ return { ...data, ...rest };
10184
+ };
10185
+ const useCancelOrderEdit = ({ preview }) => {
10186
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10187
+ const onCancel = useCallback(async () => {
10188
+ if (!preview) {
10189
+ return true;
10190
+ }
10191
+ let res = false;
10192
+ await cancelOrderEdit(void 0, {
10193
+ onError: (e) => {
10194
+ toast.error(e.message);
10195
+ },
10196
+ onSuccess: () => {
10197
+ res = true;
10198
+ }
10199
+ });
10200
+ return res;
10201
+ }, [preview, cancelOrderEdit]);
10202
+ return { onCancel };
10203
+ };
10204
+ let IS_REQUEST_RUNNING = false;
10205
+ const useInitiateOrderEdit = ({
10206
+ preview
10207
+ }) => {
10208
+ const navigate = useNavigate();
10209
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10210
+ useEffect(() => {
10211
+ async function run() {
10212
+ if (IS_REQUEST_RUNNING || !preview) {
10213
+ return;
10214
+ }
10215
+ if (preview.order_change) {
10216
+ return;
10217
+ }
10218
+ IS_REQUEST_RUNNING = true;
10219
+ await mutateAsync(void 0, {
10220
+ onError: (e) => {
10221
+ toast.error(e.message);
10222
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10223
+ return;
10224
+ }
10225
+ });
10226
+ IS_REQUEST_RUNNING = false;
10227
+ }
10228
+ run();
10229
+ }, [preview, navigate, mutateAsync]);
11179
10230
  };
11180
10231
  const Promotions = () => {
11181
10232
  const { id } = useParams();
@@ -11462,7 +10513,7 @@ const SalesChannelForm = ({ order }) => {
11462
10513
  defaultValues: {
11463
10514
  sales_channel_id: order.sales_channel_id || ""
11464
10515
  },
11465
- resolver: zodResolver(schema$2)
10516
+ resolver: zodResolver(schema$3)
11466
10517
  });
11467
10518
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11468
10519
  const { handleSuccess } = useRouteModal();
@@ -11537,9 +10588,12 @@ const SalesChannelField = ({ control, order }) => {
11537
10588
  }
11538
10589
  );
11539
10590
  };
11540
- const schema$2 = objectType({
10591
+ const schema$3 = objectType({
11541
10592
  sales_channel_id: stringType().min(1)
11542
10593
  });
10594
+ function convertNumber(value) {
10595
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10596
+ }
11543
10597
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11544
10598
  const Shipping = () => {
11545
10599
  var _a;
@@ -11847,7 +10901,7 @@ const ShippingForm = ({ preview, order }) => {
11847
10901
  ]
11848
10902
  }
11849
10903
  ) : /* @__PURE__ */ jsx(
11850
- StackedModalTrigger,
10904
+ StackedModalTrigger$1,
11851
10905
  {
11852
10906
  shippingProfileId: profile.id,
11853
10907
  shippingOption,
@@ -11958,7 +11012,7 @@ const ShippingForm = ({ preview, order }) => {
11958
11012
  ] }) })
11959
11013
  ] });
11960
11014
  };
11961
- const StackedModalTrigger = ({
11015
+ const StackedModalTrigger$1 = ({
11962
11016
  shippingProfileId,
11963
11017
  shippingOption,
11964
11018
  shippingMethod,
@@ -12379,7 +11433,7 @@ const ShippingAddressForm = ({ order }) => {
12379
11433
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12380
11434
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12381
11435
  },
12382
- resolver: zodResolver(schema$1)
11436
+ resolver: zodResolver(schema$2)
12383
11437
  });
12384
11438
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12385
11439
  const { handleSuccess } = useRouteModal();
@@ -12549,7 +11603,7 @@ const ShippingAddressForm = ({ order }) => {
12549
11603
  }
12550
11604
  ) });
12551
11605
  };
12552
- const schema$1 = addressSchema;
11606
+ const schema$2 = addressSchema;
12553
11607
  const TransferOwnership = () => {
12554
11608
  const { id } = useParams();
12555
11609
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12573,7 +11627,7 @@ const TransferOwnershipForm = ({ order }) => {
12573
11627
  defaultValues: {
12574
11628
  customer_id: order.customer_id || ""
12575
11629
  },
12576
- resolver: zodResolver(schema)
11630
+ resolver: zodResolver(schema$1)
12577
11631
  });
12578
11632
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12579
11633
  const { handleSuccess } = useRouteModal();
@@ -12872,159 +11926,1105 @@ const Illustration = () => {
12872
11926
  /* @__PURE__ */ jsx(
12873
11927
  "path",
12874
11928
  {
12875
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12876
- fill: "#A1A1AA"
12877
- }
11929
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11930
+ fill: "#A1A1AA"
11931
+ }
11932
+ ),
11933
+ /* @__PURE__ */ jsx(
11934
+ "rect",
11935
+ {
11936
+ width: "17",
11937
+ height: "3",
11938
+ rx: "1.5",
11939
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11940
+ fill: "#A1A1AA"
11941
+ }
11942
+ ),
11943
+ /* @__PURE__ */ jsx(
11944
+ "rect",
11945
+ {
11946
+ width: "12",
11947
+ height: "3",
11948
+ rx: "1.5",
11949
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11950
+ fill: "#A1A1AA"
11951
+ }
11952
+ ),
11953
+ /* @__PURE__ */ jsx(
11954
+ "path",
11955
+ {
11956
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11957
+ fill: "#52525B"
11958
+ }
11959
+ ),
11960
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
11961
+ "path",
11962
+ {
11963
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11964
+ stroke: "#A1A1AA",
11965
+ strokeWidth: "1.5",
11966
+ strokeLinecap: "round",
11967
+ strokeLinejoin: "round"
11968
+ }
11969
+ ) }),
11970
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
11971
+ "path",
11972
+ {
11973
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11974
+ stroke: "#A1A1AA",
11975
+ strokeWidth: "1.5",
11976
+ strokeLinecap: "round",
11977
+ strokeLinejoin: "round"
11978
+ }
11979
+ ) }),
11980
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
11981
+ "path",
11982
+ {
11983
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11984
+ stroke: "#A1A1AA",
11985
+ strokeWidth: "1.5",
11986
+ strokeLinecap: "round",
11987
+ strokeLinejoin: "round"
11988
+ }
11989
+ ) }),
11990
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
11991
+ "path",
11992
+ {
11993
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11994
+ stroke: "#A1A1AA",
11995
+ strokeWidth: "1.5",
11996
+ strokeLinecap: "round",
11997
+ strokeLinejoin: "round"
11998
+ }
11999
+ ) }),
12000
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12001
+ "path",
12002
+ {
12003
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12004
+ stroke: "#A1A1AA",
12005
+ strokeWidth: "1.5",
12006
+ strokeLinecap: "round",
12007
+ strokeLinejoin: "round"
12008
+ }
12009
+ ) }),
12010
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12011
+ "path",
12012
+ {
12013
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12014
+ stroke: "#A1A1AA",
12015
+ strokeWidth: "1.5",
12016
+ strokeLinecap: "round",
12017
+ strokeLinejoin: "round"
12018
+ }
12019
+ ) }),
12020
+ /* @__PURE__ */ jsxs("defs", { children: [
12021
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12022
+ "rect",
12023
+ {
12024
+ width: "12",
12025
+ height: "12",
12026
+ fill: "white",
12027
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12028
+ }
12029
+ ) }),
12030
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12031
+ "rect",
12032
+ {
12033
+ width: "12",
12034
+ height: "12",
12035
+ fill: "white",
12036
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12037
+ }
12038
+ ) }),
12039
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12040
+ "rect",
12041
+ {
12042
+ width: "12",
12043
+ height: "12",
12044
+ fill: "white",
12045
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12046
+ }
12047
+ ) }),
12048
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12049
+ "rect",
12050
+ {
12051
+ width: "12",
12052
+ height: "12",
12053
+ fill: "white",
12054
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12055
+ }
12056
+ ) }),
12057
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12058
+ "rect",
12059
+ {
12060
+ width: "12",
12061
+ height: "12",
12062
+ fill: "white",
12063
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12064
+ }
12065
+ ) }),
12066
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12067
+ "rect",
12068
+ {
12069
+ width: "12",
12070
+ height: "12",
12071
+ fill: "white",
12072
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12073
+ }
12074
+ ) })
12075
+ ] })
12076
+ ]
12077
+ }
12078
+ );
12079
+ };
12080
+ const schema$1 = objectType({
12081
+ customer_id: stringType().min(1)
12082
+ });
12083
+ const CustomItems = () => {
12084
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12085
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
12086
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
12087
+ ] });
12088
+ };
12089
+ const CustomItemsForm = () => {
12090
+ const form = useForm({
12091
+ resolver: zodResolver(schema)
12092
+ });
12093
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
12094
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
12095
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12096
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12097
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
12098
+ ] }) })
12099
+ ] }) });
12100
+ };
12101
+ const schema = objectType({
12102
+ email: stringType().email()
12103
+ });
12104
+ const NumberInput = forwardRef(
12105
+ ({
12106
+ value,
12107
+ onChange,
12108
+ size = "base",
12109
+ min = 0,
12110
+ max = 100,
12111
+ step = 1,
12112
+ className,
12113
+ disabled,
12114
+ ...props
12115
+ }, ref) => {
12116
+ const handleChange = (event) => {
12117
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
12118
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
12119
+ onChange(newValue);
12120
+ }
12121
+ };
12122
+ const handleIncrement = () => {
12123
+ const newValue = value + step;
12124
+ if (max === void 0 || newValue <= max) {
12125
+ onChange(newValue);
12126
+ }
12127
+ };
12128
+ const handleDecrement = () => {
12129
+ const newValue = value - step;
12130
+ if (min === void 0 || newValue >= min) {
12131
+ onChange(newValue);
12132
+ }
12133
+ };
12134
+ return /* @__PURE__ */ jsxs(
12135
+ "div",
12136
+ {
12137
+ className: clx(
12138
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
12139
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
12140
+ {
12141
+ "h-7": size === "small",
12142
+ "h-8": size === "base"
12143
+ },
12144
+ className
12878
12145
  ),
12879
- /* @__PURE__ */ jsx(
12880
- "rect",
12881
- {
12882
- width: "17",
12883
- height: "3",
12884
- rx: "1.5",
12885
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12886
- fill: "#A1A1AA"
12146
+ children: [
12147
+ /* @__PURE__ */ jsx(
12148
+ "input",
12149
+ {
12150
+ ref,
12151
+ type: "number",
12152
+ value,
12153
+ onChange: handleChange,
12154
+ min,
12155
+ max,
12156
+ step,
12157
+ className: clx(
12158
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
12159
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
12160
+ "placeholder:text-ui-fg-muted"
12161
+ ),
12162
+ ...props
12163
+ }
12164
+ ),
12165
+ /* @__PURE__ */ jsxs(
12166
+ "button",
12167
+ {
12168
+ className: clx(
12169
+ "flex items-center justify-center outline-none transition-fg",
12170
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12171
+ "focus:bg-ui-bg-field-component-hover",
12172
+ "hover:bg-ui-bg-field-component-hover",
12173
+ {
12174
+ "size-7": size === "small",
12175
+ "size-8": size === "base"
12176
+ }
12177
+ ),
12178
+ type: "button",
12179
+ onClick: handleDecrement,
12180
+ disabled: min !== void 0 && value <= min || disabled,
12181
+ children: [
12182
+ /* @__PURE__ */ jsx(Minus, {}),
12183
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12184
+ ]
12185
+ }
12186
+ ),
12187
+ /* @__PURE__ */ jsxs(
12188
+ "button",
12189
+ {
12190
+ className: clx(
12191
+ "flex items-center justify-center outline-none transition-fg",
12192
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12193
+ "focus:bg-ui-bg-field-hover",
12194
+ "hover:bg-ui-bg-field-hover",
12195
+ {
12196
+ "size-7": size === "small",
12197
+ "size-8": size === "base"
12198
+ }
12199
+ ),
12200
+ type: "button",
12201
+ onClick: handleIncrement,
12202
+ disabled: max !== void 0 && value >= max || disabled,
12203
+ children: [
12204
+ /* @__PURE__ */ jsx(Plus, {}),
12205
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12206
+ ]
12207
+ }
12208
+ )
12209
+ ]
12210
+ }
12211
+ );
12212
+ }
12213
+ );
12214
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12215
+ const productVariantsQueryKeys = {
12216
+ list: (query2) => [
12217
+ PRODUCT_VARIANTS_QUERY_KEY,
12218
+ query2 ? query2 : void 0
12219
+ ]
12220
+ };
12221
+ const useProductVariants = (query2, options) => {
12222
+ const { data, ...rest } = useQuery({
12223
+ queryKey: productVariantsQueryKeys.list(query2),
12224
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
12225
+ ...options
12226
+ });
12227
+ return { ...data, ...rest };
12228
+ };
12229
+ const STACKED_MODAL_ID = "items_stacked_modal";
12230
+ const Items = () => {
12231
+ const { id } = useParams();
12232
+ const {
12233
+ order: preview,
12234
+ isPending: isPreviewPending,
12235
+ isError: isPreviewError,
12236
+ error: previewError
12237
+ } = useOrderPreview(id, void 0, {
12238
+ placeholderData: keepPreviousData
12239
+ });
12240
+ useInitiateOrderEdit({ preview });
12241
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12242
+ id,
12243
+ {
12244
+ fields: "currency_code"
12245
+ },
12246
+ {
12247
+ enabled: !!id
12248
+ }
12249
+ );
12250
+ const { onCancel } = useCancelOrderEdit({ preview });
12251
+ if (isError) {
12252
+ throw error;
12253
+ }
12254
+ if (isPreviewError) {
12255
+ throw previewError;
12256
+ }
12257
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12258
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
12259
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12260
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12261
+ ] }) });
12262
+ };
12263
+ const ItemsForm = ({ preview, currencyCode }) => {
12264
+ var _a;
12265
+ const [isSubmitting, setIsSubmitting] = useState(false);
12266
+ const [modalContent, setModalContent] = useState(
12267
+ null
12268
+ );
12269
+ const { handleSuccess } = useRouteModal();
12270
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12271
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12272
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12273
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12274
+ const matches = useMemo(() => {
12275
+ return matchSorter(preview.items, query2, {
12276
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
12277
+ });
12278
+ }, [preview.items, query2]);
12279
+ const onSubmit = async () => {
12280
+ setIsSubmitting(true);
12281
+ let requestSucceeded = false;
12282
+ await requestOrderEdit(void 0, {
12283
+ onError: (e) => {
12284
+ toast.error(`Failed to request order edit: ${e.message}`);
12285
+ },
12286
+ onSuccess: () => {
12287
+ requestSucceeded = true;
12288
+ }
12289
+ });
12290
+ if (!requestSucceeded) {
12291
+ setIsSubmitting(false);
12292
+ return;
12293
+ }
12294
+ await confirmOrderEdit(void 0, {
12295
+ onError: (e) => {
12296
+ toast.error(`Failed to confirm order edit: ${e.message}`);
12297
+ },
12298
+ onSuccess: () => {
12299
+ handleSuccess();
12300
+ },
12301
+ onSettled: () => {
12302
+ setIsSubmitting(false);
12303
+ }
12304
+ });
12305
+ };
12306
+ const onKeyDown = useCallback(
12307
+ (e) => {
12308
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12309
+ if (modalContent || isSubmitting) {
12310
+ return;
12311
+ }
12312
+ onSubmit();
12313
+ }
12314
+ },
12315
+ [modalContent, isSubmitting, onSubmit]
12316
+ );
12317
+ useEffect(() => {
12318
+ document.addEventListener("keydown", onKeyDown);
12319
+ return () => {
12320
+ document.removeEventListener("keydown", onKeyDown);
12321
+ };
12322
+ }, [onKeyDown]);
12323
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12324
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12325
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
12326
+ StackedFocusModal,
12327
+ {
12328
+ id: STACKED_MODAL_ID,
12329
+ onOpenChangeCallback: (open) => {
12330
+ if (!open) {
12331
+ setModalContent(null);
12887
12332
  }
12888
- ),
12889
- /* @__PURE__ */ jsx(
12890
- "rect",
12891
- {
12892
- width: "12",
12893
- height: "3",
12894
- rx: "1.5",
12895
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12896
- fill: "#A1A1AA"
12333
+ },
12334
+ children: [
12335
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12336
+ /* @__PURE__ */ jsxs("div", { children: [
12337
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
12338
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
12339
+ ] }),
12340
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12341
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12342
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12343
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12345
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12346
+ ] }),
12347
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
12348
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
12349
+ Input,
12350
+ {
12351
+ type: "search",
12352
+ placeholder: "Search items",
12353
+ value: searchValue,
12354
+ onChange: (e) => onSearchValueChange(e.target.value)
12355
+ }
12356
+ ) }),
12357
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
12358
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
12359
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
12360
+ /* @__PURE__ */ jsx(
12361
+ StackedModalTrigger,
12362
+ {
12363
+ type: "add-items",
12364
+ setModalContent
12365
+ }
12366
+ ),
12367
+ /* @__PURE__ */ jsx(
12368
+ StackedModalTrigger,
12369
+ {
12370
+ type: "add-custom-item",
12371
+ setModalContent
12372
+ }
12373
+ )
12374
+ ] })
12375
+ ] })
12376
+ ] })
12377
+ ] }),
12378
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12379
+ /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
12380
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12381
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12382
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
12383
+ /* @__PURE__ */ jsx("div", {})
12384
+ ] }) }),
12385
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12386
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12387
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12388
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
12389
+ Item,
12390
+ {
12391
+ item,
12392
+ preview,
12393
+ currencyCode
12394
+ },
12395
+ item.id
12396
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12397
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12398
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12399
+ 'No items found for "',
12400
+ query2,
12401
+ '".'
12402
+ ] })
12403
+ ] }) })
12404
+ ] })
12405
+ ] }),
12406
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12407
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12408
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12409
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
12410
+ Text,
12411
+ {
12412
+ size: "small",
12413
+ leading: "compact",
12414
+ className: "text-ui-fg-subtle",
12415
+ children: [
12416
+ itemCount,
12417
+ " ",
12418
+ itemCount === 1 ? "item" : "items"
12419
+ ]
12420
+ }
12421
+ ) }),
12422
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
12423
+ ] })
12424
+ ] }) }),
12425
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
12426
+ CustomItemForm,
12427
+ {
12428
+ orderId: preview.id,
12429
+ currencyCode
12430
+ }
12431
+ ) : null)
12432
+ ]
12433
+ }
12434
+ ) }),
12435
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12436
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12437
+ /* @__PURE__ */ jsx(
12438
+ Button,
12439
+ {
12440
+ size: "small",
12441
+ type: "button",
12442
+ onClick: onSubmit,
12443
+ isLoading: isSubmitting,
12444
+ children: "Save"
12445
+ }
12446
+ )
12447
+ ] }) })
12448
+ ] });
12449
+ };
12450
+ const Item = ({ item, preview, currencyCode }) => {
12451
+ if (item.variant_id) {
12452
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
12453
+ }
12454
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
12455
+ };
12456
+ const VariantItem = ({ item, preview, currencyCode }) => {
12457
+ const [editing, setEditing] = useState(false);
12458
+ const form = useForm({
12459
+ defaultValues: {
12460
+ quantity: item.quantity,
12461
+ unit_price: item.unit_price
12462
+ },
12463
+ resolver: zodResolver(variantItemSchema)
12464
+ });
12465
+ const actionId = useMemo(() => {
12466
+ var _a, _b;
12467
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12468
+ }, [item]);
12469
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12470
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12471
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12472
+ const onSubmit = form.handleSubmit(async (data) => {
12473
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12474
+ setEditing(false);
12475
+ return;
12476
+ }
12477
+ if (!actionId) {
12478
+ await updateOriginalItem(
12479
+ {
12480
+ item_id: item.id,
12481
+ quantity: data.quantity,
12482
+ unit_price: convertNumber(data.unit_price)
12483
+ },
12484
+ {
12485
+ onSuccess: () => {
12486
+ setEditing(false);
12487
+ },
12488
+ onError: (e) => {
12489
+ toast.error(e.message);
12897
12490
  }
12898
- ),
12491
+ }
12492
+ );
12493
+ return;
12494
+ }
12495
+ await updateActionItem(
12496
+ {
12497
+ action_id: actionId,
12498
+ quantity: data.quantity,
12499
+ unit_price: convertNumber(data.unit_price)
12500
+ },
12501
+ {
12502
+ onSuccess: () => {
12503
+ setEditing(false);
12504
+ },
12505
+ onError: (e) => {
12506
+ toast.error(e.message);
12507
+ }
12508
+ }
12509
+ );
12510
+ });
12511
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12512
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
12513
+ /* @__PURE__ */ jsx(
12514
+ Thumbnail,
12515
+ {
12516
+ thumbnail: item.thumbnail,
12517
+ alt: item.product_title ?? void 0
12518
+ }
12519
+ ),
12520
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12521
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12522
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12523
+ /* @__PURE__ */ jsxs(
12524
+ Text,
12525
+ {
12526
+ size: "small",
12527
+ leading: "compact",
12528
+ className: "text-ui-fg-subtle",
12529
+ children: [
12530
+ "(",
12531
+ item.variant_title,
12532
+ ")"
12533
+ ]
12534
+ }
12535
+ )
12536
+ ] }),
12899
12537
  /* @__PURE__ */ jsx(
12900
- "path",
12901
- {
12902
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12903
- fill: "#52525B"
12904
- }
12905
- ),
12906
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12907
- "path",
12908
- {
12909
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12910
- stroke: "#A1A1AA",
12911
- strokeWidth: "1.5",
12912
- strokeLinecap: "round",
12913
- strokeLinejoin: "round"
12914
- }
12915
- ) }),
12916
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12917
- "path",
12918
- {
12919
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12920
- stroke: "#A1A1AA",
12921
- strokeWidth: "1.5",
12922
- strokeLinecap: "round",
12923
- strokeLinejoin: "round"
12924
- }
12925
- ) }),
12926
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12927
- "path",
12538
+ Text,
12928
12539
  {
12929
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12930
- stroke: "#A1A1AA",
12931
- strokeWidth: "1.5",
12932
- strokeLinecap: "round",
12933
- strokeLinejoin: "round"
12540
+ size: "small",
12541
+ leading: "compact",
12542
+ className: "text-ui-fg-subtle",
12543
+ children: item.variant_sku
12934
12544
  }
12935
- ) }),
12936
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12937
- "path",
12938
- {
12939
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12940
- stroke: "#A1A1AA",
12941
- strokeWidth: "1.5",
12942
- strokeLinecap: "round",
12943
- strokeLinejoin: "round"
12545
+ )
12546
+ ] })
12547
+ ] }),
12548
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
12549
+ Form$2.Field,
12550
+ {
12551
+ control: form.control,
12552
+ name: "quantity",
12553
+ render: ({ field }) => {
12554
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12555
+ }
12556
+ }
12557
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
12558
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
12559
+ Form$2.Field,
12560
+ {
12561
+ control: form.control,
12562
+ name: "unit_price",
12563
+ render: ({ field: { onChange, ...field } }) => {
12564
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12565
+ CurrencyInput,
12566
+ {
12567
+ ...field,
12568
+ symbol: getNativeSymbol(currencyCode),
12569
+ code: currencyCode,
12570
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12571
+ }
12572
+ ) }) });
12573
+ }
12574
+ }
12575
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12576
+ /* @__PURE__ */ jsx(
12577
+ IconButton,
12578
+ {
12579
+ type: "button",
12580
+ size: "small",
12581
+ onClick: editing ? onSubmit : () => {
12582
+ setEditing(true);
12583
+ },
12584
+ disabled: isPending,
12585
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12586
+ }
12587
+ )
12588
+ ] }) }) });
12589
+ };
12590
+ const variantItemSchema = objectType({
12591
+ quantity: numberType(),
12592
+ unit_price: unionType([numberType(), stringType()])
12593
+ });
12594
+ const CustomItem = ({ item, preview, currencyCode }) => {
12595
+ const [editing, setEditing] = useState(false);
12596
+ const { quantity, unit_price, title } = item;
12597
+ const form = useForm({
12598
+ defaultValues: {
12599
+ title,
12600
+ quantity,
12601
+ unit_price
12602
+ },
12603
+ resolver: zodResolver(customItemSchema)
12604
+ });
12605
+ useEffect(() => {
12606
+ form.reset({
12607
+ title,
12608
+ quantity,
12609
+ unit_price
12610
+ });
12611
+ }, [form, title, quantity, unit_price]);
12612
+ const actionId = useMemo(() => {
12613
+ var _a, _b;
12614
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12615
+ }, [item]);
12616
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12617
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12618
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12619
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12620
+ const onSubmit = form.handleSubmit(async (data) => {
12621
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12622
+ setEditing(false);
12623
+ return;
12624
+ }
12625
+ if (!actionId) {
12626
+ await updateOriginalItem(
12627
+ {
12628
+ item_id: item.id,
12629
+ quantity: data.quantity,
12630
+ unit_price: convertNumber(data.unit_price)
12631
+ },
12632
+ {
12633
+ onSuccess: () => {
12634
+ setEditing(false);
12635
+ },
12636
+ onError: (e) => {
12637
+ toast.error(e.message);
12944
12638
  }
12945
- ) }),
12946
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12947
- "path",
12948
- {
12949
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12950
- stroke: "#A1A1AA",
12951
- strokeWidth: "1.5",
12952
- strokeLinecap: "round",
12953
- strokeLinejoin: "round"
12639
+ }
12640
+ );
12641
+ return;
12642
+ }
12643
+ if (data.quantity === 0) {
12644
+ await removeActionItem(actionId, {
12645
+ onSuccess: () => {
12646
+ setEditing(false);
12647
+ },
12648
+ onError: (e) => {
12649
+ toast.error(e.message);
12650
+ }
12651
+ });
12652
+ return;
12653
+ }
12654
+ await updateActionItem(
12655
+ {
12656
+ action_id: actionId,
12657
+ quantity: data.quantity,
12658
+ unit_price: convertNumber(data.unit_price)
12659
+ },
12660
+ {
12661
+ onSuccess: () => {
12662
+ setEditing(false);
12663
+ },
12664
+ onError: (e) => {
12665
+ toast.error(e.message);
12666
+ }
12667
+ }
12668
+ );
12669
+ });
12670
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12671
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12672
+ /* @__PURE__ */ jsx(
12673
+ Thumbnail,
12674
+ {
12675
+ thumbnail: item.thumbnail,
12676
+ alt: item.title ?? void 0
12677
+ }
12678
+ ),
12679
+ editing ? /* @__PURE__ */ jsx(
12680
+ Form$2.Field,
12681
+ {
12682
+ control: form.control,
12683
+ name: "title",
12684
+ render: ({ field }) => {
12685
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
12954
12686
  }
12955
- ) }),
12956
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12957
- "path",
12687
+ }
12688
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
12689
+ ] }),
12690
+ editing ? /* @__PURE__ */ jsx(
12691
+ Form$2.Field,
12692
+ {
12693
+ control: form.control,
12694
+ name: "quantity",
12695
+ render: ({ field }) => {
12696
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12697
+ }
12698
+ }
12699
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
12700
+ editing ? /* @__PURE__ */ jsx(
12701
+ Form$2.Field,
12702
+ {
12703
+ control: form.control,
12704
+ name: "unit_price",
12705
+ render: ({ field: { onChange, ...field } }) => {
12706
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12707
+ CurrencyInput,
12708
+ {
12709
+ ...field,
12710
+ symbol: getNativeSymbol(currencyCode),
12711
+ code: currencyCode,
12712
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12713
+ }
12714
+ ) }) });
12715
+ }
12716
+ }
12717
+ ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12718
+ /* @__PURE__ */ jsx(
12719
+ IconButton,
12720
+ {
12721
+ type: "button",
12722
+ size: "small",
12723
+ onClick: editing ? onSubmit : () => {
12724
+ setEditing(true);
12725
+ },
12726
+ disabled: isPending,
12727
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12728
+ }
12729
+ )
12730
+ ] }) }) });
12731
+ };
12732
+ const StackedModalTrigger = ({
12733
+ type,
12734
+ setModalContent
12735
+ }) => {
12736
+ const { setIsOpen } = useStackedModal();
12737
+ const onClick = useCallback(() => {
12738
+ setModalContent(type);
12739
+ setIsOpen(STACKED_MODAL_ID, true);
12740
+ }, [setModalContent, setIsOpen, type]);
12741
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12742
+ };
12743
+ const VARIANT_PREFIX = "items";
12744
+ const LIMIT = 50;
12745
+ const ExistingItemsForm = ({ orderId, items }) => {
12746
+ const { setIsOpen } = useStackedModal();
12747
+ const [rowSelection, setRowSelection] = useState(
12748
+ items.reduce((acc, item) => {
12749
+ acc[item.variant_id] = true;
12750
+ return acc;
12751
+ }, {})
12752
+ );
12753
+ useEffect(() => {
12754
+ setRowSelection(
12755
+ items.reduce((acc, item) => {
12756
+ if (item.variant_id) {
12757
+ acc[item.variant_id] = true;
12758
+ }
12759
+ return acc;
12760
+ }, {})
12761
+ );
12762
+ }, [items]);
12763
+ const { q, order, offset } = useQueryParams(
12764
+ ["q", "order", "offset"],
12765
+ VARIANT_PREFIX
12766
+ );
12767
+ const { variants, count, isPending, isError, error } = useProductVariants(
12768
+ {
12769
+ q,
12770
+ order,
12771
+ offset: offset ? parseInt(offset) : void 0,
12772
+ limit: LIMIT
12773
+ },
12774
+ {
12775
+ placeholderData: keepPreviousData
12776
+ }
12777
+ );
12778
+ const columns = useColumns();
12779
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
12780
+ const onSubmit = async () => {
12781
+ const ids = Object.keys(rowSelection).filter(
12782
+ (id) => !items.find((i) => i.variant_id === id)
12783
+ );
12784
+ await mutateAsync(
12785
+ {
12786
+ items: ids.map((id) => ({
12787
+ variant_id: id,
12788
+ quantity: 1
12789
+ }))
12790
+ },
12791
+ {
12792
+ onSuccess: () => {
12793
+ setRowSelection({});
12794
+ setIsOpen(STACKED_MODAL_ID, false);
12795
+ },
12796
+ onError: (e) => {
12797
+ toast.error(e.message);
12798
+ }
12799
+ }
12800
+ );
12801
+ };
12802
+ if (isError) {
12803
+ throw error;
12804
+ }
12805
+ return /* @__PURE__ */ jsxs(
12806
+ StackedFocusModal.Content,
12807
+ {
12808
+ onOpenAutoFocus: (e) => {
12809
+ e.preventDefault();
12810
+ const searchInput = document.querySelector(
12811
+ "[data-modal-id='modal-search-input']"
12812
+ );
12813
+ if (searchInput) {
12814
+ searchInput.focus();
12815
+ }
12816
+ },
12817
+ children: [
12818
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
12819
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12820
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12821
+ ] }),
12822
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
12823
+ DataTable,
12958
12824
  {
12959
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12960
- stroke: "#A1A1AA",
12961
- strokeWidth: "1.5",
12962
- strokeLinecap: "round",
12963
- strokeLinejoin: "round"
12825
+ data: variants,
12826
+ columns,
12827
+ isLoading: isPending,
12828
+ getRowId: (row) => row.id,
12829
+ rowCount: count,
12830
+ prefix: VARIANT_PREFIX,
12831
+ layout: "fill",
12832
+ rowSelection: {
12833
+ state: rowSelection,
12834
+ onRowSelectionChange: setRowSelection,
12835
+ enableRowSelection: (row) => {
12836
+ return !items.find((i) => i.variant_id === row.original.id);
12837
+ }
12838
+ },
12839
+ autoFocusSearch: true
12964
12840
  }
12965
12841
  ) }),
12966
- /* @__PURE__ */ jsxs("defs", { children: [
12967
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12968
- "rect",
12969
- {
12970
- width: "12",
12971
- height: "12",
12972
- fill: "white",
12973
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12974
- }
12975
- ) }),
12976
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12977
- "rect",
12978
- {
12979
- width: "12",
12980
- height: "12",
12981
- fill: "white",
12982
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12983
- }
12984
- ) }),
12985
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12986
- "rect",
12987
- {
12988
- width: "12",
12989
- height: "12",
12990
- fill: "white",
12991
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12992
- }
12993
- ) }),
12994
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12995
- "rect",
12996
- {
12997
- width: "12",
12998
- height: "12",
12999
- fill: "white",
13000
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13001
- }
13002
- ) }),
13003
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13004
- "rect",
12842
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12843
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12844
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12845
+ ] }) })
12846
+ ]
12847
+ }
12848
+ );
12849
+ };
12850
+ const columnHelper = createDataTableColumnHelper();
12851
+ const useColumns = () => {
12852
+ return useMemo(() => {
12853
+ return [
12854
+ columnHelper.select(),
12855
+ columnHelper.accessor("product.title", {
12856
+ header: "Product",
12857
+ cell: ({ row }) => {
12858
+ var _a, _b, _c;
12859
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
12860
+ /* @__PURE__ */ jsx(
12861
+ Thumbnail,
12862
+ {
12863
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12864
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
12865
+ }
12866
+ ),
12867
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12868
+ ] });
12869
+ },
12870
+ enableSorting: true
12871
+ }),
12872
+ columnHelper.accessor("title", {
12873
+ header: "Variant",
12874
+ enableSorting: true
12875
+ }),
12876
+ columnHelper.accessor("sku", {
12877
+ header: "SKU",
12878
+ cell: ({ getValue }) => {
12879
+ return getValue() ?? "-";
12880
+ },
12881
+ enableSorting: true
12882
+ }),
12883
+ columnHelper.accessor("updated_at", {
12884
+ header: "Updated",
12885
+ cell: ({ getValue }) => {
12886
+ return /* @__PURE__ */ jsx(
12887
+ Tooltip,
13005
12888
  {
13006
- width: "12",
13007
- height: "12",
13008
- fill: "white",
13009
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12889
+ content: getFullDate({ date: getValue(), includeTime: true }),
12890
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
13010
12891
  }
13011
- ) }),
13012
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13013
- "rect",
12892
+ );
12893
+ },
12894
+ enableSorting: true,
12895
+ sortAscLabel: "Oldest first",
12896
+ sortDescLabel: "Newest first"
12897
+ }),
12898
+ columnHelper.accessor("created_at", {
12899
+ header: "Created",
12900
+ cell: ({ getValue }) => {
12901
+ return /* @__PURE__ */ jsx(
12902
+ Tooltip,
13014
12903
  {
13015
- width: "12",
13016
- height: "12",
13017
- fill: "white",
13018
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12904
+ content: getFullDate({ date: getValue(), includeTime: true }),
12905
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
13019
12906
  }
13020
- ) })
13021
- ] })
13022
- ]
13023
- }
13024
- );
12907
+ );
12908
+ },
12909
+ enableSorting: true,
12910
+ sortAscLabel: "Oldest first",
12911
+ sortDescLabel: "Newest first"
12912
+ })
12913
+ ];
12914
+ }, []);
13025
12915
  };
13026
- const schema = objectType({
13027
- customer_id: stringType().min(1)
12916
+ const CustomItemForm = ({ orderId, currencyCode }) => {
12917
+ const { setIsOpen } = useStackedModal();
12918
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12919
+ const form = useForm({
12920
+ defaultValues: {
12921
+ title: "",
12922
+ quantity: 1,
12923
+ unit_price: ""
12924
+ },
12925
+ resolver: zodResolver(customItemSchema)
12926
+ });
12927
+ const onSubmit = form.handleSubmit(async (data) => {
12928
+ await addItems(
12929
+ {
12930
+ items: [
12931
+ {
12932
+ title: data.title,
12933
+ quantity: data.quantity,
12934
+ unit_price: convertNumber(data.unit_price)
12935
+ }
12936
+ ]
12937
+ },
12938
+ {
12939
+ onSuccess: () => {
12940
+ setIsOpen(STACKED_MODAL_ID, false);
12941
+ },
12942
+ onError: (e) => {
12943
+ toast.error(e.message);
12944
+ }
12945
+ }
12946
+ );
12947
+ });
12948
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
12949
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12950
+ /* @__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: [
12951
+ /* @__PURE__ */ jsxs("div", { children: [
12952
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
12953
+ /* @__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." }) })
12954
+ ] }),
12955
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12956
+ /* @__PURE__ */ jsx(
12957
+ Form$2.Field,
12958
+ {
12959
+ control: form.control,
12960
+ name: "title",
12961
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12962
+ /* @__PURE__ */ jsxs("div", { children: [
12963
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
12964
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
12965
+ ] }),
12966
+ /* @__PURE__ */ jsxs("div", { children: [
12967
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12968
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12969
+ ] })
12970
+ ] }) })
12971
+ }
12972
+ ),
12973
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12974
+ /* @__PURE__ */ jsx(
12975
+ Form$2.Field,
12976
+ {
12977
+ control: form.control,
12978
+ name: "unit_price",
12979
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12980
+ /* @__PURE__ */ jsxs("div", { children: [
12981
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
12982
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12983
+ ] }),
12984
+ /* @__PURE__ */ jsxs("div", { children: [
12985
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12986
+ CurrencyInput,
12987
+ {
12988
+ symbol: getNativeSymbol(currencyCode),
12989
+ code: currencyCode,
12990
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12991
+ ...field
12992
+ }
12993
+ ) }),
12994
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12995
+ ] })
12996
+ ] }) })
12997
+ }
12998
+ ),
12999
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
13000
+ /* @__PURE__ */ jsx(
13001
+ Form$2.Field,
13002
+ {
13003
+ control: form.control,
13004
+ name: "quantity",
13005
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13006
+ /* @__PURE__ */ jsxs("div", { children: [
13007
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
13008
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
13009
+ ] }),
13010
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
13011
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
13012
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13013
+ ] })
13014
+ ] }) })
13015
+ }
13016
+ )
13017
+ ] }) }) }),
13018
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
13019
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13020
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
13021
+ ] }) })
13022
+ ] }) }) });
13023
+ };
13024
+ const customItemSchema = objectType({
13025
+ title: stringType().min(1),
13026
+ quantity: numberType(),
13027
+ unit_price: unionType([numberType(), stringType()])
13028
13028
  });
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
@@ -13050,18 +13050,10 @@ const routeModule = {
13050
13050
  Component: BillingAddress,
13051
13051
  path: "/draft-orders/:id/billing-address"
13052
13052
  },
13053
- {
13054
- Component: CustomItems,
13055
- path: "/draft-orders/:id/custom-items"
13056
- },
13057
13053
  {
13058
13054
  Component: Email,
13059
13055
  path: "/draft-orders/:id/email"
13060
13056
  },
13061
- {
13062
- Component: Items,
13063
- path: "/draft-orders/:id/items"
13064
- },
13065
13057
  {
13066
13058
  Component: Metadata,
13067
13059
  path: "/draft-orders/:id/metadata"
@@ -13085,6 +13077,14 @@ const routeModule = {
13085
13077
  {
13086
13078
  Component: TransferOwnership,
13087
13079
  path: "/draft-orders/:id/transfer-ownership"
13080
+ },
13081
+ {
13082
+ Component: CustomItems,
13083
+ path: "/draft-orders/:id/custom-items"
13084
+ },
13085
+ {
13086
+ Component: Items,
13087
+ path: "/draft-orders/:id/items"
13088
13088
  }
13089
13089
  ]
13090
13090
  }