@medusajs/draft-order 2.10.4-preview-20250928060202 → 2.10.4-preview-20250928090151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9757,6 +9757,27 @@ const BillingAddressForm = ({ order }) => {
9757
9757
  ) });
9758
9758
  };
9759
9759
  const schema$5 = addressSchema;
9760
+ const CustomItems = () => {
9761
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
+ ] });
9765
+ };
9766
+ const CustomItemsForm = () => {
9767
+ const form = useForm({
9768
+ resolver: zodResolver(schema$4)
9769
+ });
9770
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
+ ] }) })
9776
+ ] }) });
9777
+ };
9778
+ const schema$4 = objectType({
9779
+ email: stringType().email()
9780
+ });
9760
9781
  const Email = () => {
9761
9782
  const { id } = useParams();
9762
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9779,7 +9800,7 @@ const EmailForm = ({ order }) => {
9779
9800
  defaultValues: {
9780
9801
  email: order.email ?? ""
9781
9802
  },
9782
- resolver: zodResolver(schema$4)
9803
+ resolver: zodResolver(schema$3)
9783
9804
  });
9784
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9785
9806
  const { handleSuccess } = useRouteModal();
@@ -9822,518 +9843,147 @@ const EmailForm = ({ order }) => {
9822
9843
  }
9823
9844
  ) });
9824
9845
  };
9825
- const schema$4 = objectType({
9826
- email: stringType().email()
9827
- });
9828
- const CustomItems = () => {
9829
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9830
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9831
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9832
- ] });
9833
- };
9834
- const CustomItemsForm = () => {
9835
- const form = useForm({
9836
- resolver: zodResolver(schema$3)
9837
- });
9838
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9839
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9840
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9841
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9842
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9843
- ] }) })
9844
- ] }) });
9845
- };
9846
9846
  const schema$3 = objectType({
9847
9847
  email: stringType().email()
9848
9848
  });
9849
- const InlineTip = forwardRef(
9850
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9851
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9849
+ const NumberInput = forwardRef(
9850
+ ({
9851
+ value,
9852
+ onChange,
9853
+ size = "base",
9854
+ min = 0,
9855
+ max = 100,
9856
+ step = 1,
9857
+ className,
9858
+ disabled,
9859
+ ...props
9860
+ }, ref) => {
9861
+ const handleChange = (event) => {
9862
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9863
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9864
+ onChange(newValue);
9865
+ }
9866
+ };
9867
+ const handleIncrement = () => {
9868
+ const newValue = value + step;
9869
+ if (max === void 0 || newValue <= max) {
9870
+ onChange(newValue);
9871
+ }
9872
+ };
9873
+ const handleDecrement = () => {
9874
+ const newValue = value - step;
9875
+ if (min === void 0 || newValue >= min) {
9876
+ onChange(newValue);
9877
+ }
9878
+ };
9852
9879
  return /* @__PURE__ */ jsxs(
9853
9880
  "div",
9854
9881
  {
9855
- ref,
9856
9882
  className: clx(
9857
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9883
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9884
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9885
+ {
9886
+ "h-7": size === "small",
9887
+ "h-8": size === "base"
9888
+ },
9858
9889
  className
9859
9890
  ),
9860
- ...props,
9861
9891
  children: [
9862
9892
  /* @__PURE__ */ jsx(
9863
- "div",
9893
+ "input",
9864
9894
  {
9865
- role: "presentation",
9866
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9867
- "bg-ui-tag-orange-icon": variant === "warning"
9868
- })
9895
+ ref,
9896
+ type: "number",
9897
+ value,
9898
+ onChange: handleChange,
9899
+ min,
9900
+ max,
9901
+ step,
9902
+ className: clx(
9903
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9904
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9905
+ "placeholder:text-ui-fg-muted"
9906
+ ),
9907
+ ...props
9869
9908
  }
9870
9909
  ),
9871
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9872
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9873
- labelValue,
9874
- ":"
9875
- ] }),
9876
- " ",
9877
- children
9878
- ] })
9910
+ /* @__PURE__ */ jsxs(
9911
+ "button",
9912
+ {
9913
+ className: clx(
9914
+ "flex items-center justify-center outline-none transition-fg",
9915
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9916
+ "focus:bg-ui-bg-field-component-hover",
9917
+ "hover:bg-ui-bg-field-component-hover",
9918
+ {
9919
+ "size-7": size === "small",
9920
+ "size-8": size === "base"
9921
+ }
9922
+ ),
9923
+ type: "button",
9924
+ onClick: handleDecrement,
9925
+ disabled: min !== void 0 && value <= min || disabled,
9926
+ children: [
9927
+ /* @__PURE__ */ jsx(Minus, {}),
9928
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9929
+ ]
9930
+ }
9931
+ ),
9932
+ /* @__PURE__ */ jsxs(
9933
+ "button",
9934
+ {
9935
+ className: clx(
9936
+ "flex items-center justify-center outline-none transition-fg",
9937
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9938
+ "focus:bg-ui-bg-field-hover",
9939
+ "hover:bg-ui-bg-field-hover",
9940
+ {
9941
+ "size-7": size === "small",
9942
+ "size-8": size === "base"
9943
+ }
9944
+ ),
9945
+ type: "button",
9946
+ onClick: handleIncrement,
9947
+ disabled: max !== void 0 && value >= max || disabled,
9948
+ children: [
9949
+ /* @__PURE__ */ jsx(Plus, {}),
9950
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9951
+ ]
9952
+ }
9953
+ )
9879
9954
  ]
9880
9955
  }
9881
9956
  );
9882
9957
  }
9883
9958
  );
9884
- InlineTip.displayName = "InlineTip";
9885
- const MetadataFieldSchema = objectType({
9886
- key: stringType(),
9887
- disabled: booleanType().optional(),
9888
- value: anyType()
9889
- });
9890
- const MetadataSchema = objectType({
9891
- metadata: arrayType(MetadataFieldSchema)
9892
- });
9893
- const Metadata = () => {
9894
- const { id } = useParams();
9895
- const { order, isPending, isError, error } = useOrder(id, {
9896
- fields: "metadata"
9897
- });
9898
- if (isError) {
9899
- throw error;
9900
- }
9901
- const isReady = !isPending && !!order;
9902
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9903
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9904
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9905
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9906
- ] }),
9907
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9908
- ] });
9959
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9960
+ const productVariantsQueryKeys = {
9961
+ list: (query2) => [
9962
+ PRODUCT_VARIANTS_QUERY_KEY,
9963
+ query2 ? query2 : void 0
9964
+ ]
9909
9965
  };
