@medusajs/draft-order 2.12.4-preview-20251223150132 → 2.12.4-preview-20251223180143

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";
@@ -9755,6 +9755,27 @@ const BillingAddressForm = ({ order }) => {
9755
9755
  ) });
9756
9756
  };
9757
9757
  const schema$5 = addressSchema;
9758
+ const CustomItems = () => {
9759
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9760
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9761
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9762
+ ] });
9763
+ };
9764
+ const CustomItemsForm = () => {
9765
+ const form = useForm({
9766
+ resolver: zodResolver(schema$4)
9767
+ });
9768
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9769
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9770
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9772
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9773
+ ] }) })
9774
+ ] }) });
9775
+ };
9776
+ const schema$4 = objectType({
9777
+ email: stringType().email()
9778
+ });
9758
9779
  const Email = () => {
9759
9780
  const { id } = useParams();
9760
9781
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9777,7 +9798,7 @@ const EmailForm = ({ order }) => {
9777
9798
  defaultValues: {
9778
9799
  email: order.email ?? ""
9779
9800
  },
9780
- resolver: zodResolver(schema$4)
9801
+ resolver: zodResolver(schema$3)
9781
9802
  });
9782
9803
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9783
9804
  const { handleSuccess } = useRouteModal();
@@ -9820,526 +9841,176 @@ const EmailForm = ({ order }) => {
9820
9841
  }
9821
9842
  ) });
9822
9843
  };
9823
- const schema$4 = objectType({
9844
+ const schema$3 = objectType({
9824
9845
  email: stringType().email()
9825
9846
  });
9826
- const InlineTip = forwardRef(
9827
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9828
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9847
+ const NumberInput = forwardRef(
9848
+ ({
9849
+ value,
9850
+ onChange,
9851
+ size = "base",
9852
+ min = 0,
9853
+ max = 100,
9854
+ step = 1,
9855
+ className,
9856
+ disabled,
9857
+ ...props
9858
+ }, ref) => {
9859
+ const handleChange = (event) => {
9860
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9861
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9862
+ onChange(newValue);
9863
+ }
9864
+ };
9865
+ const handleIncrement = () => {
9866
+ const newValue = value + step;
9867
+ if (max === void 0 || newValue <= max) {
9868
+ onChange(newValue);
9869
+ }
9870
+ };
9871
+ const handleDecrement = () => {
9872
+ const newValue = value - step;
9873
+ if (min === void 0 || newValue >= min) {
9874
+ onChange(newValue);
9875
+ }
9876
+ };
9829
9877
  return /* @__PURE__ */ jsxs(
9830
9878
  "div",
9831
9879
  {
9832
- ref,
9833
9880
  className: clx(
9834
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9881
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9882
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9883
+ {
9884
+ "h-7": size === "small",
9885
+ "h-8": size === "base"
9886
+ },
9835
9887
  className
9836
9888
  ),
9837
- ...props,
9838
9889
  children: [
9839
9890
  /* @__PURE__ */ jsx(
9840
- "div",
9891
+ "input",
9841
9892
  {
9842
- role: "presentation",
9843
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9844
- "bg-ui-tag-orange-icon": variant === "warning"
9845
- })
9893
+ ref,
9894
+ type: "number",
9895
+ value,
9896
+ onChange: handleChange,
9897
+ min,
9898
+ max,
9899
+ step,
9900
+ className: clx(
9901
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9902
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9903
+ "placeholder:text-ui-fg-muted"
9904
+ ),
9905
+ ...props
9846
9906
  }
9847
9907
  ),
9848
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9849
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9850
- labelValue,
9851
- ":"
9852
- ] }),
9853
- " ",
9854
- children
9855
- ] })
9908
+ /* @__PURE__ */ jsxs(
9909
+ "button",
9910
+ {
9911
+ className: clx(
9912
+ "flex items-center justify-center outline-none transition-fg",
9913
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9914
+ "focus:bg-ui-bg-field-component-hover",
9915
+ "hover:bg-ui-bg-field-component-hover",
9916
+ {
9917
+ "size-7": size === "small",
9918
+ "size-8": size === "base"
9919
+ }
9920
+ ),
9921
+ type: "button",
9922
+ onClick: handleDecrement,
9923
+ disabled: min !== void 0 && value <= min || disabled,
9924
+ children: [
9925
+ /* @__PURE__ */ jsx(Minus, {}),
9926
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9927
+ ]
9928
+ }
9929
+ ),
9930
+ /* @__PURE__ */ jsxs(
9931
+ "button",
9932
+ {
9933
+ className: clx(
9934
+ "flex items-center justify-center outline-none transition-fg",
9935
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9936
+ "focus:bg-ui-bg-field-hover",
9937
+ "hover:bg-ui-bg-field-hover",
9938
+ {
9939
+ "size-7": size === "small",
9940
+ "size-8": size === "base"
9941
+ }
9942
+ ),
9943
+ type: "button",
9944
+ onClick: handleIncrement,
9945
+ disabled: max !== void 0 && value >= max || disabled,
9946
+ children: [
9947
+ /* @__PURE__ */ jsx(Plus, {}),
9948
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9949
+ ]
9950
+ }
9951
+ )
9856
9952
  ]
9857
9953
  }
9858
9954
  );
9859
9955
  }
9860
9956
  );
9861
- InlineTip.displayName = "InlineTip";
9862
- const MetadataFieldSchema = objectType({
9863
- key: stringType(),
9864
- disabled: booleanType().optional(),
9865
- value: anyType()
9866
- });
9867
- const MetadataSchema = objectType({
9868
- metadata: arrayType(MetadataFieldSchema)
9869
- });
9870
- const Metadata = () => {
9871
- const { id } = useParams();
9872
- const { order, isPending, isError, error } = useOrder(id, {
9873
- fields: "metadata"
9874
- });
9875
- if (isError) {
9876
- throw error;
9877
- }
9878
- const isReady = !isPending && !!order;
9879
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9880
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9881
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9882
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9883
- ] }),
9884
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9885
- ] });
9957
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9958
+ const productVariantsQueryKeys = {
9959
+ list: (query2) => [
9960
+ PRODUCT_VARIANTS_QUERY_KEY,
9961
+ query2 ? query2 : void 0
9962
+ ]
9886
9963
  };
