@medusajs/draft-order 2.11.4-snapshot-20251106121614 → 2.11.4-snapshot-20251106122834
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.
- package/.medusa/server/src/admin/index.js +555 -555
- package/.medusa/server/src/admin/index.mjs +556 -556
- package/package.json +16 -16
|
@@ -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,
|
|
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";
|
|
@@ -9772,54 +9772,10 @@ const CustomItemsForm = () => {
|
|
|
9772
9772
|
const schema$4 = objectType({
|
|
9773
9773
|
email: stringType().email()
|
|
9774
9774
|
});
|
|
9775
|
-
const
|
|
9776
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
9777
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
9778
|
-
return /* @__PURE__ */ jsxs(
|
|
9779
|
-
"div",
|
|
9780
|
-
{
|
|
9781
|
-
ref,
|
|
9782
|
-
className: clx(
|
|
9783
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
9784
|
-
className
|
|
9785
|
-
),
|
|
9786
|
-
...props,
|
|
9787
|
-
children: [
|
|
9788
|
-
/* @__PURE__ */ jsx(
|
|
9789
|
-
"div",
|
|
9790
|
-
{
|
|
9791
|
-
role: "presentation",
|
|
9792
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
9793
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
9794
|
-
})
|
|
9795
|
-
}
|
|
9796
|
-
),
|
|
9797
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
9798
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
9799
|
-
labelValue,
|
|
9800
|
-
":"
|
|
9801
|
-
] }),
|
|
9802
|
-
" ",
|
|
9803
|
-
children
|
|
9804
|
-
] })
|
|
9805
|
-
]
|
|
9806
|
-
}
|
|
9807
|
-
);
|
|
9808
|
-
}
|
|
9809
|
-
);
|
|
9810
|
-
InlineTip.displayName = "InlineTip";
|
|
9811
|
-
const MetadataFieldSchema = objectType({
|
|
9812
|
-
key: stringType(),
|
|
9813
|
-
disabled: booleanType().optional(),
|
|
9814
|
-
value: anyType()
|
|
9815
|
-
});
|
|
9816
|
-
const MetadataSchema = objectType({
|
|
9817
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
9818
|
-
});
|
|
9819
|
-
const Metadata = () => {
|
|
9775
|
+
const Email = () => {
|
|
9820
9776
|
const { id } = useParams();
|
|
9821
9777
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
9822
|
-
fields: "
|
|
9778
|
+
fields: "+email"
|
|
9823
9779
|
});
|
|
9824
9780
|
if (isError) {
|
|
9825
9781
|
throw error;
|
|
@@ -9827,33 +9783,26 @@ const Metadata = () => {
|
|
|
9827
9783
|
const isReady = !isPending && !!order;
|
|
9828
9784
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9829
9785
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9830
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
9831
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
9786
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
9787
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9832
9788
|
] }),
|
|
9833
|
-
|
|
9789
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
9834
9790
|
] });
|
|
9835
9791
|
};
|
|
9836
|
-
const
|
|
9837
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
9838
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
9839
|
-
const { handleSuccess } = useRouteModal();
|
|
9840
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
9841
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
9792
|
+
const EmailForm = ({ order }) => {
|
|
9842
9793
|
const form = useForm({
|
|
9843
9794
|
defaultValues: {
|
|
9844
|
-
|
|
9795
|
+
email: order.email ?? ""
|
|
9845
9796
|
},
|
|
9846
|
-
resolver: zodResolver(
|
|
9797
|
+
resolver: zodResolver(schema$3)
|
|
9847
9798
|
});
|
|
9848
|
-
const
|
|
9849
|
-
|
|
9799
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9800
|
+
const { handleSuccess } = useRouteModal();
|
|
9801
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9850
9802
|
await mutateAsync(
|
|
9851
|
-
{
|
|
9852
|
-
metadata: parsedData
|
|
9853
|
-
},
|
|
9803
|
+
{ email: data.email },
|
|
9854
9804
|
{
|
|
9855
9805
|
onSuccess: () => {
|
|
9856
|
-
toast.success("Metadata updated");
|
|
9857
9806
|
handleSuccess();
|
|
9858
9807
|
},
|
|
9859
9808
|
onError: (error) => {
|
|
@@ -9862,325 +9811,26 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
9862
9811
|
}
|
|
9863
9812
|
);
|
|
9864
9813
|
});
|
|
9865
|
-
const { fields, insert, remove } = useFieldArray({
|
|
9866
|
-
control: form.control,
|
|
9867
|
-
name: "metadata"
|
|
9868
|
-
});
|
|
9869
|
-
function deleteRow(index) {
|
|
9870
|
-
remove(index);
|
|
9871
|
-
if (fields.length === 1) {
|
|
9872
|
-
insert(0, {
|
|
9873
|
-
key: "",
|
|
9874
|
-
value: "",
|
|
9875
|
-
disabled: false
|
|
9876
|
-
});
|
|
9877
|
-
}
|
|
9878
|
-
}
|
|
9879
|
-
function insertRow(index, position) {
|
|
9880
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
9881
|
-
key: "",
|
|
9882
|
-
value: "",
|
|
9883
|
-
disabled: false
|
|
9884
|
-
});
|
|
9885
|
-
}
|
|
9886
9814
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9887
9815
|
KeyboundForm,
|
|
9888
9816
|
{
|
|
9889
|
-
onSubmit: handleSubmit,
|
|
9890
9817
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
9818
|
+
onSubmit,
|
|
9891
9819
|
children: [
|
|
9892
|
-
/* @__PURE__ */
|
|
9893
|
-
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9898
|
-
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
|
|
9906
|
-
}
|
|
9907
|
-
return /* @__PURE__ */ jsx(
|
|
9908
|
-
ConditionalTooltip,
|
|
9909
|
-
{
|
|
9910
|
-
showTooltip: isDisabled,
|
|
9911
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
9912
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
9913
|
-
/* @__PURE__ */ jsxs(
|
|
9914
|
-
"div",
|
|
9915
|
-
{
|
|
9916
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
9917
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9918
|
-
}),
|
|
9919
|
-
children: [
|
|
9920
|
-
/* @__PURE__ */ jsx(
|
|
9921
|
-
Form$2.Field,
|
|
9922
|
-
{
|
|
9923
|
-
control: form.control,
|
|
9924
|
-
name: `metadata.${index}.key`,
|
|
9925
|
-
render: ({ field: field2 }) => {
|
|
9926
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9927
|
-
GridInput,
|
|
9928
|
-
{
|
|
9929
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
9930
|
-
...field2,
|
|
9931
|
-
disabled: isDisabled,
|
|
9932
|
-
placeholder: "Key"
|
|
9933
|
-
}
|
|
9934
|
-
) }) });
|
|
9935
|
-
}
|
|
9936
|
-
}
|
|
9937
|
-
),
|
|
9938
|
-
/* @__PURE__ */ jsx(
|
|
9939
|
-
Form$2.Field,
|
|
9940
|
-
{
|
|
9941
|
-
control: form.control,
|
|
9942
|
-
name: `metadata.${index}.value`,
|
|
9943
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
9944
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9945
|
-
GridInput,
|
|
9946
|
-
{
|
|
9947
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
9948
|
-
...field2,
|
|
9949
|
-
value: isDisabled ? placeholder : value,
|
|
9950
|
-
disabled: isDisabled,
|
|
9951
|
-
placeholder: "Value"
|
|
9952
|
-
}
|
|
9953
|
-
) }) });
|
|
9954
|
-
}
|
|
9955
|
-
}
|
|
9956
|
-
)
|
|
9957
|
-
]
|
|
9958
|
-
}
|
|
9959
|
-
),
|
|
9960
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
9961
|
-
/* @__PURE__ */ jsx(
|
|
9962
|
-
DropdownMenu.Trigger,
|
|
9963
|
-
{
|
|
9964
|
-
className: clx(
|
|
9965
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
9966
|
-
{
|
|
9967
|
-
hidden: isDisabled
|
|
9968
|
-
}
|
|
9969
|
-
),
|
|
9970
|
-
disabled: isDisabled,
|
|
9971
|
-
asChild: true,
|
|
9972
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
9973
|
-
}
|
|
9974
|
-
),
|
|
9975
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
9976
|
-
/* @__PURE__ */ jsxs(
|
|
9977
|
-
DropdownMenu.Item,
|
|
9978
|
-
{
|
|
9979
|
-
className: "gap-x-2",
|
|
9980
|
-
onClick: () => insertRow(index, "above"),
|
|
9981
|
-
children: [
|
|
9982
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
9983
|
-
"Insert row above"
|
|
9984
|
-
]
|
|
9985
|
-
}
|
|
9986
|
-
),
|
|
9987
|
-
/* @__PURE__ */ jsxs(
|
|
9988
|
-
DropdownMenu.Item,
|
|
9989
|
-
{
|
|
9990
|
-
className: "gap-x-2",
|
|
9991
|
-
onClick: () => insertRow(index, "below"),
|
|
9992
|
-
children: [
|
|
9993
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
9994
|
-
"Insert row below"
|
|
9995
|
-
]
|
|
9996
|
-
}
|
|
9997
|
-
),
|
|
9998
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
9999
|
-
/* @__PURE__ */ jsxs(
|
|
10000
|
-
DropdownMenu.Item,
|
|
10001
|
-
{
|
|
10002
|
-
className: "gap-x-2",
|
|
10003
|
-
onClick: () => deleteRow(index),
|
|
10004
|
-
children: [
|
|
10005
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
10006
|
-
"Delete row"
|
|
10007
|
-
]
|
|
10008
|
-
}
|
|
10009
|
-
)
|
|
10010
|
-
] })
|
|
10011
|
-
] })
|
|
10012
|
-
] })
|
|
10013
|
-
},
|
|
10014
|
-
field.id
|
|
10015
|
-
);
|
|
10016
|
-
})
|
|
10017
|
-
] }),
|
|
10018
|
-
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." })
|
|
10019
|
-
] }),
|
|
10020
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10021
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10022
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10023
|
-
] }) })
|
|
10024
|
-
]
|
|
10025
|
-
}
|
|
10026
|
-
) });
|
|
10027
|
-
};
|
|
10028
|
-
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
10029
|
-
return /* @__PURE__ */ jsx(
|
|
10030
|
-
"input",
|
|
10031
|
-
{
|
|
10032
|
-
ref,
|
|
10033
|
-
...props,
|
|
10034
|
-
autoComplete: "off",
|
|
10035
|
-
className: clx(
|
|
10036
|
-
"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",
|
|
10037
|
-
className
|
|
10038
|
-
)
|
|
10039
|
-
}
|
|
10040
|
-
);
|
|
10041
|
-
});
|
|
10042
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
10043
|
-
const PlaceholderInner = () => {
|
|
10044
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10045
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
10046
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10047
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
10048
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
10049
|
-
] }) })
|
|
10050
|
-
] });
|
|
10051
|
-
};
|
|
10052
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
10053
|
-
function getDefaultValues(metadata) {
|
|
10054
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
10055
|
-
return [
|
|
10056
|
-
{
|
|
10057
|
-
key: "",
|
|
10058
|
-
value: "",
|
|
10059
|
-
disabled: false
|
|
10060
|
-
}
|
|
10061
|
-
];
|
|
10062
|
-
}
|
|
10063
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
10064
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
10065
|
-
return {
|
|
10066
|
-
key,
|
|
10067
|
-
value,
|
|
10068
|
-
disabled: true
|
|
10069
|
-
};
|
|
10070
|
-
}
|
|
10071
|
-
let stringValue = value;
|
|
10072
|
-
if (typeof value !== "string") {
|
|
10073
|
-
stringValue = JSON.stringify(value);
|
|
10074
|
-
}
|
|
10075
|
-
return {
|
|
10076
|
-
key,
|
|
10077
|
-
value: stringValue,
|
|
10078
|
-
original_key: key
|
|
10079
|
-
};
|
|
10080
|
-
});
|
|
10081
|
-
}
|
|
10082
|
-
function parseValues(values) {
|
|
10083
|
-
const metadata = values.metadata;
|
|
10084
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
10085
|
-
if (isEmpty) {
|
|
10086
|
-
return null;
|
|
10087
|
-
}
|
|
10088
|
-
const update = {};
|
|
10089
|
-
metadata.forEach((field) => {
|
|
10090
|
-
let key = field.key;
|
|
10091
|
-
let value = field.value;
|
|
10092
|
-
const disabled = field.disabled;
|
|
10093
|
-
if (!key || !value) {
|
|
10094
|
-
return;
|
|
10095
|
-
}
|
|
10096
|
-
if (disabled) {
|
|
10097
|
-
update[key] = value;
|
|
10098
|
-
return;
|
|
10099
|
-
}
|
|
10100
|
-
key = key.trim();
|
|
10101
|
-
value = value.trim();
|
|
10102
|
-
if (value === "true") {
|
|
10103
|
-
update[key] = true;
|
|
10104
|
-
} else if (value === "false") {
|
|
10105
|
-
update[key] = false;
|
|
10106
|
-
} else {
|
|
10107
|
-
const parsedNumber = parseFloat(value);
|
|
10108
|
-
if (!isNaN(parsedNumber)) {
|
|
10109
|
-
update[key] = parsedNumber;
|
|
10110
|
-
} else {
|
|
10111
|
-
update[key] = value;
|
|
10112
|
-
}
|
|
10113
|
-
}
|
|
10114
|
-
});
|
|
10115
|
-
return update;
|
|
10116
|
-
}
|
|
10117
|
-
function getHasUneditableRows(metadata) {
|
|
10118
|
-
if (!metadata) {
|
|
10119
|
-
return false;
|
|
10120
|
-
}
|
|
10121
|
-
return Object.values(metadata).some(
|
|
10122
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10123
|
-
);
|
|
10124
|
-
}
|
|
10125
|
-
const Email = () => {
|
|
10126
|
-
const { id } = useParams();
|
|
10127
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10128
|
-
fields: "+email"
|
|
10129
|
-
});
|
|
10130
|
-
if (isError) {
|
|
10131
|
-
throw error;
|
|
10132
|
-
}
|
|
10133
|
-
const isReady = !isPending && !!order;
|
|
10134
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10135
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10136
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
10137
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
10138
|
-
] }),
|
|
10139
|
-
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
10140
|
-
] });
|
|
10141
|
-
};
|
|
10142
|
-
const EmailForm = ({ order }) => {
|
|
10143
|
-
const form = useForm({
|
|
10144
|
-
defaultValues: {
|
|
10145
|
-
email: order.email ?? ""
|
|
10146
|
-
},
|
|
10147
|
-
resolver: zodResolver(schema$3)
|
|
10148
|
-
});
|
|
10149
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10150
|
-
const { handleSuccess } = useRouteModal();
|
|
10151
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10152
|
-
await mutateAsync(
|
|
10153
|
-
{ email: data.email },
|
|
10154
|
-
{
|
|
10155
|
-
onSuccess: () => {
|
|
10156
|
-
handleSuccess();
|
|
10157
|
-
},
|
|
10158
|
-
onError: (error) => {
|
|
10159
|
-
toast.error(error.message);
|
|
10160
|
-
}
|
|
10161
|
-
}
|
|
10162
|
-
);
|
|
10163
|
-
});
|
|
10164
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10165
|
-
KeyboundForm,
|
|
10166
|
-
{
|
|
10167
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
10168
|
-
onSubmit,
|
|
10169
|
-
children: [
|
|
10170
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
10171
|
-
Form$2.Field,
|
|
10172
|
-
{
|
|
10173
|
-
control: form.control,
|
|
10174
|
-
name: "email",
|
|
10175
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
10176
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
10177
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
10178
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10179
|
-
] })
|
|
10180
|
-
}
|
|
10181
|
-
) }),
|
|
10182
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10183
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9820
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
9821
|
+
Form$2.Field,
|
|
9822
|
+
{
|
|
9823
|
+
control: form.control,
|
|
9824
|
+
name: "email",
|
|
9825
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9826
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
9827
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9828
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9829
|
+
] })
|
|
9830
|
+
}
|
|
9831
|
+
) }),
|
|
9832
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9833
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10184
9834
|
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10185
9835
|
] }) })
|
|
10186
9836
|
]
|
|
@@ -10985,185 +10635,535 @@ const ExistingItemsForm = ({ orderId, items }) => {
|
|
|
10985
10635
|
}
|
|
10986
10636
|
);
|
|
10987
10637
|
};
|
|
10988
|
-
const columnHelper = createDataTableColumnHelper();
|
|
10989
|
-
const useColumns = () => {
|
|
10990
|
-
return useMemo(() => {
|
|
10638
|
+
const columnHelper = createDataTableColumnHelper();
|
|
10639
|
+
const useColumns = () => {
|
|
10640
|
+
return useMemo(() => {
|
|
10641
|
+
return [
|
|
10642
|
+
columnHelper.select(),
|
|
10643
|
+
columnHelper.accessor("product.title", {
|
|
10644
|
+
header: "Product",
|
|
10645
|
+
cell: ({ row }) => {
|
|
10646
|
+
var _a, _b, _c;
|
|
10647
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
10648
|
+
/* @__PURE__ */ jsx(
|
|
10649
|
+
Thumbnail,
|
|
10650
|
+
{
|
|
10651
|
+
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
10652
|
+
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
10653
|
+
}
|
|
10654
|
+
),
|
|
10655
|
+
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
10656
|
+
] });
|
|
10657
|
+
},
|
|
10658
|
+
enableSorting: true
|
|
10659
|
+
}),
|
|
10660
|
+
columnHelper.accessor("title", {
|
|
10661
|
+
header: "Variant",
|
|
10662
|
+
enableSorting: true
|
|
10663
|
+
}),
|
|
10664
|
+
columnHelper.accessor("sku", {
|
|
10665
|
+
header: "SKU",
|
|
10666
|
+
cell: ({ getValue }) => {
|
|
10667
|
+
return getValue() ?? "-";
|
|
10668
|
+
},
|
|
10669
|
+
enableSorting: true
|
|
10670
|
+
}),
|
|
10671
|
+
columnHelper.accessor("updated_at", {
|
|
10672
|
+
header: "Updated",
|
|
10673
|
+
cell: ({ getValue }) => {
|
|
10674
|
+
return /* @__PURE__ */ jsx(
|
|
10675
|
+
Tooltip,
|
|
10676
|
+
{
|
|
10677
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10678
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10679
|
+
}
|
|
10680
|
+
);
|
|
10681
|
+
},
|
|
10682
|
+
enableSorting: true,
|
|
10683
|
+
sortAscLabel: "Oldest first",
|
|
10684
|
+
sortDescLabel: "Newest first"
|
|
10685
|
+
}),
|
|
10686
|
+
columnHelper.accessor("created_at", {
|
|
10687
|
+
header: "Created",
|
|
10688
|
+
cell: ({ getValue }) => {
|
|
10689
|
+
return /* @__PURE__ */ jsx(
|
|
10690
|
+
Tooltip,
|
|
10691
|
+
{
|
|
10692
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10693
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10694
|
+
}
|
|
10695
|
+
);
|
|
10696
|
+
},
|
|
10697
|
+
enableSorting: true,
|
|
10698
|
+
sortAscLabel: "Oldest first",
|
|
10699
|
+
sortDescLabel: "Newest first"
|
|
10700
|
+
})
|
|
10701
|
+
];
|
|
10702
|
+
}, []);
|
|
10703
|
+
};
|
|
10704
|
+
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10705
|
+
const { setIsOpen } = useStackedModal();
|
|
10706
|
+
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10707
|
+
const form = useForm({
|
|
10708
|
+
defaultValues: {
|
|
10709
|
+
title: "",
|
|
10710
|
+
quantity: 1,
|
|
10711
|
+
unit_price: ""
|
|
10712
|
+
},
|
|
10713
|
+
resolver: zodResolver(customItemSchema)
|
|
10714
|
+
});
|
|
10715
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10716
|
+
await addItems(
|
|
10717
|
+
{
|
|
10718
|
+
items: [
|
|
10719
|
+
{
|
|
10720
|
+
title: data.title,
|
|
10721
|
+
quantity: data.quantity,
|
|
10722
|
+
unit_price: convertNumber(data.unit_price)
|
|
10723
|
+
}
|
|
10724
|
+
]
|
|
10725
|
+
},
|
|
10726
|
+
{
|
|
10727
|
+
onSuccess: () => {
|
|
10728
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
10729
|
+
},
|
|
10730
|
+
onError: (e) => {
|
|
10731
|
+
toast.error(e.message);
|
|
10732
|
+
}
|
|
10733
|
+
}
|
|
10734
|
+
);
|
|
10735
|
+
});
|
|
10736
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
10737
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
10738
|
+
/* @__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: [
|
|
10739
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10740
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
10741
|
+
/* @__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." }) })
|
|
10742
|
+
] }),
|
|
10743
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10744
|
+
/* @__PURE__ */ jsx(
|
|
10745
|
+
Form$2.Field,
|
|
10746
|
+
{
|
|
10747
|
+
control: form.control,
|
|
10748
|
+
name: "title",
|
|
10749
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10750
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10751
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
10752
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
10753
|
+
] }),
|
|
10754
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10755
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
10756
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10757
|
+
] })
|
|
10758
|
+
] }) })
|
|
10759
|
+
}
|
|
10760
|
+
),
|
|
10761
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10762
|
+
/* @__PURE__ */ jsx(
|
|
10763
|
+
Form$2.Field,
|
|
10764
|
+
{
|
|
10765
|
+
control: form.control,
|
|
10766
|
+
name: "unit_price",
|
|
10767
|
+
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10768
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10769
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
10770
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
10771
|
+
] }),
|
|
10772
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10773
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10774
|
+
CurrencyInput,
|
|
10775
|
+
{
|
|
10776
|
+
symbol: getNativeSymbol(currencyCode),
|
|
10777
|
+
code: currencyCode,
|
|
10778
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
10779
|
+
...field
|
|
10780
|
+
}
|
|
10781
|
+
) }),
|
|
10782
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10783
|
+
] })
|
|
10784
|
+
] }) })
|
|
10785
|
+
}
|
|
10786
|
+
),
|
|
10787
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10788
|
+
/* @__PURE__ */ jsx(
|
|
10789
|
+
Form$2.Field,
|
|
10790
|
+
{
|
|
10791
|
+
control: form.control,
|
|
10792
|
+
name: "quantity",
|
|
10793
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10794
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10795
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
10796
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
10797
|
+
] }),
|
|
10798
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
|
|
10799
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
10800
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10801
|
+
] })
|
|
10802
|
+
] }) })
|
|
10803
|
+
}
|
|
10804
|
+
)
|
|
10805
|
+
] }) }) }),
|
|
10806
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10807
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10808
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
10809
|
+
] }) })
|
|
10810
|
+
] }) }) });
|
|
10811
|
+
};
|
|
10812
|
+
const customItemSchema = objectType({
|
|
10813
|
+
title: stringType().min(1),
|
|
10814
|
+
quantity: numberType(),
|
|
10815
|
+
unit_price: unionType([numberType(), stringType()])
|
|
10816
|
+
});
|
|
10817
|
+
const InlineTip = forwardRef(
|
|
10818
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10819
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10820
|
+
return /* @__PURE__ */ jsxs(
|
|
10821
|
+
"div",
|
|
10822
|
+
{
|
|
10823
|
+
ref,
|
|
10824
|
+
className: clx(
|
|
10825
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10826
|
+
className
|
|
10827
|
+
),
|
|
10828
|
+
...props,
|
|
10829
|
+
children: [
|
|
10830
|
+
/* @__PURE__ */ jsx(
|
|
10831
|
+
"div",
|
|
10832
|
+
{
|
|
10833
|
+
role: "presentation",
|
|
10834
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10835
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10836
|
+
})
|
|
10837
|
+
}
|
|
10838
|
+
),
|
|
10839
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10840
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10841
|
+
labelValue,
|
|
10842
|
+
":"
|
|
10843
|
+
] }),
|
|
10844
|
+
" ",
|
|
10845
|
+
children
|
|
10846
|
+
] })
|
|
10847
|
+
]
|
|
10848
|
+
}
|
|
10849
|
+
);
|
|
10850
|
+
}
|
|
10851
|
+
);
|
|
10852
|
+
InlineTip.displayName = "InlineTip";
|
|
10853
|
+
const MetadataFieldSchema = objectType({
|
|
10854
|
+
key: stringType(),
|
|
10855
|
+
disabled: booleanType().optional(),
|
|
10856
|
+
value: anyType()
|
|
10857
|
+
});
|
|
10858
|
+
const MetadataSchema = objectType({
|
|
10859
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10860
|
+
});
|
|
10861
|
+
const Metadata = () => {
|
|
10862
|
+
const { id } = useParams();
|
|
10863
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10864
|
+
fields: "metadata"
|
|
10865
|
+
});
|
|
10866
|
+
if (isError) {
|
|
10867
|
+
throw error;
|
|
10868
|
+
}
|
|
10869
|
+
const isReady = !isPending && !!order;
|
|
10870
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10871
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10872
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10873
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10874
|
+
] }),
|
|
10875
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10876
|
+
] });
|
|
10877
|
+
};
|
|
10878
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10879
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10880
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10881
|
+
const { handleSuccess } = useRouteModal();
|
|
10882
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10883
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10884
|
+
const form = useForm({
|
|
10885
|
+
defaultValues: {
|
|
10886
|
+
metadata: getDefaultValues(metadata)
|
|
10887
|
+
},
|
|
10888
|
+
resolver: zodResolver(MetadataSchema)
|
|
10889
|
+
});
|
|
10890
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10891
|
+
const parsedData = parseValues(data);
|
|
10892
|
+
await mutateAsync(
|
|
10893
|
+
{
|
|
10894
|
+
metadata: parsedData
|
|
10895
|
+
},
|
|
10896
|
+
{
|
|
10897
|
+
onSuccess: () => {
|
|
10898
|
+
toast.success("Metadata updated");
|
|
10899
|
+
handleSuccess();
|
|
10900
|
+
},
|
|
10901
|
+
onError: (error) => {
|
|
10902
|
+
toast.error(error.message);
|
|
10903
|
+
}
|
|
10904
|
+
}
|
|
10905
|
+
);
|
|
10906
|
+
});
|
|
10907
|
+
const { fields, insert, remove } = useFieldArray({
|
|
10908
|
+
control: form.control,
|
|
10909
|
+
name: "metadata"
|
|
10910
|
+
});
|
|
10911
|
+
function deleteRow(index) {
|
|
10912
|
+
remove(index);
|
|
10913
|
+
if (fields.length === 1) {
|
|
10914
|
+
insert(0, {
|
|
10915
|
+
key: "",
|
|
10916
|
+
value: "",
|
|
10917
|
+
disabled: false
|
|
10918
|
+
});
|
|
10919
|
+
}
|
|
10920
|
+
}
|
|
10921
|
+
function insertRow(index, position) {
|
|
10922
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10923
|
+
key: "",
|
|
10924
|
+
value: "",
|
|
10925
|
+
disabled: false
|
|
10926
|
+
});
|
|
10927
|
+
}
|
|
10928
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10929
|
+
KeyboundForm,
|
|
10930
|
+
{
|
|
10931
|
+
onSubmit: handleSubmit,
|
|
10932
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10933
|
+
children: [
|
|
10934
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10935
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10936
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10937
|
+
/* @__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" }) }),
|
|
10938
|
+
/* @__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" }) })
|
|
10939
|
+
] }),
|
|
10940
|
+
fields.map((field, index) => {
|
|
10941
|
+
const isDisabled = field.disabled || false;
|
|
10942
|
+
let placeholder = "-";
|
|
10943
|
+
if (typeof field.value === "object") {
|
|
10944
|
+
placeholder = "{ ... }";
|
|
10945
|
+
}
|
|
10946
|
+
if (Array.isArray(field.value)) {
|
|
10947
|
+
placeholder = "[ ... ]";
|
|
10948
|
+
}
|
|
10949
|
+
return /* @__PURE__ */ jsx(
|
|
10950
|
+
ConditionalTooltip,
|
|
10951
|
+
{
|
|
10952
|
+
showTooltip: isDisabled,
|
|
10953
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
10954
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
10955
|
+
/* @__PURE__ */ jsxs(
|
|
10956
|
+
"div",
|
|
10957
|
+
{
|
|
10958
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
10959
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10960
|
+
}),
|
|
10961
|
+
children: [
|
|
10962
|
+
/* @__PURE__ */ jsx(
|
|
10963
|
+
Form$2.Field,
|
|
10964
|
+
{
|
|
10965
|
+
control: form.control,
|
|
10966
|
+
name: `metadata.${index}.key`,
|
|
10967
|
+
render: ({ field: field2 }) => {
|
|
10968
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10969
|
+
GridInput,
|
|
10970
|
+
{
|
|
10971
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10972
|
+
...field2,
|
|
10973
|
+
disabled: isDisabled,
|
|
10974
|
+
placeholder: "Key"
|
|
10975
|
+
}
|
|
10976
|
+
) }) });
|
|
10977
|
+
}
|
|
10978
|
+
}
|
|
10979
|
+
),
|
|
10980
|
+
/* @__PURE__ */ jsx(
|
|
10981
|
+
Form$2.Field,
|
|
10982
|
+
{
|
|
10983
|
+
control: form.control,
|
|
10984
|
+
name: `metadata.${index}.value`,
|
|
10985
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
10986
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10987
|
+
GridInput,
|
|
10988
|
+
{
|
|
10989
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10990
|
+
...field2,
|
|
10991
|
+
value: isDisabled ? placeholder : value,
|
|
10992
|
+
disabled: isDisabled,
|
|
10993
|
+
placeholder: "Value"
|
|
10994
|
+
}
|
|
10995
|
+
) }) });
|
|
10996
|
+
}
|
|
10997
|
+
}
|
|
10998
|
+
)
|
|
10999
|
+
]
|
|
11000
|
+
}
|
|
11001
|
+
),
|
|
11002
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
11003
|
+
/* @__PURE__ */ jsx(
|
|
11004
|
+
DropdownMenu.Trigger,
|
|
11005
|
+
{
|
|
11006
|
+
className: clx(
|
|
11007
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11008
|
+
{
|
|
11009
|
+
hidden: isDisabled
|
|
11010
|
+
}
|
|
11011
|
+
),
|
|
11012
|
+
disabled: isDisabled,
|
|
11013
|
+
asChild: true,
|
|
11014
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11015
|
+
}
|
|
11016
|
+
),
|
|
11017
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11018
|
+
/* @__PURE__ */ jsxs(
|
|
11019
|
+
DropdownMenu.Item,
|
|
11020
|
+
{
|
|
11021
|
+
className: "gap-x-2",
|
|
11022
|
+
onClick: () => insertRow(index, "above"),
|
|
11023
|
+
children: [
|
|
11024
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11025
|
+
"Insert row above"
|
|
11026
|
+
]
|
|
11027
|
+
}
|
|
11028
|
+
),
|
|
11029
|
+
/* @__PURE__ */ jsxs(
|
|
11030
|
+
DropdownMenu.Item,
|
|
11031
|
+
{
|
|
11032
|
+
className: "gap-x-2",
|
|
11033
|
+
onClick: () => insertRow(index, "below"),
|
|
11034
|
+
children: [
|
|
11035
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11036
|
+
"Insert row below"
|
|
11037
|
+
]
|
|
11038
|
+
}
|
|
11039
|
+
),
|
|
11040
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11041
|
+
/* @__PURE__ */ jsxs(
|
|
11042
|
+
DropdownMenu.Item,
|
|
11043
|
+
{
|
|
11044
|
+
className: "gap-x-2",
|
|
11045
|
+
onClick: () => deleteRow(index),
|
|
11046
|
+
children: [
|
|
11047
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11048
|
+
"Delete row"
|
|
11049
|
+
]
|
|
11050
|
+
}
|
|
11051
|
+
)
|
|
11052
|
+
] })
|
|
11053
|
+
] })
|
|
11054
|
+
] })
|
|
11055
|
+
},
|
|
11056
|
+
field.id
|
|
11057
|
+
);
|
|
11058
|
+
})
|
|
11059
|
+
] }),
|
|
11060
|
+
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." })
|
|
11061
|
+
] }),
|
|
11062
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11063
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11064
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11065
|
+
] }) })
|
|
11066
|
+
]
|
|
11067
|
+
}
|
|
11068
|
+
) });
|
|
11069
|
+
};
|
|
11070
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11071
|
+
return /* @__PURE__ */ jsx(
|
|
11072
|
+
"input",
|
|
11073
|
+
{
|
|
11074
|
+
ref,
|
|
11075
|
+
...props,
|
|
11076
|
+
autoComplete: "off",
|
|
11077
|
+
className: clx(
|
|
11078
|
+
"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",
|
|
11079
|
+
className
|
|
11080
|
+
)
|
|
11081
|
+
}
|
|
11082
|
+
);
|
|
11083
|
+
});
|
|
11084
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11085
|
+
const PlaceholderInner = () => {
|
|
11086
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11087
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11088
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11089
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11090
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11091
|
+
] }) })
|
|
11092
|
+
] });
|
|
11093
|
+
};
|
|
11094
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11095
|
+
function getDefaultValues(metadata) {
|
|
11096
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
10991
11097
|
return [
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
10998
|
-
/* @__PURE__ */ jsx(
|
|
10999
|
-
Thumbnail,
|
|
11000
|
-
{
|
|
11001
|
-
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
11002
|
-
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
11003
|
-
}
|
|
11004
|
-
),
|
|
11005
|
-
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
11006
|
-
] });
|
|
11007
|
-
},
|
|
11008
|
-
enableSorting: true
|
|
11009
|
-
}),
|
|
11010
|
-
columnHelper.accessor("title", {
|
|
11011
|
-
header: "Variant",
|
|
11012
|
-
enableSorting: true
|
|
11013
|
-
}),
|
|
11014
|
-
columnHelper.accessor("sku", {
|
|
11015
|
-
header: "SKU",
|
|
11016
|
-
cell: ({ getValue }) => {
|
|
11017
|
-
return getValue() ?? "-";
|
|
11018
|
-
},
|
|
11019
|
-
enableSorting: true
|
|
11020
|
-
}),
|
|
11021
|
-
columnHelper.accessor("updated_at", {
|
|
11022
|
-
header: "Updated",
|
|
11023
|
-
cell: ({ getValue }) => {
|
|
11024
|
-
return /* @__PURE__ */ jsx(
|
|
11025
|
-
Tooltip,
|
|
11026
|
-
{
|
|
11027
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
11028
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
11029
|
-
}
|
|
11030
|
-
);
|
|
11031
|
-
},
|
|
11032
|
-
enableSorting: true,
|
|
11033
|
-
sortAscLabel: "Oldest first",
|
|
11034
|
-
sortDescLabel: "Newest first"
|
|
11035
|
-
}),
|
|
11036
|
-
columnHelper.accessor("created_at", {
|
|
11037
|
-
header: "Created",
|
|
11038
|
-
cell: ({ getValue }) => {
|
|
11039
|
-
return /* @__PURE__ */ jsx(
|
|
11040
|
-
Tooltip,
|
|
11041
|
-
{
|
|
11042
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
11043
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
11044
|
-
}
|
|
11045
|
-
);
|
|
11046
|
-
},
|
|
11047
|
-
enableSorting: true,
|
|
11048
|
-
sortAscLabel: "Oldest first",
|
|
11049
|
-
sortDescLabel: "Newest first"
|
|
11050
|
-
})
|
|
11098
|
+
{
|
|
11099
|
+
key: "",
|
|
11100
|
+
value: "",
|
|
11101
|
+
disabled: false
|
|
11102
|
+
}
|
|
11051
11103
|
];
|
|
11052
|
-
}
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
|
|
11104
|
+
}
|
|
11105
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11106
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11107
|
+
return {
|
|
11108
|
+
key,
|
|
11109
|
+
value,
|
|
11110
|
+
disabled: true
|
|
11111
|
+
};
|
|
11112
|
+
}
|
|
11113
|
+
let stringValue = value;
|
|
11114
|
+
if (typeof value !== "string") {
|
|
11115
|
+
stringValue = JSON.stringify(value);
|
|
11116
|
+
}
|
|
11117
|
+
return {
|
|
11118
|
+
key,
|
|
11119
|
+
value: stringValue,
|
|
11120
|
+
original_key: key
|
|
11121
|
+
};
|
|
11064
11122
|
});
|
|
11065
|
-
|
|
11066
|
-
|
|
11067
|
-
|
|
11068
|
-
|
|
11069
|
-
|
|
11070
|
-
|
|
11071
|
-
|
|
11072
|
-
|
|
11073
|
-
|
|
11074
|
-
|
|
11075
|
-
|
|
11076
|
-
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11123
|
+
}
|
|
11124
|
+
function parseValues(values) {
|
|
11125
|
+
const metadata = values.metadata;
|
|
11126
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11127
|
+
if (isEmpty) {
|
|
11128
|
+
return null;
|
|
11129
|
+
}
|
|
11130
|
+
const update = {};
|
|
11131
|
+
metadata.forEach((field) => {
|
|
11132
|
+
let key = field.key;
|
|
11133
|
+
let value = field.value;
|
|
11134
|
+
const disabled = field.disabled;
|
|
11135
|
+
if (!key || !value) {
|
|
11136
|
+
return;
|
|
11137
|
+
}
|
|
11138
|
+
if (disabled) {
|
|
11139
|
+
update[key] = value;
|
|
11140
|
+
return;
|
|
11141
|
+
}
|
|
11142
|
+
key = key.trim();
|
|
11143
|
+
value = value.trim();
|
|
11144
|
+
if (value === "true") {
|
|
11145
|
+
update[key] = true;
|
|
11146
|
+
} else if (value === "false") {
|
|
11147
|
+
update[key] = false;
|
|
11148
|
+
} else {
|
|
11149
|
+
const parsedNumber = parseFloat(value);
|
|
11150
|
+
if (!isNaN(parsedNumber)) {
|
|
11151
|
+
update[key] = parsedNumber;
|
|
11152
|
+
} else {
|
|
11153
|
+
update[key] = value;
|
|
11083
11154
|
}
|
|
11084
|
-
|
|
11155
|
+
}
|
|
11085
11156
|
});
|
|
11086
|
-
return
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
{
|
|
11097
|
-
control: form.control,
|
|
11098
|
-
name: "title",
|
|
11099
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11100
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11101
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
11102
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
11103
|
-
] }),
|
|
11104
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11105
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11106
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11107
|
-
] })
|
|
11108
|
-
] }) })
|
|
11109
|
-
}
|
|
11110
|
-
),
|
|
11111
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11112
|
-
/* @__PURE__ */ jsx(
|
|
11113
|
-
Form$2.Field,
|
|
11114
|
-
{
|
|
11115
|
-
control: form.control,
|
|
11116
|
-
name: "unit_price",
|
|
11117
|
-
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11118
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11119
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
11120
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
11121
|
-
] }),
|
|
11122
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11123
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11124
|
-
CurrencyInput,
|
|
11125
|
-
{
|
|
11126
|
-
symbol: getNativeSymbol(currencyCode),
|
|
11127
|
-
code: currencyCode,
|
|
11128
|
-
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
11129
|
-
...field
|
|
11130
|
-
}
|
|
11131
|
-
) }),
|
|
11132
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11133
|
-
] })
|
|
11134
|
-
] }) })
|
|
11135
|
-
}
|
|
11136
|
-
),
|
|
11137
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11138
|
-
/* @__PURE__ */ jsx(
|
|
11139
|
-
Form$2.Field,
|
|
11140
|
-
{
|
|
11141
|
-
control: form.control,
|
|
11142
|
-
name: "quantity",
|
|
11143
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11144
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11145
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
11146
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
11147
|
-
] }),
|
|
11148
|
-
/* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
|
|
11149
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
11150
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11151
|
-
] })
|
|
11152
|
-
] }) })
|
|
11153
|
-
}
|
|
11154
|
-
)
|
|
11155
|
-
] }) }) }),
|
|
11156
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11157
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11158
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
11159
|
-
] }) })
|
|
11160
|
-
] }) }) });
|
|
11161
|
-
};
|
|
11162
|
-
const customItemSchema = objectType({
|
|
11163
|
-
title: stringType().min(1),
|
|
11164
|
-
quantity: numberType(),
|
|
11165
|
-
unit_price: unionType([numberType(), stringType()])
|
|
11166
|
-
});
|
|
11157
|
+
return update;
|
|
11158
|
+
}
|
|
11159
|
+
function getHasUneditableRows(metadata) {
|
|
11160
|
+
if (!metadata) {
|
|
11161
|
+
return false;
|
|
11162
|
+
}
|
|
11163
|
+
return Object.values(metadata).some(
|
|
11164
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11165
|
+
);
|
|
11166
|
+
}
|
|
11167
11167
|
const PROMOTION_QUERY_KEY = "promotions";
|
|
11168
11168
|
const promotionsQueryKeys = {
|
|
11169
11169
|
list: (query2) => [
|
|
@@ -13061,10 +13061,6 @@ const routeModule = {
|
|
|
13061
13061
|
Component: CustomItems,
|
|
13062
13062
|
path: "/draft-orders/:id/custom-items"
|
|
13063
13063
|
},
|
|
13064
|
-
{
|
|
13065
|
-
Component: Metadata,
|
|
13066
|
-
path: "/draft-orders/:id/metadata"
|
|
13067
|
-
},
|
|
13068
13064
|
{
|
|
13069
13065
|
Component: Email,
|
|
13070
13066
|
path: "/draft-orders/:id/email"
|
|
@@ -13073,6 +13069,10 @@ const routeModule = {
|
|
|
13073
13069
|
Component: Items,
|
|
13074
13070
|
path: "/draft-orders/:id/items"
|
|
13075
13071
|
},
|
|
13072
|
+
{
|
|
13073
|
+
Component: Metadata,
|
|
13074
|
+
path: "/draft-orders/:id/metadata"
|
|
13075
|
+
},
|
|
13076
13076
|
{
|
|
13077
13077
|
Component: Promotions,
|
|
13078
13078
|
path: "/draft-orders/:id/promotions"
|