9910
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9911
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9912
- const MetadataForm = ({ orderId, metadata }) => {
9913
- const { handleSuccess } = useRouteModal();
9914
- const hasUneditableRows = getHasUneditableRows(metadata);
9915
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9916
- const form = useForm({
9917
- defaultValues: {
9918
- metadata: getDefaultValues(metadata)
9919
- },
9920
- resolver: zodResolver(MetadataSchema)
9966
+ const useProductVariants = (query2, options) => {
9967
+ const { data, ...rest } = useQuery({
9968
+ queryKey: productVariantsQueryKeys.list(query2),
9969
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9970
+ ...options
9921
9971
  });
9922
- const handleSubmit = form.handleSubmit(async (data) => {
9923
- const parsedData = parseValues(data);
9924
- await mutateAsync(
9925
- {
9926
- metadata: parsedData
9972
+ return { ...data, ...rest };
9973
+ };
9974
+ const useCancelOrderEdit = ({ preview }) => {
9975
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9976
+ const onCancel = useCallback(async () => {
9977
+ if (!preview) {
9978
+ return true;
9979
+ }
9980
+ let res = false;
9981
+ await cancelOrderEdit(void 0, {
9982
+ onError: (e) => {
9983
+ toast.error(e.message);
9927
9984
  },
9928
- {
9929
- onSuccess: () => {
9930
- toast.success("Metadata updated");
9931
- handleSuccess();
9932
- },
9933
- onError: (error) => {
9934
- toast.error(error.message);
9935
- }
9936
- }
9937
- );
9938
- });
9939
- const { fields, insert, remove } = useFieldArray({
9940
- control: form.control,
9941
- name: "metadata"
9942
- });
9943
- function deleteRow(index) {
9944
- remove(index);
9945
- if (fields.length === 1) {
9946
- insert(0, {
9947
- key: "",
9948
- value: "",
9949
- disabled: false
9950
- });
9951
- }
9952
- }
9953
- function insertRow(index, position) {
9954
- insert(index + (position === "above" ? 0 : 1), {
9955
- key: "",
9956
- value: "",
9957
- disabled: false
9958
- });
9959
- }
9960
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9961
- KeyboundForm,
9962
- {
9963
- onSubmit: handleSubmit,
9964
- className: "flex flex-1 flex-col overflow-hidden",
9965
- children: [
9966
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9967
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9968
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9969
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9970
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9971
- ] }),
9972
- fields.map((field, index) => {
9973
- const isDisabled = field.disabled || false;
9974
- let placeholder = "-";
9975
- if (typeof field.value === "object") {
9976
- placeholder = "{ ... }";
9977
- }
9978
- if (Array.isArray(field.value)) {
9979
- placeholder = "[ ... ]";
9980
- }
9981
- return /* @__PURE__ */ jsx(
9982
- ConditionalTooltip,
9983
- {
9984
- showTooltip: isDisabled,
9985
- content: "This row is disabled because it contains non-primitive data.",
9986
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9987
- /* @__PURE__ */ jsxs(
9988
- "div",
9989
- {
9990
- className: clx("grid grid-cols-2 divide-x", {
9991
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9992
- }),
9993
- children: [
9994
- /* @__PURE__ */ jsx(
9995
- Form$2.Field,
9996
- {
9997
- control: form.control,
9998
- name: `metadata.${index}.key`,
9999
- render: ({ field: field2 }) => {
10000
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10001
- GridInput,
10002
- {
10003
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10004
- ...field2,
10005
- disabled: isDisabled,
10006
- placeholder: "Key"
10007
- }
10008
- ) }) });
10009
- }
10010
- }
10011
- ),
10012
- /* @__PURE__ */ jsx(
10013
- Form$2.Field,
10014
- {
10015
- control: form.control,
10016
- name: `metadata.${index}.value`,
10017
- render: ({ field: { value, ...field2 } }) => {
10018
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10019
- GridInput,
10020
- {
10021
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10022
- ...field2,
10023
- value: isDisabled ? placeholder : value,
10024
- disabled: isDisabled,
10025
- placeholder: "Value"
10026
- }
10027
- ) }) });
10028
- }
10029
- }
10030
- )
10031
- ]
10032
- }
10033
- ),
10034
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10035
- /* @__PURE__ */ jsx(
10036
- DropdownMenu.Trigger,
10037
- {
10038
- className: clx(
10039
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10040
- {
10041
- hidden: isDisabled
10042
- }
10043
- ),
10044
- disabled: isDisabled,
10045
- asChild: true,
10046
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10047
- }
10048
- ),
10049
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10050
- /* @__PURE__ */ jsxs(
10051
- DropdownMenu.Item,
10052
- {
10053
- className: "gap-x-2",
10054
- onClick: () => insertRow(index, "above"),
10055
- children: [
10056
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10057
- "Insert row above"
10058
- ]
10059
- }
10060
- ),
10061
- /* @__PURE__ */ jsxs(
10062
- DropdownMenu.Item,
10063
- {
10064
- className: "gap-x-2",
10065
- onClick: () => insertRow(index, "below"),
10066
- children: [
10067
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10068
- "Insert row below"
10069
- ]
10070
- }
10071
- ),
10072
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10073
- /* @__PURE__ */ jsxs(
10074
- DropdownMenu.Item,
10075
- {
10076
- className: "gap-x-2",
10077
- onClick: () => deleteRow(index),
10078
- children: [
10079
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10080
- "Delete row"
10081
- ]
10082
- }
10083
- )
10084
- ] })
10085
- ] })
10086
- ] })
10087
- },
10088
- field.id
10089
- );
10090
- })
10091
- ] }),
10092
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10093
- ] }),
10094
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10095
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10096
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10097
- ] }) })
10098
- ]
10099
- }
10100
- ) });
10101
- };
10102
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10103
- return /* @__PURE__ */ jsx(
10104
- "input",
10105
- {
10106
- ref,
10107
- ...props,
10108
- autoComplete: "off",
10109
- className: clx(
10110
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10111
- className
10112
- )
10113
- }
10114
- );
10115
- });
10116
- GridInput.displayName = "MetadataForm.GridInput";
10117
- const PlaceholderInner = () => {
10118
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10119
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10120
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10121
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10122
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10123
- ] }) })
10124
- ] });
10125
- };
10126
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10127
- function getDefaultValues(metadata) {
10128
- if (!metadata || !Object.keys(metadata).length) {
10129
- return [
10130
- {
10131
- key: "",
10132
- value: "",
10133
- disabled: false
10134
- }
10135
- ];
10136
- }
10137
- return Object.entries(metadata).map(([key, value]) => {
10138
- if (!EDITABLE_TYPES.includes(typeof value)) {
10139
- return {
10140
- key,
10141
- value,
10142
- disabled: true
10143
- };
10144
- }
10145
- let stringValue = value;
10146
- if (typeof value !== "string") {
10147
- stringValue = JSON.stringify(value);
10148
- }
10149
- return {
10150
- key,
10151
- value: stringValue,
10152
- original_key: key
10153
- };
10154
- });
10155
- }
10156
- function parseValues(values) {
10157
- const metadata = values.metadata;
10158
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10159
- if (isEmpty) {
10160
- return null;
10161
- }
10162
- const update = {};
10163
- metadata.forEach((field) => {
10164
- let key = field.key;
10165
- let value = field.value;
10166
- const disabled = field.disabled;
10167
- if (!key || !value) {
10168
- return;
10169
- }
10170
- if (disabled) {
10171
- update[key] = value;
10172
- return;
10173
- }
10174
- key = key.trim();
10175
- value = value.trim();
10176
- if (value === "true") {
10177
- update[key] = true;
10178
- } else if (value === "false") {
10179
- update[key] = false;
10180
- } else {
10181
- const parsedNumber = parseFloat(value);
10182
- if (!isNaN(parsedNumber)) {
10183
- update[key] = parsedNumber;
10184
- } else {
10185
- update[key] = value;
10186
- }
10187
- }
10188
- });
10189
- return update;
10190
- }
10191
- function getHasUneditableRows(metadata) {
10192
- if (!metadata) {
10193
- return false;
10194
- }
10195
- return Object.values(metadata).some(
10196
- (value) => !EDITABLE_TYPES.includes(typeof value)
10197
- );
10198
- }
10199
- const NumberInput = forwardRef(
10200
- ({
10201
- value,
10202
- onChange,
10203
- size = "base",
10204
- min = 0,
10205
- max = 100,
10206
- step = 1,
10207
- className,
10208
- disabled,
10209
- ...props
10210
- }, ref) => {
10211
- const handleChange = (event) => {
10212
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10213
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10214
- onChange(newValue);
10215
- }
10216
- };
10217
- const handleIncrement = () => {
10218
- const newValue = value + step;
10219
- if (max === void 0 || newValue <= max) {
10220
- onChange(newValue);
10221
- }
10222
- };
10223
- const handleDecrement = () => {
10224
- const newValue = value - step;
10225
- if (min === void 0 || newValue >= min) {
10226
- onChange(newValue);
10227
- }
10228
- };
10229
- return /* @__PURE__ */ jsxs(
10230
- "div",
10231
- {
10232
- className: clx(
10233
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10234
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10235
- {
10236
- "h-7": size === "small",
10237
- "h-8": size === "base"
10238
- },
10239
- className
10240
- ),
10241
- children: [
10242
- /* @__PURE__ */ jsx(
10243
- "input",
10244
- {
10245
- ref,
10246
- type: "number",
10247
- value,
10248
- onChange: handleChange,
10249
- min,
10250
- max,
10251
- step,
10252
- className: clx(
10253
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10254
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10255
- "placeholder:text-ui-fg-muted"
10256
- ),
10257
- ...props
10258
- }
10259
- ),
10260
- /* @__PURE__ */ jsxs(
10261
- "button",
10262
- {
10263
- className: clx(
10264
- "flex items-center justify-center outline-none transition-fg",
10265
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10266
- "focus:bg-ui-bg-field-component-hover",
10267
- "hover:bg-ui-bg-field-component-hover",
10268
- {
10269
- "size-7": size === "small",
10270
- "size-8": size === "base"
10271
- }
10272
- ),
10273
- type: "button",
10274
- onClick: handleDecrement,
10275
- disabled: min !== void 0 && value <= min || disabled,
10276
- children: [
10277
- /* @__PURE__ */ jsx(Minus, {}),
10278
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10279
- ]
10280
- }
10281
- ),
10282
- /* @__PURE__ */ jsxs(
10283
- "button",
10284
- {
10285
- className: clx(
10286
- "flex items-center justify-center outline-none transition-fg",
10287
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10288
- "focus:bg-ui-bg-field-hover",
10289
- "hover:bg-ui-bg-field-hover",
10290
- {
10291
- "size-7": size === "small",
10292
- "size-8": size === "base"
10293
- }
10294
- ),
10295
- type: "button",
10296
- onClick: handleIncrement,
10297
- disabled: max !== void 0 && value >= max || disabled,
10298
- children: [
10299
- /* @__PURE__ */ jsx(Plus, {}),
10300
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10301
- ]
10302
- }
10303
- )
10304
- ]
10305
- }
10306
- );
10307
- }
10308
- );
10309
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10310
- const productVariantsQueryKeys = {
10311
- list: (query2) => [
10312
- PRODUCT_VARIANTS_QUERY_KEY,
10313
- query2 ? query2 : void 0
10314
- ]
10315
- };
10316
- const useProductVariants = (query2, options) => {
10317
- const { data, ...rest } = useQuery({
10318
- queryKey: productVariantsQueryKeys.list(query2),
10319
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10320
- ...options
10321
- });
10322
- return { ...data, ...rest };
10323
- };
10324
- const useCancelOrderEdit = ({ preview }) => {
10325
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10326
- const onCancel = useCallback(async () => {
10327
- if (!preview) {
10328
- return true;
10329
- }
10330
- let res = false;
10331
- await cancelOrderEdit(void 0, {
10332
- onError: (e) => {
10333
- toast.error(e.message);
10334
- },
10335
- onSuccess: () => {
10336
- res = true;
9985
+ onSuccess: () => {
9986
+ res = true;
10337
9987
  }
10338
9988
  });
10339
9989
  return res;
@@ -10601,20 +10251,168 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10601
10251
  const [editing, setEditing] = useState(false);
10602
10252
  const form = useForm({
10603
10253
  defaultValues: {
10604
- quantity: item.quantity,
10605
- unit_price: item.unit_price
10254
+ quantity: item.quantity,
10255
+ unit_price: item.unit_price
10256
+ },
10257
+ resolver: zodResolver(variantItemSchema)
10258
+ });
10259
+ const actionId = useMemo(() => {
10260
+ var _a, _b;
10261
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10262
+ }, [item]);
10263
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10264
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10265
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10266
+ const onSubmit = form.handleSubmit(async (data) => {
10267
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10268
+ setEditing(false);
10269
+ return;
10270
+ }
10271
+ if (!actionId) {
10272
+ await updateOriginalItem(
10273
+ {
10274
+ item_id: item.id,
10275
+ quantity: data.quantity,
10276
+ unit_price: convertNumber(data.unit_price)
10277
+ },
10278
+ {
10279
+ onSuccess: () => {
10280
+ setEditing(false);
10281
+ },
10282
+ onError: (e) => {
10283
+ toast.error(e.message);
10284
+ }
10285
+ }
10286
+ );
10287
+ return;
10288
+ }
10289
+ await updateActionItem(
10290
+ {
10291
+ action_id: actionId,
10292
+ quantity: data.quantity,
10293
+ unit_price: convertNumber(data.unit_price)
10294
+ },
10295
+ {
10296
+ onSuccess: () => {
10297
+ setEditing(false);
10298
+ },
10299
+ onError: (e) => {
10300
+ toast.error(e.message);
10301
+ }
10302
+ }
10303
+ );
10304
+ });
10305
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10306
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10307
+ /* @__PURE__ */ jsx(
10308
+ Thumbnail,
10309
+ {
10310
+ thumbnail: item.thumbnail,
10311
+ alt: item.product_title ?? void 0
10312
+ }
10313
+ ),
10314
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10315
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10316
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10317
+ /* @__PURE__ */ jsxs(
10318
+ Text,
10319
+ {
10320
+ size: "small",
10321
+ leading: "compact",
10322
+ className: "text-ui-fg-subtle",
10323
+ children: [
10324
+ "(",
10325
+ item.variant_title,
10326
+ ")"
10327
+ ]
10328
+ }
10329
+ )
10330
+ ] }),
10331
+ /* @__PURE__ */ jsx(
10332
+ Text,
10333
+ {
10334
+ size: "small",
10335
+ leading: "compact",
10336
+ className: "text-ui-fg-subtle",
10337
+ children: item.variant_sku
10338
+ }
10339
+ )
10340
+ ] })
10341
+ ] }),
10342
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10343
+ Form$2.Field,
10344
+ {
10345
+ control: form.control,
10346
+ name: "quantity",
10347
+ render: ({ field }) => {
10348
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10349
+ }
10350
+ }
10351
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10352
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10353
+ Form$2.Field,
10354
+ {
10355
+ control: form.control,
10356
+ name: "unit_price",
10357
+ render: ({ field: { onChange, ...field } }) => {
10358
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10359
+ CurrencyInput,
10360
+ {
10361
+ ...field,
10362
+ symbol: getNativeSymbol(currencyCode),
10363
+ code: currencyCode,
10364
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10365
+ }
10366
+ ) }) });
10367
+ }
10368
+ }
10369
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10370
+ /* @__PURE__ */ jsx(
10371
+ IconButton,
10372
+ {
10373
+ type: "button",
10374
+ size: "small",
10375
+ onClick: editing ? onSubmit : () => {
10376
+ setEditing(true);
10377
+ },
10378
+ disabled: isPending,
10379
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10380
+ }
10381
+ )
10382
+ ] }) }) });
10383
+ };
10384
+ const variantItemSchema = objectType({
10385
+ quantity: numberType(),
10386
+ unit_price: unionType([numberType(), stringType()])
10387
+ });
10388
+ const CustomItem = ({ item, preview, currencyCode }) => {
10389
+ const [editing, setEditing] = useState(false);
10390
+ const { quantity, unit_price, title } = item;
10391
+ const form = useForm({
10392
+ defaultValues: {
10393
+ title,
10394
+ quantity,
10395
+ unit_price
10606
10396
  },
10607
- resolver: zodResolver(variantItemSchema)
10397
+ resolver: zodResolver(customItemSchema)
10608
10398
  });
10399
+ useEffect(() => {
10400
+ form.reset({
10401
+ title,
10402
+ quantity,
10403
+ unit_price
10404
+ });
10405
+ }, [form, title, quantity, unit_price]);
10609
10406
  const actionId = useMemo(() => {
10610
10407
  var _a, _b;
10611
10408
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10612
10409
  }, [item]);
10613
10410
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10411
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10614
10412
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10615
10413
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10616
10414
  const onSubmit = form.handleSubmit(async (data) => {
10617
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10415
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10618
10416
  setEditing(false);
10619
10417
  return;
10620
10418
  }
@@ -10636,6 +10434,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10636
10434
  );
10637
10435
  return;
10638
10436
  }
