@medusajs/draft-order 2.10.4-snapshot-20251003114416 → 2.10.4-snapshot-20251003132946
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 +528 -528
- package/.medusa/server/src/admin/index.mjs +528 -528
- package/package.json +24 -23
|
@@ -9784,6 +9784,74 @@ const CustomItemsForm = () => {
|
|
|
9784
9784
|
const schema$4 = objectType({
|
|
9785
9785
|
email: stringType().email()
|
|
9786
9786
|
});
|
|
9787
|
+
const Email = () => {
|
|
9788
|
+
const { id } = reactRouterDom.useParams();
|
|
9789
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9790
|
+
fields: "+email"
|
|
9791
|
+
});
|
|
9792
|
+
if (isError) {
|
|
9793
|
+
throw error;
|
|
9794
|
+
}
|
|
9795
|
+
const isReady = !isPending && !!order;
|
|
9796
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9797
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9798
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
9799
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9800
|
+
] }),
|
|
9801
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
9802
|
+
] });
|
|
9803
|
+
};
|
|
9804
|
+
const EmailForm = ({ order }) => {
|
|
9805
|
+
const form = reactHookForm.useForm({
|
|
9806
|
+
defaultValues: {
|
|
9807
|
+
email: order.email ?? ""
|
|
9808
|
+
},
|
|
9809
|
+
resolver: zod.zodResolver(schema$3)
|
|
9810
|
+
});
|
|
9811
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9812
|
+
const { handleSuccess } = useRouteModal();
|
|
9813
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9814
|
+
await mutateAsync(
|
|
9815
|
+
{ email: data.email },
|
|
9816
|
+
{
|
|
9817
|
+
onSuccess: () => {
|
|
9818
|
+
handleSuccess();
|
|
9819
|
+
},
|
|
9820
|
+
onError: (error) => {
|
|
9821
|
+
ui.toast.error(error.message);
|
|
9822
|
+
}
|
|
9823
|
+
}
|
|
9824
|
+
);
|
|
9825
|
+
});
|
|
9826
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9827
|
+
KeyboundForm,
|
|
9828
|
+
{
|
|
9829
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9830
|
+
onSubmit,
|
|
9831
|
+
children: [
|
|
9832
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9833
|
+
Form$2.Field,
|
|
9834
|
+
{
|
|
9835
|
+
control: form.control,
|
|
9836
|
+
name: "email",
|
|
9837
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9838
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
9839
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9840
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9841
|
+
] })
|
|
9842
|
+
}
|
|
9843
|
+
) }),
|
|
9844
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9845
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9846
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9847
|
+
] }) })
|
|
9848
|
+
]
|
|
9849
|
+
}
|
|
9850
|
+
) });
|
|
9851
|
+
};
|
|
9852
|
+
const schema$3 = objectType({
|
|
9853
|
+
email: stringType().email()
|
|
9854
|
+
});
|
|
9787
9855
|
const NumberInput = React.forwardRef(
|
|
9788
9856
|
({
|
|
9789
9857
|
value,
|
|
@@ -10758,10 +10826,54 @@ const customItemSchema = objectType({
|
|
|
10758
10826
|
quantity: numberType(),
|
|
10759
10827
|
unit_price: unionType([numberType(), stringType()])
|
|
10760
10828
|
});
|
|
10761
|
-
const
|
|
10829
|
+
const InlineTip = React.forwardRef(
|
|
10830
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10831
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10832
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10833
|
+
"div",
|
|
10834
|
+
{
|
|
10835
|
+
ref,
|
|
10836
|
+
className: ui.clx(
|
|
10837
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10838
|
+
className
|
|
10839
|
+
),
|
|
10840
|
+
...props,
|
|
10841
|
+
children: [
|
|
10842
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10843
|
+
"div",
|
|
10844
|
+
{
|
|
10845
|
+
role: "presentation",
|
|
10846
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10847
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10848
|
+
})
|
|
10849
|
+
}
|
|
10850
|
+
),
|
|
10851
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
10852
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10853
|
+
labelValue,
|
|
10854
|
+
":"
|
|
10855
|
+
] }),
|
|
10856
|
+
" ",
|
|
10857
|
+
children
|
|
10858
|
+
] })
|
|
10859
|
+
]
|
|
10860
|
+
}
|
|
10861
|
+
);
|
|
10862
|
+
}
|
|
10863
|
+
);
|
|
10864
|
+
InlineTip.displayName = "InlineTip";
|
|
10865
|
+
const MetadataFieldSchema = objectType({
|
|
10866
|
+
key: stringType(),
|
|
10867
|
+
disabled: booleanType().optional(),
|
|
10868
|
+
value: anyType()
|
|
10869
|
+
});
|
|
10870
|
+
const MetadataSchema = objectType({
|
|
10871
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10872
|
+
});
|
|
10873
|
+
const Metadata = () => {
|
|
10762
10874
|
const { id } = reactRouterDom.useParams();
|
|
10763
10875
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
10764
|
-
fields: "
|
|
10876
|
+
fields: "metadata"
|
|
10765
10877
|
});
|
|
10766
10878
|
if (isError) {
|
|
10767
10879
|
throw error;
|
|
@@ -10769,26 +10881,33 @@ const Email = () => {
|
|
|
10769
10881
|
const isReady = !isPending && !!order;
|
|
10770
10882
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10771
10883
|
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
10772
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "
|
|
10773
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "
|
|
10884
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
10885
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10774
10886
|
] }),
|
|
10775
|
-
isReady
|
|
10887
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10776
10888
|
] });
|
|
10777
10889
|
};
|
|
10778
|
-
const
|
|
10890
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10891
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10892
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10893
|
+
const { handleSuccess } = useRouteModal();
|
|
10894
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10895
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10779
10896
|
const form = reactHookForm.useForm({
|
|
10780
10897
|
defaultValues: {
|
|
10781
|
-
|
|
10898
|
+
metadata: getDefaultValues(metadata)
|
|
10782
10899
|
},
|
|
10783
|
-
resolver: zod.zodResolver(
|
|
10900
|
+
resolver: zod.zodResolver(MetadataSchema)
|
|
10784
10901
|
});
|
|
10785
|
-
const
|
|
10786
|
-
|
|
10787
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10902
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10903
|
+
const parsedData = parseValues(data);
|
|
10788
10904
|
await mutateAsync(
|
|
10789
|
-
{
|
|
10905
|
+
{
|
|
10906
|
+
metadata: parsedData
|
|
10907
|
+
},
|
|
10790
10908
|
{
|
|
10791
10909
|
onSuccess: () => {
|
|
10910
|
+
ui.toast.success("Metadata updated");
|
|
10792
10911
|
handleSuccess();
|
|
10793
10912
|
},
|
|
10794
10913
|
onError: (error) => {
|
|
@@ -10797,102 +10916,333 @@ const EmailForm = ({ order }) => {
|
|
|
10797
10916
|
}
|
|
10798
10917
|
);
|
|
10799
10918
|
});
|
|
10919
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
10920
|
+
control: form.control,
|
|
10921
|
+
name: "metadata"
|
|
10922
|
+
});
|
|
10923
|
+
function deleteRow(index) {
|
|
10924
|
+
remove(index);
|
|
10925
|
+
if (fields.length === 1) {
|
|
10926
|
+
insert(0, {
|
|
10927
|
+
key: "",
|
|
10928
|
+
value: "",
|
|
10929
|
+
disabled: false
|
|
10930
|
+
});
|
|
10931
|
+
}
|
|
10932
|
+
}
|
|
10933
|
+
function insertRow(index, position) {
|
|
10934
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10935
|
+
key: "",
|
|
10936
|
+
value: "",
|
|
10937
|
+
disabled: false
|
|
10938
|
+
});
|
|
10939
|
+
}
|
|
10800
10940
|
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10801
10941
|
KeyboundForm,
|
|
10802
10942
|
{
|
|
10943
|
+
onSubmit: handleSubmit,
|
|
10803
10944
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
10804
|
-
onSubmit,
|
|
10805
10945
|
children: [
|
|
10806
|
-
/* @__PURE__ */ jsxRuntime.
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
};
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
|
|
10854
|
-
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
|
|
10860
|
-
|
|
10861
|
-
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
}
|
|
10867
|
-
|
|
10868
|
-
|
|
10869
|
-
|
|
10870
|
-
|
|
10871
|
-
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10946
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10947
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10948
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10949
|
+
/* @__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" }) }),
|
|
10950
|
+
/* @__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" }) })
|
|
10951
|
+
] }),
|
|
10952
|
+
fields.map((field, index) => {
|
|
10953
|
+
const isDisabled = field.disabled || false;
|
|
10954
|
+
let placeholder = "-";
|
|
10955
|
+
if (typeof field.value === "object") {
|
|
10956
|
+
placeholder = "{ ... }";
|
|
10957
|
+
}
|
|
10958
|
+
if (Array.isArray(field.value)) {
|
|
10959
|
+
placeholder = "[ ... ]";
|
|
10960
|
+
}
|
|
10961
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10962
|
+
ConditionalTooltip,
|
|
10963
|
+
{
|
|
10964
|
+
showTooltip: isDisabled,
|
|
10965
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
10966
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
10967
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
10968
|
+
"div",
|
|
10969
|
+
{
|
|
10970
|
+
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
10971
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10972
|
+
}),
|
|
10973
|
+
children: [
|
|
10974
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10975
|
+
Form$2.Field,
|
|
10976
|
+
{
|
|
10977
|
+
control: form.control,
|
|
10978
|
+
name: `metadata.${index}.key`,
|
|
10979
|
+
render: ({ field: field2 }) => {
|
|
10980
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10981
|
+
GridInput,
|
|
10982
|
+
{
|
|
10983
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10984
|
+
...field2,
|
|
10985
|
+
disabled: isDisabled,
|
|
10986
|
+
placeholder: "Key"
|
|
10987
|
+
}
|
|
10988
|
+
) }) });
|
|
10989
|
+
}
|
|
10990
|
+
}
|
|
10991
|
+
),
|
|
10992
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10993
|
+
Form$2.Field,
|
|
10994
|
+
{
|
|
10995
|
+
control: form.control,
|
|
10996
|
+
name: `metadata.${index}.value`,
|
|
10997
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
10998
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10999
|
+
GridInput,
|
|
11000
|
+
{
|
|
11001
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
11002
|
+
...field2,
|
|
11003
|
+
value: isDisabled ? placeholder : value,
|
|
11004
|
+
disabled: isDisabled,
|
|
11005
|
+
placeholder: "Value"
|
|
11006
|
+
}
|
|
11007
|
+
) }) });
|
|
11008
|
+
}
|
|
11009
|
+
}
|
|
11010
|
+
)
|
|
11011
|
+
]
|
|
11012
|
+
}
|
|
11013
|
+
),
|
|
11014
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
11015
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11016
|
+
ui.DropdownMenu.Trigger,
|
|
11017
|
+
{
|
|
11018
|
+
className: ui.clx(
|
|
11019
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11020
|
+
{
|
|
11021
|
+
hidden: isDisabled
|
|
11022
|
+
}
|
|
11023
|
+
),
|
|
11024
|
+
disabled: isDisabled,
|
|
11025
|
+
asChild: true,
|
|
11026
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
11027
|
+
}
|
|
11028
|
+
),
|
|
11029
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
11030
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11031
|
+
ui.DropdownMenu.Item,
|
|
11032
|
+
{
|
|
11033
|
+
className: "gap-x-2",
|
|
11034
|
+
onClick: () => insertRow(index, "above"),
|
|
11035
|
+
children: [
|
|
11036
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11037
|
+
"Insert row above"
|
|
11038
|
+
]
|
|
11039
|
+
}
|
|
11040
|
+
),
|
|
11041
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11042
|
+
ui.DropdownMenu.Item,
|
|
11043
|
+
{
|
|
11044
|
+
className: "gap-x-2",
|
|
11045
|
+
onClick: () => insertRow(index, "below"),
|
|
11046
|
+
children: [
|
|
11047
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11048
|
+
"Insert row below"
|
|
11049
|
+
]
|
|
11050
|
+
}
|
|
11051
|
+
),
|
|
11052
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
11053
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11054
|
+
ui.DropdownMenu.Item,
|
|
11055
|
+
{
|
|
11056
|
+
className: "gap-x-2",
|
|
11057
|
+
onClick: () => deleteRow(index),
|
|
11058
|
+
children: [
|
|
11059
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
11060
|
+
"Delete row"
|
|
11061
|
+
]
|
|
11062
|
+
}
|
|
11063
|
+
)
|
|
11064
|
+
] })
|
|
11065
|
+
] })
|
|
11066
|
+
] })
|
|
11067
|
+
},
|
|
11068
|
+
field.id
|
|
11069
|
+
);
|
|
11070
|
+
})
|
|
11071
|
+
] }),
|
|
11072
|
+
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." })
|
|
11073
|
+
] }),
|
|
11074
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11075
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11076
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11077
|
+
] }) })
|
|
11078
|
+
]
|
|
11079
|
+
}
|
|
11080
|
+
) });
|
|
11081
|
+
};
|
|
11082
|
+
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
11083
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11084
|
+
"input",
|
|
11085
|
+
{
|
|
11086
|
+
ref,
|
|
11087
|
+
...props,
|
|
11088
|
+
autoComplete: "off",
|
|
11089
|
+
className: ui.clx(
|
|
11090
|
+
"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",
|
|
11091
|
+
className
|
|
11092
|
+
)
|
|
11093
|
+
}
|
|
11094
|
+
);
|
|
11095
|
+
});
|
|
11096
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11097
|
+
const PlaceholderInner = () => {
|
|
11098
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11099
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11100
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11101
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11102
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11103
|
+
] }) })
|
|
11104
|
+
] });
|
|
11105
|
+
};
|
|
11106
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11107
|
+
function getDefaultValues(metadata) {
|
|
11108
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
11109
|
+
return [
|
|
11110
|
+
{
|
|
11111
|
+
key: "",
|
|
11112
|
+
value: "",
|
|
11113
|
+
disabled: false
|
|
11114
|
+
}
|
|
11115
|
+
];
|
|
11116
|
+
}
|
|
11117
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11118
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11119
|
+
return {
|
|
11120
|
+
key,
|
|
11121
|
+
value,
|
|
11122
|
+
disabled: true
|
|
11123
|
+
};
|
|
11124
|
+
}
|
|
11125
|
+
let stringValue = value;
|
|
11126
|
+
if (typeof value !== "string") {
|
|
11127
|
+
stringValue = JSON.stringify(value);
|
|
11128
|
+
}
|
|
11129
|
+
return {
|
|
11130
|
+
key,
|
|
11131
|
+
value: stringValue,
|
|
11132
|
+
original_key: key
|
|
11133
|
+
};
|
|
11134
|
+
});
|
|
11135
|
+
}
|
|
11136
|
+
function parseValues(values) {
|
|
11137
|
+
const metadata = values.metadata;
|
|
11138
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11139
|
+
if (isEmpty) {
|
|
11140
|
+
return null;
|
|
11141
|
+
}
|
|
11142
|
+
const update = {};
|
|
11143
|
+
metadata.forEach((field) => {
|
|
11144
|
+
let key = field.key;
|
|
11145
|
+
let value = field.value;
|
|
11146
|
+
const disabled = field.disabled;
|
|
11147
|
+
if (!key || !value) {
|
|
11148
|
+
return;
|
|
11149
|
+
}
|
|
11150
|
+
if (disabled) {
|
|
11151
|
+
update[key] = value;
|
|
11152
|
+
return;
|
|
11153
|
+
}
|
|
11154
|
+
key = key.trim();
|
|
11155
|
+
value = value.trim();
|
|
11156
|
+
if (value === "true") {
|
|
11157
|
+
update[key] = true;
|
|
11158
|
+
} else if (value === "false") {
|
|
11159
|
+
update[key] = false;
|
|
11160
|
+
} else {
|
|
11161
|
+
const parsedNumber = parseFloat(value);
|
|
11162
|
+
if (!isNaN(parsedNumber)) {
|
|
11163
|
+
update[key] = parsedNumber;
|
|
11164
|
+
} else {
|
|
11165
|
+
update[key] = value;
|
|
11166
|
+
}
|
|
11167
|
+
}
|
|
11168
|
+
});
|
|
11169
|
+
return update;
|
|
11170
|
+
}
|
|
11171
|
+
function getHasUneditableRows(metadata) {
|
|
11172
|
+
if (!metadata) {
|
|
11173
|
+
return false;
|
|
11174
|
+
}
|
|
11175
|
+
return Object.values(metadata).some(
|
|
11176
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11177
|
+
);
|
|
11178
|
+
}
|
|
11179
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11180
|
+
const promotionsQueryKeys = {
|
|
11181
|
+
list: (query2) => [
|
|
11182
|
+
PROMOTION_QUERY_KEY,
|
|
11183
|
+
query2 ? query2 : void 0
|
|
11184
|
+
],
|
|
11185
|
+
detail: (id, query2) => [
|
|
11186
|
+
PROMOTION_QUERY_KEY,
|
|
11187
|
+
id,
|
|
11188
|
+
query2 ? query2 : void 0
|
|
11189
|
+
]
|
|
11190
|
+
};
|
|
11191
|
+
const usePromotions = (query2, options) => {
|
|
11192
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
11193
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11194
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11195
|
+
...options
|
|
11196
|
+
});
|
|
11197
|
+
return { ...data, ...rest };
|
|
11198
|
+
};
|
|
11199
|
+
const Promotions = () => {
|
|
11200
|
+
const { id } = reactRouterDom.useParams();
|
|
11201
|
+
const {
|
|
11202
|
+
order: preview,
|
|
11203
|
+
isError: isPreviewError,
|
|
11204
|
+
error: previewError
|
|
11205
|
+
} = useOrderPreview(id, void 0);
|
|
11206
|
+
useInitiateOrderEdit({ preview });
|
|
11207
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11208
|
+
if (isPreviewError) {
|
|
11209
|
+
throw previewError;
|
|
11210
|
+
}
|
|
11211
|
+
const isReady = !!preview;
|
|
11212
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11213
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11214
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11215
|
+
] });
|
|
11216
|
+
};
|
|
11217
|
+
const PromotionForm = ({ preview }) => {
|
|
11218
|
+
const { items, shipping_methods } = preview;
|
|
11219
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11220
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11221
|
+
const { handleSuccess } = useRouteModal();
|
|
11222
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11223
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11224
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11225
|
+
{
|
|
11226
|
+
id: promoIds
|
|
11227
|
+
},
|
|
11228
|
+
{
|
|
11229
|
+
enabled: !!promoIds.length
|
|
11230
|
+
}
|
|
11231
|
+
);
|
|
11232
|
+
const comboboxData = useComboboxData({
|
|
11233
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11234
|
+
queryFn: async (params) => {
|
|
11235
|
+
return await sdk.admin.promotion.list({
|
|
11236
|
+
...params,
|
|
11237
|
+
id: {
|
|
11238
|
+
$nin: promoIds
|
|
11239
|
+
}
|
|
11240
|
+
});
|
|
11241
|
+
},
|
|
11242
|
+
getOptions: (data) => {
|
|
11243
|
+
return data.promotions.map((promotion) => ({
|
|
11244
|
+
label: promotion.code,
|
|
11245
|
+
value: promotion.code
|
|
10896
11246
|
}));
|
|
10897
11247
|
}
|
|
10898
11248
|
});
|
|
@@ -11103,88 +11453,46 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
11103
11453
|
}
|
|
11104
11454
|
return Array.from(promotionIds);
|
|
11105
11455
|
}
|
|
11106
|
-
const
|
|
11107
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11108
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11109
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11110
|
-
"div",
|
|
11111
|
-
{
|
|
11112
|
-
ref,
|
|
11113
|
-
className: ui.clx(
|
|
11114
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11115
|
-
className
|
|
11116
|
-
),
|
|
11117
|
-
...props,
|
|
11118
|
-
children: [
|
|
11119
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11120
|
-
"div",
|
|
11121
|
-
{
|
|
11122
|
-
role: "presentation",
|
|
11123
|
-
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11124
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11125
|
-
})
|
|
11126
|
-
}
|
|
11127
|
-
),
|
|
11128
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
11129
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11130
|
-
labelValue,
|
|
11131
|
-
":"
|
|
11132
|
-
] }),
|
|
11133
|
-
" ",
|
|
11134
|
-
children
|
|
11135
|
-
] })
|
|
11136
|
-
]
|
|
11137
|
-
}
|
|
11138
|
-
);
|
|
11139
|
-
}
|
|
11140
|
-
);
|
|
11141
|
-
InlineTip.displayName = "InlineTip";
|
|
11142
|
-
const MetadataFieldSchema = objectType({
|
|
11143
|
-
key: stringType(),
|
|
11144
|
-
disabled: booleanType().optional(),
|
|
11145
|
-
value: anyType()
|
|
11146
|
-
});
|
|
11147
|
-
const MetadataSchema = objectType({
|
|
11148
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
11149
|
-
});
|
|
11150
|
-
const Metadata = () => {
|
|
11456
|
+
const SalesChannel = () => {
|
|
11151
11457
|
const { id } = reactRouterDom.useParams();
|
|
11152
|
-
const {
|
|
11153
|
-
|
|
11154
|
-
|
|
11458
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11459
|
+
id,
|
|
11460
|
+
{
|
|
11461
|
+
fields: "+sales_channel_id"
|
|
11462
|
+
},
|
|
11463
|
+
{
|
|
11464
|
+
enabled: !!id
|
|
11465
|
+
}
|
|
11466
|
+
);
|
|
11155
11467
|
if (isError) {
|
|
11156
11468
|
throw error;
|
|
11157
11469
|
}
|
|
11158
|
-
const
|
|
11470
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11159
11471
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11160
11472
|
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11161
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "
|
|
11162
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "
|
|
11473
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
11474
|
+
/* @__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" }) })
|
|
11163
11475
|
] }),
|
|
11164
|
-
|
|
11476
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
11165
11477
|
] });
|
|
11166
11478
|
};
|
|
11167
|
-
const
|
|
11168
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11169
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
11170
|
-
const { handleSuccess } = useRouteModal();
|
|
11171
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11172
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11479
|
+
const SalesChannelForm = ({ order }) => {
|
|
11173
11480
|
const form = reactHookForm.useForm({
|
|
11174
11481
|
defaultValues: {
|
|
11175
|
-
|
|
11482
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11176
11483
|
},
|
|
11177
|
-
resolver: zod.zodResolver(
|
|
11484
|
+
resolver: zod.zodResolver(schema$2)
|
|
11178
11485
|
});
|
|
11179
|
-
const
|
|
11180
|
-
|
|
11486
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11487
|
+
const { handleSuccess } = useRouteModal();
|
|
11488
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11181
11489
|
await mutateAsync(
|
|
11182
11490
|
{
|
|
11183
|
-
|
|
11491
|
+
sales_channel_id: data.sales_channel_id
|
|
11184
11492
|
},
|
|
11185
11493
|
{
|
|
11186
11494
|
onSuccess: () => {
|
|
11187
|
-
ui.toast.success("
|
|
11495
|
+
ui.toast.success("Sales channel updated");
|
|
11188
11496
|
handleSuccess();
|
|
11189
11497
|
},
|
|
11190
11498
|
onError: (error) => {
|
|
@@ -11193,266 +11501,64 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
11193
11501
|
}
|
|
11194
11502
|
);
|
|
11195
11503
|
});
|
|
11196
|
-
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
11197
|
-
control: form.control,
|
|
11198
|
-
name: "metadata"
|
|
11199
|
-
});
|
|
11200
|
-
function deleteRow(index) {
|
|
11201
|
-
remove(index);
|
|
11202
|
-
if (fields.length === 1) {
|
|
11203
|
-
insert(0, {
|
|
11204
|
-
key: "",
|
|
11205
|
-
value: "",
|
|
11206
|
-
disabled: false
|
|
11207
|
-
});
|
|
11208
|
-
}
|
|
11209
|
-
}
|
|
11210
|
-
function insertRow(index, position) {
|
|
11211
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
11212
|
-
key: "",
|
|
11213
|
-
value: "",
|
|
11214
|
-
disabled: false
|
|
11215
|
-
});
|
|
11216
|
-
}
|
|
11217
11504
|
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11218
11505
|
KeyboundForm,
|
|
11219
11506
|
{
|
|
11220
|
-
onSubmit: handleSubmit,
|
|
11221
11507
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
/* @__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" }) })
|
|
11228
|
-
] }),
|
|
11229
|
-
fields.map((field, index) => {
|
|
11230
|
-
const isDisabled = field.disabled || false;
|
|
11231
|
-
let placeholder = "-";
|
|
11232
|
-
if (typeof field.value === "object") {
|
|
11233
|
-
placeholder = "{ ... }";
|
|
11234
|
-
}
|
|
11235
|
-
if (Array.isArray(field.value)) {
|
|
11236
|
-
placeholder = "[ ... ]";
|
|
11237
|
-
}
|
|
11238
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11239
|
-
ConditionalTooltip,
|
|
11240
|
-
{
|
|
11241
|
-
showTooltip: isDisabled,
|
|
11242
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
11243
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
11244
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11245
|
-
"div",
|
|
11246
|
-
{
|
|
11247
|
-
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
11248
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
11249
|
-
}),
|
|
11250
|
-
children: [
|
|
11251
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11252
|
-
Form$2.Field,
|
|
11253
|
-
{
|
|
11254
|
-
control: form.control,
|
|
11255
|
-
name: `metadata.${index}.key`,
|
|
11256
|
-
render: ({ field: field2 }) => {
|
|
11257
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11258
|
-
GridInput,
|
|
11259
|
-
{
|
|
11260
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
11261
|
-
...field2,
|
|
11262
|
-
disabled: isDisabled,
|
|
11263
|
-
placeholder: "Key"
|
|
11264
|
-
}
|
|
11265
|
-
) }) });
|
|
11266
|
-
}
|
|
11267
|
-
}
|
|
11268
|
-
),
|
|
11269
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11270
|
-
Form$2.Field,
|
|
11271
|
-
{
|
|
11272
|
-
control: form.control,
|
|
11273
|
-
name: `metadata.${index}.value`,
|
|
11274
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
11275
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11276
|
-
GridInput,
|
|
11277
|
-
{
|
|
11278
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
11279
|
-
...field2,
|
|
11280
|
-
value: isDisabled ? placeholder : value,
|
|
11281
|
-
disabled: isDisabled,
|
|
11282
|
-
placeholder: "Value"
|
|
11283
|
-
}
|
|
11284
|
-
) }) });
|
|
11285
|
-
}
|
|
11286
|
-
}
|
|
11287
|
-
)
|
|
11288
|
-
]
|
|
11289
|
-
}
|
|
11290
|
-
),
|
|
11291
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
11292
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11293
|
-
ui.DropdownMenu.Trigger,
|
|
11294
|
-
{
|
|
11295
|
-
className: ui.clx(
|
|
11296
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11297
|
-
{
|
|
11298
|
-
hidden: isDisabled
|
|
11299
|
-
}
|
|
11300
|
-
),
|
|
11301
|
-
disabled: isDisabled,
|
|
11302
|
-
asChild: true,
|
|
11303
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
11304
|
-
}
|
|
11305
|
-
),
|
|
11306
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
11307
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11308
|
-
ui.DropdownMenu.Item,
|
|
11309
|
-
{
|
|
11310
|
-
className: "gap-x-2",
|
|
11311
|
-
onClick: () => insertRow(index, "above"),
|
|
11312
|
-
children: [
|
|
11313
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11314
|
-
"Insert row above"
|
|
11315
|
-
]
|
|
11316
|
-
}
|
|
11317
|
-
),
|
|
11318
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11319
|
-
ui.DropdownMenu.Item,
|
|
11320
|
-
{
|
|
11321
|
-
className: "gap-x-2",
|
|
11322
|
-
onClick: () => insertRow(index, "below"),
|
|
11323
|
-
children: [
|
|
11324
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11325
|
-
"Insert row below"
|
|
11326
|
-
]
|
|
11327
|
-
}
|
|
11328
|
-
),
|
|
11329
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
11330
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11331
|
-
ui.DropdownMenu.Item,
|
|
11332
|
-
{
|
|
11333
|
-
className: "gap-x-2",
|
|
11334
|
-
onClick: () => deleteRow(index),
|
|
11335
|
-
children: [
|
|
11336
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
11337
|
-
"Delete row"
|
|
11338
|
-
]
|
|
11339
|
-
}
|
|
11340
|
-
)
|
|
11341
|
-
] })
|
|
11342
|
-
] })
|
|
11343
|
-
] })
|
|
11344
|
-
},
|
|
11345
|
-
field.id
|
|
11346
|
-
);
|
|
11347
|
-
})
|
|
11348
|
-
] }),
|
|
11349
|
-
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." })
|
|
11350
|
-
] }),
|
|
11351
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11352
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11508
|
+
onSubmit,
|
|
11509
|
+
children: [
|
|
11510
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11511
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11512
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11353
11513
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11354
11514
|
] }) })
|
|
11355
11515
|
]
|
|
11356
11516
|
}
|
|
11357
11517
|
) });
|
|
11358
11518
|
};
|
|
11359
|
-
const
|
|
11519
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11520
|
+
const salesChannels = useComboboxData({
|
|
11521
|
+
queryFn: async (params) => {
|
|
11522
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11523
|
+
},
|
|
11524
|
+
queryKey: ["sales-channels"],
|
|
11525
|
+
getOptions: (data) => {
|
|
11526
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11527
|
+
label: salesChannel.name,
|
|
11528
|
+
value: salesChannel.id
|
|
11529
|
+
}));
|
|
11530
|
+
},
|
|
11531
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11532
|
+
});
|
|
11360
11533
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11361
|
-
|
|
11534
|
+
Form$2.Field,
|
|
11362
11535
|
{
|
|
11363
|
-
|
|
11364
|
-
|
|
11365
|
-
|
|
11366
|
-
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
|
|
11378
|
-
|
|
11379
|
-
|
|
11380
|
-
|
|
11381
|
-
|
|
11382
|
-
};
|
|
11383
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11384
|
-
function getDefaultValues(metadata) {
|
|
11385
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
11386
|
-
return [
|
|
11387
|
-
{
|
|
11388
|
-
key: "",
|
|
11389
|
-
value: "",
|
|
11390
|
-
disabled: false
|
|
11391
|
-
}
|
|
11392
|
-
];
|
|
11393
|
-
}
|
|
11394
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
11395
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11396
|
-
return {
|
|
11397
|
-
key,
|
|
11398
|
-
value,
|
|
11399
|
-
disabled: true
|
|
11400
|
-
};
|
|
11401
|
-
}
|
|
11402
|
-
let stringValue = value;
|
|
11403
|
-
if (typeof value !== "string") {
|
|
11404
|
-
stringValue = JSON.stringify(value);
|
|
11405
|
-
}
|
|
11406
|
-
return {
|
|
11407
|
-
key,
|
|
11408
|
-
value: stringValue,
|
|
11409
|
-
original_key: key
|
|
11410
|
-
};
|
|
11411
|
-
});
|
|
11412
|
-
}
|
|
11413
|
-
function parseValues(values) {
|
|
11414
|
-
const metadata = values.metadata;
|
|
11415
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11416
|
-
if (isEmpty) {
|
|
11417
|
-
return null;
|
|
11418
|
-
}
|
|
11419
|
-
const update = {};
|
|
11420
|
-
metadata.forEach((field) => {
|
|
11421
|
-
let key = field.key;
|
|
11422
|
-
let value = field.value;
|
|
11423
|
-
const disabled = field.disabled;
|
|
11424
|
-
if (!key || !value) {
|
|
11425
|
-
return;
|
|
11426
|
-
}
|
|
11427
|
-
if (disabled) {
|
|
11428
|
-
update[key] = value;
|
|
11429
|
-
return;
|
|
11430
|
-
}
|
|
11431
|
-
key = key.trim();
|
|
11432
|
-
value = value.trim();
|
|
11433
|
-
if (value === "true") {
|
|
11434
|
-
update[key] = true;
|
|
11435
|
-
} else if (value === "false") {
|
|
11436
|
-
update[key] = false;
|
|
11437
|
-
} else {
|
|
11438
|
-
const parsedNumber = parseFloat(value);
|
|
11439
|
-
if (!isNaN(parsedNumber)) {
|
|
11440
|
-
update[key] = parsedNumber;
|
|
11441
|
-
} else {
|
|
11442
|
-
update[key] = value;
|
|
11536
|
+
control,
|
|
11537
|
+
name: "sales_channel_id",
|
|
11538
|
+
render: ({ field }) => {
|
|
11539
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11540
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11541
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11542
|
+
Combobox,
|
|
11543
|
+
{
|
|
11544
|
+
options: salesChannels.options,
|
|
11545
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11546
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11547
|
+
searchValue: salesChannels.searchValue,
|
|
11548
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11549
|
+
placeholder: "Select sales channel",
|
|
11550
|
+
...field
|
|
11551
|
+
}
|
|
11552
|
+
) }),
|
|
11553
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11554
|
+
] });
|
|
11443
11555
|
}
|
|
11444
11556
|
}
|
|
11445
|
-
});
|
|
11446
|
-
return update;
|
|
11447
|
-
}
|
|
11448
|
-
function getHasUneditableRows(metadata) {
|
|
11449
|
-
if (!metadata) {
|
|
11450
|
-
return false;
|
|
11451
|
-
}
|
|
11452
|
-
return Object.values(metadata).some(
|
|
11453
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11454
11557
|
);
|
|
11455
|
-
}
|
|
11558
|
+
};
|
|
11559
|
+
const schema$2 = objectType({
|
|
11560
|
+
sales_channel_id: stringType().min(1)
|
|
11561
|
+
});
|
|
11456
11562
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11457
11563
|
const Shipping = () => {
|
|
11458
11564
|
var _a;
|
|
@@ -12292,7 +12398,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12292
12398
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12293
12399
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12294
12400
|
},
|
|
12295
|
-
resolver: zod.zodResolver(schema$
|
|
12401
|
+
resolver: zod.zodResolver(schema$1)
|
|
12296
12402
|
});
|
|
12297
12403
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12298
12404
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12462,113 +12568,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12462
12568
|
}
|
|
12463
12569
|
) });
|
|
12464
12570
|
};
|
|
12465
|
-
const schema$
|
|
12466
|
-
const SalesChannel = () => {
|
|
12467
|
-
const { id } = reactRouterDom.useParams();
|
|
12468
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12469
|
-
id,
|
|
12470
|
-
{
|
|
12471
|
-
fields: "+sales_channel_id"
|
|
12472
|
-
},
|
|
12473
|
-
{
|
|
12474
|
-
enabled: !!id
|
|
12475
|
-
}
|
|
12476
|
-
);
|
|
12477
|
-
if (isError) {
|
|
12478
|
-
throw error;
|
|
12479
|
-
}
|
|
12480
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
12481
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12482
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12483
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
12484
|
-
/* @__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" }) })
|
|
12485
|
-
] }),
|
|
12486
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
12487
|
-
] });
|
|
12488
|
-
};
|
|
12489
|
-
const SalesChannelForm = ({ order }) => {
|
|
12490
|
-
const form = reactHookForm.useForm({
|
|
12491
|
-
defaultValues: {
|
|
12492
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
12493
|
-
},
|
|
12494
|
-
resolver: zod.zodResolver(schema$1)
|
|
12495
|
-
});
|
|
12496
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12497
|
-
const { handleSuccess } = useRouteModal();
|
|
12498
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12499
|
-
await mutateAsync(
|
|
12500
|
-
{
|
|
12501
|
-
sales_channel_id: data.sales_channel_id
|
|
12502
|
-
},
|
|
12503
|
-
{
|
|
12504
|
-
onSuccess: () => {
|
|
12505
|
-
ui.toast.success("Sales channel updated");
|
|
12506
|
-
handleSuccess();
|
|
12507
|
-
},
|
|
12508
|
-
onError: (error) => {
|
|
12509
|
-
ui.toast.error(error.message);
|
|
12510
|
-
}
|
|
12511
|
-
}
|
|
12512
|
-
);
|
|
12513
|
-
});
|
|
12514
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12515
|
-
KeyboundForm,
|
|
12516
|
-
{
|
|
12517
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12518
|
-
onSubmit,
|
|
12519
|
-
children: [
|
|
12520
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12521
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12522
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12523
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12524
|
-
] }) })
|
|
12525
|
-
]
|
|
12526
|
-
}
|
|
12527
|
-
) });
|
|
12528
|
-
};
|
|
12529
|
-
const SalesChannelField = ({ control, order }) => {
|
|
12530
|
-
const salesChannels = useComboboxData({
|
|
12531
|
-
queryFn: async (params) => {
|
|
12532
|
-
return await sdk.admin.salesChannel.list(params);
|
|
12533
|
-
},
|
|
12534
|
-
queryKey: ["sales-channels"],
|
|
12535
|
-
getOptions: (data) => {
|
|
12536
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
12537
|
-
label: salesChannel.name,
|
|
12538
|
-
value: salesChannel.id
|
|
12539
|
-
}));
|
|
12540
|
-
},
|
|
12541
|
-
defaultValue: order.sales_channel_id || void 0
|
|
12542
|
-
});
|
|
12543
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12544
|
-
Form$2.Field,
|
|
12545
|
-
{
|
|
12546
|
-
control,
|
|
12547
|
-
name: "sales_channel_id",
|
|
12548
|
-
render: ({ field }) => {
|
|
12549
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12550
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
12551
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12552
|
-
Combobox,
|
|
12553
|
-
{
|
|
12554
|
-
options: salesChannels.options,
|
|
12555
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
12556
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
12557
|
-
searchValue: salesChannels.searchValue,
|
|
12558
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
12559
|
-
placeholder: "Select sales channel",
|
|
12560
|
-
...field
|
|
12561
|
-
}
|
|
12562
|
-
) }),
|
|
12563
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12564
|
-
] });
|
|
12565
|
-
}
|
|
12566
|
-
}
|
|
12567
|
-
);
|
|
12568
|
-
};
|
|
12569
|
-
const schema$1 = objectType({
|
|
12570
|
-
sales_channel_id: stringType().min(1)
|
|
12571
|
-
});
|
|
12571
|
+
const schema$1 = addressSchema;
|
|
12572
12572
|
const TransferOwnership = () => {
|
|
12573
12573
|
const { id } = reactRouterDom.useParams();
|
|
12574
12574
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -13073,21 +13073,25 @@ const routeModule = {
|
|
|
13073
13073
|
Component: CustomItems,
|
|
13074
13074
|
path: "/draft-orders/:id/custom-items"
|
|
13075
13075
|
},
|
|
13076
|
+
{
|
|
13077
|
+
Component: Email,
|
|
13078
|
+
path: "/draft-orders/:id/email"
|
|
13079
|
+
},
|
|
13076
13080
|
{
|
|
13077
13081
|
Component: Items,
|
|
13078
13082
|
path: "/draft-orders/:id/items"
|
|
13079
13083
|
},
|
|
13080
13084
|
{
|
|
13081
|
-
Component:
|
|
13082
|
-
path: "/draft-orders/:id/
|
|
13085
|
+
Component: Metadata,
|
|
13086
|
+
path: "/draft-orders/:id/metadata"
|
|
13083
13087
|
},
|
|
13084
13088
|
{
|
|
13085
13089
|
Component: Promotions,
|
|
13086
13090
|
path: "/draft-orders/:id/promotions"
|
|
13087
13091
|
},
|
|
13088
13092
|
{
|
|
13089
|
-
Component:
|
|
13090
|
-
path: "/draft-orders/:id/
|
|
13093
|
+
Component: SalesChannel,
|
|
13094
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13091
13095
|
},
|
|
13092
13096
|
{
|
|
13093
13097
|
Component: Shipping,
|
|
@@ -13097,10 +13101,6 @@ const routeModule = {
|
|
|
13097
13101
|
Component: ShippingAddress,
|
|
13098
13102
|
path: "/draft-orders/:id/shipping-address"
|
|
13099
13103
|
},
|
|
13100
|
-
{
|
|
13101
|
-
Component: SalesChannel,
|
|
13102
|
-
path: "/draft-orders/:id/sales-channel"
|
|
13103
|
-
},
|
|
13104
13104
|
{
|
|
13105
13105
|
Component: TransferOwnership,
|
|
13106
13106
|
path: "/draft-orders/:id/transfer-ownership"
|