9887
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9888
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9889
- const MetadataForm = ({ orderId, metadata }) => {
9890
- const { handleSuccess } = useRouteModal();
9891
- const hasUneditableRows = getHasUneditableRows(metadata);
9892
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9893
- const form = useForm({
9894
- defaultValues: {
9895
- metadata: getDefaultValues(metadata)
9896
- },
9897
- resolver: zodResolver(MetadataSchema)
9964
+ const useProductVariants = (query2, options) => {
9965
+ const { data, ...rest } = useQuery({
9966
+ queryKey: productVariantsQueryKeys.list(query2),
9967
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9968
+ ...options
9898
9969
  });
9899
- const handleSubmit = form.handleSubmit(async (data) => {
9900
- const parsedData = parseValues(data);
9901
- await mutateAsync(
9902
- {
9903
- metadata: parsedData
9970
+ return { ...data, ...rest };
9971
+ };
9972
+ const useCancelOrderEdit = ({ preview }) => {
9973
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9974
+ const onCancel = useCallback(async () => {
9975
+ if (!preview) {
9976
+ return true;
9977
+ }
9978
+ let res = false;
9979
+ await cancelOrderEdit(void 0, {
9980
+ onError: (e) => {
9981
+ toast.error(e.message);
9904
9982
  },
9905
- {
9906
- onSuccess: () => {
9907
- toast.success("Metadata updated");
9908
- handleSuccess();
9909
- },
9910
- onError: (error) => {
9911
- toast.error(error.message);
9912
- }
9983
+ onSuccess: () => {
9984
+ res = true;
9913
9985
  }
9914
- );
9915
- });
9916
- const { fields, insert, remove } = useFieldArray({
9917
- control: form.control,
9918
- name: "metadata"
9919
- });
9920
- function deleteRow(index) {
9921
- remove(index);
9922
- if (fields.length === 1) {
9923
- insert(0, {
9924
- key: "",
9925
- value: "",
9926
- disabled: false
9986
+ });
9987
+ return res;
9988
+ }, [preview, cancelOrderEdit]);
9989
+ return { onCancel };
9990
+ };
9991
+ let IS_REQUEST_RUNNING = false;
9992
+ const useInitiateOrderEdit = ({
9993
+ preview
9994
+ }) => {
9995
+ const navigate = useNavigate();
9996
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9997
+ useEffect(() => {
9998
+ async function run() {
9999
+ if (IS_REQUEST_RUNNING || !preview) {
10000
+ return;
10001
+ }
10002
+ if (preview.order_change) {
10003
+ return;
10004
+ }
10005
+ IS_REQUEST_RUNNING = true;
10006
+ await mutateAsync(void 0, {
10007
+ onError: (e) => {
10008
+ toast.error(e.message);
10009
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10010
+ return;
10011
+ }
9927
10012
  });
9928
- }
9929
- }
9930
- function insertRow(index, position) {
9931
- insert(index + (position === "above" ? 0 : 1), {
9932
- key: "",
9933
- value: "",
9934
- disabled: false
9935
- });
9936
- }
9937
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9938
- KeyboundForm,
9939
- {
9940
- onSubmit: handleSubmit,
9941
- className: "flex flex-1 flex-col overflow-hidden",
9942
- children: [
9943
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9944
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9945
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9946
- /* @__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" }) }),
9947
- /* @__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" }) })
9948
- ] }),
9949
- fields.map((field, index) => {
9950
- const isDisabled = field.disabled || false;
9951
- let placeholder = "-";
9952
- if (typeof field.value === "object") {
9953
- placeholder = "{ ... }";
9954
- }
9955
- if (Array.isArray(field.value)) {
9956
- placeholder = "[ ... ]";
9957
- }
9958
- return /* @__PURE__ */ jsx(
9959
- ConditionalTooltip,
9960
- {
9961
- showTooltip: isDisabled,
9962
- content: "This row is disabled because it contains non-primitive data.",
9963
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9964
- /* @__PURE__ */ jsxs(
9965
- "div",
9966
- {
9967
- className: clx("grid grid-cols-2 divide-x", {
9968
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9969
- }),
9970
- children: [
9971
- /* @__PURE__ */ jsx(
9972
- Form$2.Field,
9973
- {
9974
- control: form.control,
9975
- name: `metadata.${index}.key`,
9976
- render: ({ field: field2 }) => {
9977
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9978
- GridInput,
9979
- {
9980
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9981
- ...field2,
9982
- disabled: isDisabled,
9983
- placeholder: "Key"
9984
- }
9985
- ) }) });
9986
- }
9987
- }
9988
- ),
9989
- /* @__PURE__ */ jsx(
9990
- Form$2.Field,
9991
- {
9992
- control: form.control,
9993
- name: `metadata.${index}.value`,
9994
- render: ({ field: { value, ...field2 } }) => {
9995
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9996
- GridInput,
9997
- {
9998
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9999
- ...field2,
10000
- value: isDisabled ? placeholder : value,
10001
- disabled: isDisabled,
10002
- placeholder: "Value"
10003
- }
10004
- ) }) });
10005
- }
10006
- }
10007
- )
10008
- ]
10009
- }
10010
- ),
10011
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10012
- /* @__PURE__ */ jsx(
10013
- DropdownMenu.Trigger,
10014
- {
10015
- className: clx(
10016
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10017
- {
10018
- hidden: isDisabled
10019
- }
10020
- ),
10021
- disabled: isDisabled,
10022
- asChild: true,
10023
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10024
- }
10025
- ),
10026
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10027
- /* @__PURE__ */ jsxs(
10028
- DropdownMenu.Item,
10029
- {
10030
- className: "gap-x-2",
10031
- onClick: () => insertRow(index, "above"),
10032
- children: [
10033
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10034
- "Insert row above"
10035
- ]
10036
- }
10037
- ),
10038
- /* @__PURE__ */ jsxs(
10039
- DropdownMenu.Item,
10040
- {
10041
- className: "gap-x-2",
10042
- onClick: () => insertRow(index, "below"),
10043
- children: [
10044
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10045
- "Insert row below"
10046
- ]
10047
- }
10048
- ),
10049
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10050
- /* @__PURE__ */ jsxs(
10051
- DropdownMenu.Item,
10052
- {
10053
- className: "gap-x-2",
10054
- onClick: () => deleteRow(index),
10055
- children: [
10056
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10057
- "Delete row"
10058
- ]
10059
- }
10060
- )
10061
- ] })
10062
- ] })
10063
- ] })
10064
- },
10065
- field.id
10066
- );
10067
- })
10068
- ] }),
10069
- 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." })
10070
- ] }),
10071
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10072
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10073
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10074
- ] }) })
10075
- ]
10076
- }
10077
- ) });
10078
- };
10079
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10080
- return /* @__PURE__ */ jsx(
10081
- "input",
10082
- {
10083
- ref,
10084
- ...props,
10085
- autoComplete: "off",
10086
- className: clx(
10087
- "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",
10088
- className
10089
- )
10090
- }
10091
- );
10092
- });
10093
- GridInput.displayName = "MetadataForm.GridInput";
10094
- const PlaceholderInner = () => {
10095
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10096
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10097
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10098
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10099
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10100
- ] }) })
10101
- ] });
10102
- };
10103
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10104
- function getDefaultValues(metadata) {
10105
- if (!metadata || !Object.keys(metadata).length) {
10106
- return [
10107
- {
10108
- key: "",
10109
- value: "",
10110
- disabled: false
10111
- }
10112
- ];
10113
- }
10114
- return Object.entries(metadata).map(([key, value]) => {
10115
- if (!EDITABLE_TYPES.includes(typeof value)) {
10116
- return {
10117
- key,
10118
- value,
10119
- disabled: true
10120
- };
10121
- }
10122
- let stringValue = value;
10123
- if (typeof value !== "string") {
10124
- stringValue = JSON.stringify(value);
10125
- }
10126
- return {
10127
- key,
10128
- value: stringValue,
10129
- original_key: key
10130
- };
10131
- });
10132
- }
10133
- function parseValues(values) {
10134
- const metadata = values.metadata;
10135
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10136
- if (isEmpty) {
10137
- return null;
10138
- }
10139
- const update = {};
10140
- metadata.forEach((field) => {
10141
- let key = field.key;
10142
- let value = field.value;
10143
- const disabled = field.disabled;
10144
- if (!key || !value) {
10145
- return;
10146
- }
10147
- if (disabled) {
10148
- update[key] = value;
10149
- return;
10150
- }
10151
- key = key.trim();
10152
- value = value.trim();
10153
- if (value === "true") {
10154
- update[key] = true;
10155
- } else if (value === "false") {
10156
- update[key] = false;
10157
- } else {
10158
- const parsedNumber = parseFloat(value);
10159
- if (!isNaN(parsedNumber)) {
10160
- update[key] = parsedNumber;
10161
- } else {
10162
- update[key] = value;
10163
- }
10164
- }
10165
- });
10166
- return update;
10167
- }
10168
- function getHasUneditableRows(metadata) {
10169
- if (!metadata) {
10170
- return false;
10171
- }
10172
- return Object.values(metadata).some(
10173
- (value) => !EDITABLE_TYPES.includes(typeof value)
10174
- );
10175
- }
10176
- const NumberInput = forwardRef(
10177
- ({
10178
- value,
10179
- onChange,
10180
- size = "base",
10181
- min = 0,
10182
- max = 100,
10183
- step = 1,
10184
- className,
10185
- disabled,
10186
- ...props
10187
- }, ref) => {
10188
- const handleChange = (event) => {
10189
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10190
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10191
- onChange(newValue);
10192
- }
10193
- };
10194
- const handleIncrement = () => {
10195
- const newValue = value + step;
10196
- if (max === void 0 || newValue <= max) {
10197
- onChange(newValue);
10198
- }
10199
- };
10200
- const handleDecrement = () => {
10201
- const newValue = value - step;
10202
- if (min === void 0 || newValue >= min) {
10203
- onChange(newValue);
10204
- }
10205
- };
10206
- return /* @__PURE__ */ jsxs(
10207
- "div",
10208
- {
10209
- className: clx(
10210
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10211
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10212
- {
10213
- "h-7": size === "small",
10214
- "h-8": size === "base"
10215
- },
10216
- className
10217
- ),
10218
- children: [
10219
- /* @__PURE__ */ jsx(
10220
- "input",
10221
- {
10222
- ref,
10223
- type: "number",
10224
- value,
10225
- onChange: handleChange,
10226
- min,
10227
- max,
10228
- step,
10229
- className: clx(
10230
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10231
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10232
- "placeholder:text-ui-fg-muted"
10233
- ),
10234
- ...props
10235
- }
10236
- ),
10237
- /* @__PURE__ */ jsxs(
10238
- "button",
10239
- {
10240
- className: clx(
10241
- "flex items-center justify-center outline-none transition-fg",
10242
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10243
- "focus:bg-ui-bg-field-component-hover",
10244
- "hover:bg-ui-bg-field-component-hover",
10245
- {
10246
- "size-7": size === "small",
10247
- "size-8": size === "base"
10248
- }
10249
- ),
10250
- type: "button",
10251
- onClick: handleDecrement,
10252
- disabled: min !== void 0 && value <= min || disabled,
10253
- children: [
10254
- /* @__PURE__ */ jsx(Minus, {}),
10255
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10256
- ]
10257
- }
10258
- ),
10259
- /* @__PURE__ */ jsxs(
10260
- "button",
10261
- {
10262
- className: clx(
10263
- "flex items-center justify-center outline-none transition-fg",
10264
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10265
- "focus:bg-ui-bg-field-hover",
10266
- "hover:bg-ui-bg-field-hover",
10267
- {
10268
- "size-7": size === "small",
10269
- "size-8": size === "base"
10270
- }
10271
- ),
10272
- type: "button",
10273
- onClick: handleIncrement,
10274
- disabled: max !== void 0 && value >= max || disabled,
10275
- children: [
10276
- /* @__PURE__ */ jsx(Plus, {}),
10277
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10278
- ]
10279
- }
10280
- )
10281
- ]
10282
- }
10283
- );
10284
- }
10285
- );
10286
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10287
- const productVariantsQueryKeys = {
10288
- list: (query2) => [
10289
- PRODUCT_VARIANTS_QUERY_KEY,
10290
- query2 ? query2 : void 0
10291
- ]
10292
- };
10293
- const useProductVariants = (query2, options) => {
10294
- const { data, ...rest } = useQuery({
10295
- queryKey: productVariantsQueryKeys.list(query2),
10296
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10297
- ...options
10298
- });
10299
- return { ...data, ...rest };
10300
- };
10301
- const useCancelOrderEdit = ({ preview }) => {
10302
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10303
- const onCancel = useCallback(async () => {
10304
- if (!preview) {
10305
- return true;
10306
- }
10307
- let res = false;
10308
- await cancelOrderEdit(void 0, {
10309
- onError: (e) => {
10310
- toast.error(e.message);
10311
- },
10312
- onSuccess: () => {
10313
- res = true;
10314
- }
10315
- });
10316
- return res;
10317
- }, [preview, cancelOrderEdit]);
10318
- return { onCancel };
10319
- };
10320
- let IS_REQUEST_RUNNING = false;
10321
- const useInitiateOrderEdit = ({
10322
- preview
10323
- }) => {
10324
- const navigate = useNavigate();
10325
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10326
- useEffect(() => {
10327
- async function run() {
10328
- if (IS_REQUEST_RUNNING || !preview) {
10329
- return;
10330
- }
10331
- if (preview.order_change) {
10332
- return;
10333
- }
10334
- IS_REQUEST_RUNNING = true;
10335
- await mutateAsync(void 0, {
10336
- onError: (e) => {
10337
- toast.error(e.message);
10338
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10339
- return;
10340
- }
10341
- });
10342
- IS_REQUEST_RUNNING = false;
10013
+ IS_REQUEST_RUNNING = false;
10343
10014
  }
10344
10015
  run();
10345
10016
  }, [preview, navigate, mutateAsync]);
@@ -10578,20 +10249,168 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10578
10249
  const [editing, setEditing] = useState(false);
10579
10250
  const form = useForm({
10580
10251
  defaultValues: {
10581
- quantity: item.quantity,
10582
- unit_price: item.unit_price
10252
+ quantity: item.quantity,
10253
+ unit_price: item.unit_price
10254
+ },
10255
+ resolver: zodResolver(variantItemSchema)
10256
+ });
10257
+ const actionId = useMemo(() => {
10258
+ var _a, _b;
10259
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10260
+ }, [item]);
10261
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10262
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10263
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10264
+ const onSubmit = form.handleSubmit(async (data) => {
10265
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10266
+ setEditing(false);
10267
+ return;
10268
+ }
10269
+ if (!actionId) {
10270
+ await updateOriginalItem(
10271
+ {
10272
+ item_id: item.id,
10273
+ quantity: data.quantity,
10274
+ unit_price: convertNumber(data.unit_price)
10275
+ },
10276
+ {
10277
+ onSuccess: () => {
10278
+ setEditing(false);
10279
+ },
10280
+ onError: (e) => {
10281
+ toast.error(e.message);
10282
+ }
10283
+ }
10284
+ );
10285
+ return;
10286
+ }
10287
+ await updateActionItem(
10288
+ {
10289
+ action_id: actionId,
10290
+ quantity: data.quantity,
10291
+ unit_price: convertNumber(data.unit_price)
10292
+ },
10293
+ {
10294
+ onSuccess: () => {
10295
+ setEditing(false);
10296
+ },
10297
+ onError: (e) => {
10298
+ toast.error(e.message);
10299
+ }
10300
+ }
10301
+ );
10302
+ });
10303
+ 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: [
10304
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10305
+ /* @__PURE__ */ jsx(
10306
+ Thumbnail,
10307
+ {
10308
+ thumbnail: item.thumbnail,
10309
+ alt: item.product_title ?? void 0
10310
+ }
10311
+ ),
10312
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10313
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10314
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10315
+ /* @__PURE__ */ jsxs(
10316
+ Text,
10317
+ {
10318
+ size: "small",
10319
+ leading: "compact",
10320
+ className: "text-ui-fg-subtle",
10321
+ children: [
10322
+ "(",
10323
+ item.variant_title,
10324
+ ")"
10325
+ ]
10326
+ }
10327
+ )
10328
+ ] }),
10329
+ /* @__PURE__ */ jsx(
10330
+ Text,
10331
+ {
10332
+ size: "small",
10333
+ leading: "compact",
10334
+ className: "text-ui-fg-subtle",
10335
+ children: item.variant_sku
10336
+ }
10337
+ )
10338
+ ] })
10339
+ ] }),
10340
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10341
+ Form$2.Field,
10342
+ {
10343
+ control: form.control,
10344
+ name: "quantity",
10345
+ render: ({ field }) => {
10346
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10347
+ }
10348
+ }
10349
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10350
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10351
+ Form$2.Field,
10352
+ {
10353
+ control: form.control,
10354
+ name: "unit_price",
10355
+ render: ({ field: { onChange, ...field } }) => {
10356
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10357
+ CurrencyInput,
10358
+ {
10359
+ ...field,
10360
+ symbol: getNativeSymbol(currencyCode),
10361
+ code: currencyCode,
10362
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10363
+ }
10364
+ ) }) });
10365
+ }
10366
+ }
10367
+ ) }) : /* @__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) }) }),
10368
+ /* @__PURE__ */ jsx(
10369
+ IconButton,
10370
+ {
10371
+ type: "button",
10372
+ size: "small",
10373
+ onClick: editing ? onSubmit : () => {
10374
+ setEditing(true);
10375
+ },
10376
+ disabled: isPending,
10377
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10378
+ }
10379
+ )
10380
+ ] }) }) });
10381
+ };
10382
+ const variantItemSchema = objectType({
10383
+ quantity: numberType(),
10384
+ unit_price: unionType([numberType(), stringType()])
10385
+ });
10386
+ const CustomItem = ({ item, preview, currencyCode }) => {
10387
+ const [editing, setEditing] = useState(false);
10388
+ const { quantity, unit_price, title } = item;
10389
+ const form = useForm({
10390
+ defaultValues: {
10391
+ title,
10392
+ quantity,
10393
+ unit_price
10583
10394
  },
10584
- resolver: zodResolver(variantItemSchema)
10395
+ resolver: zodResolver(customItemSchema)
10585
10396
  });
10397
+ useEffect(() => {
10398
+ form.reset({
10399
+ title,
10400
+ quantity,
10401
+ unit_price
10402
+ });
10403
+ }, [form, title, quantity, unit_price]);
10586
10404
  const actionId = useMemo(() => {
10587
10405
  var _a, _b;
10588
10406
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10589
10407
  }, [item]);
10590
10408
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10409
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10591
10410
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10592
10411
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10593
10412
  const onSubmit = form.handleSubmit(async (data) => {
10594
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10413
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10595
10414
  setEditing(false);
10596
10415
  return;
10597
10416
  }
@@ -10613,6 +10432,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10613
10432
  );
10614
10433
  return;
10615
10434
  }