10437
+ if (data.quantity === 0) {
10438
+ await removeActionItem(actionId, {
10439
+ onSuccess: () => {
10440
+ setEditing(false);
10441
+ },
10442
+ onError: (e) => {
10443
+ toast.error(e.message);
10444
+ }
10445
+ });
10446
+ return;
10447
+ }
10639
10448
  await updateActionItem(
10640
10449
  {
10641
10450
  action_id: actionId,
@@ -10653,43 +10462,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10653
10462
  );
10654
10463
  });
10655
10464
  return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10656
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10465
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10657
10466
  /* @__PURE__ */ jsx(
10658
10467
  Thumbnail,
10659
10468
  {
10660
10469
  thumbnail: item.thumbnail,
10661
- alt: item.product_title ?? void 0
10470
+ alt: item.title ?? void 0
10662
10471
  }
10663
10472
  ),
10664
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10665
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10666
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10667
- /* @__PURE__ */ jsxs(
10668
- Text,
10669
- {
10670
- size: "small",
10671
- leading: "compact",
10672
- className: "text-ui-fg-subtle",
10673
- children: [
10674
- "(",
10675
- item.variant_title,
10676
- ")"
10677
- ]
10678
- }
10679
- )
10680
- ] }),
10681
- /* @__PURE__ */ jsx(
10682
- Text,
10683
- {
10684
- size: "small",
10685
- leading: "compact",
10686
- className: "text-ui-fg-subtle",
10687
- children: item.variant_sku
10473
+ editing ? /* @__PURE__ */ jsx(
10474
+ Form$2.Field,
10475
+ {
10476
+ control: form.control,
10477
+ name: "title",
10478
+ render: ({ field }) => {
10479
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10688
10480
  }
10689
- )
10690
- ] })
10481
+ }
10482
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10691
10483
  ] }),
10692
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10484
+ editing ? /* @__PURE__ */ jsx(
10693
10485
  Form$2.Field,
10694
10486
  {
10695
10487
  control: form.control,
@@ -10698,8 +10490,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10698
10490
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10699
10491
  }
10700
10492
  }
10701
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10702
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10493
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10494
+ editing ? /* @__PURE__ */ jsx(
10703
10495
  Form$2.Field,
10704
10496
  {
10705
10497
  control: form.control,
@@ -10716,7 +10508,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10716
10508
  ) }) });
10717
10509
  }
10718
10510
  }
10719
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10511
+ ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10720
10512
  /* @__PURE__ */ jsx(
10721
10513
  IconButton,
10722
10514
  {
@@ -10731,79 +10523,215 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10731
10523
  )
10732
10524
  ] }) }) });
10733
10525
  };
10734
- const variantItemSchema = objectType({
10735
- quantity: numberType(),
10736
- unit_price: unionType([numberType(), stringType()])
10737
- });
10738
- const CustomItem = ({ item, preview, currencyCode }) => {
10739
- const [editing, setEditing] = useState(false);
10740
- const { quantity, unit_price, title } = item;
10526
+ const StackedModalTrigger$1 = ({
10527
+ type,
10528
+ setModalContent
10529
+ }) => {
10530
+ const { setIsOpen } = useStackedModal();
10531
+ const onClick = useCallback(() => {
10532
+ setModalContent(type);
10533
+ setIsOpen(STACKED_MODAL_ID, true);
10534
+ }, [setModalContent, setIsOpen, type]);
10535
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10536
+ };
10537
+ const VARIANT_PREFIX = "items";
10538
+ const LIMIT = 50;
10539
+ const ExistingItemsForm = ({ orderId, items }) => {
10540
+ const { setIsOpen } = useStackedModal();
10541
+ const [rowSelection, setRowSelection] = useState(
10542
+ items.reduce((acc, item) => {
10543
+ acc[item.variant_id] = true;
10544
+ return acc;
10545
+ }, {})
10546
+ );
10547
+ useEffect(() => {
10548
+ setRowSelection(
10549
+ items.reduce((acc, item) => {
10550
+ if (item.variant_id) {
10551
+ acc[item.variant_id] = true;
10552
+ }
10553
+ return acc;
10554
+ }, {})
10555
+ );
10556
+ }, [items]);
10557
+ const { q, order, offset } = useQueryParams(
10558
+ ["q", "order", "offset"],
10559
+ VARIANT_PREFIX
10560
+ );
10561
+ const { variants, count, isPending, isError, error } = useProductVariants(
10562
+ {
10563
+ q,
10564
+ order,
10565
+ offset: offset ? parseInt(offset) : void 0,
10566
+ limit: LIMIT
10567
+ },
10568
+ {
10569
+ placeholderData: keepPreviousData
10570
+ }
10571
+ );
10572
+ const columns = useColumns();
10573
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10574
+ const onSubmit = async () => {
10575
+ const ids = Object.keys(rowSelection).filter(
10576
+ (id) => !items.find((i) => i.variant_id === id)
10577
+ );
10578
+ await mutateAsync(
10579
+ {
10580
+ items: ids.map((id) => ({
10581
+ variant_id: id,
10582
+ quantity: 1
10583
+ }))
10584
+ },
10585
+ {
10586
+ onSuccess: () => {
10587
+ setRowSelection({});
10588
+ setIsOpen(STACKED_MODAL_ID, false);
10589
+ },
10590
+ onError: (e) => {
10591
+ toast.error(e.message);
10592
+ }
10593
+ }
10594
+ );
10595
+ };
10596
+ if (isError) {
10597
+ throw error;
10598
+ }
10599
+ return /* @__PURE__ */ jsxs(
10600
+ StackedFocusModal.Content,
10601
+ {
10602
+ onOpenAutoFocus: (e) => {
10603
+ e.preventDefault();
10604
+ const searchInput = document.querySelector(
10605
+ "[data-modal-id='modal-search-input']"
10606
+ );
10607
+ if (searchInput) {
10608
+ searchInput.focus();
10609
+ }
10610
+ },
10611
+ children: [
10612
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10613
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10614
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10615
+ ] }),
10616
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10617
+ DataTable,
10618
+ {
10619
+ data: variants,
10620
+ columns,
10621
+ isLoading: isPending,
10622
+ getRowId: (row) => row.id,
10623
+ rowCount: count,
10624
+ prefix: VARIANT_PREFIX,
10625
+ layout: "fill",
10626
+ rowSelection: {
10627
+ state: rowSelection,
10628
+ onRowSelectionChange: setRowSelection,
10629
+ enableRowSelection: (row) => {
10630
+ return !items.find((i) => i.variant_id === row.original.id);
10631
+ }
10632
+ },
10633
+ autoFocusSearch: true
10634
+ }
10635
+ ) }),
10636
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10637
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10638
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10639
+ ] }) })
10640
+ ]
10641
+ }
10642
+ );
10643
+ };
10644
+ const columnHelper = createDataTableColumnHelper();
10645
+ const useColumns = () => {
10646
+ return useMemo(() => {
10647
+ return [
10648
+ columnHelper.select(),
10649
+ columnHelper.accessor("product.title", {
10650
+ header: "Product",
10651
+ cell: ({ row }) => {
10652
+ var _a, _b, _c;
10653
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10654
+ /* @__PURE__ */ jsx(
10655
+ Thumbnail,
10656
+ {
10657
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10658
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10659
+ }
10660
+ ),
10661
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10662
+ ] });
10663
+ },
10664
+ enableSorting: true
10665
+ }),
10666
+ columnHelper.accessor("title", {
10667
+ header: "Variant",
10668
+ enableSorting: true
10669
+ }),
10670
+ columnHelper.accessor("sku", {
10671
+ header: "SKU",
10672
+ cell: ({ getValue }) => {
10673
+ return getValue() ?? "-";
10674
+ },
10675
+ enableSorting: true
10676
+ }),
10677
+ columnHelper.accessor("updated_at", {
10678
+ header: "Updated",
10679
+ cell: ({ getValue }) => {
10680
+ return /* @__PURE__ */ jsx(
10681
+ Tooltip,
10682
+ {
10683
+ content: getFullDate({ date: getValue(), includeTime: true }),
10684
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10685
+ }
10686
+ );
10687
+ },
10688
+ enableSorting: true,
10689
+ sortAscLabel: "Oldest first",
10690
+ sortDescLabel: "Newest first"
10691
+ }),
10692
+ columnHelper.accessor("created_at", {
10693
+ header: "Created",
10694
+ cell: ({ getValue }) => {
10695
+ return /* @__PURE__ */ jsx(
10696
+ Tooltip,
10697
+ {
10698
+ content: getFullDate({ date: getValue(), includeTime: true }),
10699
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10700
+ }
10701
+ );
10702
+ },
10703
+ enableSorting: true,
10704
+ sortAscLabel: "Oldest first",
10705
+ sortDescLabel: "Newest first"
10706
+ })
10707
+ ];
10708
+ }, []);
10709
+ };
10710
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10711
+ const { setIsOpen } = useStackedModal();
10712
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10741
10713
  const form = useForm({
10742
10714
  defaultValues: {
10743
- title,
10744
- quantity,
10745
- unit_price
10715
+ title: "",
10716
+ quantity: 1,
10717
+ unit_price: ""
10746
10718
  },
10747
10719
  resolver: zodResolver(customItemSchema)
10748
10720
  });
