@medusajs/draft-order 2.11.1-preview-20251025000333 → 2.11.1-preview-20251025060207
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 +490 -490
- package/.medusa/server/src/admin/index.mjs +490 -490
- package/package.json +16 -16
|
@@ -9761,6 +9761,27 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9761
9761
|
) });
|
|
9762
9762
|
};
|
|
9763
9763
|
const schema$5 = addressSchema;
|
|
9764
|
+
const CustomItems = () => {
|
|
9765
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9766
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
9767
|
+
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
9768
|
+
] });
|
|
9769
|
+
};
|
|
9770
|
+
const CustomItemsForm = () => {
|
|
9771
|
+
const form = reactHookForm.useForm({
|
|
9772
|
+
resolver: zod.zodResolver(schema$4)
|
|
9773
|
+
});
|
|
9774
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9775
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
9776
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9777
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9778
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
9779
|
+
] }) })
|
|
9780
|
+
] }) });
|
|
9781
|
+
};
|
|
9782
|
+
const schema$4 = objectType({
|
|
9783
|
+
email: stringType().email()
|
|
9784
|
+
});
|
|
9764
9785
|
const Email = () => {
|
|
9765
9786
|
const { id } = reactRouterDom.useParams();
|
|
9766
9787
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9783,7 +9804,7 @@ const EmailForm = ({ order }) => {
|
|
|
9783
9804
|
defaultValues: {
|
|
9784
9805
|
email: order.email ?? ""
|
|
9785
9806
|
},
|
|
9786
|
-
resolver: zod.zodResolver(schema$
|
|
9807
|
+
resolver: zod.zodResolver(schema$3)
|
|
9787
9808
|
});
|
|
9788
9809
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9789
9810
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9826,7 +9847,7 @@ const EmailForm = ({ order }) => {
|
|
|
9826
9847
|
}
|
|
9827
9848
|
) });
|
|
9828
9849
|
};
|
|
9829
|
-
const schema$
|
|
9850
|
+
const schema$3 = objectType({
|
|
9830
9851
|
email: stringType().email()
|
|
9831
9852
|
});
|
|
9832
9853
|
const NumberInput = React.forwardRef(
|
|
@@ -10803,478 +10824,128 @@ const customItemSchema = objectType({
|
|
|
10803
10824
|
quantity: numberType(),
|
|
10804
10825
|
unit_price: unionType([numberType(), stringType()])
|
|
10805
10826
|
});
|
|
10806
|
-
const
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10824
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10825
|
-
})
|
|
10826
|
-
}
|
|
10827
|
-
),
|
|
10828
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
10829
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10830
|
-
labelValue,
|
|
10831
|
-
":"
|
|
10832
|
-
] }),
|
|
10833
|
-
" ",
|
|
10834
|
-
children
|
|
10835
|
-
] })
|
|
10836
|
-
]
|
|
10837
|
-
}
|
|
10838
|
-
);
|
|
10839
|
-
}
|
|
10840
|
-
);
|
|
10841
|
-
InlineTip.displayName = "InlineTip";
|
|
10842
|
-
const MetadataFieldSchema = objectType({
|
|
10843
|
-
key: stringType(),
|
|
10844
|
-
disabled: booleanType().optional(),
|
|
10845
|
-
value: anyType()
|
|
10846
|
-
});
|
|
10847
|
-
const MetadataSchema = objectType({
|
|
10848
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10849
|
-
});
|
|
10850
|
-
const Metadata = () => {
|
|
10851
|
-
const { id } = reactRouterDom.useParams();
|
|
10852
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10853
|
-
fields: "metadata"
|
|
10827
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
10828
|
+
const promotionsQueryKeys = {
|
|
10829
|
+
list: (query2) => [
|
|
10830
|
+
PROMOTION_QUERY_KEY,
|
|
10831
|
+
query2 ? query2 : void 0
|
|
10832
|
+
],
|
|
10833
|
+
detail: (id, query2) => [
|
|
10834
|
+
PROMOTION_QUERY_KEY,
|
|
10835
|
+
id,
|
|
10836
|
+
query2 ? query2 : void 0
|
|
10837
|
+
]
|
|
10838
|
+
};
|
|
10839
|
+
const usePromotions = (query2, options) => {
|
|
10840
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
10841
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
10842
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10843
|
+
...options
|
|
10854
10844
|
});
|
|
10855
|
-
|
|
10856
|
-
|
|
10845
|
+
return { ...data, ...rest };
|
|
10846
|
+
};
|
|
10847
|
+
const Promotions = () => {
|
|
10848
|
+
const { id } = reactRouterDom.useParams();
|
|
10849
|
+
const {
|
|
10850
|
+
order: preview,
|
|
10851
|
+
isError: isPreviewError,
|
|
10852
|
+
error: previewError
|
|
10853
|
+
} = useOrderPreview(id, void 0);
|
|
10854
|
+
useInitiateOrderEdit({ preview });
|
|
10855
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10856
|
+
if (isPreviewError) {
|
|
10857
|
+
throw previewError;
|
|
10857
10858
|
}
|
|
10858
|
-
const isReady =
|
|
10859
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10860
|
-
/* @__PURE__ */ jsxRuntime.
|
|
10861
|
-
|
|
10862
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10863
|
-
] }),
|
|
10864
|
-
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10859
|
+
const isReady = !!preview;
|
|
10860
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10861
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
10862
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
10865
10863
|
] });
|
|
10866
10864
|
};
|
|
10867
|
-
const
|
|
10868
|
-
const
|
|
10869
|
-
const
|
|
10865
|
+
const PromotionForm = ({ preview }) => {
|
|
10866
|
+
const { items, shipping_methods } = preview;
|
|
10867
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
10868
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
10870
10869
|
const { handleSuccess } = useRouteModal();
|
|
10871
|
-
const
|
|
10872
|
-
const
|
|
10873
|
-
const
|
|
10874
|
-
|
|
10875
|
-
|
|
10870
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10871
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10872
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
10873
|
+
{
|
|
10874
|
+
id: promoIds
|
|
10876
10875
|
},
|
|
10877
|
-
|
|
10876
|
+
{
|
|
10877
|
+
enabled: !!promoIds.length
|
|
10878
|
+
}
|
|
10879
|
+
);
|
|
10880
|
+
const comboboxData = useComboboxData({
|
|
10881
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
10882
|
+
queryFn: async (params) => {
|
|
10883
|
+
return await sdk.admin.promotion.list({
|
|
10884
|
+
...params,
|
|
10885
|
+
id: {
|
|
10886
|
+
$nin: promoIds
|
|
10887
|
+
}
|
|
10888
|
+
});
|
|
10889
|
+
},
|
|
10890
|
+
getOptions: (data) => {
|
|
10891
|
+
return data.promotions.map((promotion) => ({
|
|
10892
|
+
label: promotion.code,
|
|
10893
|
+
value: promotion.code
|
|
10894
|
+
}));
|
|
10895
|
+
}
|
|
10878
10896
|
});
|
|
10879
|
-
const
|
|
10880
|
-
|
|
10881
|
-
|
|
10897
|
+
const add = async (value) => {
|
|
10898
|
+
if (!value) {
|
|
10899
|
+
return;
|
|
10900
|
+
}
|
|
10901
|
+
addPromotions(
|
|
10882
10902
|
{
|
|
10883
|
-
|
|
10903
|
+
promo_codes: [value]
|
|
10884
10904
|
},
|
|
10885
10905
|
{
|
|
10886
|
-
|
|
10887
|
-
ui.toast.
|
|
10888
|
-
|
|
10906
|
+
onError: (e) => {
|
|
10907
|
+
ui.toast.error(e.message);
|
|
10908
|
+
comboboxData.onSearchValueChange("");
|
|
10909
|
+
setComboboxValue("");
|
|
10889
10910
|
},
|
|
10890
|
-
|
|
10891
|
-
|
|
10911
|
+
onSuccess: () => {
|
|
10912
|
+
comboboxData.onSearchValueChange("");
|
|
10913
|
+
setComboboxValue("");
|
|
10892
10914
|
}
|
|
10893
10915
|
}
|
|
10894
10916
|
);
|
|
10895
|
-
}
|
|
10896
|
-
const {
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
}
|
|
10917
|
+
};
|
|
10918
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10919
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10920
|
+
const onSubmit = async () => {
|
|
10921
|
+
setIsSubmitting(true);
|
|
10922
|
+
let requestSucceeded = false;
|
|
10923
|
+
await requestOrderEdit(void 0, {
|
|
10924
|
+
onError: (e) => {
|
|
10925
|
+
ui.toast.error(e.message);
|
|
10926
|
+
},
|
|
10927
|
+
onSuccess: () => {
|
|
10928
|
+
requestSucceeded = true;
|
|
10929
|
+
}
|
|
10930
|
+
});
|
|
10931
|
+
if (!requestSucceeded) {
|
|
10932
|
+
setIsSubmitting(false);
|
|
10933
|
+
return;
|
|
10908
10934
|
}
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10935
|
+
await confirmOrderEdit(void 0, {
|
|
10936
|
+
onError: (e) => {
|
|
10937
|
+
ui.toast.error(e.message);
|
|
10938
|
+
},
|
|
10939
|
+
onSuccess: () => {
|
|
10940
|
+
handleSuccess();
|
|
10941
|
+
},
|
|
10942
|
+
onSettled: () => {
|
|
10943
|
+
setIsSubmitting(false);
|
|
10944
|
+
}
|
|
10915
10945
|
});
|
|
10916
|
-
}
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
{
|
|
10920
|
-
onSubmit: handleSubmit,
|
|
10921
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
10922
|
-
children: [
|
|
10923
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10924
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10925
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10926
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
10927
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
10928
|
-
] }),
|
|
10929
|
-
fields.map((field, index) => {
|
|
10930
|
-
const isDisabled = field.disabled || false;
|
|
10931
|
-
let placeholder = "-";
|
|
10932
|
-
if (typeof field.value === "object") {
|
|
10933
|
-
placeholder = "{ ... }";
|
|
10934
|
-
}
|
|
10935
|
-
if (Array.isArray(field.value)) {
|
|
10936
|
-
placeholder = "[ ... ]";
|
|
10937
|
-
}
|
|
10938
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10939
|
-
ConditionalTooltip,
|
|
10940
|
-
{
|
|
10941
|
-
showTooltip: isDisabled,
|
|
10942
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
10943
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
10944
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
10945
|
-
"div",
|
|
10946
|
-
{
|
|
10947
|
-
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
10948
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10949
|
-
}),
|
|
10950
|
-
children: [
|
|
10951
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10952
|
-
Form$2.Field,
|
|
10953
|
-
{
|
|
10954
|
-
control: form.control,
|
|
10955
|
-
name: `metadata.${index}.key`,
|
|
10956
|
-
render: ({ field: field2 }) => {
|
|
10957
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10958
|
-
GridInput,
|
|
10959
|
-
{
|
|
10960
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10961
|
-
...field2,
|
|
10962
|
-
disabled: isDisabled,
|
|
10963
|
-
placeholder: "Key"
|
|
10964
|
-
}
|
|
10965
|
-
) }) });
|
|
10966
|
-
}
|
|
10967
|
-
}
|
|
10968
|
-
),
|
|
10969
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10970
|
-
Form$2.Field,
|
|
10971
|
-
{
|
|
10972
|
-
control: form.control,
|
|
10973
|
-
name: `metadata.${index}.value`,
|
|
10974
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
10975
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10976
|
-
GridInput,
|
|
10977
|
-
{
|
|
10978
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10979
|
-
...field2,
|
|
10980
|
-
value: isDisabled ? placeholder : value,
|
|
10981
|
-
disabled: isDisabled,
|
|
10982
|
-
placeholder: "Value"
|
|
10983
|
-
}
|
|
10984
|
-
) }) });
|
|
10985
|
-
}
|
|
10986
|
-
}
|
|
10987
|
-
)
|
|
10988
|
-
]
|
|
10989
|
-
}
|
|
10990
|
-
),
|
|
10991
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
10992
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10993
|
-
ui.DropdownMenu.Trigger,
|
|
10994
|
-
{
|
|
10995
|
-
className: ui.clx(
|
|
10996
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
10997
|
-
{
|
|
10998
|
-
hidden: isDisabled
|
|
10999
|
-
}
|
|
11000
|
-
),
|
|
11001
|
-
disabled: isDisabled,
|
|
11002
|
-
asChild: true,
|
|
11003
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
11004
|
-
}
|
|
11005
|
-
),
|
|
11006
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
11007
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11008
|
-
ui.DropdownMenu.Item,
|
|
11009
|
-
{
|
|
11010
|
-
className: "gap-x-2",
|
|
11011
|
-
onClick: () => insertRow(index, "above"),
|
|
11012
|
-
children: [
|
|
11013
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11014
|
-
"Insert row above"
|
|
11015
|
-
]
|
|
11016
|
-
}
|
|
11017
|
-
),
|
|
11018
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11019
|
-
ui.DropdownMenu.Item,
|
|
11020
|
-
{
|
|
11021
|
-
className: "gap-x-2",
|
|
11022
|
-
onClick: () => insertRow(index, "below"),
|
|
11023
|
-
children: [
|
|
11024
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11025
|
-
"Insert row below"
|
|
11026
|
-
]
|
|
11027
|
-
}
|
|
11028
|
-
),
|
|
11029
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
11030
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11031
|
-
ui.DropdownMenu.Item,
|
|
11032
|
-
{
|
|
11033
|
-
className: "gap-x-2",
|
|
11034
|
-
onClick: () => deleteRow(index),
|
|
11035
|
-
children: [
|
|
11036
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
11037
|
-
"Delete row"
|
|
11038
|
-
]
|
|
11039
|
-
}
|
|
11040
|
-
)
|
|
11041
|
-
] })
|
|
11042
|
-
] })
|
|
11043
|
-
] })
|
|
11044
|
-
},
|
|
11045
|
-
field.id
|
|
11046
|
-
);
|
|
11047
|
-
})
|
|
11048
|
-
] }),
|
|
11049
|
-
hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
11050
|
-
] }),
|
|
11051
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11052
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11053
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11054
|
-
] }) })
|
|
11055
|
-
]
|
|
11056
|
-
}
|
|
11057
|
-
) });
|
|
11058
|
-
};
|
|
11059
|
-
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
11060
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11061
|
-
"input",
|
|
11062
|
-
{
|
|
11063
|
-
ref,
|
|
11064
|
-
...props,
|
|
11065
|
-
autoComplete: "off",
|
|
11066
|
-
className: ui.clx(
|
|
11067
|
-
"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",
|
|
11068
|
-
className
|
|
11069
|
-
)
|
|
11070
|
-
}
|
|
11071
|
-
);
|
|
11072
|
-
});
|
|
11073
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
11074
|
-
const PlaceholderInner = () => {
|
|
11075
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11076
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11077
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11078
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11079
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11080
|
-
] }) })
|
|
11081
|
-
] });
|
|
11082
|
-
};
|
|
11083
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11084
|
-
function getDefaultValues(metadata) {
|
|
11085
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
11086
|
-
return [
|
|
11087
|
-
{
|
|
11088
|
-
key: "",
|
|
11089
|
-
value: "",
|
|
11090
|
-
disabled: false
|
|
11091
|
-
}
|
|
11092
|
-
];
|
|
11093
|
-
}
|
|
11094
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
11095
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11096
|
-
return {
|
|
11097
|
-
key,
|
|
11098
|
-
value,
|
|
11099
|
-
disabled: true
|
|
11100
|
-
};
|
|
11101
|
-
}
|
|
11102
|
-
let stringValue = value;
|
|
11103
|
-
if (typeof value !== "string") {
|
|
11104
|
-
stringValue = JSON.stringify(value);
|
|
11105
|
-
}
|
|
11106
|
-
return {
|
|
11107
|
-
key,
|
|
11108
|
-
value: stringValue,
|
|
11109
|
-
original_key: key
|
|
11110
|
-
};
|
|
11111
|
-
});
|
|
11112
|
-
}
|
|
11113
|
-
function parseValues(values) {
|
|
11114
|
-
const metadata = values.metadata;
|
|
11115
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11116
|
-
if (isEmpty) {
|
|
11117
|
-
return null;
|
|
11118
|
-
}
|
|
11119
|
-
const update = {};
|
|
11120
|
-
metadata.forEach((field) => {
|
|
11121
|
-
let key = field.key;
|
|
11122
|
-
let value = field.value;
|
|
11123
|
-
const disabled = field.disabled;
|
|
11124
|
-
if (!key || !value) {
|
|
11125
|
-
return;
|
|
11126
|
-
}
|
|
11127
|
-
if (disabled) {
|
|
11128
|
-
update[key] = value;
|
|
11129
|
-
return;
|
|
11130
|
-
}
|
|
11131
|
-
key = key.trim();
|
|
11132
|
-
value = value.trim();
|
|
11133
|
-
if (value === "true") {
|
|
11134
|
-
update[key] = true;
|
|
11135
|
-
} else if (value === "false") {
|
|
11136
|
-
update[key] = false;
|
|
11137
|
-
} else {
|
|
11138
|
-
const parsedNumber = parseFloat(value);
|
|
11139
|
-
if (!isNaN(parsedNumber)) {
|
|
11140
|
-
update[key] = parsedNumber;
|
|
11141
|
-
} else {
|
|
11142
|
-
update[key] = value;
|
|
11143
|
-
}
|
|
11144
|
-
}
|
|
11145
|
-
});
|
|
11146
|
-
return update;
|
|
11147
|
-
}
|
|
11148
|
-
function getHasUneditableRows(metadata) {
|
|
11149
|
-
if (!metadata) {
|
|
11150
|
-
return false;
|
|
11151
|
-
}
|
|
11152
|
-
return Object.values(metadata).some(
|
|
11153
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11154
|
-
);
|
|
11155
|
-
}
|
|
11156
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
11157
|
-
const promotionsQueryKeys = {
|
|
11158
|
-
list: (query2) => [
|
|
11159
|
-
PROMOTION_QUERY_KEY,
|
|
11160
|
-
query2 ? query2 : void 0
|
|
11161
|
-
],
|
|
11162
|
-
detail: (id, query2) => [
|
|
11163
|
-
PROMOTION_QUERY_KEY,
|
|
11164
|
-
id,
|
|
11165
|
-
query2 ? query2 : void 0
|
|
11166
|
-
]
|
|
11167
|
-
};
|
|
11168
|
-
const usePromotions = (query2, options) => {
|
|
11169
|
-
const { data, ...rest } = reactQuery.useQuery({
|
|
11170
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
11171
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11172
|
-
...options
|
|
11173
|
-
});
|
|
11174
|
-
return { ...data, ...rest };
|
|
11175
|
-
};
|
|
11176
|
-
const Promotions = () => {
|
|
11177
|
-
const { id } = reactRouterDom.useParams();
|
|
11178
|
-
const {
|
|
11179
|
-
order: preview,
|
|
11180
|
-
isError: isPreviewError,
|
|
11181
|
-
error: previewError
|
|
11182
|
-
} = useOrderPreview(id, void 0);
|
|
11183
|
-
useInitiateOrderEdit({ preview });
|
|
11184
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11185
|
-
if (isPreviewError) {
|
|
11186
|
-
throw previewError;
|
|
11187
|
-
}
|
|
11188
|
-
const isReady = !!preview;
|
|
11189
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11190
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11191
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11192
|
-
] });
|
|
11193
|
-
};
|
|
11194
|
-
const PromotionForm = ({ preview }) => {
|
|
11195
|
-
const { items, shipping_methods } = preview;
|
|
11196
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11197
|
-
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11198
|
-
const { handleSuccess } = useRouteModal();
|
|
11199
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11200
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11201
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
11202
|
-
{
|
|
11203
|
-
id: promoIds
|
|
11204
|
-
},
|
|
11205
|
-
{
|
|
11206
|
-
enabled: !!promoIds.length
|
|
11207
|
-
}
|
|
11208
|
-
);
|
|
11209
|
-
const comboboxData = useComboboxData({
|
|
11210
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
11211
|
-
queryFn: async (params) => {
|
|
11212
|
-
return await sdk.admin.promotion.list({
|
|
11213
|
-
...params,
|
|
11214
|
-
id: {
|
|
11215
|
-
$nin: promoIds
|
|
11216
|
-
}
|
|
11217
|
-
});
|
|
11218
|
-
},
|
|
11219
|
-
getOptions: (data) => {
|
|
11220
|
-
return data.promotions.map((promotion) => ({
|
|
11221
|
-
label: promotion.code,
|
|
11222
|
-
value: promotion.code
|
|
11223
|
-
}));
|
|
11224
|
-
}
|
|
11225
|
-
});
|
|
11226
|
-
const add = async (value) => {
|
|
11227
|
-
if (!value) {
|
|
11228
|
-
return;
|
|
11229
|
-
}
|
|
11230
|
-
addPromotions(
|
|
11231
|
-
{
|
|
11232
|
-
promo_codes: [value]
|
|
11233
|
-
},
|
|
11234
|
-
{
|
|
11235
|
-
onError: (e) => {
|
|
11236
|
-
ui.toast.error(e.message);
|
|
11237
|
-
comboboxData.onSearchValueChange("");
|
|
11238
|
-
setComboboxValue("");
|
|
11239
|
-
},
|
|
11240
|
-
onSuccess: () => {
|
|
11241
|
-
comboboxData.onSearchValueChange("");
|
|
11242
|
-
setComboboxValue("");
|
|
11243
|
-
}
|
|
11244
|
-
}
|
|
11245
|
-
);
|
|
11246
|
-
};
|
|
11247
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11248
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11249
|
-
const onSubmit = async () => {
|
|
11250
|
-
setIsSubmitting(true);
|
|
11251
|
-
let requestSucceeded = false;
|
|
11252
|
-
await requestOrderEdit(void 0, {
|
|
11253
|
-
onError: (e) => {
|
|
11254
|
-
ui.toast.error(e.message);
|
|
11255
|
-
},
|
|
11256
|
-
onSuccess: () => {
|
|
11257
|
-
requestSucceeded = true;
|
|
11258
|
-
}
|
|
11259
|
-
});
|
|
11260
|
-
if (!requestSucceeded) {
|
|
11261
|
-
setIsSubmitting(false);
|
|
11262
|
-
return;
|
|
11263
|
-
}
|
|
11264
|
-
await confirmOrderEdit(void 0, {
|
|
11265
|
-
onError: (e) => {
|
|
11266
|
-
ui.toast.error(e.message);
|
|
11267
|
-
},
|
|
11268
|
-
onSuccess: () => {
|
|
11269
|
-
handleSuccess();
|
|
11270
|
-
},
|
|
11271
|
-
onSettled: () => {
|
|
11272
|
-
setIsSubmitting(false);
|
|
11273
|
-
}
|
|
11274
|
-
});
|
|
11275
|
-
};
|
|
11276
|
-
if (isError) {
|
|
11277
|
-
throw error;
|
|
10946
|
+
};
|
|
10947
|
+
if (isError) {
|
|
10948
|
+
throw error;
|
|
11278
10949
|
}
|
|
11279
10950
|
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11280
10951
|
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
@@ -11458,7 +11129,7 @@ const SalesChannelForm = ({ order }) => {
|
|
|
11458
11129
|
defaultValues: {
|
|
11459
11130
|
sales_channel_id: order.sales_channel_id || ""
|
|
11460
11131
|
},
|
|
11461
|
-
resolver: zod.zodResolver(schema$
|
|
11132
|
+
resolver: zod.zodResolver(schema$2)
|
|
11462
11133
|
});
|
|
11463
11134
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11464
11135
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11533,7 +11204,7 @@ const SalesChannelField = ({ control, order }) => {
|
|
|
11533
11204
|
}
|
|
11534
11205
|
);
|
|
11535
11206
|
};
|
|
11536
|
-
const schema$
|
|
11207
|
+
const schema$2 = objectType({
|
|
11537
11208
|
sales_channel_id: stringType().min(1)
|
|
11538
11209
|
});
|
|
11539
11210
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
@@ -12375,7 +12046,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12375
12046
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12376
12047
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12377
12048
|
},
|
|
12378
|
-
resolver: zod.zodResolver(schema$
|
|
12049
|
+
resolver: zod.zodResolver(schema$1)
|
|
12379
12050
|
});
|
|
12380
12051
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12381
12052
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12545,7 +12216,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12545
12216
|
}
|
|
12546
12217
|
) });
|
|
12547
12218
|
};
|
|
12548
|
-
const schema$
|
|
12219
|
+
const schema$1 = addressSchema;
|
|
12549
12220
|
const TransferOwnership = () => {
|
|
12550
12221
|
const { id } = reactRouterDom.useParams();
|
|
12551
12222
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12569,7 +12240,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12569
12240
|
defaultValues: {
|
|
12570
12241
|
customer_id: order.customer_id || ""
|
|
12571
12242
|
},
|
|
12572
|
-
resolver: zod.zodResolver(schema
|
|
12243
|
+
resolver: zod.zodResolver(schema)
|
|
12573
12244
|
});
|
|
12574
12245
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12575
12246
|
const { handleSuccess } = useRouteModal();
|
|
@@ -13017,32 +12688,361 @@ const Illustration = () => {
|
|
|
13017
12688
|
] })
|
|
13018
12689
|
]
|
|
13019
12690
|
}
|
|
13020
|
-
);
|
|
12691
|
+
);
|
|
12692
|
+
};
|
|
12693
|
+
const schema = objectType({
|
|
12694
|
+
customer_id: stringType().min(1)
|
|
12695
|
+
});
|
|
12696
|
+
const InlineTip = React.forwardRef(
|
|
12697
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
12698
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
12699
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12700
|
+
"div",
|
|
12701
|
+
{
|
|
12702
|
+
ref,
|
|
12703
|
+
className: ui.clx(
|
|
12704
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
12705
|
+
className
|
|
12706
|
+
),
|
|
12707
|
+
...props,
|
|
12708
|
+
children: [
|
|
12709
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12710
|
+
"div",
|
|
12711
|
+
{
|
|
12712
|
+
role: "presentation",
|
|
12713
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
12714
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
12715
|
+
})
|
|
12716
|
+
}
|
|
12717
|
+
),
|
|
12718
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
12719
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
12720
|
+
labelValue,
|
|
12721
|
+
":"
|
|
12722
|
+
] }),
|
|
12723
|
+
" ",
|
|
12724
|
+
children
|
|
12725
|
+
] })
|
|
12726
|
+
]
|
|
12727
|
+
}
|
|
12728
|
+
);
|
|
12729
|
+
}
|
|
12730
|
+
);
|
|
12731
|
+
InlineTip.displayName = "InlineTip";
|
|
12732
|
+
const MetadataFieldSchema = objectType({
|
|
12733
|
+
key: stringType(),
|
|
12734
|
+
disabled: booleanType().optional(),
|
|
12735
|
+
value: anyType()
|
|
12736
|
+
});
|
|
12737
|
+
const MetadataSchema = objectType({
|
|
12738
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
12739
|
+
});
|
|
12740
|
+
const Metadata = () => {
|
|
12741
|
+
const { id } = reactRouterDom.useParams();
|
|
12742
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12743
|
+
fields: "metadata"
|
|
12744
|
+
});
|
|
12745
|
+
if (isError) {
|
|
12746
|
+
throw error;
|
|
12747
|
+
}
|
|
12748
|
+
const isReady = !isPending && !!order;
|
|
12749
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12750
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12751
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
12752
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
12753
|
+
] }),
|
|
12754
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
12755
|
+
] });
|
|
12756
|
+
};
|
|
12757
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
12758
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
12759
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
12760
|
+
const { handleSuccess } = useRouteModal();
|
|
12761
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
12762
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
12763
|
+
const form = reactHookForm.useForm({
|
|
12764
|
+
defaultValues: {
|
|
12765
|
+
metadata: getDefaultValues(metadata)
|
|
12766
|
+
},
|
|
12767
|
+
resolver: zod.zodResolver(MetadataSchema)
|
|
12768
|
+
});
|
|
12769
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
12770
|
+
const parsedData = parseValues(data);
|
|
12771
|
+
await mutateAsync(
|
|
12772
|
+
{
|
|
12773
|
+
metadata: parsedData
|
|
12774
|
+
},
|
|
12775
|
+
{
|
|
12776
|
+
onSuccess: () => {
|
|
12777
|
+
ui.toast.success("Metadata updated");
|
|
12778
|
+
handleSuccess();
|
|
12779
|
+
},
|
|
12780
|
+
onError: (error) => {
|
|
12781
|
+
ui.toast.error(error.message);
|
|
12782
|
+
}
|
|
12783
|
+
}
|
|
12784
|
+
);
|
|
12785
|
+
});
|
|
12786
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
12787
|
+
control: form.control,
|
|
12788
|
+
name: "metadata"
|
|
12789
|
+
});
|
|
12790
|
+
function deleteRow(index) {
|
|
12791
|
+
remove(index);
|
|
12792
|
+
if (fields.length === 1) {
|
|
12793
|
+
insert(0, {
|
|
12794
|
+
key: "",
|
|
12795
|
+
value: "",
|
|
12796
|
+
disabled: false
|
|
12797
|
+
});
|
|
12798
|
+
}
|
|
12799
|
+
}
|
|
12800
|
+
function insertRow(index, position) {
|
|
12801
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
12802
|
+
key: "",
|
|
12803
|
+
value: "",
|
|
12804
|
+
disabled: false
|
|
12805
|
+
});
|
|
12806
|
+
}
|
|
12807
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12808
|
+
KeyboundForm,
|
|
12809
|
+
{
|
|
12810
|
+
onSubmit: handleSubmit,
|
|
12811
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12812
|
+
children: [
|
|
12813
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
12814
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
12815
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
12816
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
12817
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
12818
|
+
] }),
|
|
12819
|
+
fields.map((field, index) => {
|
|
12820
|
+
const isDisabled = field.disabled || false;
|
|
12821
|
+
let placeholder = "-";
|
|
12822
|
+
if (typeof field.value === "object") {
|
|
12823
|
+
placeholder = "{ ... }";
|
|
12824
|
+
}
|
|
12825
|
+
if (Array.isArray(field.value)) {
|
|
12826
|
+
placeholder = "[ ... ]";
|
|
12827
|
+
}
|
|
12828
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12829
|
+
ConditionalTooltip,
|
|
12830
|
+
{
|
|
12831
|
+
showTooltip: isDisabled,
|
|
12832
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
12833
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
12834
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12835
|
+
"div",
|
|
12836
|
+
{
|
|
12837
|
+
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
12838
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
12839
|
+
}),
|
|
12840
|
+
children: [
|
|
12841
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12842
|
+
Form$2.Field,
|
|
12843
|
+
{
|
|
12844
|
+
control: form.control,
|
|
12845
|
+
name: `metadata.${index}.key`,
|
|
12846
|
+
render: ({ field: field2 }) => {
|
|
12847
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12848
|
+
GridInput,
|
|
12849
|
+
{
|
|
12850
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
12851
|
+
...field2,
|
|
12852
|
+
disabled: isDisabled,
|
|
12853
|
+
placeholder: "Key"
|
|
12854
|
+
}
|
|
12855
|
+
) }) });
|
|
12856
|
+
}
|
|
12857
|
+
}
|
|
12858
|
+
),
|
|
12859
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12860
|
+
Form$2.Field,
|
|
12861
|
+
{
|
|
12862
|
+
control: form.control,
|
|
12863
|
+
name: `metadata.${index}.value`,
|
|
12864
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
12865
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12866
|
+
GridInput,
|
|
12867
|
+
{
|
|
12868
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
12869
|
+
...field2,
|
|
12870
|
+
value: isDisabled ? placeholder : value,
|
|
12871
|
+
disabled: isDisabled,
|
|
12872
|
+
placeholder: "Value"
|
|
12873
|
+
}
|
|
12874
|
+
) }) });
|
|
12875
|
+
}
|
|
12876
|
+
}
|
|
12877
|
+
)
|
|
12878
|
+
]
|
|
12879
|
+
}
|
|
12880
|
+
),
|
|
12881
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
12882
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12883
|
+
ui.DropdownMenu.Trigger,
|
|
12884
|
+
{
|
|
12885
|
+
className: ui.clx(
|
|
12886
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
12887
|
+
{
|
|
12888
|
+
hidden: isDisabled
|
|
12889
|
+
}
|
|
12890
|
+
),
|
|
12891
|
+
disabled: isDisabled,
|
|
12892
|
+
asChild: true,
|
|
12893
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
12894
|
+
}
|
|
12895
|
+
),
|
|
12896
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
12897
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12898
|
+
ui.DropdownMenu.Item,
|
|
12899
|
+
{
|
|
12900
|
+
className: "gap-x-2",
|
|
12901
|
+
onClick: () => insertRow(index, "above"),
|
|
12902
|
+
children: [
|
|
12903
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
12904
|
+
"Insert row above"
|
|
12905
|
+
]
|
|
12906
|
+
}
|
|
12907
|
+
),
|
|
12908
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12909
|
+
ui.DropdownMenu.Item,
|
|
12910
|
+
{
|
|
12911
|
+
className: "gap-x-2",
|
|
12912
|
+
onClick: () => insertRow(index, "below"),
|
|
12913
|
+
children: [
|
|
12914
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
12915
|
+
"Insert row below"
|
|
12916
|
+
]
|
|
12917
|
+
}
|
|
12918
|
+
),
|
|
12919
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
12920
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12921
|
+
ui.DropdownMenu.Item,
|
|
12922
|
+
{
|
|
12923
|
+
className: "gap-x-2",
|
|
12924
|
+
onClick: () => deleteRow(index),
|
|
12925
|
+
children: [
|
|
12926
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
12927
|
+
"Delete row"
|
|
12928
|
+
]
|
|
12929
|
+
}
|
|
12930
|
+
)
|
|
12931
|
+
] })
|
|
12932
|
+
] })
|
|
12933
|
+
] })
|
|
12934
|
+
},
|
|
12935
|
+
field.id
|
|
12936
|
+
);
|
|
12937
|
+
})
|
|
12938
|
+
] }),
|
|
12939
|
+
hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
12940
|
+
] }),
|
|
12941
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12942
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12943
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12944
|
+
] }) })
|
|
12945
|
+
]
|
|
12946
|
+
}
|
|
12947
|
+
) });
|
|
13021
12948
|
};
|
|
13022
|
-
const
|
|
13023
|
-
|
|
12949
|
+
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
12950
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12951
|
+
"input",
|
|
12952
|
+
{
|
|
12953
|
+
ref,
|
|
12954
|
+
...props,
|
|
12955
|
+
autoComplete: "off",
|
|
12956
|
+
className: ui.clx(
|
|
12957
|
+
"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",
|
|
12958
|
+
className
|
|
12959
|
+
)
|
|
12960
|
+
}
|
|
12961
|
+
);
|
|
13024
12962
|
});
|
|
13025
|
-
|
|
13026
|
-
|
|
13027
|
-
|
|
13028
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12963
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
12964
|
+
const PlaceholderInner = () => {
|
|
12965
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
12966
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
12967
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12968
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
12969
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
12970
|
+
] }) })
|
|
13029
12971
|
] });
|
|
13030
12972
|
};
|
|
13031
|
-
const
|
|
13032
|
-
|
|
13033
|
-
|
|
12973
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
12974
|
+
function getDefaultValues(metadata) {
|
|
12975
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
12976
|
+
return [
|
|
12977
|
+
{
|
|
12978
|
+
key: "",
|
|
12979
|
+
value: "",
|
|
12980
|
+
disabled: false
|
|
12981
|
+
}
|
|
12982
|
+
];
|
|
12983
|
+
}
|
|
12984
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
12985
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
12986
|
+
return {
|
|
12987
|
+
key,
|
|
12988
|
+
value,
|
|
12989
|
+
disabled: true
|
|
12990
|
+
};
|
|
12991
|
+
}
|
|
12992
|
+
let stringValue = value;
|
|
12993
|
+
if (typeof value !== "string") {
|
|
12994
|
+
stringValue = JSON.stringify(value);
|
|
12995
|
+
}
|
|
12996
|
+
return {
|
|
12997
|
+
key,
|
|
12998
|
+
value: stringValue,
|
|
12999
|
+
original_key: key
|
|
13000
|
+
};
|
|
13034
13001
|
});
|
|
13035
|
-
|
|
13036
|
-
|
|
13037
|
-
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
};
|
|
13043
|
-
|
|
13044
|
-
|
|
13045
|
-
|
|
13002
|
+
}
|
|
13003
|
+
function parseValues(values) {
|
|
13004
|
+
const metadata = values.metadata;
|
|
13005
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
13006
|
+
if (isEmpty) {
|
|
13007
|
+
return null;
|
|
13008
|
+
}
|
|
13009
|
+
const update = {};
|
|
13010
|
+
metadata.forEach((field) => {
|
|
13011
|
+
let key = field.key;
|
|
13012
|
+
let value = field.value;
|
|
13013
|
+
const disabled = field.disabled;
|
|
13014
|
+
if (!key || !value) {
|
|
13015
|
+
return;
|
|
13016
|
+
}
|
|
13017
|
+
if (disabled) {
|
|
13018
|
+
update[key] = value;
|
|
13019
|
+
return;
|
|
13020
|
+
}
|
|
13021
|
+
key = key.trim();
|
|
13022
|
+
value = value.trim();
|
|
13023
|
+
if (value === "true") {
|
|
13024
|
+
update[key] = true;
|
|
13025
|
+
} else if (value === "false") {
|
|
13026
|
+
update[key] = false;
|
|
13027
|
+
} else {
|
|
13028
|
+
const parsedNumber = parseFloat(value);
|
|
13029
|
+
if (!isNaN(parsedNumber)) {
|
|
13030
|
+
update[key] = parsedNumber;
|
|
13031
|
+
} else {
|
|
13032
|
+
update[key] = value;
|
|
13033
|
+
}
|
|
13034
|
+
}
|
|
13035
|
+
});
|
|
13036
|
+
return update;
|
|
13037
|
+
}
|
|
13038
|
+
function getHasUneditableRows(metadata) {
|
|
13039
|
+
if (!metadata) {
|
|
13040
|
+
return false;
|
|
13041
|
+
}
|
|
13042
|
+
return Object.values(metadata).some(
|
|
13043
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
13044
|
+
);
|
|
13045
|
+
}
|
|
13046
13046
|
const widgetModule = { widgets: [] };
|
|
13047
13047
|
const routeModule = {
|
|
13048
13048
|
routes: [
|
|
@@ -13067,6 +13067,10 @@ const routeModule = {
|
|
|
13067
13067
|
Component: BillingAddress,
|
|
13068
13068
|
path: "/draft-orders/:id/billing-address"
|
|
13069
13069
|
},
|
|
13070
|
+
{
|
|
13071
|
+
Component: CustomItems,
|
|
13072
|
+
path: "/draft-orders/:id/custom-items"
|
|
13073
|
+
},
|
|
13070
13074
|
{
|
|
13071
13075
|
Component: Email,
|
|
13072
13076
|
path: "/draft-orders/:id/email"
|
|
@@ -13075,10 +13079,6 @@ const routeModule = {
|
|
|
13075
13079
|
Component: Items,
|
|
13076
13080
|
path: "/draft-orders/:id/items"
|
|
13077
13081
|
},
|
|
13078
|
-
{
|
|
13079
|
-
Component: Metadata,
|
|
13080
|
-
path: "/draft-orders/:id/metadata"
|
|
13081
|
-
},
|
|
13082
13082
|
{
|
|
13083
13083
|
Component: Promotions,
|
|
13084
13084
|
path: "/draft-orders/:id/promotions"
|
|
@@ -13100,8 +13100,8 @@ const routeModule = {
|
|
|
13100
13100
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13101
13101
|
},
|
|
13102
13102
|
{
|
|
13103
|
-
Component:
|
|
13104
|
-
path: "/draft-orders/:id/
|
|
13103
|
+
Component: Metadata,
|
|
13104
|
+
path: "/draft-orders/:id/metadata"
|
|
13105
13105
|
}
|
|
13106
13106
|
]
|
|
13107
13107
|
}
|