10435
+ if (data.quantity === 0) {
10436
+ await removeActionItem(actionId, {
10437
+ onSuccess: () => {
10438
+ setEditing(false);
10439
+ },
10440
+ onError: (e) => {
10441
+ toast.error(e.message);
10442
+ }
10443
+ });
10444
+ return;
10445
+ }
10616
10446
  await updateActionItem(
10617
10447
  {
10618
10448
  action_id: actionId,
@@ -10630,43 +10460,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10630
10460
  );
10631
10461
  });
10632
10462
  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: [
10633
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10463
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10634
10464
  /* @__PURE__ */ jsx(
10635
10465
  Thumbnail,
10636
10466
  {
10637
10467
  thumbnail: item.thumbnail,
10638
- alt: item.product_title ?? void 0
10468
+ alt: item.title ?? void 0
10639
10469
  }
10640
10470
  ),
10641
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10642
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10643
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10644
- /* @__PURE__ */ jsxs(
10645
- Text,
10646
- {
10647
- size: "small",
10648
- leading: "compact",
10649
- className: "text-ui-fg-subtle",
10650
- children: [
10651
- "(",
10652
- item.variant_title,
10653
- ")"
10654
- ]
10655
- }
10656
- )
10657
- ] }),
10658
- /* @__PURE__ */ jsx(
10659
- Text,
10660
- {
10661
- size: "small",
10662
- leading: "compact",
10663
- className: "text-ui-fg-subtle",
10664
- children: item.variant_sku
10471
+ editing ? /* @__PURE__ */ jsx(
10472
+ Form$2.Field,
10473
+ {
10474
+ control: form.control,
10475
+ name: "title",
10476
+ render: ({ field }) => {
10477
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10665
10478
  }
10666
- )
10667
- ] })
10479
+ }
10480
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10668
10481
  ] }),