10749
- useEffect(() => {
10750
- form.reset({
10751
- title,
10752
- quantity,
10753
- unit_price
10754
- });
10755
- }, [form, title, quantity, unit_price]);
10756
- const actionId = useMemo(() => {
10757
- var _a, _b;
10758
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10759
- }, [item]);
10760
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10761
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10762
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10763
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10764
10721
  const onSubmit = form.handleSubmit(async (data) => {
10765
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10766
- setEditing(false);
10767
- return;
10768
- }
10769
- if (!actionId) {
10770
- await updateOriginalItem(
10771
- {
10772
- item_id: item.id,
10773
- quantity: data.quantity,
10774
- unit_price: convertNumber(data.unit_price)
10775
- },
10776
- {
10777
- onSuccess: () => {
10778
- setEditing(false);
10779
- },
10780
- onError: (e) => {
10781
- toast.error(e.message);
10782
- }
10783
- }
10784
- );
10785
- return;
10786
- }
10787
- if (data.quantity === 0) {
10788
- await removeActionItem(actionId, {
10789
- onSuccess: () => {
10790
- setEditing(false);
10791
- },
10792
- onError: (e) => {
10793
- toast.error(e.message);
10794
- }
10795
- });
10796
- return;
10797
- }
10798
- await updateActionItem(
10722
+ await addItems(
10799
10723
  {
10800
- action_id: actionId,
10801
- quantity: data.quantity,
10802
- unit_price: convertNumber(data.unit_price)
10724
+ items: [
10725
+ {
10726
+ title: data.title,
10727
+ quantity: data.quantity,
10728
+ unit_price: convertNumber(data.unit_price)
10729
+ }
10730
+ ]
10803
10731
  },
10804
10732
  {
10805
10733
  onSuccess: () => {
10806
- setEditing(false);
10734
+ setIsOpen(STACKED_MODAL_ID, false);
10807
10735
  },
10808
10736
  onError: (e) => {
10809
10737
  toast.error(e.message);
@@ -10811,365 +10739,714 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10811
10739
  }
10812
10740
  );
10813
10741
  });
10814
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10815
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10742
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10743
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10744
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10745
+ /* @__PURE__ */ jsxs("div", { children: [
10746
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10747
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10748
+ ] }),
10749
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10816
10750
  /* @__PURE__ */ jsx(
10817
- Thumbnail,
10751
+ Form$2.Field,
10818
10752
  {
10819
- thumbnail: item.thumbnail,
10820
- alt: item.title ?? void 0
10753
+ control: form.control,
10754
+ name: "title",
10755
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10756
+ /* @__PURE__ */ jsxs("div", { children: [
10757
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10758
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10759
+ ] }),
10760
+ /* @__PURE__ */ jsxs("div", { children: [
10761
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10762
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10763
+ ] })
10764
+ ] }) })
10821
10765
  }
10822
10766
  ),
10823
- editing ? /* @__PURE__ */ jsx(
10767
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10768
+ /* @__PURE__ */ jsx(
10824
10769
  Form$2.Field,
10825
10770
  {
10826
10771
  control: form.control,
10827
- name: "title",
10828
- render: ({ field }) => {
10829
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10830
- }
10772
+ name: "unit_price",
10773
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10774
+ /* @__PURE__ */ jsxs("div", { children: [
10775
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10776
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10777
+ ] }),
10778
+ /* @__PURE__ */ jsxs("div", { children: [
10779
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10780
+ CurrencyInput,
10781
+ {
10782
+ symbol: getNativeSymbol(currencyCode),
10783
+ code: currencyCode,
10784
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10785
+ ...field
10786
+ }
10787
+ ) }),
10788
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10789
+ ] })
10790
+ ] }) })
10831
10791
  }
10832
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10833
- ] }),
10834
- editing ? /* @__PURE__ */ jsx(
10835
- Form$2.Field,
10836
- {
10837
- control: form.control,
10838
- name: "quantity",
10839
- render: ({ field }) => {
10840
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10792
+ ),
10793
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10794
+ /* @__PURE__ */ jsx(
10795
+ Form$2.Field,
10796
+ {
10797
+ control: form.control,
10798
+ name: "quantity",
10799
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10800
+ /* @__PURE__ */ jsxs("div", { children: [
10801
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10802
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10803
+ ] }),
10804
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10805
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10806
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10807
+ ] })
10808
+ ] }) })
10841
10809
  }
10842
- }
10843
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10844
- editing ? /* @__PURE__ */ jsx(
10845
- Form$2.Field,
10810
+ )
10811
+ ] }) }) }),
10812
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10813
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10814
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10815
+ ] }) })
10816
+ ] }) }) });
10817
+ };
10818
+ const customItemSchema = objectType({
10819
+ title: stringType().min(1),
10820
+ quantity: numberType(),
10821
+ unit_price: unionType([numberType(), stringType()])
10822
+ });
10823
+ const InlineTip = forwardRef(
10824
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10825
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10826
+ return /* @__PURE__ */ jsxs(
10827
+ "div",
10846
10828
  {
10847
- control: form.control,
10848
- name: "unit_price",
10849
- render: ({ field: { onChange, ...field } }) => {
10850
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10851
- CurrencyInput,
10829
+ ref,
10830
+ className: clx(
10831
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10832
+ className
10833
+ ),
10834
+ ...props,
10835
+ children: [
10836
+ /* @__PURE__ */ jsx(
10837
+ "div",
10852
10838
  {
10853
- ...field,
10854
- symbol: getNativeSymbol(currencyCode),
10855
- code: currencyCode,
10856
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10839
+ role: "presentation",
10840
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10841
+ "bg-ui-tag-orange-icon": variant === "warning"
10842
+ })
10857
10843
  }
10858
- ) }) });
10859
- }
10860
- }
10861
- ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10862
- /* @__PURE__ */ jsx(
10863
- IconButton,
10864
- {
10865
- type: "button",
10866
- size: "small",
10867
- onClick: editing ? onSubmit : () => {
10868
- setEditing(true);
10869
- },
10870
- disabled: isPending,
10871
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10872
- }
10873
- )
10874
- ] }) }) });
10875
- };
10876
- const StackedModalTrigger$1 = ({
10877
- type,
10878
- setModalContent
10879
- }) => {
10880
- const { setIsOpen } = useStackedModal();
10881
- const onClick = useCallback(() => {
10882
- setModalContent(type);
10883
- setIsOpen(STACKED_MODAL_ID, true);
10884
- }, [setModalContent, setIsOpen, type]);
10885
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10886
- };
10887
- const VARIANT_PREFIX = "items";
10888
- const LIMIT = 50;
10889
- const ExistingItemsForm = ({ orderId, items }) => {
10890
- const { setIsOpen } = useStackedModal();
10891
- const [rowSelection, setRowSelection] = useState(
10892
- items.reduce((acc, item) => {
10893
- acc[item.variant_id] = true;
10894
- return acc;
10895
- }, {})
10896
- );
10897
- useEffect(() => {
10898
- setRowSelection(
10899
- items.reduce((acc, item) => {
10900
- if (item.variant_id) {
10901
- acc[item.variant_id] = true;
10902
- }
10903
- return acc;
10904
- }, {})
10844
+ ),
10845
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10846
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10847
+ labelValue,
10848
+ ":"
10849
+ ] }),
10850
+ " ",
10851
+ children
10852
+ ] })
10853
+ ]
10854
+ }
10905
10855
  );
