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