10669
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10482
+ editing ? /* @__PURE__ */ jsx(
10670
10483
  Form$2.Field,
10671
10484
  {
10672
10485
  control: form.control,
@@ -10675,8 +10488,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10675
10488
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10676
10489
  }
10677
10490
  }
10678
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10679
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10491
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10492
+ editing ? /* @__PURE__ */ jsx(
10680
10493
  Form$2.Field,
10681
10494
  {
10682
10495
  control: form.control,
@@ -10693,7 +10506,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10693
10506
  ) }) });
10694
10507
  }
10695
10508
  }
10696
- ) }) : /* @__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) }) }),
10509
+ ) : /* @__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) }) }),
10697
10510
  /* @__PURE__ */ jsx(
10698
10511
  IconButton,
10699
10512
  {
@@ -10708,79 +10521,215 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10708
10521
  )
10709
10522
  ] }) }) });
10710
10523
  };
10711
- const variantItemSchema = objectType({
10712
- quantity: numberType(),
10713
- unit_price: unionType([numberType(), stringType()])
10714
- });
10715
- const CustomItem = ({ item, preview, currencyCode }) => {
10716
- const [editing, setEditing] = useState(false);
10717
- const { quantity, unit_price, title } = item;
10524
+ const StackedModalTrigger$1 = ({
10525
+ type,
10526
+ setModalContent
10527
+ }) => {
10528
+ const { setIsOpen } = useStackedModal();
10529
+ const onClick = useCallback(() => {
10530
+ setModalContent(type);
10531
+ setIsOpen(STACKED_MODAL_ID, true);
10532
+ }, [setModalContent, setIsOpen, type]);
10533
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10534
+ };
10535
+ const VARIANT_PREFIX = "items";
10536
+ const LIMIT = 50;
10537
+ const ExistingItemsForm = ({ orderId, items }) => {
10538
+ const { setIsOpen } = useStackedModal();
10539
+ const [rowSelection, setRowSelection] = useState(
10540
+ items.reduce((acc, item) => {
10541
+ acc[item.variant_id] = true;
10542
+ return acc;
10543
+ }, {})
10544
+ );
10545
+ useEffect(() => {
10546
+ setRowSelection(
10547
+ items.reduce((acc, item) => {
10548
+ if (item.variant_id) {
10549
+ acc[item.variant_id] = true;
10550
+ }
10551
+ return acc;
10552
+ }, {})
10553
+ );
10554
+ }, [items]);
10555
+ const { q, order, offset } = useQueryParams(
10556
+ ["q", "order", "offset"],
10557
+ VARIANT_PREFIX
10558
+ );
10559
+ const { variants, count, isPending, isError, error } = useProductVariants(
10560
+ {
10561
+ q,
10562
+ order,
10563
+ offset: offset ? parseInt(offset) : void 0,
10564
+ limit: LIMIT
10565
+ },
10566
+ {
10567
+ placeholderData: keepPreviousData
10568
+ }
10569
+ );
10570
+ const columns = useColumns();
10571
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10572
+ const onSubmit = async () => {
10573
+ const ids = Object.keys(rowSelection).filter(
10574
+ (id) => !items.find((i) => i.variant_id === id)
10575
+ );
10576
+ await mutateAsync(
10577
+ {
10578
+ items: ids.map((id) => ({
10579
+ variant_id: id,
10580
+ quantity: 1
10581
+ }))
10582
+ },
10583
+ {
10584
+ onSuccess: () => {
10585
+ setRowSelection({});
10586
+ setIsOpen(STACKED_MODAL_ID, false);
10587
+ },
10588
+ onError: (e) => {
10589
+ toast.error(e.message);
10590
+ }
10591
+ }
10592
+ );
10593
+ };
10594
+ if (isError) {
10595
+ throw error;
10596
+ }
10597
+ return /* @__PURE__ */ jsxs(
10598
+ StackedFocusModal.Content,
10599
+ {
10600
+ onOpenAutoFocus: (e) => {
10601
+ e.preventDefault();
10602
+ const searchInput = document.querySelector(
10603
+ "[data-modal-id='modal-search-input']"
10604
+ );
10605
+ if (searchInput) {
10606
+ searchInput.focus();
10607
+ }
10608
+ },
10609
+ children: [
10610
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10611
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10612
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10613
+ ] }),
10614
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10615
+ DataTable,
10616
+ {
10617
+ data: variants,
10618
+ columns,
10619
+ isLoading: isPending,
10620
+ getRowId: (row) => row.id,
10621
+ rowCount: count,
10622
+ prefix: VARIANT_PREFIX,
10623
+ layout: "fill",
10624
+ rowSelection: {
10625
+ state: rowSelection,
10626
+ onRowSelectionChange: setRowSelection,
10627
+ enableRowSelection: (row) => {
10628
+ return !items.find((i) => i.variant_id === row.original.id);
10629
+ }
10630
+ },
10631
+ autoFocusSearch: true
10632
+ }
10633
+ ) }),
10634
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10635
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10636
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10637
+ ] }) })
10638
+ ]
10639
+ }
10640
+ );
10641
+ };
10642
+ const columnHelper = createDataTableColumnHelper();
10643
+ const useColumns = () => {
10644
+ return useMemo(() => {
10645
+ return [
10646
+ columnHelper.select(),
10647
+ columnHelper.accessor("product.title", {
10648
+ header: "Product",
10649
+ cell: ({ row }) => {
10650
+ var _a, _b, _c;
10651
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10652
+ /* @__PURE__ */ jsx(
10653
+ Thumbnail,
10654
+ {
10655
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10656
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10657
+ }
10658
+ ),
10659
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10660
+ ] });
10661
+ },
10662
+ enableSorting: true
10663
+ }),
10664
+ columnHelper.accessor("title", {
10665
+ header: "Variant",
10666
+ enableSorting: true
10667
+ }),
10668
+ columnHelper.accessor("sku", {
10669
+ header: "SKU",
10670
+ cell: ({ getValue }) => {
10671
+ return getValue() ?? "-";
10672
+ },
10673
+ enableSorting: true
10674
+ }),
10675
+ columnHelper.accessor("updated_at", {
10676
+ header: "Updated",
10677
+ cell: ({ getValue }) => {
10678
+ return /* @__PURE__ */ jsx(
10679
+ Tooltip,
10680
+ {
10681
+ content: getFullDate({ date: getValue(), includeTime: true }),
10682
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10683
+ }
10684
+ );
10685
+ },
10686
+ enableSorting: true,
10687
+ sortAscLabel: "Oldest first",
10688
+ sortDescLabel: "Newest first"
10689
+ }),
10690
+ columnHelper.accessor("created_at", {
10691
+ header: "Created",
10692
+ cell: ({ getValue }) => {
10693
+ return /* @__PURE__ */ jsx(
10694
+ Tooltip,
10695
+ {
10696
+ content: getFullDate({ date: getValue(), includeTime: true }),
10697
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10698
+ }
10699
+ );
10700
+ },
10701
+ enableSorting: true,
10702
+ sortAscLabel: "Oldest first",
10703
+ sortDescLabel: "Newest first"
10704
+ })
10705
+ ];
10706
+ }, []);
10707
+ };
10708
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10709
+ const { setIsOpen } = useStackedModal();
10710
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10718
10711
  const form = useForm({
10719
10712
  defaultValues: {
10720
- title,
10721
- quantity,
10722
- unit_price
10713
+ title: "",
10714
+ quantity: 1,
10715
+ unit_price: ""
10723
10716
  },
10724
10717
  resolver: zodResolver(customItemSchema)
10725
10718
  });