10906
- }, [items]);
10907
- const { q, order, offset } = useQueryParams(
10908
- ["q", "order", "offset"],
10909
- VARIANT_PREFIX
10910
- );
10911
- const { variants, count, isPending, isError, error } = useProductVariants(
10912
- {
10913
- q,
10914
- order,
10915
- offset: offset ? parseInt(offset) : void 0,
10916
- limit: LIMIT
10856
+ }
10857
+ );
10858
+ InlineTip.displayName = "InlineTip";
10859
+ const MetadataFieldSchema = objectType({
10860
+ key: stringType(),
10861
+ disabled: booleanType().optional(),
10862
+ value: anyType()
10863
+ });
10864
+ const MetadataSchema = objectType({
10865
+ metadata: arrayType(MetadataFieldSchema)
10866
+ });
10867
+ const Metadata = () => {
10868
+ const { id } = useParams();
10869
+ const { order, isPending, isError, error } = useOrder(id, {
10870
+ fields: "metadata"
10871
+ });
10872
+ if (isError) {
10873
+ throw error;
10874
+ }
10875
+ const isReady = !isPending && !!order;
10876
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10877
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10878
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10879
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10880
+ ] }),
10881
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10882
+ ] });
10883
+ };
10884
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10885
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10886
+ const MetadataForm = ({ orderId, metadata }) => {
10887
+ const { handleSuccess } = useRouteModal();
10888
+ const hasUneditableRows = getHasUneditableRows(metadata);
10889
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10890
+ const form = useForm({
10891
+ defaultValues: {
10892
+ metadata: getDefaultValues(metadata)
10917
10893
  },
10918
- {
10919
- placeholderData: keepPreviousData
10920
- }
10921
- );
10922
- const columns = useColumns();
10923
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10924
- const onSubmit = async () => {
10925
- const ids = Object.keys(rowSelection).filter(
10926
- (id) => !items.find((i) => i.variant_id === id)
10927
- );
10894
+ resolver: zodResolver(MetadataSchema)
10895
+ });
10896
+ const handleSubmit = form.handleSubmit(async (data) => {
10897
+ const parsedData = parseValues(data);
10928
10898
  await mutateAsync(
10929
10899
  {
10930
- items: ids.map((id) => ({
10931
- variant_id: id,
10932
- quantity: 1
10933
- }))
10900
+ metadata: parsedData
10934
10901
  },
10935
10902
  {
10936
10903
  onSuccess: () => {
10937
- setRowSelection({});
10938
- setIsOpen(STACKED_MODAL_ID, false);
10904
+ toast.success("Metadata updated");
10905
+ handleSuccess();
10939
10906
  },
10940
- onError: (e) => {
10941
- toast.error(e.message);
10907
+ onError: (error) => {
10908
+ toast.error(error.message);
10942
10909
  }
10943
10910
  }
10944
10911
  );
10945
- };
10946
- if (isError) {
10947
- throw error;
10912
+ });
10913
+ const { fields, insert, remove } = useFieldArray({
10914
+ control: form.control,
10915
+ name: "metadata"
10916
+ });
10917
+ function deleteRow(index) {
10918
+ remove(index);
10919
+ if (fields.length === 1) {
10920
+ insert(0, {
10921
+ key: "",
10922
+ value: "",
10923
+ disabled: false
10924
+ });
10925
+ }
10948
10926
  }
10949
- return /* @__PURE__ */ jsxs(
10950
- StackedFocusModal.Content,
10927
+ function insertRow(index, position) {
10928
+ insert(index + (position === "above" ? 0 : 1), {
10929
+ key: "",
10930
+ value: "",
10931
+ disabled: false
10932
+ });
10933
+ }
10934
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10935
+ KeyboundForm,
10951
10936
  {
10952
- onOpenAutoFocus: (e) => {
10953
- e.preventDefault();
10954
- const searchInput = document.querySelector(
10955
- "[data-modal-id='modal-search-input']"
10956
- );
10957
- if (searchInput) {
10958
- searchInput.focus();
10959
- }
10960
- },
10937
+ onSubmit: handleSubmit,
10938
+ className: "flex flex-1 flex-col overflow-hidden",
10961
10939
  children: [
10962
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10963
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10964
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10965
- ] }),
10966
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10967
- DataTable,
10968
- {
10969
- data: variants,
10970
- columns,
10971
- isLoading: isPending,
10972
- getRowId: (row) => row.id,
10973
- rowCount: count,
10974
- prefix: VARIANT_PREFIX,
10975
- layout: "fill",
10976
- rowSelection: {
10977
- state: rowSelection,
10978
- onRowSelectionChange: setRowSelection,
10979
- enableRowSelection: (row) => {
10980
- return !items.find((i) => i.variant_id === row.original.id);
10940
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10941
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10942
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10943
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10944
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10945
+ ] }),
10946
+ fields.map((field, index) => {
10947
+ const isDisabled = field.disabled || false;
10948
+ let placeholder = "-";
10949
+ if (typeof field.value === "object") {
10950
+ placeholder = "{ ... }";
10981
10951
  }
10982
- },
10983
- autoFocusSearch: true
10984
- }
10985
- ) }),
10986
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10987
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10988
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10952
+ if (Array.isArray(field.value)) {
10953
+ placeholder = "[ ... ]";
10954
+ }
10955
+ return /* @__PURE__ */ jsx(
10956
+ ConditionalTooltip,
10957
+ {
10958
+ showTooltip: isDisabled,
10959
+ content: "This row is disabled because it contains non-primitive data.",
10960
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10961
+ /* @__PURE__ */ jsxs(
10962
+ "div",
10963
+ {
10964
+ className: clx("grid grid-cols-2 divide-x", {
10965
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10966
+ }),
10967
+ children: [
10968
+ /* @__PURE__ */ jsx(
10969
+ Form$2.Field,
10970
+ {
10971
+ control: form.control,
10972
+ name: `metadata.${index}.key`,
10973
+ render: ({ field: field2 }) => {
10974
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10975
+ GridInput,
10976
+ {
10977
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10978
+ ...field2,
10979
+ disabled: isDisabled,
10980
+ placeholder: "Key"
10981
+ }
10982
+ ) }) });
10983
+ }
10984
+ }
10985
+ ),
10986
+ /* @__PURE__ */ jsx(
10987
+ Form$2.Field,
10988
+ {
10989
+ control: form.control,
10990
+ name: `metadata.${index}.value`,
10991
+ render: ({ field: { value, ...field2 } }) => {
10992
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10993
+ GridInput,
10994
+ {
10995
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10996
+ ...field2,
10997
+ value: isDisabled ? placeholder : value,
10998
+ disabled: isDisabled,
10999
+ placeholder: "Value"
11000
+ }
11001
+ ) }) });
11002
+ }
11003
+ }
11004
+ )
11005
+ ]
11006
+ }
11007
+ ),
11008
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11009
+ /* @__PURE__ */ jsx(
11010
+ DropdownMenu.Trigger,
11011
+ {
11012
+ className: clx(
11013
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11014
+ {
11015
+ hidden: isDisabled
11016
+ }
11017
+ ),
11018
+ disabled: isDisabled,
11019
+ asChild: true,
11020
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11021
+ }
11022
+ ),
11023
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11024
+ /* @__PURE__ */ jsxs(
11025
+ DropdownMenu.Item,
11026
+ {
11027
+ className: "gap-x-2",
11028
+ onClick: () => insertRow(index, "above"),
11029
+ children: [
11030
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11031
+ "Insert row above"
11032
+ ]
11033
+ }
11034
+ ),
11035
+ /* @__PURE__ */ jsxs(
11036
+ DropdownMenu.Item,
11037
+ {
11038
+ className: "gap-x-2",
11039
+ onClick: () => insertRow(index, "below"),
11040
+ children: [
11041
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11042
+ "Insert row below"
11043
+ ]
11044
+ }
11045
+ ),
11046
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11047
+ /* @__PURE__ */ jsxs(
11048
+ DropdownMenu.Item,
11049
+ {
11050
+ className: "gap-x-2",
11051
+ onClick: () => deleteRow(index),
11052
+ children: [
11053
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11054
+ "Delete row"
11055
+ ]
11056
+ }
11057
+ )
11058
+ ] })
11059
+ ] })
11060
+ ] })
11061
+ },
11062
+ field.id
11063
+ );
11064
+ })
11065
+ ] }),
11066
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11067
+ ] }),
11068
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11069
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11070
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10989
11071
  ] }) })
10990
11072
  ]
10991
11073
  }
11074
+ ) });
11075
+ };
11076
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11077
+ return /* @__PURE__ */ jsx(
11078
+ "input",
11079
+ {
11080
+ ref,
11081
+ ...props,
11082
+ autoComplete: "off",
11083
+ className: clx(
11084
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11085
+ className
11086
+ )
11087
+ }
10992
11088
  );
11089
+ });
11090
+ GridInput.displayName = "MetadataForm.GridInput";
11091
+ const PlaceholderInner = () => {
11092
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11093
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11094
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11095
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11096
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11097
+ ] }) })
11098
+ ] });
10993
11099
  };
