@medusajs/draft-order 2.10.0-snapshot-20250828112445 → 2.10.0-snapshot-20250828113245
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 +718 -718
- package/.medusa/server/src/admin/index.mjs +719 -719
- package/package.json +26 -23
|
@@ -9750,75 +9750,10 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9750
9750
|
) });
|
|
9751
9751
|
};
|
|
9752
9752
|
const schema$5 = addressSchema;
|
|
9753
|
-
const
|
|
9754
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9755
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
9756
|
-
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
9757
|
-
] });
|
|
9758
|
-
};
|
|
9759
|
-
const CustomItemsForm = () => {
|
|
9760
|
-
const form = reactHookForm.useForm({
|
|
9761
|
-
resolver: zod.zodResolver(schema$4)
|
|
9762
|
-
});
|
|
9763
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9764
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
9765
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9766
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9767
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
9768
|
-
] }) })
|
|
9769
|
-
] }) });
|
|
9770
|
-
};
|
|
9771
|
-
const schema$4 = objectType({
|
|
9772
|
-
email: stringType().email()
|
|
9773
|
-
});
|
|
9774
|
-
const InlineTip = React.forwardRef(
|
|
9775
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
9776
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
9777
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9778
|
-
"div",
|
|
9779
|
-
{
|
|
9780
|
-
ref,
|
|
9781
|
-
className: ui.clx(
|
|
9782
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
9783
|
-
className
|
|
9784
|
-
),
|
|
9785
|
-
...props,
|
|
9786
|
-
children: [
|
|
9787
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9788
|
-
"div",
|
|
9789
|
-
{
|
|
9790
|
-
role: "presentation",
|
|
9791
|
-
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
9792
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
9793
|
-
})
|
|
9794
|
-
}
|
|
9795
|
-
),
|
|
9796
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
9797
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
9798
|
-
labelValue,
|
|
9799
|
-
":"
|
|
9800
|
-
] }),
|
|
9801
|
-
" ",
|
|
9802
|
-
children
|
|
9803
|
-
] })
|
|
9804
|
-
]
|
|
9805
|
-
}
|
|
9806
|
-
);
|
|
9807
|
-
}
|
|
9808
|
-
);
|
|
9809
|
-
InlineTip.displayName = "InlineTip";
|
|
9810
|
-
const MetadataFieldSchema = objectType({
|
|
9811
|
-
key: stringType(),
|
|
9812
|
-
disabled: booleanType().optional(),
|
|
9813
|
-
value: anyType()
|
|
9814
|
-
});
|
|
9815
|
-
const MetadataSchema = objectType({
|
|
9816
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
9817
|
-
});
|
|
9818
|
-
const Metadata = () => {
|
|
9753
|
+
const Email = () => {
|
|
9819
9754
|
const { id } = reactRouterDom.useParams();
|
|
9820
9755
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
9821
|
-
fields: "
|
|
9756
|
+
fields: "+email"
|
|
9822
9757
|
});
|
|
9823
9758
|
if (isError) {
|
|
9824
9759
|
throw error;
|
|
@@ -9826,33 +9761,26 @@ const Metadata = () => {
|
|
|
9826
9761
|
const isReady = !isPending && !!order;
|
|
9827
9762
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9828
9763
|
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9829
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "
|
|
9830
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "
|
|
9764
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
9765
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9831
9766
|
] }),
|
|
9832
|
-
|
|
9767
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
9833
9768
|
] });
|
|
9834
9769
|
};
|
|
9835
|
-
const
|
|
9836
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
9837
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
9838
|
-
const { handleSuccess } = useRouteModal();
|
|
9839
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
9840
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
9770
|
+
const EmailForm = ({ order }) => {
|
|
9841
9771
|
const form = reactHookForm.useForm({
|
|
9842
9772
|
defaultValues: {
|
|
9843
|
-
|
|
9773
|
+
email: order.email ?? ""
|
|
9844
9774
|
},
|
|
9845
|
-
resolver: zod.zodResolver(
|
|
9775
|
+
resolver: zod.zodResolver(schema$4)
|
|
9846
9776
|
});
|
|
9847
|
-
const
|
|
9848
|
-
|
|
9777
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9778
|
+
const { handleSuccess } = useRouteModal();
|
|
9779
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9849
9780
|
await mutateAsync(
|
|
9850
|
-
{
|
|
9851
|
-
metadata: parsedData
|
|
9852
|
-
},
|
|
9781
|
+
{ email: data.email },
|
|
9853
9782
|
{
|
|
9854
9783
|
onSuccess: () => {
|
|
9855
|
-
ui.toast.success("Metadata updated");
|
|
9856
9784
|
handleSuccess();
|
|
9857
9785
|
},
|
|
9858
9786
|
onError: (error) => {
|
|
@@ -9861,347 +9789,116 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
9861
9789
|
}
|
|
9862
9790
|
);
|
|
9863
9791
|
});
|
|
9864
|
-
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
9865
|
-
control: form.control,
|
|
9866
|
-
name: "metadata"
|
|
9867
|
-
});
|
|
9868
|
-
function deleteRow(index) {
|
|
9869
|
-
remove(index);
|
|
9870
|
-
if (fields.length === 1) {
|
|
9871
|
-
insert(0, {
|
|
9872
|
-
key: "",
|
|
9873
|
-
value: "",
|
|
9874
|
-
disabled: false
|
|
9875
|
-
});
|
|
9876
|
-
}
|
|
9877
|
-
}
|
|
9878
|
-
function insertRow(index, position) {
|
|
9879
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
9880
|
-
key: "",
|
|
9881
|
-
value: "",
|
|
9882
|
-
disabled: false
|
|
9883
|
-
});
|
|
9884
|
-
}
|
|
9885
9792
|
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9886
9793
|
KeyboundForm,
|
|
9887
9794
|
{
|
|
9888
|
-
onSubmit: handleSubmit,
|
|
9889
9795
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
9796
|
+
onSubmit,
|
|
9890
9797
|
children: [
|
|
9891
|
-
/* @__PURE__ */ jsxRuntime.
|
|
9892
|
-
|
|
9893
|
-
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9898
|
-
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
|
|
9906
|
-
|
|
9907
|
-
|
|
9798
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9799
|
+
Form$2.Field,
|
|
9800
|
+
{
|
|
9801
|
+
control: form.control,
|
|
9802
|
+
name: "email",
|
|
9803
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9804
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
9805
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9806
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9807
|
+
] })
|
|
9808
|
+
}
|
|
9809
|
+
) }),
|
|
9810
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9811
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9812
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9813
|
+
] }) })
|
|
9814
|
+
]
|
|
9815
|
+
}
|
|
9816
|
+
) });
|
|
9817
|
+
};
|
|
9818
|
+
const schema$4 = objectType({
|
|
9819
|
+
email: stringType().email()
|
|
9820
|
+
});
|
|
9821
|
+
const NumberInput = React.forwardRef(
|
|
9822
|
+
({
|
|
9823
|
+
value,
|
|
9824
|
+
onChange,
|
|
9825
|
+
size = "base",
|
|
9826
|
+
min = 0,
|
|
9827
|
+
max = 100,
|
|
9828
|
+
step = 1,
|
|
9829
|
+
className,
|
|
9830
|
+
disabled,
|
|
9831
|
+
...props
|
|
9832
|
+
}, ref) => {
|
|
9833
|
+
const handleChange = (event) => {
|
|
9834
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
9835
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
9836
|
+
onChange(newValue);
|
|
9837
|
+
}
|
|
9838
|
+
};
|
|
9839
|
+
const handleIncrement = () => {
|
|
9840
|
+
const newValue = value + step;
|
|
9841
|
+
if (max === void 0 || newValue <= max) {
|
|
9842
|
+
onChange(newValue);
|
|
9843
|
+
}
|
|
9844
|
+
};
|
|
9845
|
+
const handleDecrement = () => {
|
|
9846
|
+
const newValue = value - step;
|
|
9847
|
+
if (min === void 0 || newValue >= min) {
|
|
9848
|
+
onChange(newValue);
|
|
9849
|
+
}
|
|
9850
|
+
};
|
|
9851
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9852
|
+
"div",
|
|
9853
|
+
{
|
|
9854
|
+
className: ui.clx(
|
|
9855
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
9856
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
9857
|
+
{
|
|
9858
|
+
"h-7": size === "small",
|
|
9859
|
+
"h-8": size === "base"
|
|
9860
|
+
},
|
|
9861
|
+
className
|
|
9862
|
+
),
|
|
9863
|
+
children: [
|
|
9864
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9865
|
+
"input",
|
|
9866
|
+
{
|
|
9867
|
+
ref,
|
|
9868
|
+
type: "number",
|
|
9869
|
+
value,
|
|
9870
|
+
onChange: handleChange,
|
|
9871
|
+
min,
|
|
9872
|
+
max,
|
|
9873
|
+
step,
|
|
9874
|
+
className: ui.clx(
|
|
9875
|
+
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
9876
|
+
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
9877
|
+
"placeholder:text-ui-fg-muted"
|
|
9878
|
+
),
|
|
9879
|
+
...props
|
|
9880
|
+
}
|
|
9881
|
+
),
|
|
9882
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9883
|
+
"button",
|
|
9884
|
+
{
|
|
9885
|
+
className: ui.clx(
|
|
9886
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
9887
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9888
|
+
"focus:bg-ui-bg-field-component-hover",
|
|
9889
|
+
"hover:bg-ui-bg-field-component-hover",
|
|
9908
9890
|
{
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9913
|
-
"div",
|
|
9914
|
-
{
|
|
9915
|
-
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
9916
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9917
|
-
}),
|
|
9918
|
-
children: [
|
|
9919
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9920
|
-
Form$2.Field,
|
|
9921
|
-
{
|
|
9922
|
-
control: form.control,
|
|
9923
|
-
name: `metadata.${index}.key`,
|
|
9924
|
-
render: ({ field: field2 }) => {
|
|
9925
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9926
|
-
GridInput,
|
|
9927
|
-
{
|
|
9928
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
9929
|
-
...field2,
|
|
9930
|
-
disabled: isDisabled,
|
|
9931
|
-
placeholder: "Key"
|
|
9932
|
-
}
|
|
9933
|
-
) }) });
|
|
9934
|
-
}
|
|
9935
|
-
}
|
|
9936
|
-
),
|
|
9937
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9938
|
-
Form$2.Field,
|
|
9939
|
-
{
|
|
9940
|
-
control: form.control,
|
|
9941
|
-
name: `metadata.${index}.value`,
|
|
9942
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
9943
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9944
|
-
GridInput,
|
|
9945
|
-
{
|
|
9946
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
9947
|
-
...field2,
|
|
9948
|
-
value: isDisabled ? placeholder : value,
|
|
9949
|
-
disabled: isDisabled,
|
|
9950
|
-
placeholder: "Value"
|
|
9951
|
-
}
|
|
9952
|
-
) }) });
|
|
9953
|
-
}
|
|
9954
|
-
}
|
|
9955
|
-
)
|
|
9956
|
-
]
|
|
9957
|
-
}
|
|
9958
|
-
),
|
|
9959
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
9960
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9961
|
-
ui.DropdownMenu.Trigger,
|
|
9962
|
-
{
|
|
9963
|
-
className: ui.clx(
|
|
9964
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
9965
|
-
{
|
|
9966
|
-
hidden: isDisabled
|
|
9967
|
-
}
|
|
9968
|
-
),
|
|
9969
|
-
disabled: isDisabled,
|
|
9970
|
-
asChild: true,
|
|
9971
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
9972
|
-
}
|
|
9973
|
-
),
|
|
9974
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
9975
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9976
|
-
ui.DropdownMenu.Item,
|
|
9977
|
-
{
|
|
9978
|
-
className: "gap-x-2",
|
|
9979
|
-
onClick: () => insertRow(index, "above"),
|
|
9980
|
-
children: [
|
|
9981
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
9982
|
-
"Insert row above"
|
|
9983
|
-
]
|
|
9984
|
-
}
|
|
9985
|
-
),
|
|
9986
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9987
|
-
ui.DropdownMenu.Item,
|
|
9988
|
-
{
|
|
9989
|
-
className: "gap-x-2",
|
|
9990
|
-
onClick: () => insertRow(index, "below"),
|
|
9991
|
-
children: [
|
|
9992
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
9993
|
-
"Insert row below"
|
|
9994
|
-
]
|
|
9995
|
-
}
|
|
9996
|
-
),
|
|
9997
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
9998
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9999
|
-
ui.DropdownMenu.Item,
|
|
10000
|
-
{
|
|
10001
|
-
className: "gap-x-2",
|
|
10002
|
-
onClick: () => deleteRow(index),
|
|
10003
|
-
children: [
|
|
10004
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
10005
|
-
"Delete row"
|
|
10006
|
-
]
|
|
10007
|
-
}
|
|
10008
|
-
)
|
|
10009
|
-
] })
|
|
10010
|
-
] })
|
|
10011
|
-
] })
|
|
10012
|
-
},
|
|
10013
|
-
field.id
|
|
10014
|
-
);
|
|
10015
|
-
})
|
|
10016
|
-
] }),
|
|
10017
|
-
hasUneditableRows && /* @__PURE__ */ jsxRuntime.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." })
|
|
10018
|
-
] }),
|
|
10019
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10020
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10021
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10022
|
-
] }) })
|
|
10023
|
-
]
|
|
10024
|
-
}
|
|
10025
|
-
) });
|
|
10026
|
-
};
|
|
10027
|
-
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
10028
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10029
|
-
"input",
|
|
10030
|
-
{
|
|
10031
|
-
ref,
|
|
10032
|
-
...props,
|
|
10033
|
-
autoComplete: "off",
|
|
10034
|
-
className: ui.clx(
|
|
10035
|
-
"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",
|
|
10036
|
-
className
|
|
10037
|
-
)
|
|
10038
|
-
}
|
|
10039
|
-
);
|
|
10040
|
-
});
|
|
10041
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
10042
|
-
const PlaceholderInner = () => {
|
|
10043
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10044
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
10045
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10046
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
10047
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
10048
|
-
] }) })
|
|
10049
|
-
] });
|
|
10050
|
-
};
|
|
10051
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
10052
|
-
function getDefaultValues(metadata) {
|
|
10053
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
10054
|
-
return [
|
|
10055
|
-
{
|
|
10056
|
-
key: "",
|
|
10057
|
-
value: "",
|
|
10058
|
-
disabled: false
|
|
10059
|
-
}
|
|
10060
|
-
];
|
|
10061
|
-
}
|
|
10062
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
10063
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
10064
|
-
return {
|
|
10065
|
-
key,
|
|
10066
|
-
value,
|
|
10067
|
-
disabled: true
|
|
10068
|
-
};
|
|
10069
|
-
}
|
|
10070
|
-
let stringValue = value;
|
|
10071
|
-
if (typeof value !== "string") {
|
|
10072
|
-
stringValue = JSON.stringify(value);
|
|
10073
|
-
}
|
|
10074
|
-
return {
|
|
10075
|
-
key,
|
|
10076
|
-
value: stringValue,
|
|
10077
|
-
original_key: key
|
|
10078
|
-
};
|
|
10079
|
-
});
|
|
10080
|
-
}
|
|
10081
|
-
function parseValues(values) {
|
|
10082
|
-
const metadata = values.metadata;
|
|
10083
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
10084
|
-
if (isEmpty) {
|
|
10085
|
-
return null;
|
|
10086
|
-
}
|
|
10087
|
-
const update = {};
|
|
10088
|
-
metadata.forEach((field) => {
|
|
10089
|
-
let key = field.key;
|
|
10090
|
-
let value = field.value;
|
|
10091
|
-
const disabled = field.disabled;
|
|
10092
|
-
if (!key || !value) {
|
|
10093
|
-
return;
|
|
10094
|
-
}
|
|
10095
|
-
if (disabled) {
|
|
10096
|
-
update[key] = value;
|
|
10097
|
-
return;
|
|
10098
|
-
}
|
|
10099
|
-
key = key.trim();
|
|
10100
|
-
value = value.trim();
|
|
10101
|
-
if (value === "true") {
|
|
10102
|
-
update[key] = true;
|
|
10103
|
-
} else if (value === "false") {
|
|
10104
|
-
update[key] = false;
|
|
10105
|
-
} else {
|
|
10106
|
-
const parsedNumber = parseFloat(value);
|
|
10107
|
-
if (!isNaN(parsedNumber)) {
|
|
10108
|
-
update[key] = parsedNumber;
|
|
10109
|
-
} else {
|
|
10110
|
-
update[key] = value;
|
|
10111
|
-
}
|
|
10112
|
-
}
|
|
10113
|
-
});
|
|
10114
|
-
return update;
|
|
10115
|
-
}
|
|
10116
|
-
function getHasUneditableRows(metadata) {
|
|
10117
|
-
if (!metadata) {
|
|
10118
|
-
return false;
|
|
10119
|
-
}
|
|
10120
|
-
return Object.values(metadata).some(
|
|
10121
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10122
|
-
);
|
|
10123
|
-
}
|
|
10124
|
-
const NumberInput = React.forwardRef(
|
|
10125
|
-
({
|
|
10126
|
-
value,
|
|
10127
|
-
onChange,
|
|
10128
|
-
size = "base",
|
|
10129
|
-
min = 0,
|
|
10130
|
-
max = 100,
|
|
10131
|
-
step = 1,
|
|
10132
|
-
className,
|
|
10133
|
-
disabled,
|
|
10134
|
-
...props
|
|
10135
|
-
}, ref) => {
|
|
10136
|
-
const handleChange = (event) => {
|
|
10137
|
-
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
10138
|
-
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
10139
|
-
onChange(newValue);
|
|
10140
|
-
}
|
|
10141
|
-
};
|
|
10142
|
-
const handleIncrement = () => {
|
|
10143
|
-
const newValue = value + step;
|
|
10144
|
-
if (max === void 0 || newValue <= max) {
|
|
10145
|
-
onChange(newValue);
|
|
10146
|
-
}
|
|
10147
|
-
};
|
|
10148
|
-
const handleDecrement = () => {
|
|
10149
|
-
const newValue = value - step;
|
|
10150
|
-
if (min === void 0 || newValue >= min) {
|
|
10151
|
-
onChange(newValue);
|
|
10152
|
-
}
|
|
10153
|
-
};
|
|
10154
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10155
|
-
"div",
|
|
10156
|
-
{
|
|
10157
|
-
className: ui.clx(
|
|
10158
|
-
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
10159
|
-
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
10160
|
-
{
|
|
10161
|
-
"h-7": size === "small",
|
|
10162
|
-
"h-8": size === "base"
|
|
10163
|
-
},
|
|
10164
|
-
className
|
|
10165
|
-
),
|
|
10166
|
-
children: [
|
|
10167
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10168
|
-
"input",
|
|
10169
|
-
{
|
|
10170
|
-
ref,
|
|
10171
|
-
type: "number",
|
|
10172
|
-
value,
|
|
10173
|
-
onChange: handleChange,
|
|
10174
|
-
min,
|
|
10175
|
-
max,
|
|
10176
|
-
step,
|
|
10177
|
-
className: ui.clx(
|
|
10178
|
-
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
10179
|
-
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
10180
|
-
"placeholder:text-ui-fg-muted"
|
|
9891
|
+
"size-7": size === "small",
|
|
9892
|
+
"size-8": size === "base"
|
|
9893
|
+
}
|
|
10181
9894
|
),
|
|
10182
|
-
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
10190
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
10191
|
-
"focus:bg-ui-bg-field-component-hover",
|
|
10192
|
-
"hover:bg-ui-bg-field-component-hover",
|
|
10193
|
-
{
|
|
10194
|
-
"size-7": size === "small",
|
|
10195
|
-
"size-8": size === "base"
|
|
10196
|
-
}
|
|
10197
|
-
),
|
|
10198
|
-
type: "button",
|
|
10199
|
-
onClick: handleDecrement,
|
|
10200
|
-
disabled: min !== void 0 && value <= min || disabled,
|
|
10201
|
-
children: [
|
|
10202
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
|
|
10203
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
10204
|
-
]
|
|
9895
|
+
type: "button",
|
|
9896
|
+
onClick: handleDecrement,
|
|
9897
|
+
disabled: min !== void 0 && value <= min || disabled,
|
|
9898
|
+
children: [
|
|
9899
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
|
|
9900
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
9901
|
+
]
|
|
10205
9902
|
}
|
|
10206
9903
|
),
|
|
10207
9904
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -10982,119 +10679,469 @@ const useColumns = () => {
|
|
|
10982
10679
|
];
|
|
10983
10680
|
}, []);
|
|
10984
10681
|
};
|
|
10985
|
-
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10986
|
-
const { setIsOpen } = useStackedModal();
|
|
10987
|
-
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10988
|
-
const form = reactHookForm.useForm({
|
|
10989
|
-
defaultValues: {
|
|
10990
|
-
title: "",
|
|
10991
|
-
quantity: 1,
|
|
10992
|
-
unit_price: ""
|
|
10993
|
-
},
|
|
10994
|
-
resolver: zod.zodResolver(customItemSchema)
|
|
10995
|
-
});
|
|
10996
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10997
|
-
await addItems(
|
|
10998
|
-
{
|
|
10999
|
-
items: [
|
|
11000
|
-
{
|
|
11001
|
-
title: data.title,
|
|
11002
|
-
quantity: data.quantity,
|
|
11003
|
-
unit_price: convertNumber(data.unit_price)
|
|
11004
|
-
}
|
|
11005
|
-
]
|
|
11006
|
-
},
|
|
10682
|
+
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10683
|
+
const { setIsOpen } = useStackedModal();
|
|
10684
|
+
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10685
|
+
const form = reactHookForm.useForm({
|
|
10686
|
+
defaultValues: {
|
|
10687
|
+
title: "",
|
|
10688
|
+
quantity: 1,
|
|
10689
|
+
unit_price: ""
|
|
10690
|
+
},
|
|
10691
|
+
resolver: zod.zodResolver(customItemSchema)
|
|
10692
|
+
});
|
|
10693
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10694
|
+
await addItems(
|
|
10695
|
+
{
|
|
10696
|
+
items: [
|
|
10697
|
+
{
|
|
10698
|
+
title: data.title,
|
|
10699
|
+
quantity: data.quantity,
|
|
10700
|
+
unit_price: convertNumber(data.unit_price)
|
|
10701
|
+
}
|
|
10702
|
+
]
|
|
10703
|
+
},
|
|
10704
|
+
{
|
|
10705
|
+
onSuccess: () => {
|
|
10706
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
10707
|
+
},
|
|
10708
|
+
onError: (e) => {
|
|
10709
|
+
ui.toast.error(e.message);
|
|
10710
|
+
}
|
|
10711
|
+
}
|
|
10712
|
+
);
|
|
10713
|
+
});
|
|
10714
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
|
|
10715
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
|
|
10716
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
|
|
10717
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10718
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
|
|
10719
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
|
|
10720
|
+
] }),
|
|
10721
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10722
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10723
|
+
Form$2.Field,
|
|
10724
|
+
{
|
|
10725
|
+
control: form.control,
|
|
10726
|
+
name: "title",
|
|
10727
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10728
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10729
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
|
|
10730
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
10731
|
+
] }),
|
|
10732
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10733
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
10734
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
10735
|
+
] })
|
|
10736
|
+
] }) })
|
|
10737
|
+
}
|
|
10738
|
+
),
|
|
10739
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10740
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10741
|
+
Form$2.Field,
|
|
10742
|
+
{
|
|
10743
|
+
control: form.control,
|
|
10744
|
+
name: "unit_price",
|
|
10745
|
+
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10746
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10747
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
|
|
10748
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
10749
|
+
] }),
|
|
10750
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10751
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10752
|
+
ui.CurrencyInput,
|
|
10753
|
+
{
|
|
10754
|
+
symbol: getNativeSymbol(currencyCode),
|
|
10755
|
+
code: currencyCode,
|
|
10756
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
10757
|
+
...field
|
|
10758
|
+
}
|
|
10759
|
+
) }),
|
|
10760
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
10761
|
+
] })
|
|
10762
|
+
] }) })
|
|
10763
|
+
}
|
|
10764
|
+
),
|
|
10765
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10766
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10767
|
+
Form$2.Field,
|
|
10768
|
+
{
|
|
10769
|
+
control: form.control,
|
|
10770
|
+
name: "quantity",
|
|
10771
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10772
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10773
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
|
|
10774
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
10775
|
+
] }),
|
|
10776
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
|
|
10777
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
10778
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
10779
|
+
] })
|
|
10780
|
+
] }) })
|
|
10781
|
+
}
|
|
10782
|
+
)
|
|
10783
|
+
] }) }) }),
|
|
10784
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10785
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10786
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
10787
|
+
] }) })
|
|
10788
|
+
] }) }) });
|
|
10789
|
+
};
|
|
10790
|
+
const customItemSchema = objectType({
|
|
10791
|
+
title: stringType().min(1),
|
|
10792
|
+
quantity: numberType(),
|
|
10793
|
+
unit_price: unionType([numberType(), stringType()])
|
|
10794
|
+
});
|
|
10795
|
+
const InlineTip = React.forwardRef(
|
|
10796
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10797
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10798
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10799
|
+
"div",
|
|
10800
|
+
{
|
|
10801
|
+
ref,
|
|
10802
|
+
className: ui.clx(
|
|
10803
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10804
|
+
className
|
|
10805
|
+
),
|
|
10806
|
+
...props,
|
|
10807
|
+
children: [
|
|
10808
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10809
|
+
"div",
|
|
10810
|
+
{
|
|
10811
|
+
role: "presentation",
|
|
10812
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10813
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10814
|
+
})
|
|
10815
|
+
}
|
|
10816
|
+
),
|
|
10817
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
10818
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10819
|
+
labelValue,
|
|
10820
|
+
":"
|
|
10821
|
+
] }),
|
|
10822
|
+
" ",
|
|
10823
|
+
children
|
|
10824
|
+
] })
|
|
10825
|
+
]
|
|
10826
|
+
}
|
|
10827
|
+
);
|
|
10828
|
+
}
|
|
10829
|
+
);
|
|
10830
|
+
InlineTip.displayName = "InlineTip";
|
|
10831
|
+
const MetadataFieldSchema = objectType({
|
|
10832
|
+
key: stringType(),
|
|
10833
|
+
disabled: booleanType().optional(),
|
|
10834
|
+
value: anyType()
|
|
10835
|
+
});
|
|
10836
|
+
const MetadataSchema = objectType({
|
|
10837
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10838
|
+
});
|
|
10839
|
+
const Metadata = () => {
|
|
10840
|
+
const { id } = reactRouterDom.useParams();
|
|
10841
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10842
|
+
fields: "metadata"
|
|
10843
|
+
});
|
|
10844
|
+
if (isError) {
|
|
10845
|
+
throw error;
|
|
10846
|
+
}
|
|
10847
|
+
const isReady = !isPending && !!order;
|
|
10848
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10849
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
10850
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
10851
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10852
|
+
] }),
|
|
10853
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10854
|
+
] });
|
|
10855
|
+
};
|
|
10856
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10857
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10858
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10859
|
+
const { handleSuccess } = useRouteModal();
|
|
10860
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10861
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10862
|
+
const form = reactHookForm.useForm({
|
|
10863
|
+
defaultValues: {
|
|
10864
|
+
metadata: getDefaultValues(metadata)
|
|
10865
|
+
},
|
|
10866
|
+
resolver: zod.zodResolver(MetadataSchema)
|
|
10867
|
+
});
|
|
10868
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10869
|
+
const parsedData = parseValues(data);
|
|
10870
|
+
await mutateAsync(
|
|
10871
|
+
{
|
|
10872
|
+
metadata: parsedData
|
|
10873
|
+
},
|
|
10874
|
+
{
|
|
10875
|
+
onSuccess: () => {
|
|
10876
|
+
ui.toast.success("Metadata updated");
|
|
10877
|
+
handleSuccess();
|
|
10878
|
+
},
|
|
10879
|
+
onError: (error) => {
|
|
10880
|
+
ui.toast.error(error.message);
|
|
10881
|
+
}
|
|
10882
|
+
}
|
|
10883
|
+
);
|
|
10884
|
+
});
|
|
10885
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
10886
|
+
control: form.control,
|
|
10887
|
+
name: "metadata"
|
|
10888
|
+
});
|
|
10889
|
+
function deleteRow(index) {
|
|
10890
|
+
remove(index);
|
|
10891
|
+
if (fields.length === 1) {
|
|
10892
|
+
insert(0, {
|
|
10893
|
+
key: "",
|
|
10894
|
+
value: "",
|
|
10895
|
+
disabled: false
|
|
10896
|
+
});
|
|
10897
|
+
}
|
|
10898
|
+
}
|
|
10899
|
+
function insertRow(index, position) {
|
|
10900
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10901
|
+
key: "",
|
|
10902
|
+
value: "",
|
|
10903
|
+
disabled: false
|
|
10904
|
+
});
|
|
10905
|
+
}
|
|
10906
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10907
|
+
KeyboundForm,
|
|
10908
|
+
{
|
|
10909
|
+
onSubmit: handleSubmit,
|
|
10910
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10911
|
+
children: [
|
|
10912
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10913
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10914
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10915
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
10916
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
10917
|
+
] }),
|
|
10918
|
+
fields.map((field, index) => {
|
|
10919
|
+
const isDisabled = field.disabled || false;
|
|
10920
|
+
let placeholder = "-";
|
|
10921
|
+
if (typeof field.value === "object") {
|
|
10922
|
+
placeholder = "{ ... }";
|
|
10923
|
+
}
|
|
10924
|
+
if (Array.isArray(field.value)) {
|
|
10925
|
+
placeholder = "[ ... ]";
|
|
10926
|
+
}
|
|
10927
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10928
|
+
ConditionalTooltip,
|
|
10929
|
+
{
|
|
10930
|
+
showTooltip: isDisabled,
|
|
10931
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
10932
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
10933
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
10934
|
+
"div",
|
|
10935
|
+
{
|
|
10936
|
+
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
10937
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10938
|
+
}),
|
|
10939
|
+
children: [
|
|
10940
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10941
|
+
Form$2.Field,
|
|
10942
|
+
{
|
|
10943
|
+
control: form.control,
|
|
10944
|
+
name: `metadata.${index}.key`,
|
|
10945
|
+
render: ({ field: field2 }) => {
|
|
10946
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10947
|
+
GridInput,
|
|
10948
|
+
{
|
|
10949
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10950
|
+
...field2,
|
|
10951
|
+
disabled: isDisabled,
|
|
10952
|
+
placeholder: "Key"
|
|
10953
|
+
}
|
|
10954
|
+
) }) });
|
|
10955
|
+
}
|
|
10956
|
+
}
|
|
10957
|
+
),
|
|
10958
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10959
|
+
Form$2.Field,
|
|
10960
|
+
{
|
|
10961
|
+
control: form.control,
|
|
10962
|
+
name: `metadata.${index}.value`,
|
|
10963
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
10964
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10965
|
+
GridInput,
|
|
10966
|
+
{
|
|
10967
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10968
|
+
...field2,
|
|
10969
|
+
value: isDisabled ? placeholder : value,
|
|
10970
|
+
disabled: isDisabled,
|
|
10971
|
+
placeholder: "Value"
|
|
10972
|
+
}
|
|
10973
|
+
) }) });
|
|
10974
|
+
}
|
|
10975
|
+
}
|
|
10976
|
+
)
|
|
10977
|
+
]
|
|
10978
|
+
}
|
|
10979
|
+
),
|
|
10980
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
10981
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10982
|
+
ui.DropdownMenu.Trigger,
|
|
10983
|
+
{
|
|
10984
|
+
className: ui.clx(
|
|
10985
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
10986
|
+
{
|
|
10987
|
+
hidden: isDisabled
|
|
10988
|
+
}
|
|
10989
|
+
),
|
|
10990
|
+
disabled: isDisabled,
|
|
10991
|
+
asChild: true,
|
|
10992
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
10993
|
+
}
|
|
10994
|
+
),
|
|
10995
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
10996
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
10997
|
+
ui.DropdownMenu.Item,
|
|
10998
|
+
{
|
|
10999
|
+
className: "gap-x-2",
|
|
11000
|
+
onClick: () => insertRow(index, "above"),
|
|
11001
|
+
children: [
|
|
11002
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11003
|
+
"Insert row above"
|
|
11004
|
+
]
|
|
11005
|
+
}
|
|
11006
|
+
),
|
|
11007
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11008
|
+
ui.DropdownMenu.Item,
|
|
11009
|
+
{
|
|
11010
|
+
className: "gap-x-2",
|
|
11011
|
+
onClick: () => insertRow(index, "below"),
|
|
11012
|
+
children: [
|
|
11013
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11014
|
+
"Insert row below"
|
|
11015
|
+
]
|
|
11016
|
+
}
|
|
11017
|
+
),
|
|
11018
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
11019
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11020
|
+
ui.DropdownMenu.Item,
|
|
11021
|
+
{
|
|
11022
|
+
className: "gap-x-2",
|
|
11023
|
+
onClick: () => deleteRow(index),
|
|
11024
|
+
children: [
|
|
11025
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
11026
|
+
"Delete row"
|
|
11027
|
+
]
|
|
11028
|
+
}
|
|
11029
|
+
)
|
|
11030
|
+
] })
|
|
11031
|
+
] })
|
|
11032
|
+
] })
|
|
11033
|
+
},
|
|
11034
|
+
field.id
|
|
11035
|
+
);
|
|
11036
|
+
})
|
|
11037
|
+
] }),
|
|
11038
|
+
hasUneditableRows && /* @__PURE__ */ jsxRuntime.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." })
|
|
11039
|
+
] }),
|
|
11040
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11041
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11042
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11043
|
+
] }) })
|
|
11044
|
+
]
|
|
11045
|
+
}
|
|
11046
|
+
) });
|
|
11047
|
+
};
|
|
11048
|
+
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
11049
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11050
|
+
"input",
|
|
11051
|
+
{
|
|
11052
|
+
ref,
|
|
11053
|
+
...props,
|
|
11054
|
+
autoComplete: "off",
|
|
11055
|
+
className: ui.clx(
|
|
11056
|
+
"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",
|
|
11057
|
+
className
|
|
11058
|
+
)
|
|
11059
|
+
}
|
|
11060
|
+
);
|
|
11061
|
+
});
|
|
11062
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11063
|
+
const PlaceholderInner = () => {
|
|
11064
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11065
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11066
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11067
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11068
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11069
|
+
] }) })
|
|
11070
|
+
] });
|
|
11071
|
+
};
|
|
11072
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11073
|
+
function getDefaultValues(metadata) {
|
|
11074
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
11075
|
+
return [
|
|
11007
11076
|
{
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
onError: (e) => {
|
|
11012
|
-
ui.toast.error(e.message);
|
|
11013
|
-
}
|
|
11077
|
+
key: "",
|
|
11078
|
+
value: "",
|
|
11079
|
+
disabled: false
|
|
11014
11080
|
}
|
|
11015
|
-
|
|
11081
|
+
];
|
|
11082
|
+
}
|
|
11083
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11084
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11085
|
+
return {
|
|
11086
|
+
key,
|
|
11087
|
+
value,
|
|
11088
|
+
disabled: true
|
|
11089
|
+
};
|
|
11090
|
+
}
|
|
11091
|
+
let stringValue = value;
|
|
11092
|
+
if (typeof value !== "string") {
|
|
11093
|
+
stringValue = JSON.stringify(value);
|
|
11094
|
+
}
|
|
11095
|
+
return {
|
|
11096
|
+
key,
|
|
11097
|
+
value: stringValue,
|
|
11098
|
+
original_key: key
|
|
11099
|
+
};
|
|
11016
11100
|
});
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
}
|
|
11062
|
-
) }),
|
|
11063
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11064
|
-
] })
|
|
11065
|
-
] }) })
|
|
11066
|
-
}
|
|
11067
|
-
),
|
|
11068
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11069
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11070
|
-
Form$2.Field,
|
|
11071
|
-
{
|
|
11072
|
-
control: form.control,
|
|
11073
|
-
name: "quantity",
|
|
11074
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11075
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11076
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
|
|
11077
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
11078
|
-
] }),
|
|
11079
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
|
|
11080
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
11081
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11082
|
-
] })
|
|
11083
|
-
] }) })
|
|
11084
|
-
}
|
|
11085
|
-
)
|
|
11086
|
-
] }) }) }),
|
|
11087
|
-
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
11088
|
-
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11089
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
11090
|
-
] }) })
|
|
11091
|
-
] }) }) });
|
|
11092
|
-
};
|
|
11093
|
-
const customItemSchema = objectType({
|
|
11094
|
-
title: stringType().min(1),
|
|
11095
|
-
quantity: numberType(),
|
|
11096
|
-
unit_price: unionType([numberType(), stringType()])
|
|
11097
|
-
});
|
|
11101
|
+
}
|
|
11102
|
+
function parseValues(values) {
|
|
11103
|
+
const metadata = values.metadata;
|
|
11104
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11105
|
+
if (isEmpty) {
|
|
11106
|
+
return null;
|
|
11107
|
+
}
|
|
11108
|
+
const update = {};
|
|
11109
|
+
metadata.forEach((field) => {
|
|
11110
|
+
let key = field.key;
|
|
11111
|
+
let value = field.value;
|
|
11112
|
+
const disabled = field.disabled;
|
|
11113
|
+
if (!key || !value) {
|
|
11114
|
+
return;
|
|
11115
|
+
}
|
|
11116
|
+
if (disabled) {
|
|
11117
|
+
update[key] = value;
|
|
11118
|
+
return;
|
|
11119
|
+
}
|
|
11120
|
+
key = key.trim();
|
|
11121
|
+
value = value.trim();
|
|
11122
|
+
if (value === "true") {
|
|
11123
|
+
update[key] = true;
|
|
11124
|
+
} else if (value === "false") {
|
|
11125
|
+
update[key] = false;
|
|
11126
|
+
} else {
|
|
11127
|
+
const parsedNumber = parseFloat(value);
|
|
11128
|
+
if (!isNaN(parsedNumber)) {
|
|
11129
|
+
update[key] = parsedNumber;
|
|
11130
|
+
} else {
|
|
11131
|
+
update[key] = value;
|
|
11132
|
+
}
|
|
11133
|
+
}
|
|
11134
|
+
});
|
|
11135
|
+
return update;
|
|
11136
|
+
}
|
|
11137
|
+
function getHasUneditableRows(metadata) {
|
|
11138
|
+
if (!metadata) {
|
|
11139
|
+
return false;
|
|
11140
|
+
}
|
|
11141
|
+
return Object.values(metadata).some(
|
|
11142
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11143
|
+
);
|
|
11144
|
+
}
|
|
11098
11145
|
const PROMOTION_QUERY_KEY = "promotions";
|
|
11099
11146
|
const promotionsQueryKeys = {
|
|
11100
11147
|
list: (query2) => [
|
|
@@ -11360,18 +11407,124 @@ function getPromotionCodes(items, shippingMethods) {
|
|
|
11360
11407
|
}
|
|
11361
11408
|
}
|
|
11362
11409
|
}
|
|
11363
|
-
}
|
|
11364
|
-
for (const shippingMethod of shippingMethods) {
|
|
11365
|
-
if (shippingMethod.adjustments) {
|
|
11366
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11367
|
-
if (adjustment.code) {
|
|
11368
|
-
codes.add(adjustment.code);
|
|
11369
|
-
}
|
|
11410
|
+
}
|
|
11411
|
+
for (const shippingMethod of shippingMethods) {
|
|
11412
|
+
if (shippingMethod.adjustments) {
|
|
11413
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11414
|
+
if (adjustment.code) {
|
|
11415
|
+
codes.add(adjustment.code);
|
|
11416
|
+
}
|
|
11417
|
+
}
|
|
11418
|
+
}
|
|
11419
|
+
}
|
|
11420
|
+
return Array.from(codes);
|
|
11421
|
+
}
|
|
11422
|
+
const SalesChannel = () => {
|
|
11423
|
+
const { id } = reactRouterDom.useParams();
|
|
11424
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11425
|
+
id,
|
|
11426
|
+
{
|
|
11427
|
+
fields: "+sales_channel_id"
|
|
11428
|
+
},
|
|
11429
|
+
{
|
|
11430
|
+
enabled: !!id
|
|
11431
|
+
}
|
|
11432
|
+
);
|
|
11433
|
+
if (isError) {
|
|
11434
|
+
throw error;
|
|
11435
|
+
}
|
|
11436
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11437
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11438
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11439
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
11440
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11441
|
+
] }),
|
|
11442
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
11443
|
+
] });
|
|
11444
|
+
};
|
|
11445
|
+
const SalesChannelForm = ({ order }) => {
|
|
11446
|
+
const form = reactHookForm.useForm({
|
|
11447
|
+
defaultValues: {
|
|
11448
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11449
|
+
},
|
|
11450
|
+
resolver: zod.zodResolver(schema$3)
|
|
11451
|
+
});
|
|
11452
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11453
|
+
const { handleSuccess } = useRouteModal();
|
|
11454
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11455
|
+
await mutateAsync(
|
|
11456
|
+
{
|
|
11457
|
+
sales_channel_id: data.sales_channel_id
|
|
11458
|
+
},
|
|
11459
|
+
{
|
|
11460
|
+
onSuccess: () => {
|
|
11461
|
+
ui.toast.success("Sales channel updated");
|
|
11462
|
+
handleSuccess();
|
|
11463
|
+
},
|
|
11464
|
+
onError: (error) => {
|
|
11465
|
+
ui.toast.error(error.message);
|
|
11466
|
+
}
|
|
11467
|
+
}
|
|
11468
|
+
);
|
|
11469
|
+
});
|
|
11470
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11471
|
+
KeyboundForm,
|
|
11472
|
+
{
|
|
11473
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11474
|
+
onSubmit,
|
|
11475
|
+
children: [
|
|
11476
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11477
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11478
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11479
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11480
|
+
] }) })
|
|
11481
|
+
]
|
|
11482
|
+
}
|
|
11483
|
+
) });
|
|
11484
|
+
};
|
|
11485
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11486
|
+
const salesChannels = useComboboxData({
|
|
11487
|
+
queryFn: async (params) => {
|
|
11488
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11489
|
+
},
|
|
11490
|
+
queryKey: ["sales-channels"],
|
|
11491
|
+
getOptions: (data) => {
|
|
11492
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11493
|
+
label: salesChannel.name,
|
|
11494
|
+
value: salesChannel.id
|
|
11495
|
+
}));
|
|
11496
|
+
},
|
|
11497
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11498
|
+
});
|
|
11499
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11500
|
+
Form$2.Field,
|
|
11501
|
+
{
|
|
11502
|
+
control,
|
|
11503
|
+
name: "sales_channel_id",
|
|
11504
|
+
render: ({ field }) => {
|
|
11505
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11506
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11507
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11508
|
+
Combobox,
|
|
11509
|
+
{
|
|
11510
|
+
options: salesChannels.options,
|
|
11511
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11512
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11513
|
+
searchValue: salesChannels.searchValue,
|
|
11514
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11515
|
+
placeholder: "Select sales channel",
|
|
11516
|
+
...field
|
|
11517
|
+
}
|
|
11518
|
+
) }),
|
|
11519
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11520
|
+
] });
|
|
11370
11521
|
}
|
|
11371
11522
|
}
|
|
11372
|
-
|
|
11373
|
-
|
|
11374
|
-
|
|
11523
|
+
);
|
|
11524
|
+
};
|
|
11525
|
+
const schema$3 = objectType({
|
|
11526
|
+
sales_channel_id: stringType().min(1)
|
|
11527
|
+
});
|
|
11375
11528
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11376
11529
|
const Shipping = () => {
|
|
11377
11530
|
var _a;
|
|
@@ -12211,7 +12364,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12211
12364
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12212
12365
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12213
12366
|
},
|
|
12214
|
-
resolver: zod.zodResolver(schema$
|
|
12367
|
+
resolver: zod.zodResolver(schema$2)
|
|
12215
12368
|
});
|
|
12216
12369
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12217
12370
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12381,7 +12534,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12381
12534
|
}
|
|
12382
12535
|
) });
|
|
12383
12536
|
};
|
|
12384
|
-
const schema$
|
|
12537
|
+
const schema$2 = addressSchema;
|
|
12385
12538
|
const TransferOwnership = () => {
|
|
12386
12539
|
const { id } = reactRouterDom.useParams();
|
|
12387
12540
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12405,7 +12558,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12405
12558
|
defaultValues: {
|
|
12406
12559
|
customer_id: order.customer_id || ""
|
|
12407
12560
|
},
|
|
12408
|
-
resolver: zod.zodResolver(schema$
|
|
12561
|
+
resolver: zod.zodResolver(schema$1)
|
|
12409
12562
|
});
|
|
12410
12563
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12411
12564
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12855,179 +13008,26 @@ const Illustration = () => {
|
|
|
12855
13008
|
}
|
|
12856
13009
|
);
|
|
12857
13010
|
};
|
|
12858
|
-
const schema$2 = objectType({
|
|
12859
|
-
customer_id: stringType().min(1)
|
|
12860
|
-
});
|
|
12861
|
-
const SalesChannel = () => {
|
|
12862
|
-
const { id } = reactRouterDom.useParams();
|
|
12863
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12864
|
-
id,
|
|
12865
|
-
{
|
|
12866
|
-
fields: "+sales_channel_id"
|
|
12867
|
-
},
|
|
12868
|
-
{
|
|
12869
|
-
enabled: !!id
|
|
12870
|
-
}
|
|
12871
|
-
);
|
|
12872
|
-
if (isError) {
|
|
12873
|
-
throw error;
|
|
12874
|
-
}
|
|
12875
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
12876
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12877
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12878
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
12879
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12880
|
-
] }),
|
|
12881
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
12882
|
-
] });
|
|
12883
|
-
};
|
|
12884
|
-
const SalesChannelForm = ({ order }) => {
|
|
12885
|
-
const form = reactHookForm.useForm({
|
|
12886
|
-
defaultValues: {
|
|
12887
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
12888
|
-
},
|
|
12889
|
-
resolver: zod.zodResolver(schema$1)
|
|
12890
|
-
});
|
|
12891
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12892
|
-
const { handleSuccess } = useRouteModal();
|
|
12893
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12894
|
-
await mutateAsync(
|
|
12895
|
-
{
|
|
12896
|
-
sales_channel_id: data.sales_channel_id
|
|
12897
|
-
},
|
|
12898
|
-
{
|
|
12899
|
-
onSuccess: () => {
|
|
12900
|
-
ui.toast.success("Sales channel updated");
|
|
12901
|
-
handleSuccess();
|
|
12902
|
-
},
|
|
12903
|
-
onError: (error) => {
|
|
12904
|
-
ui.toast.error(error.message);
|
|
12905
|
-
}
|
|
12906
|
-
}
|
|
12907
|
-
);
|
|
12908
|
-
});
|
|
12909
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12910
|
-
KeyboundForm,
|
|
12911
|
-
{
|
|
12912
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12913
|
-
onSubmit,
|
|
12914
|
-
children: [
|
|
12915
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12916
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12917
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12918
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12919
|
-
] }) })
|
|
12920
|
-
]
|
|
12921
|
-
}
|
|
12922
|
-
) });
|
|
12923
|
-
};
|
|
12924
|
-
const SalesChannelField = ({ control, order }) => {
|
|
12925
|
-
const salesChannels = useComboboxData({
|
|
12926
|
-
queryFn: async (params) => {
|
|
12927
|
-
return await sdk.admin.salesChannel.list(params);
|
|
12928
|
-
},
|
|
12929
|
-
queryKey: ["sales-channels"],
|
|
12930
|
-
getOptions: (data) => {
|
|
12931
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
12932
|
-
label: salesChannel.name,
|
|
12933
|
-
value: salesChannel.id
|
|
12934
|
-
}));
|
|
12935
|
-
},
|
|
12936
|
-
defaultValue: order.sales_channel_id || void 0
|
|
12937
|
-
});
|
|
12938
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12939
|
-
Form$2.Field,
|
|
12940
|
-
{
|
|
12941
|
-
control,
|
|
12942
|
-
name: "sales_channel_id",
|
|
12943
|
-
render: ({ field }) => {
|
|
12944
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12945
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
12946
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12947
|
-
Combobox,
|
|
12948
|
-
{
|
|
12949
|
-
options: salesChannels.options,
|
|
12950
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
12951
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
12952
|
-
searchValue: salesChannels.searchValue,
|
|
12953
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
12954
|
-
placeholder: "Select sales channel",
|
|
12955
|
-
...field
|
|
12956
|
-
}
|
|
12957
|
-
) }),
|
|
12958
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12959
|
-
] });
|
|
12960
|
-
}
|
|
12961
|
-
}
|
|
12962
|
-
);
|
|
12963
|
-
};
|
|
12964
13011
|
const schema$1 = objectType({
|
|
12965
|
-
|
|
13012
|
+
customer_id: stringType().min(1)
|
|
12966
13013
|
});
|
|
12967
|
-
const
|
|
12968
|
-
const { id } = reactRouterDom.useParams();
|
|
12969
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
12970
|
-
fields: "+email"
|
|
12971
|
-
});
|
|
12972
|
-
if (isError) {
|
|
12973
|
-
throw error;
|
|
12974
|
-
}
|
|
12975
|
-
const isReady = !isPending && !!order;
|
|
13014
|
+
const CustomItems = () => {
|
|
12976
13015
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12977
|
-
/* @__PURE__ */ jsxRuntime.
|
|
12978
|
-
|
|
12979
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
12980
|
-
] }),
|
|
12981
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
13016
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
13017
|
+
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
12982
13018
|
] });
|
|
12983
13019
|
};
|
|
12984
|
-
const
|
|
13020
|
+
const CustomItemsForm = () => {
|
|
12985
13021
|
const form = reactHookForm.useForm({
|
|
12986
|
-
defaultValues: {
|
|
12987
|
-
email: order.email ?? ""
|
|
12988
|
-
},
|
|
12989
13022
|
resolver: zod.zodResolver(schema)
|
|
12990
13023
|
});
|
|
12991
|
-
|
|
12992
|
-
|
|
12993
|
-
|
|
12994
|
-
|
|
12995
|
-
{
|
|
12996
|
-
|
|
12997
|
-
|
|
12998
|
-
handleSuccess();
|
|
12999
|
-
},
|
|
13000
|
-
onError: (error) => {
|
|
13001
|
-
ui.toast.error(error.message);
|
|
13002
|
-
}
|
|
13003
|
-
}
|
|
13004
|
-
);
|
|
13005
|
-
});
|
|
13006
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
13007
|
-
KeyboundForm,
|
|
13008
|
-
{
|
|
13009
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
13010
|
-
onSubmit,
|
|
13011
|
-
children: [
|
|
13012
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
13013
|
-
Form$2.Field,
|
|
13014
|
-
{
|
|
13015
|
-
control: form.control,
|
|
13016
|
-
name: "email",
|
|
13017
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
13018
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
13019
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
13020
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
13021
|
-
] })
|
|
13022
|
-
}
|
|
13023
|
-
) }),
|
|
13024
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13025
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13026
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13027
|
-
] }) })
|
|
13028
|
-
]
|
|
13029
|
-
}
|
|
13030
|
-
) });
|
|
13024
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
13025
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
13026
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13027
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13028
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
13029
|
+
] }) })
|
|
13030
|
+
] }) });
|
|
13031
13031
|
};
|
|
13032
13032
|
const schema = objectType({
|
|
13033
13033
|
email: stringType().email()
|
|
@@ -13057,21 +13057,25 @@ const routeModule = {
|
|
|
13057
13057
|
path: "/draft-orders/:id/billing-address"
|
|
13058
13058
|
},
|
|
13059
13059
|
{
|
|
13060
|
-
Component:
|
|
13061
|
-
path: "/draft-orders/:id/
|
|
13062
|
-
},
|
|
13063
|
-
{
|
|
13064
|
-
Component: Metadata,
|
|
13065
|
-
path: "/draft-orders/:id/metadata"
|
|
13060
|
+
Component: Email,
|
|
13061
|
+
path: "/draft-orders/:id/email"
|
|
13066
13062
|
},
|
|
13067
13063
|
{
|
|
13068
13064
|
Component: Items,
|
|
13069
13065
|
path: "/draft-orders/:id/items"
|
|
13070
13066
|
},
|
|
13067
|
+
{
|
|
13068
|
+
Component: Metadata,
|
|
13069
|
+
path: "/draft-orders/:id/metadata"
|
|
13070
|
+
},
|
|
13071
13071
|
{
|
|
13072
13072
|
Component: Promotions,
|
|
13073
13073
|
path: "/draft-orders/:id/promotions"
|
|
13074
13074
|
},
|
|
13075
|
+
{
|
|
13076
|
+
Component: SalesChannel,
|
|
13077
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13078
|
+
},
|
|
13075
13079
|
{
|
|
13076
13080
|
Component: Shipping,
|
|
13077
13081
|
path: "/draft-orders/:id/shipping"
|
|
@@ -13085,12 +13089,8 @@ const routeModule = {
|
|
|
13085
13089
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13086
13090
|
},
|
|
13087
13091
|
{
|
|
13088
|
-
Component:
|
|
13089
|
-
path: "/draft-orders/:id/
|
|
13090
|
-
},
|
|
13091
|
-
{
|
|
13092
|
-
Component: Email,
|
|
13093
|
-
path: "/draft-orders/:id/email"
|
|
13092
|
+
Component: CustomItems,
|
|
13093
|
+
path: "/draft-orders/:id/custom-items"
|
|
13094
13094
|
}
|
|
13095
13095
|
]
|
|
13096
13096
|
}
|