10726
- useEffect(() => {
10727
- form.reset({
10728
- title,
10729
- quantity,
10730
- unit_price
10731
- });
10732
- }, [form, title, quantity, unit_price]);
10733
- const actionId = useMemo(() => {
10734
- var _a, _b;
10735
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10736
- }, [item]);
10737
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10738
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10739
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10740
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10741
10719
  const onSubmit = form.handleSubmit(async (data) => {
10742
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10743
- setEditing(false);
10744
- return;
10745
- }
10746
- if (!actionId) {
10747
- await updateOriginalItem(
10748
- {
10749
- item_id: item.id,
10750
- quantity: data.quantity,
10751
- unit_price: convertNumber(data.unit_price)
10752
- },
10753
- {
10754
- onSuccess: () => {
10755
- setEditing(false);
10756
- },
10757
- onError: (e) => {
10758
- toast.error(e.message);
10759
- }
10760
- }
10761
- );
10762
- return;
10763
- }
10764
- if (data.quantity === 0) {
10765
- await removeActionItem(actionId, {
10766
- onSuccess: () => {
10767
- setEditing(false);
10768
- },
10769
- onError: (e) => {
10770
- toast.error(e.message);
10771
- }
10772
- });
10773
- return;
10774
- }
10775
- await updateActionItem(
10720
+ await addItems(
10776
10721
  {
10777
- action_id: actionId,
10778
- quantity: data.quantity,
10779
- unit_price: convertNumber(data.unit_price)
10722
+ items: [
10723
+ {
10724
+ title: data.title,
10725
+ quantity: data.quantity,
10726
+ unit_price: convertNumber(data.unit_price)
10727
+ }
10728
+ ]
10780
10729
  },
10781
10730
  {
10782
10731
  onSuccess: () => {
10783
- setEditing(false);
10732
+ setIsOpen(STACKED_MODAL_ID, false);
10784
10733
  },
10785
10734
  onError: (e) => {
10786
10735
  toast.error(e.message);
@@ -10788,386 +10737,437 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10788
10737
  }
10789
10738
  );
10790
10739
  });
10791
- 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: [
10792
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10740
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10741
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10742
+ /* @__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: [
10743
+ /* @__PURE__ */ jsxs("div", { children: [
10744
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10745
+ /* @__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." }) })
10746
+ ] }),
10747
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10793
10748
  /* @__PURE__ */ jsx(
10794
- Thumbnail,
10749
+ Form$2.Field,
10795
10750
  {
10796
- thumbnail: item.thumbnail,
10797
- alt: item.title ?? void 0
10751
+ control: form.control,
10752
+ name: "title",
10753
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10754
+ /* @__PURE__ */ jsxs("div", { children: [
10755
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10756
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10757
+ ] }),
10758
+ /* @__PURE__ */ jsxs("div", { children: [
10759
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10760
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10761
+ ] })
10762
+ ] }) })
10798
10763
  }
10799
10764
  ),
10800
- editing ? /* @__PURE__ */ jsx(
10765
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10766
+ /* @__PURE__ */ jsx(
10801
10767
  Form$2.Field,
10802
10768
  {
10803
10769
  control: form.control,
10804
- name: "title",
10805
- render: ({ field }) => {
10806
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10807
- }
10770
+ name: "unit_price",
10771
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10772
+ /* @__PURE__ */ jsxs("div", { children: [
10773
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10774
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10775
+ ] }),
10776
+ /* @__PURE__ */ jsxs("div", { children: [
10777
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10778
+ CurrencyInput,
10779
+ {
10780
+ symbol: getNativeSymbol(currencyCode),
10781
+ code: currencyCode,
10782
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10783
+ ...field
10784
+ }
10785
+ ) }),
10786
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10787
+ ] })
10788
+ ] }) })
10808
10789
  }
10809
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10810
- ] }),
10811
- editing ? /* @__PURE__ */ jsx(
10812
- Form$2.Field,
10813
- {
10814
- control: form.control,
10815
- name: "quantity",
10816
- render: ({ field }) => {
10817
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10790
+ ),
10791
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10792
+ /* @__PURE__ */ jsx(
10793
+ Form$2.Field,
10794
+ {
10795
+ control: form.control,
10796
+ name: "quantity",
10797
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10798
+ /* @__PURE__ */ jsxs("div", { children: [
10799
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10800
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10801
+ ] }),
10802
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10803
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10804
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10805
+ ] })
10806
+ ] }) })
10818
10807
  }
10819
- }
10820
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10821
- editing ? /* @__PURE__ */ jsx(
10822
- Form$2.Field,
10808
+ )
10809
+ ] }) }) }),
10810
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10811
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10812
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10813
+ ] }) })
10814
+ ] }) }) });
10815
+ };
10816
+ const customItemSchema = objectType({
10817
+ title: stringType().min(1),
10818
+ quantity: numberType(),
10819
+ unit_price: unionType([numberType(), stringType()])
10820
+ });
10821
+ const InlineTip = forwardRef(
10822
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10824
+ return /* @__PURE__ */ jsxs(
10825
+ "div",
10823
10826
  {
10824
- control: form.control,
10825
- name: "unit_price",
10826
- render: ({ field: { onChange, ...field } }) => {
10827
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10828
- CurrencyInput,
10827
+ ref,
10828
+ className: clx(
10829
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10830
+ className
10831
+ ),
10832
+ ...props,
10833
+ children: [
10834
+ /* @__PURE__ */ jsx(
10835
+ "div",
10829
10836
  {
10830
- ...field,
10831
- symbol: getNativeSymbol(currencyCode),
10832
- code: currencyCode,
10833
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10837
+ role: "presentation",
10838
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10839
+ "bg-ui-tag-orange-icon": variant === "warning"
10840
+ })
10834
10841
  }
10835
- ) }) });
10836
- }
10837
- }
10838
- ) : /* @__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) }) }),
10839
- /* @__PURE__ */ jsx(
10840
- IconButton,
10841
- {
10842
- type: "button",
10843
- size: "small",
10844
- onClick: editing ? onSubmit : () => {
10845
- setEditing(true);
10846
- },
10847
- disabled: isPending,
10848
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10849
- }
10850
- )
10851
- ] }) }) });
10852
- };
10853
- const StackedModalTrigger$1 = ({
10854
- type,
10855
- setModalContent
10856
- }) => {
10857
- const { setIsOpen } = useStackedModal();
10858
- const onClick = useCallback(() => {
10859
- setModalContent(type);
10860
- setIsOpen(STACKED_MODAL_ID, true);
10861
- }, [setModalContent, setIsOpen, type]);
10862
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10863
- };
10864
- const VARIANT_PREFIX = "items";
10865
- const LIMIT = 50;
10866
- const ExistingItemsForm = ({ orderId, items }) => {
10867
- const { setIsOpen } = useStackedModal();
10868
- const [rowSelection, setRowSelection] = useState(
10869
- items.reduce((acc, item) => {
10870
- acc[item.variant_id] = true;
10871
- return acc;
10872
- }, {})
10873
- );
10874
- useEffect(() => {
10875
- setRowSelection(
10876
- items.reduce((acc, item) => {
10877
- if (item.variant_id) {
10878
- acc[item.variant_id] = true;
10879
- }
10880
- return acc;
10881
- }, {})
10842
+ ),
10843
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10844
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10845
+ labelValue,
10846
+ ":"
10847
+ ] }),
10848
+ " ",
10849
+ children
10850
+ ] })
10851
+ ]
10852
+ }
10882
10853
  );