10994
- const columnHelper = createDataTableColumnHelper();
10995
- const useColumns = () => {
10996
- return useMemo(() => {
11100
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11101
+ function getDefaultValues(metadata) {
11102
+ if (!metadata || !Object.keys(metadata).length) {
10997
11103
  return [
10998
- columnHelper.select(),
10999
- columnHelper.accessor("product.title", {
11000
- header: "Product",
11001
- cell: ({ row }) => {
11002
- var _a, _b, _c;
11003
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
11004
- /* @__PURE__ */ jsx(
11005
- Thumbnail,
11006
- {
11007
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11008
- alt: (_b = row.original.product) == null ? void 0 : _b.title
11009
- }
11010
- ),
11011
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11012
- ] });
11013
- },
11014
- enableSorting: true
11015
- }),
11016
- columnHelper.accessor("title", {
11017
- header: "Variant",
11018
- enableSorting: true
11019
- }),
11020
- columnHelper.accessor("sku", {
11021
- header: "SKU",
11022
- cell: ({ getValue }) => {
11023
- return getValue() ?? "-";
11024
- },
11025
- enableSorting: true
11026
- }),
11027
- columnHelper.accessor("updated_at", {
11028
- header: "Updated",
11029
- cell: ({ getValue }) => {
11030
- return /* @__PURE__ */ jsx(
11031
- Tooltip,
11032
- {
11033
- content: getFullDate({ date: getValue(), includeTime: true }),
11034
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11035
- }
11036
- );
11037
- },
11038
- enableSorting: true,
11039
- sortAscLabel: "Oldest first",
11040
- sortDescLabel: "Newest first"
11041
- }),
11042
- columnHelper.accessor("created_at", {
11043
- header: "Created",
11044
- cell: ({ getValue }) => {
11045
- return /* @__PURE__ */ jsx(
11046
- Tooltip,
11047
- {
11048
- content: getFullDate({ date: getValue(), includeTime: true }),
11049
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11050
- }
11051
- );
11052
- },
11053
- enableSorting: true,
11054
- sortAscLabel: "Oldest first",
11055
- sortDescLabel: "Newest first"
11056
- })
11104
+ {
11105
+ key: "",
11106
+ value: "",
11107
+ disabled: false
11108
+ }
11057
11109
  ];
11058
- }, []);
11110
+ }
11111
+ return Object.entries(metadata).map(([key, value]) => {
11112
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11113
+ return {
11114
+ key,
11115
+ value,
11116
+ disabled: true
11117
+ };
11118
+ }
11119
+ let stringValue = value;
11120
+ if (typeof value !== "string") {
11121
+ stringValue = JSON.stringify(value);
11122
+ }
11123
+ return {
11124
+ key,
11125
+ value: stringValue,
11126
+ original_key: key
11127
+ };
11128
+ });
11129
+ }
11130
+ function parseValues(values) {
11131
+ const metadata = values.metadata;
11132
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11133
+ if (isEmpty) {
11134
+ return null;
11135
+ }
11136
+ const update = {};
11137
+ metadata.forEach((field) => {
11138
+ let key = field.key;
11139
+ let value = field.value;
11140
+ const disabled = field.disabled;
11141
+ if (!key || !value) {
11142
+ return;
11143
+ }
11144
+ if (disabled) {
11145
+ update[key] = value;
11146
+ return;
11147
+ }
11148
+ key = key.trim();
11149
+ value = value.trim();
11150
+ if (value === "true") {
11151
+ update[key] = true;
11152
+ } else if (value === "false") {
11153
+ update[key] = false;
11154
+ } else {
11155
+ const parsedNumber = parseFloat(value);
11156
+ if (!isNaN(parsedNumber)) {
11157
+ update[key] = parsedNumber;
11158
+ } else {
11159
+ update[key] = value;
11160
+ }
11161
+ }
11162
+ });
11163
+ return update;
11164
+ }
11165
+ function getHasUneditableRows(metadata) {
11166
+ if (!metadata) {
11167
+ return false;
11168
+ }
11169
+ return Object.values(metadata).some(
11170
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11171
+ );
11172
+ }
11173
+ const PROMOTION_QUERY_KEY = "promotions";
11174
+ const promotionsQueryKeys = {
11175
+ list: (query2) => [
11176
+ PROMOTION_QUERY_KEY,
11177
+ query2 ? query2 : void 0
11178
+ ],
11179
+ detail: (id, query2) => [
11180
+ PROMOTION_QUERY_KEY,
11181
+ id,
11182
+ query2 ? query2 : void 0
11183
+ ]
11059
11184
  };
11060
- const CustomItemForm = ({ orderId, currencyCode }) => {
11061
- const { setIsOpen } = useStackedModal();
11062
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11063
- const form = useForm({
11064
- defaultValues: {
11065
- title: "",
11066
- quantity: 1,
11067
- unit_price: ""
11185
+ const usePromotions = (query2, options) => {
11186
+ const { data, ...rest } = useQuery({
11187
+ queryKey: promotionsQueryKeys.list(query2),
11188
+ queryFn: async () => sdk.admin.promotion.list(query2),
11189
+ ...options
11190
+ });
11191
+ return { ...data, ...rest };
11192
+ };
11193
+ const Promotions = () => {
11194
+ const { id } = useParams();
11195
+ const {
11196
+ order: preview,
11197
+ isError: isPreviewError,
11198
+ error: previewError
11199
+ } = useOrderPreview(id, void 0);
11200
+ useInitiateOrderEdit({ preview });
11201
+ const { onCancel } = useCancelOrderEdit({ preview });
11202
+ if (isPreviewError) {
11203
+ throw previewError;
11204
+ }
11205
+ const isReady = !!preview;
11206
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11207
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11208
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11209
+ ] });
11210
+ };
11211
+ const PromotionForm = ({ preview }) => {
11212
+ const { items, shipping_methods } = preview;
11213
+ const [isSubmitting, setIsSubmitting] = useState(false);
11214
+ const [comboboxValue, setComboboxValue] = useState("");
11215
+ const { handleSuccess } = useRouteModal();
11216
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11217
+ const promoIds = getPromotionIds(items, shipping_methods);
11218
+ const { promotions, isPending, isError, error } = usePromotions(
11219
+ {
11220
+ id: promoIds
11068
11221
  },
11069
- resolver: zodResolver(customItemSchema)
11222
+ {
11223
+ enabled: !!promoIds.length
11224
+ }
11225
+ );
11226
+ const comboboxData = useComboboxData({
11227
+ queryKey: ["promotions", "combobox", promoIds],
11228
+ queryFn: async (params) => {
11229
+ return await sdk.admin.promotion.list({
11230
+ ...params,
11231
+ id: {
11232
+ $nin: promoIds
11233
+ }
11234
+ });
11235
+ },
11236
+ getOptions: (data) => {
11237
+ return data.promotions.map((promotion) => ({
11238
+ label: promotion.code,
11239
+ value: promotion.code
11240
+ }));
11241
+ }
11070
11242
  });
11071
- const onSubmit = form.handleSubmit(async (data) => {
11072
- await addItems(
11243
+ const add = async (value) => {
11244
+ if (!value) {
11245
+ return;
11246
+ }
11247
+ addPromotions(
11073
11248
  {
11074
- items: [
11075
- {
11076
- title: data.title,
11077
- quantity: data.quantity,
11078
- unit_price: convertNumber(data.unit_price)
11079
- }
11080
- ]
11249
+ promo_codes: [value]
11081
11250
  },
11082
11251
  {
11083
- onSuccess: () => {
11084
- setIsOpen(STACKED_MODAL_ID, false);
11085
- },
11086
11252
  onError: (e) => {
11087
11253
  toast.error(e.message);
11254
+ comboboxData.onSearchValueChange("");
11255
+ setComboboxValue("");
11256
+ },
11257
+ onSuccess: () => {
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
11088
11260
  }
11089
11261
  }
11090
11262
  );
11091
- });
11092
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
11093
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11094
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
11095
- /* @__PURE__ */ jsxs("div", { children: [
11096
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
11097
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
11263
+ };
11264
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11265
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11266
+ const onSubmit = async () => {
11267
+ setIsSubmitting(true);
11268
+ let requestSucceeded = false;
11269
+ await requestOrderEdit(void 0, {
11270
+ onError: (e) => {
11271
+ toast.error(e.message);
11272
+ },
11273
+ onSuccess: () => {
11274
+ requestSucceeded = true;
11275
+ }
11276
+ });
11277
+ if (!requestSucceeded) {
11278
+ setIsSubmitting(false);
11279
+ return;
11280
+ }
11281
+ await confirmOrderEdit(void 0, {
11282
+ onError: (e) => {
11283
+ toast.error(e.message);
11284
+ },
11285
+ onSuccess: () => {
11286
+ handleSuccess();
11287
+ },
11288
+ onSettled: () => {
11289
+ setIsSubmitting(false);
11290
+ }
11291
+ });
11292
+ };
11293
+ if (isError) {
11294
+ throw error;
11295
+ }
11296
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11297
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11298
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11299
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11300
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11301
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11302
+ ] }),
11303
+ /* @__PURE__ */ jsx(
11304
+ Combobox,
11305
+ {
11306
+ id: "promotion-combobox",
11307
+ "aria-describedby": "promotion-combobox-hint",
11308
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11309
+ fetchNextPage: comboboxData.fetchNextPage,
11310
+ options: comboboxData.options,
11311
+ onSearchValueChange: comboboxData.onSearchValueChange,
11312
+ searchValue: comboboxData.searchValue,
11313
+ disabled: comboboxData.disabled || isAddingPromotions,
11314
+ onChange: add,
11315
+ value: comboboxValue
11316
+ }
11317
+ )
11098
11318
  ] }),
