@medusajs/draft-order 2.11.0-snapshot-20251014110210 → 2.11.0-snapshot-20251016121452
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 +518 -518
- package/.medusa/server/src/admin/index.mjs +518 -518
- package/package.json +24 -23
|
@@ -9778,74 +9778,6 @@ 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
|
-
});
|
|
9849
9781
|
const NumberInput = forwardRef(
|
|
9850
9782
|
({
|
|
9851
9783
|
value,
|
|
@@ -10820,459 +10752,109 @@ const customItemSchema = objectType({
|
|
|
10820
10752
|
quantity: numberType(),
|
|
10821
10753
|
unit_price: unionType([numberType(), stringType()])
|
|
10822
10754
|
});
|
|
10823
|
-
const
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
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 = () => {
|
|
10868
|
-
const { id } = useParams();
|
|
10869
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10870
|
-
fields: "metadata"
|
|
10755
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
10756
|
+
const promotionsQueryKeys = {
|
|
10757
|
+
list: (query2) => [
|
|
10758
|
+
PROMOTION_QUERY_KEY,
|
|
10759
|
+
query2 ? query2 : void 0
|
|
10760
|
+
],
|
|
10761
|
+
detail: (id, query2) => [
|
|
10762
|
+
PROMOTION_QUERY_KEY,
|
|
10763
|
+
id,
|
|
10764
|
+
query2 ? query2 : void 0
|
|
10765
|
+
]
|
|
10766
|
+
};
|
|
10767
|
+
const usePromotions = (query2, options) => {
|
|
10768
|
+
const { data, ...rest } = useQuery({
|
|
10769
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
10770
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10771
|
+
...options
|
|
10871
10772
|
});
|
|
10872
|
-
|
|
10873
|
-
|
|
10773
|
+
return { ...data, ...rest };
|
|
10774
|
+
};
|
|
10775
|
+
const Promotions = () => {
|
|
10776
|
+
const { id } = useParams();
|
|
10777
|
+
const {
|
|
10778
|
+
order: preview,
|
|
10779
|
+
isError: isPreviewError,
|
|
10780
|
+
error: previewError
|
|
10781
|
+
} = useOrderPreview(id, void 0);
|
|
10782
|
+
useInitiateOrderEdit({ preview });
|
|
10783
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10784
|
+
if (isPreviewError) {
|
|
10785
|
+
throw previewError;
|
|
10874
10786
|
}
|
|
10875
|
-
const isReady =
|
|
10876
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10877
|
-
/* @__PURE__ */
|
|
10878
|
-
|
|
10879
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10880
|
-
] }),
|
|
10881
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10787
|
+
const isReady = !!preview;
|
|
10788
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10789
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
10790
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
10882
10791
|
] });
|
|
10883
10792
|
};
|
|
10884
|
-
const
|
|
10885
|
-
const
|
|
10886
|
-
const
|
|
10793
|
+
const PromotionForm = ({ preview }) => {
|
|
10794
|
+
const { items, shipping_methods } = preview;
|
|
10795
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10796
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
10887
10797
|
const { handleSuccess } = useRouteModal();
|
|
10888
|
-
const
|
|
10889
|
-
const
|
|
10890
|
-
const
|
|
10891
|
-
|
|
10892
|
-
|
|
10798
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10799
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10800
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
10801
|
+
{
|
|
10802
|
+
id: promoIds
|
|
10893
10803
|
},
|
|
10894
|
-
|
|
10804
|
+
{
|
|
10805
|
+
enabled: !!promoIds.length
|
|
10806
|
+
}
|
|
10807
|
+
);
|
|
10808
|
+
const comboboxData = useComboboxData({
|
|
10809
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
10810
|
+
queryFn: async (params) => {
|
|
10811
|
+
return await sdk.admin.promotion.list({
|
|
10812
|
+
...params,
|
|
10813
|
+
id: {
|
|
10814
|
+
$nin: promoIds
|
|
10815
|
+
}
|
|
10816
|
+
});
|
|
10817
|
+
},
|
|
10818
|
+
getOptions: (data) => {
|
|
10819
|
+
return data.promotions.map((promotion) => ({
|
|
10820
|
+
label: promotion.code,
|
|
10821
|
+
value: promotion.code
|
|
10822
|
+
}));
|
|
10823
|
+
}
|
|
10895
10824
|
});
|
|
10896
|
-
const
|
|
10897
|
-
|
|
10898
|
-
|
|
10825
|
+
const add = async (value) => {
|
|
10826
|
+
if (!value) {
|
|
10827
|
+
return;
|
|
10828
|
+
}
|
|
10829
|
+
addPromotions(
|
|
10899
10830
|
{
|
|
10900
|
-
|
|
10831
|
+
promo_codes: [value]
|
|
10901
10832
|
},
|
|
10902
10833
|
{
|
|
10903
|
-
|
|
10904
|
-
toast.
|
|
10905
|
-
|
|
10834
|
+
onError: (e) => {
|
|
10835
|
+
toast.error(e.message);
|
|
10836
|
+
comboboxData.onSearchValueChange("");
|
|
10837
|
+
setComboboxValue("");
|
|
10906
10838
|
},
|
|
10907
|
-
|
|
10908
|
-
|
|
10839
|
+
onSuccess: () => {
|
|
10840
|
+
comboboxData.onSearchValueChange("");
|
|
10841
|
+
setComboboxValue("");
|
|
10909
10842
|
}
|
|
10910
10843
|
}
|
|
10911
10844
|
);
|
|
10912
|
-
}
|
|
10913
|
-
const {
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
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
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10935
|
-
KeyboundForm,
|
|
10936
|
-
{
|
|
10937
|
-
onSubmit: handleSubmit,
|
|
10938
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
10939
|
-
children: [
|
|
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
|
|
11240
|
-
}));
|
|
11241
|
-
}
|
|
11242
|
-
});
|
|
11243
|
-
const add = async (value) => {
|
|
11244
|
-
if (!value) {
|
|
11245
|
-
return;
|
|
11246
|
-
}
|
|
11247
|
-
addPromotions(
|
|
11248
|
-
{
|
|
11249
|
-
promo_codes: [value]
|
|
11250
|
-
},
|
|
11251
|
-
{
|
|
11252
|
-
onError: (e) => {
|
|
11253
|
-
toast.error(e.message);
|
|
11254
|
-
comboboxData.onSearchValueChange("");
|
|
11255
|
-
setComboboxValue("");
|
|
11256
|
-
},
|
|
11257
|
-
onSuccess: () => {
|
|
11258
|
-
comboboxData.onSearchValueChange("");
|
|
11259
|
-
setComboboxValue("");
|
|
11260
|
-
}
|
|
11261
|
-
}
|
|
11262
|
-
);
|
|
11263
|
-
};
|
|
11264
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11265
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11266
|
-
const onSubmit = async () => {
|
|
11267
|
-
setIsSubmitting(true);
|
|
11268
|
-
let requestSucceeded = false;
|
|
11269
|
-
await requestOrderEdit(void 0, {
|
|
11270
|
-
onError: (e) => {
|
|
11271
|
-
toast.error(e.message);
|
|
11272
|
-
},
|
|
11273
|
-
onSuccess: () => {
|
|
11274
|
-
requestSucceeded = true;
|
|
11275
|
-
}
|
|
10845
|
+
};
|
|
10846
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10847
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10848
|
+
const onSubmit = async () => {
|
|
10849
|
+
setIsSubmitting(true);
|
|
10850
|
+
let requestSucceeded = false;
|
|
10851
|
+
await requestOrderEdit(void 0, {
|
|
10852
|
+
onError: (e) => {
|
|
10853
|
+
toast.error(e.message);
|
|
10854
|
+
},
|
|
10855
|
+
onSuccess: () => {
|
|
10856
|
+
requestSucceeded = true;
|
|
10857
|
+
}
|
|
11276
10858
|
});
|
|
11277
10859
|
if (!requestSucceeded) {
|
|
11278
10860
|
setIsSubmitting(false);
|
|
@@ -11447,6 +11029,74 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
11447
11029
|
}
|
|
11448
11030
|
return Array.from(promotionIds);
|
|
11449
11031
|
}
|
|
11032
|
+
const Email = () => {
|
|
11033
|
+
const { id } = useParams();
|
|
11034
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11035
|
+
fields: "+email"
|
|
11036
|
+
});
|
|
11037
|
+
if (isError) {
|
|
11038
|
+
throw error;
|
|
11039
|
+
}
|
|
11040
|
+
const isReady = !isPending && !!order;
|
|
11041
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11042
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11043
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
11044
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
11045
|
+
] }),
|
|
11046
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
11047
|
+
] });
|
|
11048
|
+
};
|
|
11049
|
+
const EmailForm = ({ order }) => {
|
|
11050
|
+
const form = useForm({
|
|
11051
|
+
defaultValues: {
|
|
11052
|
+
email: order.email ?? ""
|
|
11053
|
+
},
|
|
11054
|
+
resolver: zodResolver(schema$3)
|
|
11055
|
+
});
|
|
11056
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11057
|
+
const { handleSuccess } = useRouteModal();
|
|
11058
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11059
|
+
await mutateAsync(
|
|
11060
|
+
{ email: data.email },
|
|
11061
|
+
{
|
|
11062
|
+
onSuccess: () => {
|
|
11063
|
+
handleSuccess();
|
|
11064
|
+
},
|
|
11065
|
+
onError: (error) => {
|
|
11066
|
+
toast.error(error.message);
|
|
11067
|
+
}
|
|
11068
|
+
}
|
|
11069
|
+
);
|
|
11070
|
+
});
|
|
11071
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11072
|
+
KeyboundForm,
|
|
11073
|
+
{
|
|
11074
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11075
|
+
onSubmit,
|
|
11076
|
+
children: [
|
|
11077
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
11078
|
+
Form$2.Field,
|
|
11079
|
+
{
|
|
11080
|
+
control: form.control,
|
|
11081
|
+
name: "email",
|
|
11082
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11083
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
11084
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11085
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11086
|
+
] })
|
|
11087
|
+
}
|
|
11088
|
+
) }),
|
|
11089
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11090
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11091
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11092
|
+
] }) })
|
|
11093
|
+
]
|
|
11094
|
+
}
|
|
11095
|
+
) });
|
|
11096
|
+
};
|
|
11097
|
+
const schema$3 = objectType({
|
|
11098
|
+
email: stringType().email()
|
|
11099
|
+
});
|
|
11450
11100
|
const SalesChannel = () => {
|
|
11451
11101
|
const { id } = useParams();
|
|
11452
11102
|
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
@@ -13034,11 +12684,361 @@ const Illustration = () => {
|
|
|
13034
12684
|
] })
|
|
13035
12685
|
]
|
|
13036
12686
|
}
|
|
13037
|
-
);
|
|
12687
|
+
);
|
|
12688
|
+
};
|
|
12689
|
+
const schema = objectType({
|
|
12690
|
+
customer_id: stringType().min(1)
|
|
12691
|
+
});
|
|
12692
|
+
const InlineTip = forwardRef(
|
|
12693
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
12694
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
12695
|
+
return /* @__PURE__ */ jsxs(
|
|
12696
|
+
"div",
|
|
12697
|
+
{
|
|
12698
|
+
ref,
|
|
12699
|
+
className: clx(
|
|
12700
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
12701
|
+
className
|
|
12702
|
+
),
|
|
12703
|
+
...props,
|
|
12704
|
+
children: [
|
|
12705
|
+
/* @__PURE__ */ jsx(
|
|
12706
|
+
"div",
|
|
12707
|
+
{
|
|
12708
|
+
role: "presentation",
|
|
12709
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
12710
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
12711
|
+
})
|
|
12712
|
+
}
|
|
12713
|
+
),
|
|
12714
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
12715
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
12716
|
+
labelValue,
|
|
12717
|
+
":"
|
|
12718
|
+
] }),
|
|
12719
|
+
" ",
|
|
12720
|
+
children
|
|
12721
|
+
] })
|
|
12722
|
+
]
|
|
12723
|
+
}
|
|
12724
|
+
);
|
|
12725
|
+
}
|
|
12726
|
+
);
|
|
12727
|
+
InlineTip.displayName = "InlineTip";
|
|
12728
|
+
const MetadataFieldSchema = objectType({
|
|
12729
|
+
key: stringType(),
|
|
12730
|
+
disabled: booleanType().optional(),
|
|
12731
|
+
value: anyType()
|
|
12732
|
+
});
|
|
12733
|
+
const MetadataSchema = objectType({
|
|
12734
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
12735
|
+
});
|
|
12736
|
+
const Metadata = () => {
|
|
12737
|
+
const { id } = useParams();
|
|
12738
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12739
|
+
fields: "metadata"
|
|
12740
|
+
});
|
|
12741
|
+
if (isError) {
|
|
12742
|
+
throw error;
|
|
12743
|
+
}
|
|
12744
|
+
const isReady = !isPending && !!order;
|
|
12745
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12746
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12747
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
12748
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
12749
|
+
] }),
|
|
12750
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
12751
|
+
] });
|
|
12752
|
+
};
|
|
12753
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
12754
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
12755
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
12756
|
+
const { handleSuccess } = useRouteModal();
|
|
12757
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
12758
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
12759
|
+
const form = useForm({
|
|
12760
|
+
defaultValues: {
|
|
12761
|
+
metadata: getDefaultValues(metadata)
|
|
12762
|
+
},
|
|
12763
|
+
resolver: zodResolver(MetadataSchema)
|
|
12764
|
+
});
|
|
12765
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
12766
|
+
const parsedData = parseValues(data);
|
|
12767
|
+
await mutateAsync(
|
|
12768
|
+
{
|
|
12769
|
+
metadata: parsedData
|
|
12770
|
+
},
|
|
12771
|
+
{
|
|
12772
|
+
onSuccess: () => {
|
|
12773
|
+
toast.success("Metadata updated");
|
|
12774
|
+
handleSuccess();
|
|
12775
|
+
},
|
|
12776
|
+
onError: (error) => {
|
|
12777
|
+
toast.error(error.message);
|
|
12778
|
+
}
|
|
12779
|
+
}
|
|
12780
|
+
);
|
|
12781
|
+
});
|
|
12782
|
+
const { fields, insert, remove } = useFieldArray({
|
|
12783
|
+
control: form.control,
|
|
12784
|
+
name: "metadata"
|
|
12785
|
+
});
|
|
12786
|
+
function deleteRow(index) {
|
|
12787
|
+
remove(index);
|
|
12788
|
+
if (fields.length === 1) {
|
|
12789
|
+
insert(0, {
|
|
12790
|
+
key: "",
|
|
12791
|
+
value: "",
|
|
12792
|
+
disabled: false
|
|
12793
|
+
});
|
|
12794
|
+
}
|
|
12795
|
+
}
|
|
12796
|
+
function insertRow(index, position) {
|
|
12797
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
12798
|
+
key: "",
|
|
12799
|
+
value: "",
|
|
12800
|
+
disabled: false
|
|
12801
|
+
});
|
|
12802
|
+
}
|
|
12803
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12804
|
+
KeyboundForm,
|
|
12805
|
+
{
|
|
12806
|
+
onSubmit: handleSubmit,
|
|
12807
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12808
|
+
children: [
|
|
12809
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
12810
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
12811
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
12812
|
+
/* @__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" }) }),
|
|
12813
|
+
/* @__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" }) })
|
|
12814
|
+
] }),
|
|
12815
|
+
fields.map((field, index) => {
|
|
12816
|
+
const isDisabled = field.disabled || false;
|
|
12817
|
+
let placeholder = "-";
|
|
12818
|
+
if (typeof field.value === "object") {
|
|
12819
|
+
placeholder = "{ ... }";
|
|
12820
|
+
}
|
|
12821
|
+
if (Array.isArray(field.value)) {
|
|
12822
|
+
placeholder = "[ ... ]";
|
|
12823
|
+
}
|
|
12824
|
+
return /* @__PURE__ */ jsx(
|
|
12825
|
+
ConditionalTooltip,
|
|
12826
|
+
{
|
|
12827
|
+
showTooltip: isDisabled,
|
|
12828
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
12829
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
12830
|
+
/* @__PURE__ */ jsxs(
|
|
12831
|
+
"div",
|
|
12832
|
+
{
|
|
12833
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
12834
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
12835
|
+
}),
|
|
12836
|
+
children: [
|
|
12837
|
+
/* @__PURE__ */ jsx(
|
|
12838
|
+
Form$2.Field,
|
|
12839
|
+
{
|
|
12840
|
+
control: form.control,
|
|
12841
|
+
name: `metadata.${index}.key`,
|
|
12842
|
+
render: ({ field: field2 }) => {
|
|
12843
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12844
|
+
GridInput,
|
|
12845
|
+
{
|
|
12846
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
12847
|
+
...field2,
|
|
12848
|
+
disabled: isDisabled,
|
|
12849
|
+
placeholder: "Key"
|
|
12850
|
+
}
|
|
12851
|
+
) }) });
|
|
12852
|
+
}
|
|
12853
|
+
}
|
|
12854
|
+
),
|
|
12855
|
+
/* @__PURE__ */ jsx(
|
|
12856
|
+
Form$2.Field,
|
|
12857
|
+
{
|
|
12858
|
+
control: form.control,
|
|
12859
|
+
name: `metadata.${index}.value`,
|
|
12860
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
12861
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12862
|
+
GridInput,
|
|
12863
|
+
{
|
|
12864
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
12865
|
+
...field2,
|
|
12866
|
+
value: isDisabled ? placeholder : value,
|
|
12867
|
+
disabled: isDisabled,
|
|
12868
|
+
placeholder: "Value"
|
|
12869
|
+
}
|
|
12870
|
+
) }) });
|
|
12871
|
+
}
|
|
12872
|
+
}
|
|
12873
|
+
)
|
|
12874
|
+
]
|
|
12875
|
+
}
|
|
12876
|
+
),
|
|
12877
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
12878
|
+
/* @__PURE__ */ jsx(
|
|
12879
|
+
DropdownMenu.Trigger,
|
|
12880
|
+
{
|
|
12881
|
+
className: clx(
|
|
12882
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
12883
|
+
{
|
|
12884
|
+
hidden: isDisabled
|
|
12885
|
+
}
|
|
12886
|
+
),
|
|
12887
|
+
disabled: isDisabled,
|
|
12888
|
+
asChild: true,
|
|
12889
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
12890
|
+
}
|
|
12891
|
+
),
|
|
12892
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
12893
|
+
/* @__PURE__ */ jsxs(
|
|
12894
|
+
DropdownMenu.Item,
|
|
12895
|
+
{
|
|
12896
|
+
className: "gap-x-2",
|
|
12897
|
+
onClick: () => insertRow(index, "above"),
|
|
12898
|
+
children: [
|
|
12899
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
12900
|
+
"Insert row above"
|
|
12901
|
+
]
|
|
12902
|
+
}
|
|
12903
|
+
),
|
|
12904
|
+
/* @__PURE__ */ jsxs(
|
|
12905
|
+
DropdownMenu.Item,
|
|
12906
|
+
{
|
|
12907
|
+
className: "gap-x-2",
|
|
12908
|
+
onClick: () => insertRow(index, "below"),
|
|
12909
|
+
children: [
|
|
12910
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
12911
|
+
"Insert row below"
|
|
12912
|
+
]
|
|
12913
|
+
}
|
|
12914
|
+
),
|
|
12915
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
12916
|
+
/* @__PURE__ */ jsxs(
|
|
12917
|
+
DropdownMenu.Item,
|
|
12918
|
+
{
|
|
12919
|
+
className: "gap-x-2",
|
|
12920
|
+
onClick: () => deleteRow(index),
|
|
12921
|
+
children: [
|
|
12922
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
12923
|
+
"Delete row"
|
|
12924
|
+
]
|
|
12925
|
+
}
|
|
12926
|
+
)
|
|
12927
|
+
] })
|
|
12928
|
+
] })
|
|
12929
|
+
] })
|
|
12930
|
+
},
|
|
12931
|
+
field.id
|
|
12932
|
+
);
|
|
12933
|
+
})
|
|
12934
|
+
] }),
|
|
12935
|
+
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." })
|
|
12936
|
+
] }),
|
|
12937
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12938
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12939
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12940
|
+
] }) })
|
|
12941
|
+
]
|
|
12942
|
+
}
|
|
12943
|
+
) });
|
|
13038
12944
|
};
|
|
13039
|
-
const
|
|
13040
|
-
|
|
12945
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
12946
|
+
return /* @__PURE__ */ jsx(
|
|
12947
|
+
"input",
|
|
12948
|
+
{
|
|
12949
|
+
ref,
|
|
12950
|
+
...props,
|
|
12951
|
+
autoComplete: "off",
|
|
12952
|
+
className: clx(
|
|
12953
|
+
"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",
|
|
12954
|
+
className
|
|
12955
|
+
)
|
|
12956
|
+
}
|
|
12957
|
+
);
|
|
13041
12958
|
});
|
|
12959
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
12960
|
+
const PlaceholderInner = () => {
|
|
12961
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
12962
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
12963
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12964
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
12965
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
12966
|
+
] }) })
|
|
12967
|
+
] });
|
|
12968
|
+
};
|
|
12969
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
12970
|
+
function getDefaultValues(metadata) {
|
|
12971
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
12972
|
+
return [
|
|
12973
|
+
{
|
|
12974
|
+
key: "",
|
|
12975
|
+
value: "",
|
|
12976
|
+
disabled: false
|
|
12977
|
+
}
|
|
12978
|
+
];
|
|
12979
|
+
}
|
|
12980
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
12981
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
12982
|
+
return {
|
|
12983
|
+
key,
|
|
12984
|
+
value,
|
|
12985
|
+
disabled: true
|
|
12986
|
+
};
|
|
12987
|
+
}
|
|
12988
|
+
let stringValue = value;
|
|
12989
|
+
if (typeof value !== "string") {
|
|
12990
|
+
stringValue = JSON.stringify(value);
|
|
12991
|
+
}
|
|
12992
|
+
return {
|
|
12993
|
+
key,
|
|
12994
|
+
value: stringValue,
|
|
12995
|
+
original_key: key
|
|
12996
|
+
};
|
|
12997
|
+
});
|
|
12998
|
+
}
|
|
12999
|
+
function parseValues(values) {
|
|
13000
|
+
const metadata = values.metadata;
|
|
13001
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
13002
|
+
if (isEmpty) {
|
|
13003
|
+
return null;
|
|
13004
|
+
}
|
|
13005
|
+
const update = {};
|
|
13006
|
+
metadata.forEach((field) => {
|
|
13007
|
+
let key = field.key;
|
|
13008
|
+
let value = field.value;
|
|
13009
|
+
const disabled = field.disabled;
|
|
13010
|
+
if (!key || !value) {
|
|
13011
|
+
return;
|
|
13012
|
+
}
|
|
13013
|
+
if (disabled) {
|
|
13014
|
+
update[key] = value;
|
|
13015
|
+
return;
|
|
13016
|
+
}
|
|
13017
|
+
key = key.trim();
|
|
13018
|
+
value = value.trim();
|
|
13019
|
+
if (value === "true") {
|
|
13020
|
+
update[key] = true;
|
|
13021
|
+
} else if (value === "false") {
|
|
13022
|
+
update[key] = false;
|
|
13023
|
+
} else {
|
|
13024
|
+
const parsedNumber = parseFloat(value);
|
|
13025
|
+
if (!isNaN(parsedNumber)) {
|
|
13026
|
+
update[key] = parsedNumber;
|
|
13027
|
+
} else {
|
|
13028
|
+
update[key] = value;
|
|
13029
|
+
}
|
|
13030
|
+
}
|
|
13031
|
+
});
|
|
13032
|
+
return update;
|
|
13033
|
+
}
|
|
13034
|
+
function getHasUneditableRows(metadata) {
|
|
13035
|
+
if (!metadata) {
|
|
13036
|
+
return false;
|
|
13037
|
+
}
|
|
13038
|
+
return Object.values(metadata).some(
|
|
13039
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
13040
|
+
);
|
|
13041
|
+
}
|
|
13042
13042
|
const widgetModule = { widgets: [] };
|
|
13043
13043
|
const routeModule = {
|
|
13044
13044
|
routes: [
|
|
@@ -13067,22 +13067,18 @@ 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
|
-
},
|
|
13074
13070
|
{
|
|
13075
13071
|
Component: Items,
|
|
13076
13072
|
path: "/draft-orders/:id/items"
|
|
13077
13073
|
},
|
|
13078
|
-
{
|
|
13079
|
-
Component: Metadata,
|
|
13080
|
-
path: "/draft-orders/:id/metadata"
|
|
13081
|
-
},
|
|
13082
13074
|
{
|
|
13083
13075
|
Component: Promotions,
|
|
13084
13076
|
path: "/draft-orders/:id/promotions"
|
|
13085
13077
|
},
|
|
13078
|
+
{
|
|
13079
|
+
Component: Email,
|
|
13080
|
+
path: "/draft-orders/:id/email"
|
|
13081
|
+
},
|
|
13086
13082
|
{
|
|
13087
13083
|
Component: SalesChannel,
|
|
13088
13084
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13098,6 +13094,10 @@ const routeModule = {
|
|
|
13098
13094
|
{
|
|
13099
13095
|
Component: TransferOwnership,
|
|
13100
13096
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13097
|
+
},
|
|
13098
|
+
{
|
|
13099
|
+
Component: Metadata,
|
|
13100
|
+
path: "/draft-orders/:id/metadata"
|
|
13101
13101
|
}
|
|
13102
13102
|
]
|
|
13103
13103
|
}
|