10883
- }, [items]);
10884
- const { q, order, offset } = useQueryParams(
10885
- ["q", "order", "offset"],
10886
- VARIANT_PREFIX
10887
- );
10888
- const { variants, count, isPending, isError, error } = useProductVariants(
10889
- {
10890
- q,
10891
- order,
10892
- offset: offset ? parseInt(offset) : void 0,
10893
- limit: LIMIT
10854
+ }
10855
+ );
10856
+ InlineTip.displayName = "InlineTip";
10857
+ const MetadataFieldSchema = objectType({
10858
+ key: stringType(),
10859
+ disabled: booleanType().optional(),
10860
+ value: anyType()
10861
+ });
10862
+ const MetadataSchema = objectType({
10863
+ metadata: arrayType(MetadataFieldSchema)
10864
+ });
10865
+ const Metadata = () => {
10866
+ const { id } = useParams();
10867
+ const { order, isPending, isError, error } = useOrder(id, {
10868
+ fields: "metadata"
10869
+ });
10870
+ if (isError) {
10871
+ throw error;
10872
+ }
10873
+ const isReady = !isPending && !!order;
10874
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10875
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10876
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10877
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10878
+ ] }),
10879
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10880
+ ] });
10881
+ };
10882
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10883
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10884
+ const MetadataForm = ({ orderId, metadata }) => {
10885
+ const { handleSuccess } = useRouteModal();
10886
+ const hasUneditableRows = getHasUneditableRows(metadata);
10887
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10888
+ const form = useForm({
10889
+ defaultValues: {
10890
+ metadata: getDefaultValues(metadata)
10894
10891
  },
10895
- {
10896
- placeholderData: keepPreviousData
10897
- }
10898
- );
10899
- const columns = useColumns();
10900
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10901
- const onSubmit = async () => {
10902
- const ids = Object.keys(rowSelection).filter(
10903
- (id) => !items.find((i) => i.variant_id === id)
10904
- );
10892
+ resolver: zodResolver(MetadataSchema)
10893
+ });
10894
+ const handleSubmit = form.handleSubmit(async (data) => {
10895
+ const parsedData = parseValues(data);
10905
10896
  await mutateAsync(
10906
10897
  {
10907
- items: ids.map((id) => ({
10908
- variant_id: id,
10909
- quantity: 1
10910
- }))
10898
+ metadata: parsedData
10911
10899
  },
10912
10900
  {
10913
10901
  onSuccess: () => {
10914
- setRowSelection({});
10915
- setIsOpen(STACKED_MODAL_ID, false);
10902
+ toast.success("Metadata updated");
10903
+ handleSuccess();
10916
10904
  },
10917
- onError: (e) => {
10918
- toast.error(e.message);
10905
+ onError: (error) => {
10906
+ toast.error(error.message);
10919
10907
  }
10920
10908
  }
10921
10909
  );
10922
- };
10923
- if (isError) {
10924
- throw error;
10910
+ });
10911
+ const { fields, insert, remove } = useFieldArray({
10912
+ control: form.control,
10913
+ name: "metadata"
10914
+ });
10915
+ function deleteRow(index) {
10916
+ remove(index);
10917
+ if (fields.length === 1) {
10918
+ insert(0, {
10919
+ key: "",
10920
+ value: "",
10921
+ disabled: false
10922
+ });
10923
+ }
10925
10924
  }
10926
- return /* @__PURE__ */ jsxs(
10927
- StackedFocusModal.Content,
10925
+ function insertRow(index, position) {
10926
+ insert(index + (position === "above" ? 0 : 1), {
10927
+ key: "",
10928
+ value: "",
10929
+ disabled: false
10930
+ });
10931
+ }
10932
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10933
+ KeyboundForm,
10928
10934
  {
10929
- onOpenAutoFocus: (e) => {
10930
- e.preventDefault();
10931
- const searchInput = document.querySelector(
10932
- "[data-modal-id='modal-search-input']"
10933
- );
10934
- if (searchInput) {
10935
- searchInput.focus();
10936
- }
10937
- },
10935
+ onSubmit: handleSubmit,
10936
+ className: "flex flex-1 flex-col overflow-hidden",
10938
10937
  children: [
10939
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10940
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10941
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10942
- ] }),
10943
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10944
- DataTable,
10945
- {
10946
- data: variants,
10947
- columns,
10948
- isLoading: isPending,
10949
- getRowId: (row) => row.id,
10950
- rowCount: count,
10951
- prefix: VARIANT_PREFIX,
10952
- layout: "fill",
10953
- rowSelection: {
10954
- state: rowSelection,
10955
- onRowSelectionChange: setRowSelection,
10956
- enableRowSelection: (row) => {
10957
- return !items.find((i) => i.variant_id === row.original.id);
10938
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10939
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10940
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10941
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10942
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10943
+ ] }),
10944
+ fields.map((field, index) => {
10945
+ const isDisabled = field.disabled || false;
10946
+ let placeholder = "-";
10947
+ if (typeof field.value === "object") {
10948
+ placeholder = "{ ... }";
10958
10949
  }
10959
- },
10960
- autoFocusSearch: true
10961
- }
10962
- ) }),
10963
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10964
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10965
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10950
+ if (Array.isArray(field.value)) {
10951
+ placeholder = "[ ... ]";
10952
+ }
10953
+ return /* @__PURE__ */ jsx(
10954
+ ConditionalTooltip,
10955
+ {
10956
+ showTooltip: isDisabled,
10957
+ content: "This row is disabled because it contains non-primitive data.",
10958
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10959
+ /* @__PURE__ */ jsxs(
10960
+ "div",
10961
+ {
10962
+ className: clx("grid grid-cols-2 divide-x", {
10963
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10964
+ }),
10965
+ children: [
10966
+ /* @__PURE__ */ jsx(
10967
+ Form$2.Field,
10968
+ {
10969
+ control: form.control,
10970
+ name: `metadata.${index}.key`,
10971
+ render: ({ field: field2 }) => {
10972
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10973
+ GridInput,
10974
+ {
10975
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10976
+ ...field2,
10977
+ disabled: isDisabled,
10978
+ placeholder: "Key"
10979
+ }
10980
+ ) }) });
10981
+ }
10982
+ }
10983
+ ),
10984
+ /* @__PURE__ */ jsx(
10985
+ Form$2.Field,
10986
+ {
10987
+ control: form.control,
10988
+ name: `metadata.${index}.value`,
10989
+ render: ({ field: { value, ...field2 } }) => {
10990
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10991
+ GridInput,
10992
+ {
10993
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10994
+ ...field2,
10995
+ value: isDisabled ? placeholder : value,
10996
+ disabled: isDisabled,
10997
+ placeholder: "Value"
10998
+ }
10999
+ ) }) });
11000
+ }
11001
+ }
11002
+ )
11003
+ ]
11004
+ }
11005
+ ),
11006
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11007
+ /* @__PURE__ */ jsx(
11008
+ DropdownMenu.Trigger,
11009
+ {
11010
+ className: clx(
11011
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11012
+ {
11013
+ hidden: isDisabled
11014
+ }
11015
+ ),
11016
+ disabled: isDisabled,
11017
+ asChild: true,
11018
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11019
+ }
11020
+ ),
11021
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11022
+ /* @__PURE__ */ jsxs(
11023
+ DropdownMenu.Item,
11024
+ {
11025
+ className: "gap-x-2",
11026
+ onClick: () => insertRow(index, "above"),
11027
+ children: [
11028
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11029
+ "Insert row above"
11030
+ ]
11031
+ }
11032
+ ),
11033
+ /* @__PURE__ */ jsxs(
11034
+ DropdownMenu.Item,
11035
+ {
11036
+ className: "gap-x-2",
11037
+ onClick: () => insertRow(index, "below"),
11038
+ children: [
11039
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11040
+ "Insert row below"
11041
+ ]
11042
+ }
11043
+ ),
11044
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11045
+ /* @__PURE__ */ jsxs(
11046
+ DropdownMenu.Item,
11047
+ {
11048
+ className: "gap-x-2",
11049
+ onClick: () => deleteRow(index),
11050
+ children: [
11051
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11052
+ "Delete row"
11053
+ ]
11054
+ }
11055
+ )
11056
+ ] })
11057
+ ] })
11058
+ ] })
11059
+ },
11060
+ field.id
11061
+ );
11062
+ })
11063
+ ] }),
11064
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11065
+ ] }),
11066
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11067
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11068
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10966
11069
  ] }) })
10967
11070
  ]
10968
11071
  }
11072
+ ) });
11073
+ };
11074
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11075
+ return /* @__PURE__ */ jsx(
11076
+ "input",
11077
+ {
11078
+ ref,
11079
+ ...props,
11080
+ autoComplete: "off",
11081
+ className: clx(
11082
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11083
+ className
11084
+ )
11085
+ }
10969
11086
  );
11087
+ });
11088
+ GridInput.displayName = "MetadataForm.GridInput";
11089
+ const PlaceholderInner = () => {
11090
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11091
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11092
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11093
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11094
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11095
+ ] }) })
11096
+ ] });
10970
11097
  };
10971
- const columnHelper = createDataTableColumnHelper();
10972
- const useColumns = () => {
10973
- return useMemo(() => {
11098
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11099
+ function getDefaultValues(metadata) {
11100
+ if (!metadata || !Object.keys(metadata).length) {
10974
11101
  return [
10975
- columnHelper.select(),
10976
- columnHelper.accessor("product.title", {
10977
- header: "Product",
10978
- cell: ({ row }) => {
10979
- var _a, _b, _c;
10980
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10981
- /* @__PURE__ */ jsx(
10982
- Thumbnail,
10983
- {
10984
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10985
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10986
- }
10987
- ),
10988
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10989
- ] });
10990
- },
10991
- enableSorting: true
10992
- }),
10993
- columnHelper.accessor("title", {
10994
- header: "Variant",
10995
- enableSorting: true
10996
- }),
10997
- columnHelper.accessor("sku", {
10998
- header: "SKU",
10999
- cell: ({ getValue }) => {
11000
- return getValue() ?? "-";
11001
- },
11002
- enableSorting: true
11003
- }),
11004
- columnHelper.accessor("updated_at", {
11005
- header: "Updated",
11006
- cell: ({ getValue }) => {
11007
- return /* @__PURE__ */ jsx(
11008
- Tooltip,
11009
- {
11010
- content: getFullDate({ date: getValue(), includeTime: true }),
11011
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11012
- }
11013
- );
11014
- },
11015
- enableSorting: true,
11016
- sortAscLabel: "Oldest first",
11017
- sortDescLabel: "Newest first"
11018
- }),
11019
- columnHelper.accessor("created_at", {
11020
- header: "Created",
11021
- cell: ({ getValue }) => {
11022
- return /* @__PURE__ */ jsx(
11023
- Tooltip,
11024
- {
11025
- content: getFullDate({ date: getValue(), includeTime: true }),
11026
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11027
- }
11028
- );
11029
- },
11030
- enableSorting: true,
11031
- sortAscLabel: "Oldest first",
11032
- sortDescLabel: "Newest first"
11033
- })
11034
- ];
11035
- }, []);
11036
- };
11037
- const CustomItemForm = ({ orderId, currencyCode }) => {
11038
- const { setIsOpen } = useStackedModal();
11039
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11040
- const form = useForm({
11041
- defaultValues: {
11042
- title: "",
11043
- quantity: 1,
11044
- unit_price: ""
11045
- },
11046
- resolver: zodResolver(customItemSchema)
11047
- });
11048
- const onSubmit = form.handleSubmit(async (data) => {
11049
- await addItems(
11050
- {
11051
- items: [
11052
- {
11053
- title: data.title,
11054
- quantity: data.quantity,
11055
- unit_price: convertNumber(data.unit_price)
11056
- }
11057
- ]
11058
- },
11059
11102
  {
11060
- onSuccess: () => {
11061
- setIsOpen(STACKED_MODAL_ID, false);
11062
- },
11063
- onError: (e) => {
11064
- toast.error(e.message);
11065
- }
11103
+ key: "",
11104
+ value: "",
11105
+ disabled: false
11066
11106
  }
11067
- );
11107
+ ];
11108
+ }
11109
+ return Object.entries(metadata).map(([key, value]) => {
11110
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11111
+ return {
11112
+ key,
11113
+ value,
11114
+ disabled: true
11115
+ };
11116
+ }
11117
+ let stringValue = value;
11118
+ if (typeof value !== "string") {
11119
+ stringValue = JSON.stringify(value);
11120
+ }
11121
+ return {
11122
+ key,
11123
+ value: stringValue,
11124
+ original_key: key
11125
+ };
11068
11126
  });