11099
11319
  /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11320
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11321
+ PromotionItem,
11322
+ {
11323
+ promotion,
11324
+ orderId: preview.id,
11325
+ isLoading: isPending
11326
+ },
11327
+ promotion.id
11328
+ )) })
11329
+ ] }) }),
11330
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11331
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11100
11332
  /* @__PURE__ */ jsx(
11101
- Form$2.Field,
11333
+ Button,
11102
11334
  {
11103
- control: form.control,
11104
- name: "title",
11105
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11106
- /* @__PURE__ */ jsxs("div", { children: [
11107
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
11108
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
11109
- ] }),
11110
- /* @__PURE__ */ jsxs("div", { children: [
11111
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11112
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11113
- ] })
11114
- ] }) })
11335
+ size: "small",
11336
+ type: "submit",
11337
+ isLoading: isSubmitting || isAddingPromotions,
11338
+ children: "Save"
11115
11339
  }
11116
- ),
11117
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11118
- /* @__PURE__ */ jsx(
11119
- Form$2.Field,
11340
+ )
11341
+ ] }) })
11342
+ ] });
11343
+ };
11344
+ const PromotionItem = ({
11345
+ promotion,
11346
+ orderId,
11347
+ isLoading
11348
+ }) => {
11349
+ var _a;
11350
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11351
+ const onRemove = async () => {
11352
+ removePromotions(
11353
+ {
11354
+ promo_codes: [promotion.code]
11355
+ },
11356
+ {
11357
+ onError: (e) => {
11358
+ toast.error(e.message);
11359
+ }
11360
+ }
11361
+ );
11362
+ };
11363
+ const displayValue = getDisplayValue(promotion);
11364
+ return /* @__PURE__ */ jsxs(
11365
+ "div",
11366
+ {
11367
+ className: clx(
11368
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11120
11369
  {
11121
- control: form.control,
11122
- name: "unit_price",
11123
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11124
- /* @__PURE__ */ jsxs("div", { children: [
11125
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
11126
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11127
- ] }),
11128
- /* @__PURE__ */ jsxs("div", { children: [
11129
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11130
- CurrencyInput,
11131
- {
11132
- symbol: getNativeSymbol(currencyCode),
11133
- code: currencyCode,
11134
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11135
- ...field
11136
- }
11137
- ) }),
11138
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11139
- ] })
11140
- ] }) })
11370
+ "animate-pulse": isLoading
11141
11371
  }
11142
11372
  ),
11143
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11144
- /* @__PURE__ */ jsx(
11145
- Form$2.Field,
11146
- {
11147
- control: form.control,
11148
- name: "quantity",
11149
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11150
- /* @__PURE__ */ jsxs("div", { children: [
11151
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
11152
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11373
+ children: [
11374
+ /* @__PURE__ */ jsxs("div", { children: [
11375
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11376
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11377
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11378
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11379
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11153
11380
  ] }),
11154
- /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
11155
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11156
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11157
- ] })
11158
- ] }) })
11159
- }
11160
- )
11161
- ] }) }) }),
11162
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11163
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11164
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11165
- ] }) })
11166
- ] }) }) });
11381
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11382
+ ] })
11383
+ ] }),
11384
+ /* @__PURE__ */ jsx(
11385
+ IconButton,
11386
+ {
11387
+ size: "small",
11388
+ type: "button",
11389
+ variant: "transparent",
11390
+ onClick: onRemove,
11391
+ isLoading: isPending || isLoading,
11392
+ children: /* @__PURE__ */ jsx(XMark, {})
11393
+ }
11394
+ )
11395
+ ]
11396
+ },
11397
+ promotion.id
11398
+ );
11167
11399
  };
11168
- const customItemSchema = objectType({
11169
- title: stringType().min(1),
11170
- quantity: numberType(),
11171
- unit_price: unionType([numberType(), stringType()])
11400
+ function getDisplayValue(promotion) {
11401
+ var _a, _b, _c, _d;
11402
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11403
+ if (!value) {
11404
+ return null;
11405
+ }
11406
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11407
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11408
+ if (!currency) {
11409
+ return null;
11410
+ }
11411
+ return getLocaleAmount(value, currency);
11412
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11413
+ return formatPercentage(value);
11414
+ }
11415
+ return null;
11416
+ }
11417
+ const formatter = new Intl.NumberFormat([], {
11418
+ style: "percent",
11419
+ minimumFractionDigits: 2
11172
11420
  });
11421
+ const formatPercentage = (value, isPercentageValue = false) => {
11422
+ let val = value || 0;
11423
+ if (!isPercentageValue) {
11424
+ val = val / 100;
11425
+ }
11426
+ return formatter.format(val);
11427
+ };
11428
+ function getPromotionIds(items, shippingMethods) {
11429
+ const promotionIds = /* @__PURE__ */ new Set();
11430
+ for (const item of items) {
11431
+ if (item.adjustments) {
11432
+ for (const adjustment of item.adjustments) {
11433
+ if (adjustment.promotion_id) {
11434
+ promotionIds.add(adjustment.promotion_id);
11435
+ }
11436
+ }
11437
+ }
11438
+ }
11439
+ for (const shippingMethod of shippingMethods) {
11440
+ if (shippingMethod.adjustments) {
11441
+ for (const adjustment of shippingMethod.adjustments) {
11442
+ if (adjustment.promotion_id) {
11443
+ promotionIds.add(adjustment.promotion_id);
11444
+ }
11445
+ }
11446
+ }
11447
+ }
11448
+ return Array.from(promotionIds);
11449
+ }
11173
11450
  const SalesChannel = () => {
11174
11451
  const { id } = useParams();
11175
11452
  const { draft_order, isPending, isError, error } = useDraftOrder(
@@ -12652,393 +12929,116 @@ const Illustration = () => {
12652
12929
  /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12653
12930
  "path",
12654
12931
  {
12655
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12656
- stroke: "#A1A1AA",
12657
- strokeWidth: "1.5",
12658
- strokeLinecap: "round",
12659
- strokeLinejoin: "round"
12660
- }
12661
- ) }),
12662
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12663
- "path",
12664
- {
12665
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12666
- stroke: "#A1A1AA",
12667
- strokeWidth: "1.5",
12668
- strokeLinecap: "round",
12669
- strokeLinejoin: "round"
12670
- }
12671
- ) }),
12672
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12673
- "path",
12674
- {
12675
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12676
- stroke: "#A1A1AA",
12677
- strokeWidth: "1.5",
12678
- strokeLinecap: "round",
12679
- strokeLinejoin: "round"
12680
- }
12681
- ) }),
12682
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12683
- "path",
12684
- {
12685
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12686
- stroke: "#A1A1AA",
12687
- strokeWidth: "1.5",
12688
- strokeLinecap: "round",
12689
- strokeLinejoin: "round"
12690
- }
12691
- ) }),
12692
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12693
- "path",
12694
- {
12695
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12696
- stroke: "#A1A1AA",
12697
- strokeWidth: "1.5",
12698
- strokeLinecap: "round",
12699
- strokeLinejoin: "round"
12700
- }
12701
- ) }),
12702
- /* @__PURE__ */ jsxs("defs", { children: [
12703
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12704
- "rect",
12705
- {
12706
- width: "12",
12707
- height: "12",
12708
- fill: "white",
12709
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12710
- }
12711
- ) }),
12712
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12713
- "rect",
12714
- {
12715
- width: "12",
12716
- height: "12",
12717
- fill: "white",
12718
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12719
- }
12720
- ) }),
12721
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12722
- "rect",
12723
- {
12724
- width: "12",
12725
- height: "12",
12726
- fill: "white",
12727
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12728
- }
12729
- ) }),
12730
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12731
- "rect",
12732
- {
12733
- width: "12",
12734
- height: "12",
12735
- fill: "white",
12736
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12737
- }
12738
- ) }),
12739
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12740
- "rect",
12741
- {
12742
- width: "12",
12743
- height: "12",
12744
- fill: "white",
12745
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12746
- }
12747
- ) }),
12748
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12749
- "rect",
12750
- {
12751
- width: "12",
12752
- height: "12",
12753
- fill: "white",
12754
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12755
- }
12756
- ) })
12757
- ] })
12758
- ]
12759
- }
12760
- );
12761
- };
12762
- const schema = objectType({
12763
- customer_id: stringType().min(1)
12764
- });
12765
- const PROMOTION_QUERY_KEY = "promotions";
12766
- const promotionsQueryKeys = {
12767
- list: (query2) => [
12768
- PROMOTION_QUERY_KEY,
12769
- query2 ? query2 : void 0
12770
- ],
12771
- detail: (id, query2) => [
12772
- PROMOTION_QUERY_KEY,
12773
- id,
12774
- query2 ? query2 : void 0
12775
- ]
12776
- };
12777
- const usePromotions = (query2, options) => {
12778
- const { data, ...rest } = useQuery({
12779
- queryKey: promotionsQueryKeys.list(query2),
12780
- queryFn: async () => sdk.admin.promotion.list(query2),
12781
- ...options
12782
- });
12783
- return { ...data, ...rest };
12784
- };
12785
- const Promotions = () => {
12786
- const { id } = useParams();
12787
- const {
12788
- order: preview,
12789
- isError: isPreviewError,
12790
- error: previewError
12791
- } = useOrderPreview(id, void 0);
12792
- useInitiateOrderEdit({ preview });
12793
- const { onCancel } = useCancelOrderEdit({ preview });
12794
- if (isPreviewError) {
12795
- throw previewError;
12796
- }
12797
- const isReady = !!preview;
12798
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12799
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12800
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12801
- ] });
12802
- };
12803
- const PromotionForm = ({ preview }) => {
12804
- const { items, shipping_methods } = preview;
12805
- const [isSubmitting, setIsSubmitting] = useState(false);
12806
- const [comboboxValue, setComboboxValue] = useState("");
12807
- const { handleSuccess } = useRouteModal();
12808
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12809
- const promoIds = getPromotionIds(items, shipping_methods);
12810
- const { promotions, isPending, isError, error } = usePromotions(
12811
- {
12812
- id: promoIds
12813
- },
12814
- {
12815
- enabled: !!promoIds.length
12816
- }
12817
- );
12818
- const comboboxData = useComboboxData({
12819
- queryKey: ["promotions", "combobox", promoIds],
12820
- queryFn: async (params) => {
12821
- return await sdk.admin.promotion.list({
12822
- ...params,
12823
- id: {
12824
- $nin: promoIds
12825
- }
12826
- });
12827
- },
12828
- getOptions: (data) => {
12829
- return data.promotions.map((promotion) => ({
12830
- label: promotion.code,
12831
- value: promotion.code
12832
- }));
12833
- }
12834
- });
12835
- const add = async (value) => {
12836
- if (!value) {
12837
- return;
12838
- }
12839
- addPromotions(
12840
- {
12841
- promo_codes: [value]
12842
- },
12843
- {
12844
- onError: (e) => {
12845
- toast.error(e.message);
12846
- comboboxData.onSearchValueChange("");
12847
- setComboboxValue("");
12848
- },
12849
- onSuccess: () => {
12850
- comboboxData.onSearchValueChange("");
12851
- setComboboxValue("");
12852
- }
12853
- }
12854
- );
12855
- };
12856
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12857
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12858
- const onSubmit = async () => {
12859
- setIsSubmitting(true);
12860
- let requestSucceeded = false;
12861
- await requestOrderEdit(void 0, {
12862
- onError: (e) => {
12863
- toast.error(e.message);
12864
- },
12865
- onSuccess: () => {
12866
- requestSucceeded = true;
12867
- }
12868
- });
12869
- if (!requestSucceeded) {
12870
- setIsSubmitting(false);
12871
- return;
12872
- }
12873
- await confirmOrderEdit(void 0, {
12874
- onError: (e) => {
12875
- toast.error(e.message);
12876
- },
12877
- onSuccess: () => {
12878
- handleSuccess();
12879
- },
12880
- onSettled: () => {
12881
- setIsSubmitting(false);
12882
- }
12883
- });
12884
- };
12885
- if (isError) {
12886
- throw error;
12887
- }
12888
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12889
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12890
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12891
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12892
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12893
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12894
- ] }),
12895
- /* @__PURE__ */ jsx(
12896
- Combobox,
12897
- {
12898
- id: "promotion-combobox",
12899
- "aria-describedby": "promotion-combobox-hint",
12900
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12901
- fetchNextPage: comboboxData.fetchNextPage,
12902
- options: comboboxData.options,
12903
- onSearchValueChange: comboboxData.onSearchValueChange,
12904
- searchValue: comboboxData.searchValue,
12905
- disabled: comboboxData.disabled || isAddingPromotions,
12906
- onChange: add,
12907
- value: comboboxValue
12932
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12933
+ stroke: "#A1A1AA",
12934
+ strokeWidth: "1.5",
12935
+ strokeLinecap: "round",
12936
+ strokeLinejoin: "round"
12908
12937
  }
12909
- )
12910
- ] }),
12911
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12912
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12913
- PromotionItem,
12914
- {
12915
- promotion,
12916
- orderId: preview.id,
12917
- isLoading: isPending
12918
- },
12919
- promotion.id
12920
- )) })
12921
- ] }) }),
12922
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12923
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12924
- /* @__PURE__ */ jsx(
12925
- Button,
12926
- {
12927
- size: "small",
12928
- type: "submit",
12929
- isLoading: isSubmitting || isAddingPromotions,
12930
- children: "Save"
12931
- }
12932
- )
12933
- ] }) })
12934
- ] });
12935
- };
12936
- const PromotionItem = ({
12937
- promotion,
12938
- orderId,
12939
- isLoading
12940
- }) => {
12941
- var _a;
12942
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12943
- const onRemove = async () => {
12944
- removePromotions(
12945
- {
12946
- promo_codes: [promotion.code]
12947
- },
12948
- {
12949
- onError: (e) => {
12950
- toast.error(e.message);
12951
- }
12952
- }
12953
- );
12954
- };
12955
- const displayValue = getDisplayValue(promotion);
12956
- return /* @__PURE__ */ jsxs(
12957
- "div",
12958
- {
12959
- className: clx(
12960
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12961
- {
12962
- "animate-pulse": isLoading
12963
- }
12964
- ),
12965
- children: [
12966
- /* @__PURE__ */ jsxs("div", { children: [
12967
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12968
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12969
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12970
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12971
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12972
- ] }),
12973
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12974
- ] })
12975
- ] }),
12976
- /* @__PURE__ */ jsx(
12977
- IconButton,
12938
+ ) }),
12939
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12940
+ "path",
12978
12941
  {
12979
- size: "small",
12980
- type: "button",
12981
- variant: "transparent",
12982
- onClick: onRemove,
12983
- isLoading: isPending || isLoading,
12984
- children: /* @__PURE__ */ jsx(XMark, {})
12942
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12943
+ stroke: "#A1A1AA",
12944
+ strokeWidth: "1.5",
12945
+ strokeLinecap: "round",
12946
+ strokeLinejoin: "round"
12985
12947
  }
