@medusajs/draft-order 2.11.0-snapshot-20251019075109 → 2.11.0
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 +495 -497
- package/.medusa/server/src/admin/index.mjs +495 -497
- package/package.json +22 -24
|
@@ -7817,12 +7817,10 @@ const CustomerField$1 = ({ control, setValue }) => {
|
|
|
7817
7817
|
(option) => option.value === value
|
|
7818
7818
|
)) == null ? void 0 : _a.label;
|
|
7819
7819
|
const customerEmail = ((_b = label == null ? void 0 : label.match(/\((.*@.*)\)$/)) == null ? void 0 : _b[1]) || label;
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
});
|
|
7825
|
-
}
|
|
7820
|
+
setValue("email", customerEmail || "", {
|
|
7821
|
+
shouldDirty: true,
|
|
7822
|
+
shouldTouch: true
|
|
7823
|
+
});
|
|
7826
7824
|
},
|
|
7827
7825
|
[email, setValue, customers.options]
|
|
7828
7826
|
);
|
|
@@ -9778,74 +9776,6 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9778
9776
|
) });
|
|
9779
9777
|
};
|
|
9780
9778
|
const schema$4 = addressSchema;
|
|
9781
|
-
const Email = () => {
|
|
9782
|
-
const { id } = useParams();
|
|
9783
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
9784
|
-
fields: "+email"
|
|
9785
|
-
});
|
|
9786
|
-
if (isError) {
|
|
9787
|
-
throw error;
|
|
9788
|
-
}
|
|
9789
|
-
const isReady = !isPending && !!order;
|
|
9790
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9791
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9792
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
9793
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9794
|
-
] }),
|
|
9795
|
-
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
9796
|
-
] });
|
|
9797
|
-
};
|
|
9798
|
-
const EmailForm = ({ order }) => {
|
|
9799
|
-
const form = useForm({
|
|
9800
|
-
defaultValues: {
|
|
9801
|
-
email: order.email ?? ""
|
|
9802
|
-
},
|
|
9803
|
-
resolver: zodResolver(schema$3)
|
|
9804
|
-
});
|
|
9805
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9806
|
-
const { handleSuccess } = useRouteModal();
|
|
9807
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9808
|
-
await mutateAsync(
|
|
9809
|
-
{ email: data.email },
|
|
9810
|
-
{
|
|
9811
|
-
onSuccess: () => {
|
|
9812
|
-
handleSuccess();
|
|
9813
|
-
},
|
|
9814
|
-
onError: (error) => {
|
|
9815
|
-
toast.error(error.message);
|
|
9816
|
-
}
|
|
9817
|
-
}
|
|
9818
|
-
);
|
|
9819
|
-
});
|
|
9820
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9821
|
-
KeyboundForm,
|
|
9822
|
-
{
|
|
9823
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
9824
|
-
onSubmit,
|
|
9825
|
-
children: [
|
|
9826
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
9827
|
-
Form$2.Field,
|
|
9828
|
-
{
|
|
9829
|
-
control: form.control,
|
|
9830
|
-
name: "email",
|
|
9831
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9832
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
9833
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9834
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9835
|
-
] })
|
|
9836
|
-
}
|
|
9837
|
-
) }),
|
|
9838
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9839
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9840
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9841
|
-
] }) })
|
|
9842
|
-
]
|
|
9843
|
-
}
|
|
9844
|
-
) });
|
|
9845
|
-
};
|
|
9846
|
-
const schema$3 = objectType({
|
|
9847
|
-
email: stringType().email()
|
|
9848
|
-
});
|
|
9849
9779
|
const NumberInput = forwardRef(
|
|
9850
9780
|
({
|
|
9851
9781
|
value,
|
|
@@ -10820,54 +10750,10 @@ const customItemSchema = objectType({
|
|
|
10820
10750
|
quantity: numberType(),
|
|
10821
10751
|
unit_price: unionType([numberType(), stringType()])
|
|
10822
10752
|
});
|
|
10823
|
-
const
|
|
10824
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10825
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10826
|
-
return /* @__PURE__ */ jsxs(
|
|
10827
|
-
"div",
|
|
10828
|
-
{
|
|
10829
|
-
ref,
|
|
10830
|
-
className: clx(
|
|
10831
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10832
|
-
className
|
|
10833
|
-
),
|
|
10834
|
-
...props,
|
|
10835
|
-
children: [
|
|
10836
|
-
/* @__PURE__ */ jsx(
|
|
10837
|
-
"div",
|
|
10838
|
-
{
|
|
10839
|
-
role: "presentation",
|
|
10840
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10841
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10842
|
-
})
|
|
10843
|
-
}
|
|
10844
|
-
),
|
|
10845
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10846
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10847
|
-
labelValue,
|
|
10848
|
-
":"
|
|
10849
|
-
] }),
|
|
10850
|
-
" ",
|
|
10851
|
-
children
|
|
10852
|
-
] })
|
|
10853
|
-
]
|
|
10854
|
-
}
|
|
10855
|
-
);
|
|
10856
|
-
}
|
|
10857
|
-
);
|
|
10858
|
-
InlineTip.displayName = "InlineTip";
|
|
10859
|
-
const MetadataFieldSchema = objectType({
|
|
10860
|
-
key: stringType(),
|
|
10861
|
-
disabled: booleanType().optional(),
|
|
10862
|
-
value: anyType()
|
|
10863
|
-
});
|
|
10864
|
-
const MetadataSchema = objectType({
|
|
10865
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10866
|
-
});
|
|
10867
|
-
const Metadata = () => {
|
|
10753
|
+
const Email = () => {
|
|
10868
10754
|
const { id } = useParams();
|
|
10869
10755
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
10870
|
-
fields: "
|
|
10756
|
+
fields: "+email"
|
|
10871
10757
|
});
|
|
10872
10758
|
if (isError) {
|
|
10873
10759
|
throw error;
|
|
@@ -10875,33 +10761,103 @@ const Metadata = () => {
|
|
|
10875
10761
|
const isReady = !isPending && !!order;
|
|
10876
10762
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10877
10763
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10878
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
10879
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
10764
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
10765
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
10880
10766
|
] }),
|
|
10881
|
-
|
|
10767
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
10882
10768
|
] });
|
|
10883
10769
|
};
|
|
10884
|
-
const
|
|
10885
|
-
const
|
|
10886
|
-
|
|
10770
|
+
const EmailForm = ({ order }) => {
|
|
10771
|
+
const form = useForm({
|
|
10772
|
+
defaultValues: {
|
|
10773
|
+
email: order.email ?? ""
|
|
10774
|
+
},
|
|
10775
|
+
resolver: zodResolver(schema$3)
|
|
10776
|
+
});
|
|
10777
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10887
10778
|
const { handleSuccess } = useRouteModal();
|
|
10888
|
-
const
|
|
10889
|
-
|
|
10779
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10780
|
+
await mutateAsync(
|
|
10781
|
+
{ email: data.email },
|
|
10782
|
+
{
|
|
10783
|
+
onSuccess: () => {
|
|
10784
|
+
handleSuccess();
|
|
10785
|
+
},
|
|
10786
|
+
onError: (error) => {
|
|
10787
|
+
toast.error(error.message);
|
|
10788
|
+
}
|
|
10789
|
+
}
|
|
10790
|
+
);
|
|
10791
|
+
});
|
|
10792
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10793
|
+
KeyboundForm,
|
|
10794
|
+
{
|
|
10795
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10796
|
+
onSubmit,
|
|
10797
|
+
children: [
|
|
10798
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
10799
|
+
Form$2.Field,
|
|
10800
|
+
{
|
|
10801
|
+
control: form.control,
|
|
10802
|
+
name: "email",
|
|
10803
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
10804
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
10805
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
10806
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10807
|
+
] })
|
|
10808
|
+
}
|
|
10809
|
+
) }),
|
|
10810
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10811
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10812
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10813
|
+
] }) })
|
|
10814
|
+
]
|
|
10815
|
+
}
|
|
10816
|
+
) });
|
|
10817
|
+
};
|
|
10818
|
+
const schema$3 = objectType({
|
|
10819
|
+
email: stringType().email()
|
|
10820
|
+
});
|
|
10821
|
+
const SalesChannel = () => {
|
|
10822
|
+
const { id } = useParams();
|
|
10823
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10824
|
+
id,
|
|
10825
|
+
{
|
|
10826
|
+
fields: "+sales_channel_id"
|
|
10827
|
+
},
|
|
10828
|
+
{
|
|
10829
|
+
enabled: !!id
|
|
10830
|
+
}
|
|
10831
|
+
);
|
|
10832
|
+
if (isError) {
|
|
10833
|
+
throw error;
|
|
10834
|
+
}
|
|
10835
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
10836
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10837
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10838
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
10839
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
10840
|
+
] }),
|
|
10841
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
10842
|
+
] });
|
|
10843
|
+
};
|
|
10844
|
+
const SalesChannelForm = ({ order }) => {
|
|
10890
10845
|
const form = useForm({
|
|
10891
10846
|
defaultValues: {
|
|
10892
|
-
|
|
10847
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
10893
10848
|
},
|
|
10894
|
-
resolver: zodResolver(
|
|
10849
|
+
resolver: zodResolver(schema$2)
|
|
10895
10850
|
});
|
|
10896
|
-
const
|
|
10897
|
-
|
|
10851
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10852
|
+
const { handleSuccess } = useRouteModal();
|
|
10853
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10898
10854
|
await mutateAsync(
|
|
10899
10855
|
{
|
|
10900
|
-
|
|
10856
|
+
sales_channel_id: data.sales_channel_id
|
|
10901
10857
|
},
|
|
10902
10858
|
{
|
|
10903
10859
|
onSuccess: () => {
|
|
10904
|
-
toast.success("
|
|
10860
|
+
toast.success("Sales channel updated");
|
|
10905
10861
|
handleSuccess();
|
|
10906
10862
|
},
|
|
10907
10863
|
onError: (error) => {
|
|
@@ -10910,266 +10866,64 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
10910
10866
|
}
|
|
10911
10867
|
);
|
|
10912
10868
|
});
|
|
10913
|
-
const { fields, insert, remove } = useFieldArray({
|
|
10914
|
-
control: form.control,
|
|
10915
|
-
name: "metadata"
|
|
10916
|
-
});
|
|
10917
|
-
function deleteRow(index) {
|
|
10918
|
-
remove(index);
|
|
10919
|
-
if (fields.length === 1) {
|
|
10920
|
-
insert(0, {
|
|
10921
|
-
key: "",
|
|
10922
|
-
value: "",
|
|
10923
|
-
disabled: false
|
|
10924
|
-
});
|
|
10925
|
-
}
|
|
10926
|
-
}
|
|
10927
|
-
function insertRow(index, position) {
|
|
10928
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
10929
|
-
key: "",
|
|
10930
|
-
value: "",
|
|
10931
|
-
disabled: false
|
|
10932
|
-
});
|
|
10933
|
-
}
|
|
10934
10869
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10935
10870
|
KeyboundForm,
|
|
10936
10871
|
{
|
|
10937
|
-
onSubmit: handleSubmit,
|
|
10938
10872
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
10873
|
+
onSubmit,
|
|
10939
10874
|
children: [
|
|
10940
|
-
/* @__PURE__ */
|
|
10941
|
-
|
|
10942
|
-
|
|
10943
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
10944
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
10945
|
-
] }),
|
|
10946
|
-
fields.map((field, index) => {
|
|
10947
|
-
const isDisabled = field.disabled || false;
|
|
10948
|
-
let placeholder = "-";
|
|
10949
|
-
if (typeof field.value === "object") {
|
|
10950
|
-
placeholder = "{ ... }";
|
|
10951
|
-
}
|
|
10952
|
-
if (Array.isArray(field.value)) {
|
|
10953
|
-
placeholder = "[ ... ]";
|
|
10954
|
-
}
|
|
10955
|
-
return /* @__PURE__ */ jsx(
|
|
10956
|
-
ConditionalTooltip,
|
|
10957
|
-
{
|
|
10958
|
-
showTooltip: isDisabled,
|
|
10959
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
10960
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
10961
|
-
/* @__PURE__ */ jsxs(
|
|
10962
|
-
"div",
|
|
10963
|
-
{
|
|
10964
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
10965
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10966
|
-
}),
|
|
10967
|
-
children: [
|
|
10968
|
-
/* @__PURE__ */ jsx(
|
|
10969
|
-
Form$2.Field,
|
|
10970
|
-
{
|
|
10971
|
-
control: form.control,
|
|
10972
|
-
name: `metadata.${index}.key`,
|
|
10973
|
-
render: ({ field: field2 }) => {
|
|
10974
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10975
|
-
GridInput,
|
|
10976
|
-
{
|
|
10977
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10978
|
-
...field2,
|
|
10979
|
-
disabled: isDisabled,
|
|
10980
|
-
placeholder: "Key"
|
|
10981
|
-
}
|
|
10982
|
-
) }) });
|
|
10983
|
-
}
|
|
10984
|
-
}
|
|
10985
|
-
),
|
|
10986
|
-
/* @__PURE__ */ jsx(
|
|
10987
|
-
Form$2.Field,
|
|
10988
|
-
{
|
|
10989
|
-
control: form.control,
|
|
10990
|
-
name: `metadata.${index}.value`,
|
|
10991
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
10992
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10993
|
-
GridInput,
|
|
10994
|
-
{
|
|
10995
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10996
|
-
...field2,
|
|
10997
|
-
value: isDisabled ? placeholder : value,
|
|
10998
|
-
disabled: isDisabled,
|
|
10999
|
-
placeholder: "Value"
|
|
11000
|
-
}
|
|
11001
|
-
) }) });
|
|
11002
|
-
}
|
|
11003
|
-
}
|
|
11004
|
-
)
|
|
11005
|
-
]
|
|
11006
|
-
}
|
|
11007
|
-
),
|
|
11008
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
11009
|
-
/* @__PURE__ */ jsx(
|
|
11010
|
-
DropdownMenu.Trigger,
|
|
11011
|
-
{
|
|
11012
|
-
className: clx(
|
|
11013
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11014
|
-
{
|
|
11015
|
-
hidden: isDisabled
|
|
11016
|
-
}
|
|
11017
|
-
),
|
|
11018
|
-
disabled: isDisabled,
|
|
11019
|
-
asChild: true,
|
|
11020
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11021
|
-
}
|
|
11022
|
-
),
|
|
11023
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11024
|
-
/* @__PURE__ */ jsxs(
|
|
11025
|
-
DropdownMenu.Item,
|
|
11026
|
-
{
|
|
11027
|
-
className: "gap-x-2",
|
|
11028
|
-
onClick: () => insertRow(index, "above"),
|
|
11029
|
-
children: [
|
|
11030
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11031
|
-
"Insert row above"
|
|
11032
|
-
]
|
|
11033
|
-
}
|
|
11034
|
-
),
|
|
11035
|
-
/* @__PURE__ */ jsxs(
|
|
11036
|
-
DropdownMenu.Item,
|
|
11037
|
-
{
|
|
11038
|
-
className: "gap-x-2",
|
|
11039
|
-
onClick: () => insertRow(index, "below"),
|
|
11040
|
-
children: [
|
|
11041
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11042
|
-
"Insert row below"
|
|
11043
|
-
]
|
|
11044
|
-
}
|
|
11045
|
-
),
|
|
11046
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11047
|
-
/* @__PURE__ */ jsxs(
|
|
11048
|
-
DropdownMenu.Item,
|
|
11049
|
-
{
|
|
11050
|
-
className: "gap-x-2",
|
|
11051
|
-
onClick: () => deleteRow(index),
|
|
11052
|
-
children: [
|
|
11053
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11054
|
-
"Delete row"
|
|
11055
|
-
]
|
|
11056
|
-
}
|
|
11057
|
-
)
|
|
11058
|
-
] })
|
|
11059
|
-
] })
|
|
11060
|
-
] })
|
|
11061
|
-
},
|
|
11062
|
-
field.id
|
|
11063
|
-
);
|
|
11064
|
-
})
|
|
11065
|
-
] }),
|
|
11066
|
-
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
11067
|
-
] }),
|
|
11068
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11069
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10875
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
10876
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10877
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11070
10878
|
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11071
10879
|
] }) })
|
|
11072
10880
|
]
|
|
11073
10881
|
}
|
|
11074
10882
|
) });
|
|
11075
10883
|
};
|
|
11076
|
-
const
|
|
10884
|
+
const SalesChannelField = ({ control, order }) => {
|
|
10885
|
+
const salesChannels = useComboboxData({
|
|
10886
|
+
queryFn: async (params) => {
|
|
10887
|
+
return await sdk.admin.salesChannel.list(params);
|
|
10888
|
+
},
|
|
10889
|
+
queryKey: ["sales-channels"],
|
|
10890
|
+
getOptions: (data) => {
|
|
10891
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
10892
|
+
label: salesChannel.name,
|
|
10893
|
+
value: salesChannel.id
|
|
10894
|
+
}));
|
|
10895
|
+
},
|
|
10896
|
+
defaultValue: order.sales_channel_id || void 0
|
|
10897
|
+
});
|
|
11077
10898
|
return /* @__PURE__ */ jsx(
|
|
11078
|
-
|
|
10899
|
+
Form$2.Field,
|
|
11079
10900
|
{
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11083
|
-
|
|
11084
|
-
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11099
|
-
};
|
|
11100
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11101
|
-
function getDefaultValues(metadata) {
|
|
11102
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
11103
|
-
return [
|
|
11104
|
-
{
|
|
11105
|
-
key: "",
|
|
11106
|
-
value: "",
|
|
11107
|
-
disabled: false
|
|
11108
|
-
}
|
|
11109
|
-
];
|
|
11110
|
-
}
|
|
11111
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
11112
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11113
|
-
return {
|
|
11114
|
-
key,
|
|
11115
|
-
value,
|
|
11116
|
-
disabled: true
|
|
11117
|
-
};
|
|
11118
|
-
}
|
|
11119
|
-
let stringValue = value;
|
|
11120
|
-
if (typeof value !== "string") {
|
|
11121
|
-
stringValue = JSON.stringify(value);
|
|
11122
|
-
}
|
|
11123
|
-
return {
|
|
11124
|
-
key,
|
|
11125
|
-
value: stringValue,
|
|
11126
|
-
original_key: key
|
|
11127
|
-
};
|
|
11128
|
-
});
|
|
11129
|
-
}
|
|
11130
|
-
function parseValues(values) {
|
|
11131
|
-
const metadata = values.metadata;
|
|
11132
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11133
|
-
if (isEmpty) {
|
|
11134
|
-
return null;
|
|
11135
|
-
}
|
|
11136
|
-
const update = {};
|
|
11137
|
-
metadata.forEach((field) => {
|
|
11138
|
-
let key = field.key;
|
|
11139
|
-
let value = field.value;
|
|
11140
|
-
const disabled = field.disabled;
|
|
11141
|
-
if (!key || !value) {
|
|
11142
|
-
return;
|
|
11143
|
-
}
|
|
11144
|
-
if (disabled) {
|
|
11145
|
-
update[key] = value;
|
|
11146
|
-
return;
|
|
11147
|
-
}
|
|
11148
|
-
key = key.trim();
|
|
11149
|
-
value = value.trim();
|
|
11150
|
-
if (value === "true") {
|
|
11151
|
-
update[key] = true;
|
|
11152
|
-
} else if (value === "false") {
|
|
11153
|
-
update[key] = false;
|
|
11154
|
-
} else {
|
|
11155
|
-
const parsedNumber = parseFloat(value);
|
|
11156
|
-
if (!isNaN(parsedNumber)) {
|
|
11157
|
-
update[key] = parsedNumber;
|
|
11158
|
-
} else {
|
|
11159
|
-
update[key] = value;
|
|
10901
|
+
control,
|
|
10902
|
+
name: "sales_channel_id",
|
|
10903
|
+
render: ({ field }) => {
|
|
10904
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
10905
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
10906
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10907
|
+
Combobox,
|
|
10908
|
+
{
|
|
10909
|
+
options: salesChannels.options,
|
|
10910
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
10911
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
10912
|
+
searchValue: salesChannels.searchValue,
|
|
10913
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
10914
|
+
placeholder: "Select sales channel",
|
|
10915
|
+
...field
|
|
10916
|
+
}
|
|
10917
|
+
) }),
|
|
10918
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10919
|
+
] });
|
|
11160
10920
|
}
|
|
11161
10921
|
}
|
|
11162
|
-
});
|
|
11163
|
-
return update;
|
|
11164
|
-
}
|
|
11165
|
-
function getHasUneditableRows(metadata) {
|
|
11166
|
-
if (!metadata) {
|
|
11167
|
-
return false;
|
|
11168
|
-
}
|
|
11169
|
-
return Object.values(metadata).some(
|
|
11170
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11171
10922
|
);
|
|
11172
|
-
}
|
|
10923
|
+
};
|
|
10924
|
+
const schema$2 = objectType({
|
|
10925
|
+
sales_channel_id: stringType().min(1)
|
|
10926
|
+
});
|
|
11173
10927
|
const PROMOTION_QUERY_KEY = "promotions";
|
|
11174
10928
|
const promotionsQueryKeys = {
|
|
11175
10929
|
list: (query2) => [
|
|
@@ -11447,115 +11201,9 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
11447
11201
|
}
|
|
11448
11202
|
return Array.from(promotionIds);
|
|
11449
11203
|
}
|
|
11450
|
-
const
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
id,
|
|
11454
|
-
{
|
|
11455
|
-
fields: "+sales_channel_id"
|
|
11456
|
-
},
|
|
11457
|
-
{
|
|
11458
|
-
enabled: !!id
|
|
11459
|
-
}
|
|
11460
|
-
);
|
|
11461
|
-
if (isError) {
|
|
11462
|
-
throw error;
|
|
11463
|
-
}
|
|
11464
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
11465
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11466
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11467
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11468
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11469
|
-
] }),
|
|
11470
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11471
|
-
] });
|
|
11472
|
-
};
|
|
11473
|
-
const SalesChannelForm = ({ order }) => {
|
|
11474
|
-
const form = useForm({
|
|
11475
|
-
defaultValues: {
|
|
11476
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11477
|
-
},
|
|
11478
|
-
resolver: zodResolver(schema$2)
|
|
11479
|
-
});
|
|
11480
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11481
|
-
const { handleSuccess } = useRouteModal();
|
|
11482
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11483
|
-
await mutateAsync(
|
|
11484
|
-
{
|
|
11485
|
-
sales_channel_id: data.sales_channel_id
|
|
11486
|
-
},
|
|
11487
|
-
{
|
|
11488
|
-
onSuccess: () => {
|
|
11489
|
-
toast.success("Sales channel updated");
|
|
11490
|
-
handleSuccess();
|
|
11491
|
-
},
|
|
11492
|
-
onError: (error) => {
|
|
11493
|
-
toast.error(error.message);
|
|
11494
|
-
}
|
|
11495
|
-
}
|
|
11496
|
-
);
|
|
11497
|
-
});
|
|
11498
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11499
|
-
KeyboundForm,
|
|
11500
|
-
{
|
|
11501
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11502
|
-
onSubmit,
|
|
11503
|
-
children: [
|
|
11504
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11505
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11506
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11507
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11508
|
-
] }) })
|
|
11509
|
-
]
|
|
11510
|
-
}
|
|
11511
|
-
) });
|
|
11512
|
-
};
|
|
11513
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11514
|
-
const salesChannels = useComboboxData({
|
|
11515
|
-
queryFn: async (params) => {
|
|
11516
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11517
|
-
},
|
|
11518
|
-
queryKey: ["sales-channels"],
|
|
11519
|
-
getOptions: (data) => {
|
|
11520
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11521
|
-
label: salesChannel.name,
|
|
11522
|
-
value: salesChannel.id
|
|
11523
|
-
}));
|
|
11524
|
-
},
|
|
11525
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11526
|
-
});
|
|
11527
|
-
return /* @__PURE__ */ jsx(
|
|
11528
|
-
Form$2.Field,
|
|
11529
|
-
{
|
|
11530
|
-
control,
|
|
11531
|
-
name: "sales_channel_id",
|
|
11532
|
-
render: ({ field }) => {
|
|
11533
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11534
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11535
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11536
|
-
Combobox,
|
|
11537
|
-
{
|
|
11538
|
-
options: salesChannels.options,
|
|
11539
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11540
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11541
|
-
searchValue: salesChannels.searchValue,
|
|
11542
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11543
|
-
placeholder: "Select sales channel",
|
|
11544
|
-
...field
|
|
11545
|
-
}
|
|
11546
|
-
) }),
|
|
11547
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11548
|
-
] });
|
|
11549
|
-
}
|
|
11550
|
-
}
|
|
11551
|
-
);
|
|
11552
|
-
};
|
|
11553
|
-
const schema$2 = objectType({
|
|
11554
|
-
sales_channel_id: stringType().min(1)
|
|
11555
|
-
});
|
|
11556
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11557
|
-
const Shipping = () => {
|
|
11558
|
-
var _a;
|
|
11204
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11205
|
+
const Shipping = () => {
|
|
11206
|
+
var _a;
|
|
11559
11207
|
const { id } = useParams();
|
|
11560
11208
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
11561
11209
|
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
@@ -13039,6 +12687,356 @@ const Illustration = () => {
|
|
|
13039
12687
|
const schema = objectType({
|
|
13040
12688
|
customer_id: stringType().min(1)
|
|
13041
12689
|
});
|
|
12690
|
+
const InlineTip = forwardRef(
|
|
12691
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
12692
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
12693
|
+
return /* @__PURE__ */ jsxs(
|
|
12694
|
+
"div",
|
|
12695
|
+
{
|
|
12696
|
+
ref,
|
|
12697
|
+
className: clx(
|
|
12698
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
12699
|
+
className
|
|
12700
|
+
),
|
|
12701
|
+
...props,
|
|
12702
|
+
children: [
|
|
12703
|
+
/* @__PURE__ */ jsx(
|
|
12704
|
+
"div",
|
|
12705
|
+
{
|
|
12706
|
+
role: "presentation",
|
|
12707
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
12708
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
12709
|
+
})
|
|
12710
|
+
}
|
|
12711
|
+
),
|
|
12712
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
12713
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
12714
|
+
labelValue,
|
|
12715
|
+
":"
|
|
12716
|
+
] }),
|
|
12717
|
+
" ",
|
|
12718
|
+
children
|
|
12719
|
+
] })
|
|
12720
|
+
]
|
|
12721
|
+
}
|
|
12722
|
+
);
|
|
12723
|
+
}
|
|
12724
|
+
);
|
|
12725
|
+
InlineTip.displayName = "InlineTip";
|
|
12726
|
+
const MetadataFieldSchema = objectType({
|
|
12727
|
+
key: stringType(),
|
|
12728
|
+
disabled: booleanType().optional(),
|
|
12729
|
+
value: anyType()
|
|
12730
|
+
});
|
|
12731
|
+
const MetadataSchema = objectType({
|
|
12732
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
12733
|
+
});
|
|
12734
|
+
const Metadata = () => {
|
|
12735
|
+
const { id } = useParams();
|
|
12736
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12737
|
+
fields: "metadata"
|
|
12738
|
+
});
|
|
12739
|
+
if (isError) {
|
|
12740
|
+
throw error;
|
|
12741
|
+
}
|
|
12742
|
+
const isReady = !isPending && !!order;
|
|
12743
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12744
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12745
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
12746
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
12747
|
+
] }),
|
|
12748
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
12749
|
+
] });
|
|
12750
|
+
};
|
|
12751
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
12752
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
12753
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
12754
|
+
const { handleSuccess } = useRouteModal();
|
|
12755
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
12756
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
12757
|
+
const form = useForm({
|
|
12758
|
+
defaultValues: {
|
|
12759
|
+
metadata: getDefaultValues(metadata)
|
|
12760
|
+
},
|
|
12761
|
+
resolver: zodResolver(MetadataSchema)
|
|
12762
|
+
});
|
|
12763
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
12764
|
+
const parsedData = parseValues(data);
|
|
12765
|
+
await mutateAsync(
|
|
12766
|
+
{
|
|
12767
|
+
metadata: parsedData
|
|
12768
|
+
},
|
|
12769
|
+
{
|
|
12770
|
+
onSuccess: () => {
|
|
12771
|
+
toast.success("Metadata updated");
|
|
12772
|
+
handleSuccess();
|
|
12773
|
+
},
|
|
12774
|
+
onError: (error) => {
|
|
12775
|
+
toast.error(error.message);
|
|
12776
|
+
}
|
|
12777
|
+
}
|
|
12778
|
+
);
|
|
12779
|
+
});
|
|
12780
|
+
const { fields, insert, remove } = useFieldArray({
|
|
12781
|
+
control: form.control,
|
|
12782
|
+
name: "metadata"
|
|
12783
|
+
});
|
|
12784
|
+
function deleteRow(index) {
|
|
12785
|
+
remove(index);
|
|
12786
|
+
if (fields.length === 1) {
|
|
12787
|
+
insert(0, {
|
|
12788
|
+
key: "",
|
|
12789
|
+
value: "",
|
|
12790
|
+
disabled: false
|
|
12791
|
+
});
|
|
12792
|
+
}
|
|
12793
|
+
}
|
|
12794
|
+
function insertRow(index, position) {
|
|
12795
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
12796
|
+
key: "",
|
|
12797
|
+
value: "",
|
|
12798
|
+
disabled: false
|
|
12799
|
+
});
|
|
12800
|
+
}
|
|
12801
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12802
|
+
KeyboundForm,
|
|
12803
|
+
{
|
|
12804
|
+
onSubmit: handleSubmit,
|
|
12805
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12806
|
+
children: [
|
|
12807
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
12808
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
12809
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
12810
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
12811
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
12812
|
+
] }),
|
|
12813
|
+
fields.map((field, index) => {
|
|
12814
|
+
const isDisabled = field.disabled || false;
|
|
12815
|
+
let placeholder = "-";
|
|
12816
|
+
if (typeof field.value === "object") {
|
|
12817
|
+
placeholder = "{ ... }";
|
|
12818
|
+
}
|
|
12819
|
+
if (Array.isArray(field.value)) {
|
|
12820
|
+
placeholder = "[ ... ]";
|
|
12821
|
+
}
|
|
12822
|
+
return /* @__PURE__ */ jsx(
|
|
12823
|
+
ConditionalTooltip,
|
|
12824
|
+
{
|
|
12825
|
+
showTooltip: isDisabled,
|
|
12826
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
12827
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
12828
|
+
/* @__PURE__ */ jsxs(
|
|
12829
|
+
"div",
|
|
12830
|
+
{
|
|
12831
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
12832
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
12833
|
+
}),
|
|
12834
|
+
children: [
|
|
12835
|
+
/* @__PURE__ */ jsx(
|
|
12836
|
+
Form$2.Field,
|
|
12837
|
+
{
|
|
12838
|
+
control: form.control,
|
|
12839
|
+
name: `metadata.${index}.key`,
|
|
12840
|
+
render: ({ field: field2 }) => {
|
|
12841
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12842
|
+
GridInput,
|
|
12843
|
+
{
|
|
12844
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
12845
|
+
...field2,
|
|
12846
|
+
disabled: isDisabled,
|
|
12847
|
+
placeholder: "Key"
|
|
12848
|
+
}
|
|
12849
|
+
) }) });
|
|
12850
|
+
}
|
|
12851
|
+
}
|
|
12852
|
+
),
|
|
12853
|
+
/* @__PURE__ */ jsx(
|
|
12854
|
+
Form$2.Field,
|
|
12855
|
+
{
|
|
12856
|
+
control: form.control,
|
|
12857
|
+
name: `metadata.${index}.value`,
|
|
12858
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
12859
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12860
|
+
GridInput,
|
|
12861
|
+
{
|
|
12862
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
12863
|
+
...field2,
|
|
12864
|
+
value: isDisabled ? placeholder : value,
|
|
12865
|
+
disabled: isDisabled,
|
|
12866
|
+
placeholder: "Value"
|
|
12867
|
+
}
|
|
12868
|
+
) }) });
|
|
12869
|
+
}
|
|
12870
|
+
}
|
|
12871
|
+
)
|
|
12872
|
+
]
|
|
12873
|
+
}
|
|
12874
|
+
),
|
|
12875
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
12876
|
+
/* @__PURE__ */ jsx(
|
|
12877
|
+
DropdownMenu.Trigger,
|
|
12878
|
+
{
|
|
12879
|
+
className: clx(
|
|
12880
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
12881
|
+
{
|
|
12882
|
+
hidden: isDisabled
|
|
12883
|
+
}
|
|
12884
|
+
),
|
|
12885
|
+
disabled: isDisabled,
|
|
12886
|
+
asChild: true,
|
|
12887
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
12888
|
+
}
|
|
12889
|
+
),
|
|
12890
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
12891
|
+
/* @__PURE__ */ jsxs(
|
|
12892
|
+
DropdownMenu.Item,
|
|
12893
|
+
{
|
|
12894
|
+
className: "gap-x-2",
|
|
12895
|
+
onClick: () => insertRow(index, "above"),
|
|
12896
|
+
children: [
|
|
12897
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
12898
|
+
"Insert row above"
|
|
12899
|
+
]
|
|
12900
|
+
}
|
|
12901
|
+
),
|
|
12902
|
+
/* @__PURE__ */ jsxs(
|
|
12903
|
+
DropdownMenu.Item,
|
|
12904
|
+
{
|
|
12905
|
+
className: "gap-x-2",
|
|
12906
|
+
onClick: () => insertRow(index, "below"),
|
|
12907
|
+
children: [
|
|
12908
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
12909
|
+
"Insert row below"
|
|
12910
|
+
]
|
|
12911
|
+
}
|
|
12912
|
+
),
|
|
12913
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
12914
|
+
/* @__PURE__ */ jsxs(
|
|
12915
|
+
DropdownMenu.Item,
|
|
12916
|
+
{
|
|
12917
|
+
className: "gap-x-2",
|
|
12918
|
+
onClick: () => deleteRow(index),
|
|
12919
|
+
children: [
|
|
12920
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
12921
|
+
"Delete row"
|
|
12922
|
+
]
|
|
12923
|
+
}
|
|
12924
|
+
)
|
|
12925
|
+
] })
|
|
12926
|
+
] })
|
|
12927
|
+
] })
|
|
12928
|
+
},
|
|
12929
|
+
field.id
|
|
12930
|
+
);
|
|
12931
|
+
})
|
|
12932
|
+
] }),
|
|
12933
|
+
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
12934
|
+
] }),
|
|
12935
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12936
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12937
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12938
|
+
] }) })
|
|
12939
|
+
]
|
|
12940
|
+
}
|
|
12941
|
+
) });
|
|
12942
|
+
};
|
|
12943
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
12944
|
+
return /* @__PURE__ */ jsx(
|
|
12945
|
+
"input",
|
|
12946
|
+
{
|
|
12947
|
+
ref,
|
|
12948
|
+
...props,
|
|
12949
|
+
autoComplete: "off",
|
|
12950
|
+
className: clx(
|
|
12951
|
+
"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",
|
|
12952
|
+
className
|
|
12953
|
+
)
|
|
12954
|
+
}
|
|
12955
|
+
);
|
|
12956
|
+
});
|
|
12957
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
12958
|
+
const PlaceholderInner = () => {
|
|
12959
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
12960
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
12961
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12962
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
12963
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
12964
|
+
] }) })
|
|
12965
|
+
] });
|
|
12966
|
+
};
|
|
12967
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
12968
|
+
function getDefaultValues(metadata) {
|
|
12969
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
12970
|
+
return [
|
|
12971
|
+
{
|
|
12972
|
+
key: "",
|
|
12973
|
+
value: "",
|
|
12974
|
+
disabled: false
|
|
12975
|
+
}
|
|
12976
|
+
];
|
|
12977
|
+
}
|
|
12978
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
12979
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
12980
|
+
return {
|
|
12981
|
+
key,
|
|
12982
|
+
value,
|
|
12983
|
+
disabled: true
|
|
12984
|
+
};
|
|
12985
|
+
}
|
|
12986
|
+
let stringValue = value;
|
|
12987
|
+
if (typeof value !== "string") {
|
|
12988
|
+
stringValue = JSON.stringify(value);
|
|
12989
|
+
}
|
|
12990
|
+
return {
|
|
12991
|
+
key,
|
|
12992
|
+
value: stringValue,
|
|
12993
|
+
original_key: key
|
|
12994
|
+
};
|
|
12995
|
+
});
|
|
12996
|
+
}
|
|
12997
|
+
function parseValues(values) {
|
|
12998
|
+
const metadata = values.metadata;
|
|
12999
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
13000
|
+
if (isEmpty) {
|
|
13001
|
+
return null;
|
|
13002
|
+
}
|
|
13003
|
+
const update = {};
|
|
13004
|
+
metadata.forEach((field) => {
|
|
13005
|
+
let key = field.key;
|
|
13006
|
+
let value = field.value;
|
|
13007
|
+
const disabled = field.disabled;
|
|
13008
|
+
if (!key || !value) {
|
|
13009
|
+
return;
|
|
13010
|
+
}
|
|
13011
|
+
if (disabled) {
|
|
13012
|
+
update[key] = value;
|
|
13013
|
+
return;
|
|
13014
|
+
}
|
|
13015
|
+
key = key.trim();
|
|
13016
|
+
value = value.trim();
|
|
13017
|
+
if (value === "true") {
|
|
13018
|
+
update[key] = true;
|
|
13019
|
+
} else if (value === "false") {
|
|
13020
|
+
update[key] = false;
|
|
13021
|
+
} else {
|
|
13022
|
+
const parsedNumber = parseFloat(value);
|
|
13023
|
+
if (!isNaN(parsedNumber)) {
|
|
13024
|
+
update[key] = parsedNumber;
|
|
13025
|
+
} else {
|
|
13026
|
+
update[key] = value;
|
|
13027
|
+
}
|
|
13028
|
+
}
|
|
13029
|
+
});
|
|
13030
|
+
return update;
|
|
13031
|
+
}
|
|
13032
|
+
function getHasUneditableRows(metadata) {
|
|
13033
|
+
if (!metadata) {
|
|
13034
|
+
return false;
|
|
13035
|
+
}
|
|
13036
|
+
return Object.values(metadata).some(
|
|
13037
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
13038
|
+
);
|
|
13039
|
+
}
|
|
13042
13040
|
const widgetModule = { widgets: [] };
|
|
13043
13041
|
const routeModule = {
|
|
13044
13042
|
routes: [
|
|
@@ -13067,26 +13065,22 @@ const routeModule = {
|
|
|
13067
13065
|
Component: BillingAddress,
|
|
13068
13066
|
path: "/draft-orders/:id/billing-address"
|
|
13069
13067
|
},
|
|
13070
|
-
{
|
|
13071
|
-
Component: Email,
|
|
13072
|
-
path: "/draft-orders/:id/email"
|
|
13073
|
-
},
|
|
13074
13068
|
{
|
|
13075
13069
|
Component: Items,
|
|
13076
13070
|
path: "/draft-orders/:id/items"
|
|
13077
13071
|
},
|
|
13078
13072
|
{
|
|
13079
|
-
Component:
|
|
13080
|
-
path: "/draft-orders/:id/
|
|
13081
|
-
},
|
|
13082
|
-
{
|
|
13083
|
-
Component: Promotions,
|
|
13084
|
-
path: "/draft-orders/:id/promotions"
|
|
13073
|
+
Component: Email,
|
|
13074
|
+
path: "/draft-orders/:id/email"
|
|
13085
13075
|
},
|
|
13086
13076
|
{
|
|
13087
13077
|
Component: SalesChannel,
|
|
13088
13078
|
path: "/draft-orders/:id/sales-channel"
|
|
13089
13079
|
},
|
|
13080
|
+
{
|
|
13081
|
+
Component: Promotions,
|
|
13082
|
+
path: "/draft-orders/:id/promotions"
|
|
13083
|
+
},
|
|
13090
13084
|
{
|
|
13091
13085
|
Component: Shipping,
|
|
13092
13086
|
path: "/draft-orders/:id/shipping"
|
|
@@ -13098,6 +13092,10 @@ const routeModule = {
|
|
|
13098
13092
|
{
|
|
13099
13093
|
Component: TransferOwnership,
|
|
13100
13094
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13095
|
+
},
|
|
13096
|
+
{
|
|
13097
|
+
Component: Metadata,
|
|
13098
|
+
path: "/draft-orders/:id/metadata"
|
|
13101
13099
|
}
|
|
13102
13100
|
]
|
|
13103
13101
|
}
|