11069
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
11070
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11071
- /* @__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: [
11072
- /* @__PURE__ */ jsxs("div", { children: [
11073
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
11074
- /* @__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." }) })
11075
- ] }),
11076
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11077
- /* @__PURE__ */ jsx(
11078
- Form$2.Field,
11079
- {
11080
- control: form.control,
11081
- name: "title",
11082
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11083
- /* @__PURE__ */ jsxs("div", { children: [
11084
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
11085
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
11086
- ] }),
11087
- /* @__PURE__ */ jsxs("div", { children: [
11088
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11089
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11090
- ] })
11091
- ] }) })
11092
- }
11093
- ),
11094
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11095
- /* @__PURE__ */ jsx(
11096
- Form$2.Field,
11097
- {
11098
- control: form.control,
11099
- name: "unit_price",
11100
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11101
- /* @__PURE__ */ jsxs("div", { children: [
11102
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
11103
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11104
- ] }),
11105
- /* @__PURE__ */ jsxs("div", { children: [
11106
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11107
- CurrencyInput,
11108
- {
11109
- symbol: getNativeSymbol(currencyCode),
11110
- code: currencyCode,
11111
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11112
- ...field
11113
- }
11114
- ) }),
11115
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11116
- ] })
11117
- ] }) })
11118
- }
11119
- ),
11120
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11121
- /* @__PURE__ */ jsx(
11122
- Form$2.Field,
11123
- {
11124
- control: form.control,
11125
- name: "quantity",
11126
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11127
- /* @__PURE__ */ jsxs("div", { children: [
11128
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
11129
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11130
- ] }),
11131
- /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
11132
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11133
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11134
- ] })
11135
- ] }) })
11136
- }
11137
- )
11138
- ] }) }) }),
11139
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11140
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11141
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11142
- ] }) })
11143
- ] }) }) });
11144
- };
11145
- const customItemSchema = objectType({
11146
- title: stringType().min(1),
11147
- quantity: numberType(),
11148
- unit_price: unionType([numberType(), stringType()])
11149
- });
11150
- const CustomItems = () => {
11151
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11152
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
11153
- /* @__PURE__ */ jsx(CustomItemsForm, {})
11154
- ] });
11155
- };
11156
- const CustomItemsForm = () => {
11157
- const form = useForm({
11158
- resolver: zodResolver(schema$3)
11127
+ }
11128
+ function parseValues(values) {
11129
+ const metadata = values.metadata;
11130
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11131
+ if (isEmpty) {
11132
+ return null;
11133
+ }
11134
+ const update = {};
11135
+ metadata.forEach((field) => {
11136
+ let key = field.key;
11137
+ let value = field.value;
11138
+ const disabled = field.disabled;
11139
+ if (!key || !value) {
11140
+ return;
11141
+ }
11142
+ if (disabled) {
11143
+ update[key] = value;
11144
+ return;
11145
+ }
11146
+ key = key.trim();
11147
+ value = value.trim();
11148
+ if (value === "true") {
11149
+ update[key] = true;
11150
+ } else if (value === "false") {
11151
+ update[key] = false;
11152
+ } else {
11153
+ const parsedNumber = parseFloat(value);
11154
+ if (!isNaN(parsedNumber)) {
11155
+ update[key] = parsedNumber;
11156
+ } else {
11157
+ update[key] = value;
11158
+ }
11159
+ }
11159
11160
  });
11160
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11161
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
11162
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11163
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11164
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
11165
- ] }) })
11166
- ] }) });
11167
- };
11168
- const schema$3 = objectType({
11169
- email: stringType().email()
11170
- });
11161
+ return update;
11162
+ }
11163
+ function getHasUneditableRows(metadata) {
11164
+ if (!metadata) {
11165
+ return false;
11166
+ }
11167
+ return Object.values(metadata).some(
11168
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11169
+ );
11170
+ }
11171
11171
  const PROMOTION_QUERY_KEY = "promotions";
11172
11172
  const promotionsQueryKeys = {
11173
11173
  list: (query2) => [
@@ -12337,230 +12337,27 @@ const CustomAmountField = ({
12337
12337
  Form$2.Field,
12338
12338
  {
12339
12339
  control,
12340
- name: "custom_amount",
12341
- render: ({ field: { onChange, ...field } }) => {
12342
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12343
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12345
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12346
- ] }),
12347
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12348
- CurrencyInput,
12349
- {
12350
- ...field,
12351
- onValueChange: (value) => onChange(value),
12352
- symbol: getNativeSymbol(currencyCode),
12353
- code: currencyCode
12354
- }
12355
- ) })
12356
- ] });
12357
- }
12358
- }
12359
- );
12360
- };
12361
- const ShippingAddress = () => {
12362
- const { id } = useParams();
12363
- const { order, isPending, isError, error } = useOrder(id, {
12364
- fields: "+shipping_address"
12365
- });
12366
- if (isError) {
12367
- throw error;
12368
- }
12369
- const isReady = !isPending && !!order;
12370
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12371
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12372
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12373
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12374
- ] }),
12375
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12376
- ] });
12377
- };
12378
- const ShippingAddressForm = ({ order }) => {
12379
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12380
- const form = useForm({
12381
- defaultValues: {
12382
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12383
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12384
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12385
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12386
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12387
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12388
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12389
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12390
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12392
- },
12393
- resolver: zodResolver(schema$1)
12394
- });
12395
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12396
- const { handleSuccess } = useRouteModal();
12397
- const onSubmit = form.handleSubmit(async (data) => {
12398
- await mutateAsync(
12399
- {
12400
- shipping_address: {
12401
- first_name: data.first_name,
12402
- last_name: data.last_name,
12403
- company: data.company,
12404
- address_1: data.address_1,
12405
- address_2: data.address_2,
12406
- city: data.city,
12407
- province: data.province,
12408
- country_code: data.country_code,
12409
- postal_code: data.postal_code,
12410
- phone: data.phone
12411
- }
12412
- },
12413
- {
12414
- onSuccess: () => {
12415
- handleSuccess();
12416
- },
12417
- onError: (error) => {
12418
- toast.error(error.message);
12419
- }
12420
- }
12421
- );
12422
- });
12423
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12424
- KeyboundForm,
12425
- {
12426
- className: "flex flex-1 flex-col overflow-hidden",
12427
- onSubmit,
12428
- children: [
12429
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12430
- /* @__PURE__ */ jsx(
12431
- Form$2.Field,
12432
- {
12433
- control: form.control,
12434
- name: "country_code",
12435
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12436
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12437
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12438
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12439
- ] })
12440
- }
12441
- ),
12442
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12443
- /* @__PURE__ */ jsx(
12444
- Form$2.Field,
12445
- {
12446
- control: form.control,
12447
- name: "first_name",
12448
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12449
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12450
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12451
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12452
- ] })
12453
- }
12454
- ),
12455
- /* @__PURE__ */ jsx(
12456
- Form$2.Field,
12457
- {
12458
- control: form.control,
12459
- name: "last_name",
12460
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12461
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12462
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12463
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12464
- ] })
12465
- }
12466
- )
12467
- ] }),
12468
- /* @__PURE__ */ jsx(
12469
- Form$2.Field,
12470
- {
12471
- control: form.control,
12472
- name: "company",
12473
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12474
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12475
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12476
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12477
- ] })
12478
- }
12479
- ),
12480
- /* @__PURE__ */ jsx(
12481
- Form$2.Field,
12482
- {
12483
- control: form.control,
12484
- name: "address_1",
12485
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12486
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12487
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12488
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12489
- ] })
12490
- }
12491
- ),
12492
- /* @__PURE__ */ jsx(
12493
- Form$2.Field,
12494
- {
12495
- control: form.control,
12496
- name: "address_2",
12497
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12498
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12499
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12500
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12501
- ] })
12502
- }
12503
- ),
12504
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12505
- /* @__PURE__ */ jsx(
12506
- Form$2.Field,
12507
- {
12508
- control: form.control,
12509
- name: "postal_code",
12510
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12511
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12512
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12513
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12514
- ] })
12515
- }
12516
- ),
12517
- /* @__PURE__ */ jsx(
12518
- Form$2.Field,
12519
- {
12520
- control: form.control,
12521
- name: "city",
12522
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12523
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12524
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12525
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12526
- ] })
12527
- }
12528
- )
12529
- ] }),
12530
- /* @__PURE__ */ jsx(
12531
- Form$2.Field,
12532
- {
12533
- control: form.control,
12534
- name: "province",
12535
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12536
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12537
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12538
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12539
- ] })
12540
- }
12541
- ),
12542
- /* @__PURE__ */ jsx(
12543
- Form$2.Field,
12340
+ name: "custom_amount",
12341
+ render: ({ field: { onChange, ...field } }) => {
12342
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12343
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12345
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12346
+ ] }),
12347
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12348
+ CurrencyInput,
12544
12349
  {
12545
- control: form.control,
12546
- name: "phone",
12547
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12548
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12549
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12550
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12551
- ] })
12350
+ ...field,
12351
+ onValueChange: (value) => onChange(value),
12352
+ symbol: getNativeSymbol(currencyCode),
12353
+ code: currencyCode
12552
12354
  }
