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