@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
|
@@ -9778,6 +9778,74 @@ const CustomItemsForm = () => {
|
|
|
9778
9778
|
const schema$4 = objectType({
|
|
9779
9779
|
email: stringType().email()
|
|
9780
9780
|
});
|
|
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
|
+
});
|
|
9781
9849
|
const NumberInput = forwardRef(
|
|
9782
9850
|
({
|
|
9783
9851
|
value,
|
|
@@ -10752,10 +10820,54 @@ const customItemSchema = objectType({
|
|
|
10752
10820
|
quantity: numberType(),
|
|
10753
10821
|
unit_price: unionType([numberType(), stringType()])
|
|
10754
10822
|
});
|
|
10755
|
-
const
|
|
10823
|
+
const InlineTip = forwardRef(
|
|
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 = () => {
|
|
10756
10868
|
const { id } = useParams();
|
|
10757
10869
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
10758
|
-
fields: "
|
|
10870
|
+
fields: "metadata"
|
|
10759
10871
|
});
|
|
10760
10872
|
if (isError) {
|
|
10761
10873
|
throw error;
|
|
@@ -10763,26 +10875,33 @@ const Email = () => {
|
|
|
10763
10875
|
const isReady = !isPending && !!order;
|
|
10764
10876
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10765
10877
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10766
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
10767
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
10878
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10879
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10768
10880
|
] }),
|
|
10769
|
-
isReady
|
|
10881
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10770
10882
|
] });
|
|
10771
10883
|
};
|
|
10772
|
-
const
|
|
10884
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10885
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10886
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10887
|
+
const { handleSuccess } = useRouteModal();
|
|
10888
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10889
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10773
10890
|
const form = useForm({
|
|
10774
10891
|
defaultValues: {
|
|
10775
|
-
|
|
10892
|
+
metadata: getDefaultValues(metadata)
|
|
10776
10893
|
},
|
|
10777
|
-
resolver: zodResolver(
|
|
10894
|
+
resolver: zodResolver(MetadataSchema)
|
|
10778
10895
|
});
|
|
10779
|
-
const
|
|
10780
|
-
|
|
10781
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10896
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10897
|
+
const parsedData = parseValues(data);
|
|
10782
10898
|
await mutateAsync(
|
|
10783
|
-
{
|
|
10899
|
+
{
|
|
10900
|
+
metadata: parsedData
|
|
10901
|
+
},
|
|
10784
10902
|
{
|
|
10785
10903
|
onSuccess: () => {
|
|
10904
|
+
toast.success("Metadata updated");
|
|
10786
10905
|
handleSuccess();
|
|
10787
10906
|
},
|
|
10788
10907
|
onError: (error) => {
|
|
@@ -10791,102 +10910,333 @@ const EmailForm = ({ order }) => {
|
|
|
10791
10910
|
}
|
|
10792
10911
|
);
|
|
10793
10912
|
});
|
|
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
|
+
}
|
|
10794
10934
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10795
10935
|
KeyboundForm,
|
|
10796
10936
|
{
|
|
10937
|
+
onSubmit: handleSubmit,
|
|
10797
10938
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
10798
|
-
onSubmit,
|
|
10799
10939
|
children: [
|
|
10800
|
-
/* @__PURE__ */
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10805
|
-
|
|
10806
|
-
|
|
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
|
-
|
|
10940
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10941
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10942
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
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" }) }),
|
|
11070
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11071
|
+
] }) })
|
|
11072
|
+
]
|
|
11073
|
+
}
|
|
11074
|
+
) });
|
|
11075
|
+
};
|
|
11076
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11077
|
+
return /* @__PURE__ */ jsx(
|
|
11078
|
+
"input",
|
|
11079
|
+
{
|
|
11080
|
+
ref,
|
|
11081
|
+
...props,
|
|
11082
|
+
autoComplete: "off",
|
|
11083
|
+
className: clx(
|
|
11084
|
+
"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",
|
|
11085
|
+
className
|
|
11086
|
+
)
|
|
11087
|
+
}
|
|
11088
|
+
);
|
|
11089
|
+
});
|
|
11090
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11091
|
+
const PlaceholderInner = () => {
|
|
11092
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11093
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11094
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11095
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11096
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
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;
|
|
11160
|
+
}
|
|
11161
|
+
}
|
|
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
|
+
);
|
|
11172
|
+
}
|
|
11173
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11174
|
+
const promotionsQueryKeys = {
|
|
11175
|
+
list: (query2) => [
|
|
11176
|
+
PROMOTION_QUERY_KEY,
|
|
11177
|
+
query2 ? query2 : void 0
|
|
11178
|
+
],
|
|
11179
|
+
detail: (id, query2) => [
|
|
11180
|
+
PROMOTION_QUERY_KEY,
|
|
11181
|
+
id,
|
|
11182
|
+
query2 ? query2 : void 0
|
|
11183
|
+
]
|
|
11184
|
+
};
|
|
11185
|
+
const usePromotions = (query2, options) => {
|
|
11186
|
+
const { data, ...rest } = useQuery({
|
|
11187
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11188
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11189
|
+
...options
|
|
11190
|
+
});
|
|
11191
|
+
return { ...data, ...rest };
|
|
11192
|
+
};
|
|
11193
|
+
const Promotions = () => {
|
|
11194
|
+
const { id } = useParams();
|
|
11195
|
+
const {
|
|
11196
|
+
order: preview,
|
|
11197
|
+
isError: isPreviewError,
|
|
11198
|
+
error: previewError
|
|
11199
|
+
} = useOrderPreview(id, void 0);
|
|
11200
|
+
useInitiateOrderEdit({ preview });
|
|
11201
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11202
|
+
if (isPreviewError) {
|
|
11203
|
+
throw previewError;
|
|
11204
|
+
}
|
|
11205
|
+
const isReady = !!preview;
|
|
11206
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11207
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
11208
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
11209
|
+
] });
|
|
11210
|
+
};
|
|
11211
|
+
const PromotionForm = ({ preview }) => {
|
|
11212
|
+
const { items, shipping_methods } = preview;
|
|
11213
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11214
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
11215
|
+
const { handleSuccess } = useRouteModal();
|
|
11216
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11217
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11218
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11219
|
+
{
|
|
11220
|
+
id: promoIds
|
|
11221
|
+
},
|
|
11222
|
+
{
|
|
11223
|
+
enabled: !!promoIds.length
|
|
11224
|
+
}
|
|
11225
|
+
);
|
|
11226
|
+
const comboboxData = useComboboxData({
|
|
11227
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11228
|
+
queryFn: async (params) => {
|
|
11229
|
+
return await sdk.admin.promotion.list({
|
|
11230
|
+
...params,
|
|
11231
|
+
id: {
|
|
11232
|
+
$nin: promoIds
|
|
11233
|
+
}
|
|
11234
|
+
});
|
|
11235
|
+
},
|
|
11236
|
+
getOptions: (data) => {
|
|
11237
|
+
return data.promotions.map((promotion) => ({
|
|
11238
|
+
label: promotion.code,
|
|
11239
|
+
value: promotion.code
|
|
10890
11240
|
}));
|
|
10891
11241
|
}
|
|
10892
11242
|
});
|
|
@@ -11097,88 +11447,46 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
11097
11447
|
}
|
|
11098
11448
|
return Array.from(promotionIds);
|
|
11099
11449
|
}
|
|
11100
|
-
const
|
|
11101
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11102
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11103
|
-
return /* @__PURE__ */ jsxs(
|
|
11104
|
-
"div",
|
|
11105
|
-
{
|
|
11106
|
-
ref,
|
|
11107
|
-
className: clx(
|
|
11108
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11109
|
-
className
|
|
11110
|
-
),
|
|
11111
|
-
...props,
|
|
11112
|
-
children: [
|
|
11113
|
-
/* @__PURE__ */ jsx(
|
|
11114
|
-
"div",
|
|
11115
|
-
{
|
|
11116
|
-
role: "presentation",
|
|
11117
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11118
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11119
|
-
})
|
|
11120
|
-
}
|
|
11121
|
-
),
|
|
11122
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
11123
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11124
|
-
labelValue,
|
|
11125
|
-
":"
|
|
11126
|
-
] }),
|
|
11127
|
-
" ",
|
|
11128
|
-
children
|
|
11129
|
-
] })
|
|
11130
|
-
]
|
|
11131
|
-
}
|
|
11132
|
-
);
|
|
11133
|
-
}
|
|
11134
|
-
);
|
|
11135
|
-
InlineTip.displayName = "InlineTip";
|
|
11136
|
-
const MetadataFieldSchema = objectType({
|
|
11137
|
-
key: stringType(),
|
|
11138
|
-
disabled: booleanType().optional(),
|
|
11139
|
-
value: anyType()
|
|
11140
|
-
});
|
|
11141
|
-
const MetadataSchema = objectType({
|
|
11142
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
11143
|
-
});
|
|
11144
|
-
const Metadata = () => {
|
|
11450
|
+
const SalesChannel = () => {
|
|
11145
11451
|
const { id } = useParams();
|
|
11146
|
-
const {
|
|
11147
|
-
|
|
11148
|
-
|
|
11452
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11453
|
+
id,
|
|
11454
|
+
{
|
|
11455
|
+
fields: "+sales_channel_id"
|
|
11456
|
+
},
|
|
11457
|
+
{
|
|
11458
|
+
enabled: !!id
|
|
11459
|
+
}
|
|
11460
|
+
);
|
|
11149
11461
|
if (isError) {
|
|
11150
11462
|
throw error;
|
|
11151
11463
|
}
|
|
11152
|
-
const
|
|
11464
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11153
11465
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11154
11466
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11155
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
11156
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", 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" }) })
|
|
11157
11469
|
] }),
|
|
11158
|
-
|
|
11470
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11159
11471
|
] });
|
|
11160
11472
|
};
|
|
11161
|
-
const
|
|
11162
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11163
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
11164
|
-
const { handleSuccess } = useRouteModal();
|
|
11165
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11166
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11473
|
+
const SalesChannelForm = ({ order }) => {
|
|
11167
11474
|
const form = useForm({
|
|
11168
11475
|
defaultValues: {
|
|
11169
|
-
|
|
11476
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11170
11477
|
},
|
|
11171
|
-
resolver: zodResolver(
|
|
11478
|
+
resolver: zodResolver(schema$2)
|
|
11172
11479
|
});
|
|
11173
|
-
const
|
|
11174
|
-
|
|
11480
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11481
|
+
const { handleSuccess } = useRouteModal();
|
|
11482
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11175
11483
|
await mutateAsync(
|
|
11176
11484
|
{
|
|
11177
|
-
|
|
11485
|
+
sales_channel_id: data.sales_channel_id
|
|
11178
11486
|
},
|
|
11179
11487
|
{
|
|
11180
11488
|
onSuccess: () => {
|
|
11181
|
-
toast.success("
|
|
11489
|
+
toast.success("Sales channel updated");
|
|
11182
11490
|
handleSuccess();
|
|
11183
11491
|
},
|
|
11184
11492
|
onError: (error) => {
|
|
@@ -11187,266 +11495,64 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
11187
11495
|
}
|
|
11188
11496
|
);
|
|
11189
11497
|
});
|
|
11190
|
-
const { fields, insert, remove } = useFieldArray({
|
|
11191
|
-
control: form.control,
|
|
11192
|
-
name: "metadata"
|
|
11193
|
-
});
|
|
11194
|
-
function deleteRow(index) {
|
|
11195
|
-
remove(index);
|
|
11196
|
-
if (fields.length === 1) {
|
|
11197
|
-
insert(0, {
|
|
11198
|
-
key: "",
|
|
11199
|
-
value: "",
|
|
11200
|
-
disabled: false
|
|
11201
|
-
});
|
|
11202
|
-
}
|
|
11203
|
-
}
|
|
11204
|
-
function insertRow(index, position) {
|
|
11205
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
11206
|
-
key: "",
|
|
11207
|
-
value: "",
|
|
11208
|
-
disabled: false
|
|
11209
|
-
});
|
|
11210
|
-
}
|
|
11211
11498
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11212
11499
|
KeyboundForm,
|
|
11213
11500
|
{
|
|
11214
|
-
onSubmit: handleSubmit,
|
|
11215
11501
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
11216
|
-
|
|
11217
|
-
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
|
|
11221
|
-
/* @__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" }) })
|
|
11222
|
-
] }),
|
|
11223
|
-
fields.map((field, index) => {
|
|
11224
|
-
const isDisabled = field.disabled || false;
|
|
11225
|
-
let placeholder = "-";
|
|
11226
|
-
if (typeof field.value === "object") {
|
|
11227
|
-
placeholder = "{ ... }";
|
|
11228
|
-
}
|
|
11229
|
-
if (Array.isArray(field.value)) {
|
|
11230
|
-
placeholder = "[ ... ]";
|
|
11231
|
-
}
|
|
11232
|
-
return /* @__PURE__ */ jsx(
|
|
11233
|
-
ConditionalTooltip,
|
|
11234
|
-
{
|
|
11235
|
-
showTooltip: isDisabled,
|
|
11236
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
11237
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
11238
|
-
/* @__PURE__ */ jsxs(
|
|
11239
|
-
"div",
|
|
11240
|
-
{
|
|
11241
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
11242
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
11243
|
-
}),
|
|
11244
|
-
children: [
|
|
11245
|
-
/* @__PURE__ */ jsx(
|
|
11246
|
-
Form$2.Field,
|
|
11247
|
-
{
|
|
11248
|
-
control: form.control,
|
|
11249
|
-
name: `metadata.${index}.key`,
|
|
11250
|
-
render: ({ field: field2 }) => {
|
|
11251
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11252
|
-
GridInput,
|
|
11253
|
-
{
|
|
11254
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
11255
|
-
...field2,
|
|
11256
|
-
disabled: isDisabled,
|
|
11257
|
-
placeholder: "Key"
|
|
11258
|
-
}
|
|
11259
|
-
) }) });
|
|
11260
|
-
}
|
|
11261
|
-
}
|
|
11262
|
-
),
|
|
11263
|
-
/* @__PURE__ */ jsx(
|
|
11264
|
-
Form$2.Field,
|
|
11265
|
-
{
|
|
11266
|
-
control: form.control,
|
|
11267
|
-
name: `metadata.${index}.value`,
|
|
11268
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
11269
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11270
|
-
GridInput,
|
|
11271
|
-
{
|
|
11272
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
11273
|
-
...field2,
|
|
11274
|
-
value: isDisabled ? placeholder : value,
|
|
11275
|
-
disabled: isDisabled,
|
|
11276
|
-
placeholder: "Value"
|
|
11277
|
-
}
|
|
11278
|
-
) }) });
|
|
11279
|
-
}
|
|
11280
|
-
}
|
|
11281
|
-
)
|
|
11282
|
-
]
|
|
11283
|
-
}
|
|
11284
|
-
),
|
|
11285
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
11286
|
-
/* @__PURE__ */ jsx(
|
|
11287
|
-
DropdownMenu.Trigger,
|
|
11288
|
-
{
|
|
11289
|
-
className: clx(
|
|
11290
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11291
|
-
{
|
|
11292
|
-
hidden: isDisabled
|
|
11293
|
-
}
|
|
11294
|
-
),
|
|
11295
|
-
disabled: isDisabled,
|
|
11296
|
-
asChild: true,
|
|
11297
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11298
|
-
}
|
|
11299
|
-
),
|
|
11300
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11301
|
-
/* @__PURE__ */ jsxs(
|
|
11302
|
-
DropdownMenu.Item,
|
|
11303
|
-
{
|
|
11304
|
-
className: "gap-x-2",
|
|
11305
|
-
onClick: () => insertRow(index, "above"),
|
|
11306
|
-
children: [
|
|
11307
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11308
|
-
"Insert row above"
|
|
11309
|
-
]
|
|
11310
|
-
}
|
|
11311
|
-
),
|
|
11312
|
-
/* @__PURE__ */ jsxs(
|
|
11313
|
-
DropdownMenu.Item,
|
|
11314
|
-
{
|
|
11315
|
-
className: "gap-x-2",
|
|
11316
|
-
onClick: () => insertRow(index, "below"),
|
|
11317
|
-
children: [
|
|
11318
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11319
|
-
"Insert row below"
|
|
11320
|
-
]
|
|
11321
|
-
}
|
|
11322
|
-
),
|
|
11323
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11324
|
-
/* @__PURE__ */ jsxs(
|
|
11325
|
-
DropdownMenu.Item,
|
|
11326
|
-
{
|
|
11327
|
-
className: "gap-x-2",
|
|
11328
|
-
onClick: () => deleteRow(index),
|
|
11329
|
-
children: [
|
|
11330
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11331
|
-
"Delete row"
|
|
11332
|
-
]
|
|
11333
|
-
}
|
|
11334
|
-
)
|
|
11335
|
-
] })
|
|
11336
|
-
] })
|
|
11337
|
-
] })
|
|
11338
|
-
},
|
|
11339
|
-
field.id
|
|
11340
|
-
);
|
|
11341
|
-
})
|
|
11342
|
-
] }),
|
|
11343
|
-
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." })
|
|
11344
|
-
] }),
|
|
11345
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11346
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
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" }) }),
|
|
11347
11507
|
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11348
11508
|
] }) })
|
|
11349
11509
|
]
|
|
11350
11510
|
}
|
|
11351
11511
|
) });
|
|
11352
11512
|
};
|
|
11353
|
-
const
|
|
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
|
+
});
|
|
11354
11527
|
return /* @__PURE__ */ jsx(
|
|
11355
|
-
|
|
11528
|
+
Form$2.Field,
|
|
11356
11529
|
{
|
|
11357
|
-
|
|
11358
|
-
|
|
11359
|
-
|
|
11360
|
-
|
|
11361
|
-
|
|
11362
|
-
|
|
11363
|
-
|
|
11364
|
-
|
|
11365
|
-
|
|
11366
|
-
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
};
|
|
11377
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11378
|
-
function getDefaultValues(metadata) {
|
|
11379
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
11380
|
-
return [
|
|
11381
|
-
{
|
|
11382
|
-
key: "",
|
|
11383
|
-
value: "",
|
|
11384
|
-
disabled: false
|
|
11385
|
-
}
|
|
11386
|
-
];
|
|
11387
|
-
}
|
|
11388
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
11389
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11390
|
-
return {
|
|
11391
|
-
key,
|
|
11392
|
-
value,
|
|
11393
|
-
disabled: true
|
|
11394
|
-
};
|
|
11395
|
-
}
|
|
11396
|
-
let stringValue = value;
|
|
11397
|
-
if (typeof value !== "string") {
|
|
11398
|
-
stringValue = JSON.stringify(value);
|
|
11399
|
-
}
|
|
11400
|
-
return {
|
|
11401
|
-
key,
|
|
11402
|
-
value: stringValue,
|
|
11403
|
-
original_key: key
|
|
11404
|
-
};
|
|
11405
|
-
});
|
|
11406
|
-
}
|
|
11407
|
-
function parseValues(values) {
|
|
11408
|
-
const metadata = values.metadata;
|
|
11409
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11410
|
-
if (isEmpty) {
|
|
11411
|
-
return null;
|
|
11412
|
-
}
|
|
11413
|
-
const update = {};
|
|
11414
|
-
metadata.forEach((field) => {
|
|
11415
|
-
let key = field.key;
|
|
11416
|
-
let value = field.value;
|
|
11417
|
-
const disabled = field.disabled;
|
|
11418
|
-
if (!key || !value) {
|
|
11419
|
-
return;
|
|
11420
|
-
}
|
|
11421
|
-
if (disabled) {
|
|
11422
|
-
update[key] = value;
|
|
11423
|
-
return;
|
|
11424
|
-
}
|
|
11425
|
-
key = key.trim();
|
|
11426
|
-
value = value.trim();
|
|
11427
|
-
if (value === "true") {
|
|
11428
|
-
update[key] = true;
|
|
11429
|
-
} else if (value === "false") {
|
|
11430
|
-
update[key] = false;
|
|
11431
|
-
} else {
|
|
11432
|
-
const parsedNumber = parseFloat(value);
|
|
11433
|
-
if (!isNaN(parsedNumber)) {
|
|
11434
|
-
update[key] = parsedNumber;
|
|
11435
|
-
} else {
|
|
11436
|
-
update[key] = value;
|
|
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
|
+
] });
|
|
11437
11549
|
}
|
|
11438
11550
|
}
|
|
11439
|
-
});
|
|
11440
|
-
return update;
|
|
11441
|
-
}
|
|
11442
|
-
function getHasUneditableRows(metadata) {
|
|
11443
|
-
if (!metadata) {
|
|
11444
|
-
return false;
|
|
11445
|
-
}
|
|
11446
|
-
return Object.values(metadata).some(
|
|
11447
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11448
11551
|
);
|
|
11449
|
-
}
|
|
11552
|
+
};
|
|
11553
|
+
const schema$2 = objectType({
|
|
11554
|
+
sales_channel_id: stringType().min(1)
|
|
11555
|
+
});
|
|
11450
11556
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11451
11557
|
const Shipping = () => {
|
|
11452
11558
|
var _a;
|
|
@@ -12286,7 +12392,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12286
12392
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12287
12393
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12288
12394
|
},
|
|
12289
|
-
resolver: zodResolver(schema$
|
|
12395
|
+
resolver: zodResolver(schema$1)
|
|
12290
12396
|
});
|
|
12291
12397
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12292
12398
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12456,113 +12562,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12456
12562
|
}
|
|
12457
12563
|
) });
|
|
12458
12564
|
};
|
|
12459
|
-
const schema$
|
|
12460
|
-
const SalesChannel = () => {
|
|
12461
|
-
const { id } = useParams();
|
|
12462
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12463
|
-
id,
|
|
12464
|
-
{
|
|
12465
|
-
fields: "+sales_channel_id"
|
|
12466
|
-
},
|
|
12467
|
-
{
|
|
12468
|
-
enabled: !!id
|
|
12469
|
-
}
|
|
12470
|
-
);
|
|
12471
|
-
if (isError) {
|
|
12472
|
-
throw error;
|
|
12473
|
-
}
|
|
12474
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
12475
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12476
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12477
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
12478
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12479
|
-
] }),
|
|
12480
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
12481
|
-
] });
|
|
12482
|
-
};
|
|
12483
|
-
const SalesChannelForm = ({ order }) => {
|
|
12484
|
-
const form = useForm({
|
|
12485
|
-
defaultValues: {
|
|
12486
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
12487
|
-
},
|
|
12488
|
-
resolver: zodResolver(schema$1)
|
|
12489
|
-
});
|
|
12490
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12491
|
-
const { handleSuccess } = useRouteModal();
|
|
12492
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12493
|
-
await mutateAsync(
|
|
12494
|
-
{
|
|
12495
|
-
sales_channel_id: data.sales_channel_id
|
|
12496
|
-
},
|
|
12497
|
-
{
|
|
12498
|
-
onSuccess: () => {
|
|
12499
|
-
toast.success("Sales channel updated");
|
|
12500
|
-
handleSuccess();
|
|
12501
|
-
},
|
|
12502
|
-
onError: (error) => {
|
|
12503
|
-
toast.error(error.message);
|
|
12504
|
-
}
|
|
12505
|
-
}
|
|
12506
|
-
);
|
|
12507
|
-
});
|
|
12508
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12509
|
-
KeyboundForm,
|
|
12510
|
-
{
|
|
12511
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12512
|
-
onSubmit,
|
|
12513
|
-
children: [
|
|
12514
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12515
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12516
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12517
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12518
|
-
] }) })
|
|
12519
|
-
]
|
|
12520
|
-
}
|
|
12521
|
-
) });
|
|
12522
|
-
};
|
|
12523
|
-
const SalesChannelField = ({ control, order }) => {
|
|
12524
|
-
const salesChannels = useComboboxData({
|
|
12525
|
-
queryFn: async (params) => {
|
|
12526
|
-
return await sdk.admin.salesChannel.list(params);
|
|
12527
|
-
},
|
|
12528
|
-
queryKey: ["sales-channels"],
|
|
12529
|
-
getOptions: (data) => {
|
|
12530
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
12531
|
-
label: salesChannel.name,
|
|
12532
|
-
value: salesChannel.id
|
|
12533
|
-
}));
|
|
12534
|
-
},
|
|
12535
|
-
defaultValue: order.sales_channel_id || void 0
|
|
12536
|
-
});
|
|
12537
|
-
return /* @__PURE__ */ jsx(
|
|
12538
|
-
Form$2.Field,
|
|
12539
|
-
{
|
|
12540
|
-
control,
|
|
12541
|
-
name: "sales_channel_id",
|
|
12542
|
-
render: ({ field }) => {
|
|
12543
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12544
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
12545
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12546
|
-
Combobox,
|
|
12547
|
-
{
|
|
12548
|
-
options: salesChannels.options,
|
|
12549
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
12550
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
12551
|
-
searchValue: salesChannels.searchValue,
|
|
12552
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
12553
|
-
placeholder: "Select sales channel",
|
|
12554
|
-
...field
|
|
12555
|
-
}
|
|
12556
|
-
) }),
|
|
12557
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12558
|
-
] });
|
|
12559
|
-
}
|
|
12560
|
-
}
|
|
12561
|
-
);
|
|
12562
|
-
};
|
|
12563
|
-
const schema$1 = objectType({
|
|
12564
|
-
sales_channel_id: stringType().min(1)
|
|
12565
|
-
});
|
|
12565
|
+
const schema$1 = addressSchema;
|
|
12566
12566
|
const TransferOwnership = () => {
|
|
12567
12567
|
const { id } = useParams();
|
|
12568
12568
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -13067,21 +13067,25 @@ const routeModule = {
|
|
|
13067
13067
|
Component: CustomItems,
|
|
13068
13068
|
path: "/draft-orders/:id/custom-items"
|
|
13069
13069
|
},
|
|
13070
|
+
{
|
|
13071
|
+
Component: Email,
|
|
13072
|
+
path: "/draft-orders/:id/email"
|
|
13073
|
+
},
|
|
13070
13074
|
{
|
|
13071
13075
|
Component: Items,
|
|
13072
13076
|
path: "/draft-orders/:id/items"
|
|
13073
13077
|
},
|
|
13074
13078
|
{
|
|
13075
|
-
Component:
|
|
13076
|
-
path: "/draft-orders/:id/
|
|
13079
|
+
Component: Metadata,
|
|
13080
|
+
path: "/draft-orders/:id/metadata"
|
|
13077
13081
|
},
|
|
13078
13082
|
{
|
|
13079
13083
|
Component: Promotions,
|
|
13080
13084
|
path: "/draft-orders/:id/promotions"
|
|
13081
13085
|
},
|
|
13082
13086
|
{
|
|
13083
|
-
Component:
|
|
13084
|
-
path: "/draft-orders/:id/
|
|
13087
|
+
Component: SalesChannel,
|
|
13088
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13085
13089
|
},
|
|
13086
13090
|
{
|
|
13087
13091
|
Component: Shipping,
|
|
@@ -13091,10 +13095,6 @@ const routeModule = {
|
|
|
13091
13095
|
Component: ShippingAddress,
|
|
13092
13096
|
path: "/draft-orders/:id/shipping-address"
|
|
13093
13097
|
},
|
|
13094
|
-
{
|
|
13095
|
-
Component: SalesChannel,
|
|
13096
|
-
path: "/draft-orders/:id/sales-channel"
|
|
13097
|
-
},
|
|
13098
13098
|
{
|
|
13099
13099
|
Component: TransferOwnership,
|
|
13100
13100
|
path: "/draft-orders/:id/transfer-ownership"
|