12553
- )
12554
- ] }) }),
12555
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12556
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12557
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12558
- ] }) })
12559
- ]
12355
+ ) })
12356
+ ] });
12357
+ }
12560
12358
  }
12561
- ) });
12359
+ );
12562
12360
  };
12563
- const schema$1 = addressSchema;
12564
12361
  const TransferOwnership = () => {
12565
12362
  const { id } = useParams();
12566
12363
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12584,7 +12381,7 @@ const TransferOwnershipForm = ({ order }) => {
12584
12381
  defaultValues: {
12585
12382
  customer_id: order.customer_id || ""
12586
12383
  },
12587
- resolver: zodResolver(schema)
12384
+ resolver: zodResolver(schema$1)
12588
12385
  });
12589
12386
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
12387
  const { handleSuccess } = useRouteModal();
@@ -13034,9 +12831,212 @@ const Illustration = () => {
13034
12831
  }
13035
12832
  );
13036
12833
  };
13037
- const schema = objectType({
12834
+ const schema$1 = objectType({
13038
12835
  customer_id: stringType().min(1)
13039
12836
  });
12837
+ const ShippingAddress = () => {
12838
+ const { id } = useParams();
12839
+ const { order, isPending, isError, error } = useOrder(id, {
12840
+ fields: "+shipping_address"
12841
+ });
12842
+ if (isError) {
12843
+ throw error;
12844
+ }
12845
+ const isReady = !isPending && !!order;
12846
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12847
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12848
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12849
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12850
+ ] }),
12851
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12852
+ ] });
12853
+ };
12854
+ const ShippingAddressForm = ({ order }) => {
12855
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12856
+ const form = useForm({
12857
+ defaultValues: {
12858
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12859
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12860
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12861
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12862
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12863
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12864
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12865
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12866
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12867
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12868
+ },
12869
+ resolver: zodResolver(schema)
12870
+ });
12871
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12872
+ const { handleSuccess } = useRouteModal();
12873
+ const onSubmit = form.handleSubmit(async (data) => {
12874
+ await mutateAsync(
12875
+ {
12876
+ shipping_address: {
12877
+ first_name: data.first_name,
12878
+ last_name: data.last_name,
12879
+ company: data.company,
12880
+ address_1: data.address_1,
12881
+ address_2: data.address_2,
12882
+ city: data.city,
12883
+ province: data.province,
12884
+ country_code: data.country_code,
12885
+ postal_code: data.postal_code,
12886
+ phone: data.phone
12887
+ }
12888
+ },
12889
+ {
12890
+ onSuccess: () => {
12891
+ handleSuccess();
12892
+ },
12893
+ onError: (error) => {
12894
+ toast.error(error.message);
12895
+ }
12896
+ }
12897
+ );
12898
+ });
12899
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12900
+ KeyboundForm,
12901
+ {
12902
+ className: "flex flex-1 flex-col overflow-hidden",
12903
+ onSubmit,
12904
+ children: [
12905
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12906
+ /* @__PURE__ */ jsx(
12907
+ Form$2.Field,
12908
+ {
12909
+ control: form.control,
12910
+ name: "country_code",
12911
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12912
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12913
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12914
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12915
+ ] })
12916
+ }
12917
+ ),
12918
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12919
+ /* @__PURE__ */ jsx(
12920
+ Form$2.Field,
12921
+ {
12922
+ control: form.control,
12923
+ name: "first_name",
12924
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12925
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12926
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12927
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12928
+ ] })
12929
+ }
12930
+ ),
12931
+ /* @__PURE__ */ jsx(
12932
+ Form$2.Field,
12933
+ {
12934
+ control: form.control,
12935
+ name: "last_name",
12936
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12937
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12938
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12939
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12940
+ ] })
12941
+ }
12942
+ )
12943
+ ] }),
12944
+ /* @__PURE__ */ jsx(
12945
+ Form$2.Field,
12946
+ {
12947
+ control: form.control,
12948
+ name: "company",
12949
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12950
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12951
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12952
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
+ ] })
12954
+ }
12955
+ ),
12956
+ /* @__PURE__ */ jsx(
12957
+ Form$2.Field,
12958
+ {
12959
+ control: form.control,
12960
+ name: "address_1",
12961
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12962
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12963
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12964
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12965
+ ] })
12966
+ }
12967
+ ),
12968
+ /* @__PURE__ */ jsx(
12969
+ Form$2.Field,
12970
+ {
12971
+ control: form.control,
12972
+ name: "address_2",
12973
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12974
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12975
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12976
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12977
+ ] })
12978
+ }
12979
+ ),
12980
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12981
+ /* @__PURE__ */ jsx(
12982
+ Form$2.Field,
12983
+ {
12984
+ control: form.control,
12985
+ name: "postal_code",
12986
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12987
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12988
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12989
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12990
+ ] })
12991
+ }
12992
+ ),
12993
+ /* @__PURE__ */ jsx(
12994
+ Form$2.Field,
12995
+ {
12996
+ control: form.control,
12997
+ name: "city",
12998
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12999
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13000
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13001
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13002
+ ] })
13003
+ }
13004
+ )
13005
+ ] }),
13006
+ /* @__PURE__ */ jsx(
13007
+ Form$2.Field,
13008
+ {
13009
+ control: form.control,
13010
+ name: "province",
13011
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13013
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
+ ] })
13016
+ }
13017
+ ),
13018
+ /* @__PURE__ */ jsx(
13019
+ Form$2.Field,
13020
+ {
13021
+ control: form.control,
13022
+ name: "phone",
13023
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13024
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13025
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13026
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13027
+ ] })
13028
+ }
13029
+ )
13030
+ ] }) }),
13031
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13033
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13034
+ ] }) })
13035
+ ]
13036
+ }
13037
+ ) });
13038
+ };
13039
+ const schema = addressSchema;
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13062,20 +13062,20 @@ const routeModule = {
13062
13062
  path: "/draft-orders/:id/billing-address"
13063
13063
  },
13064
13064
  {
13065
- Component: Email,
13066
- path: "/draft-orders/:id/email"
13065
+ Component: CustomItems,
13066
+ path: "/draft-orders/:id/custom-items"
13067
13067
  },
13068
13068
  {
13069
- Component: Metadata,
13070
- path: "/draft-orders/:id/metadata"
13069
+ Component: Email,
13070
+ path: "/draft-orders/:id/email"
13071
13071
  },
13072
13072
  {
13073
13073
  Component: Items,
13074
13074
  path: "/draft-orders/:id/items"
13075
13075
  },
13076
13076
  {
13077
- Component: CustomItems,
13078
- path: "/draft-orders/:id/custom-items"
13077
+ Component: Metadata,
13078
+ path: "/draft-orders/:id/metadata"
13079
13079
  },
13080
13080
  {
13081
13081
  Component: Promotions,
@@ -13089,13 +13089,13 @@ const routeModule = {
13089
13089
  Component: Shipping,
13090
13090
  path: "/draft-orders/:id/shipping"
13091
13091
  },
13092
- {
13093
- Component: ShippingAddress,
13094
- path: "/draft-orders/:id/shipping-address"
13095
- },
13096
13092
  {
13097
13093
  Component: TransferOwnership,
13098
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
+ },
13096
+ {
13097
+ Component: ShippingAddress,
13098
+ path: "/draft-orders/:id/shipping-address"
13099
13099
  }
13100
13100
  ]
13101
13101
  }