12986
- )
12948
+ ) }),
12949
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12950
+ "path",
12951
+ {
12952
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12953
+ stroke: "#A1A1AA",
12954
+ strokeWidth: "1.5",
12955
+ strokeLinecap: "round",
12956
+ strokeLinejoin: "round"
12957
+ }
12958
+ ) }),
12959
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
+ "path",
12961
+ {
12962
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
+ stroke: "#A1A1AA",
12964
+ strokeWidth: "1.5",
12965
+ strokeLinecap: "round",
12966
+ strokeLinejoin: "round"
12967
+ }
12968
+ ) }),
12969
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
+ "path",
12971
+ {
12972
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
+ stroke: "#A1A1AA",
12974
+ strokeWidth: "1.5",
12975
+ strokeLinecap: "round",
12976
+ strokeLinejoin: "round"
12977
+ }
12978
+ ) }),
12979
+ /* @__PURE__ */ jsxs("defs", { children: [
12980
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
+ "rect",
12982
+ {
12983
+ width: "12",
12984
+ height: "12",
12985
+ fill: "white",
12986
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12987
+ }
12988
+ ) }),
12989
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
+ "rect",
12991
+ {
12992
+ width: "12",
12993
+ height: "12",
12994
+ fill: "white",
12995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12996
+ }
12997
+ ) }),
12998
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
+ "rect",
13000
+ {
13001
+ width: "12",
13002
+ height: "12",
13003
+ fill: "white",
13004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13005
+ }
13006
+ ) }),
13007
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
+ "rect",
13009
+ {
13010
+ width: "12",
13011
+ height: "12",
13012
+ fill: "white",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13014
+ }
13015
+ ) }),
13016
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
+ "rect",
13018
+ {
13019
+ width: "12",
13020
+ height: "12",
13021
+ fill: "white",
13022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13023
+ }
13024
+ ) }),
13025
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
+ "rect",
13027
+ {
13028
+ width: "12",
13029
+ height: "12",
13030
+ fill: "white",
13031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13032
+ }
13033
+ ) })
13034
+ ] })
12987
13035
  ]
12988
- },
12989
- promotion.id
13036
+ }
12990
13037
  );
12991
13038
  };
12992
- function getDisplayValue(promotion) {
12993
- var _a, _b, _c, _d;
12994
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12995
- if (!value) {
12996
- return null;
12997
- }
12998
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12999
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13000
- if (!currency) {
13001
- return null;
13002
- }
13003
- return getLocaleAmount(value, currency);
13004
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13005
- return formatPercentage(value);
13006
- }
13007
- return null;
13008
- }
13009
- const formatter = new Intl.NumberFormat([], {
13010
- style: "percent",
13011
- minimumFractionDigits: 2
13039
+ const schema = objectType({
13040
+ customer_id: stringType().min(1)
13012
13041
  });
13013
- const formatPercentage = (value, isPercentageValue = false) => {
13014
- let val = value || 0;
13015
- if (!isPercentageValue) {
13016
- val = val / 100;
13017
- }
13018
- return formatter.format(val);
13019
- };
13020
- function getPromotionIds(items, shippingMethods) {
13021
- const promotionIds = /* @__PURE__ */ new Set();
13022
- for (const item of items) {
13023
- if (item.adjustments) {
13024
- for (const adjustment of item.adjustments) {
13025
- if (adjustment.promotion_id) {
13026
- promotionIds.add(adjustment.promotion_id);
13027
- }
13028
- }
13029
- }
13030
- }
13031
- for (const shippingMethod of shippingMethods) {
13032
- if (shippingMethod.adjustments) {
13033
- for (const adjustment of shippingMethod.adjustments) {
13034
- if (adjustment.promotion_id) {
13035
- promotionIds.add(adjustment.promotion_id);
13036
- }
13037
- }
13038
- }
13039
- }
13040
- return Array.from(promotionIds);
13041
- }
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13063,21 +13063,25 @@ const routeModule = {
13063
13063
  Component: BillingAddress,
13064
13064
  path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
+ {
13067
+ Component: CustomItems,
13068
+ path: "/draft-orders/:id/custom-items"
13069
+ },
13066
13070
  {
13067
13071
  Component: Email,
13068
13072
  path: "/draft-orders/:id/email"
13069
13073
  },
13070
13074
  {
13071
- Component: CustomItems,
13072
- path: "/draft-orders/:id/custom-items"
13075
+ Component: Items,
13076
+ path: "/draft-orders/:id/items"
13073
13077
  },
13074
13078
  {
13075
13079
  Component: Metadata,
13076
13080
  path: "/draft-orders/:id/metadata"
13077
13081
  },
13078
13082
  {
13079
- Component: Items,
13080
- path: "/draft-orders/:id/items"
13083
+ Component: Promotions,
13084
+ path: "/draft-orders/:id/promotions"
13081
13085
  },
13082
13086
  {
13083
13087
  Component: SalesChannel,
@@ -13094,10 +13098,6 @@ const routeModule = {
13094
13098
  {
13095
13099
  Component: TransferOwnership,
13096
13100
  path: "/draft-orders/:id/transfer-ownership"
13097
- },
13098
- {
13099
- Component: Promotions,
13100
- path: "/draft-orders/:id/promotions"
13101
13101
  }
13102
13102
  ]
13103
13103
  }