@medusajs/draft-order 2.11.2-preview-20251029060154 → 2.11.2-preview-20251029090152
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 +505 -505
- package/.medusa/server/src/admin/index.mjs +505 -505
- package/package.json +16 -16
|
@@ -9571,74 +9571,6 @@ const ID = () => {
|
|
|
9571
9571
|
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
|
|
9572
9572
|
] });
|
|
9573
9573
|
};
|
|
9574
|
-
const Email = () => {
|
|
9575
|
-
const { id } = reactRouterDom.useParams();
|
|
9576
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
9577
|
-
fields: "+email"
|
|
9578
|
-
});
|
|
9579
|
-
if (isError) {
|
|
9580
|
-
throw error;
|
|
9581
|
-
}
|
|
9582
|
-
const isReady = !isPending && !!order;
|
|
9583
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9584
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9585
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
9586
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9587
|
-
] }),
|
|
9588
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
9589
|
-
] });
|
|
9590
|
-
};
|
|
9591
|
-
const EmailForm = ({ order }) => {
|
|
9592
|
-
const form = reactHookForm.useForm({
|
|
9593
|
-
defaultValues: {
|
|
9594
|
-
email: order.email ?? ""
|
|
9595
|
-
},
|
|
9596
|
-
resolver: zod.zodResolver(schema$5)
|
|
9597
|
-
});
|
|
9598
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9599
|
-
const { handleSuccess } = useRouteModal();
|
|
9600
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9601
|
-
await mutateAsync(
|
|
9602
|
-
{ email: data.email },
|
|
9603
|
-
{
|
|
9604
|
-
onSuccess: () => {
|
|
9605
|
-
handleSuccess();
|
|
9606
|
-
},
|
|
9607
|
-
onError: (error) => {
|
|
9608
|
-
ui.toast.error(error.message);
|
|
9609
|
-
}
|
|
9610
|
-
}
|
|
9611
|
-
);
|
|
9612
|
-
});
|
|
9613
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9614
|
-
KeyboundForm,
|
|
9615
|
-
{
|
|
9616
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
9617
|
-
onSubmit,
|
|
9618
|
-
children: [
|
|
9619
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9620
|
-
Form$2.Field,
|
|
9621
|
-
{
|
|
9622
|
-
control: form.control,
|
|
9623
|
-
name: "email",
|
|
9624
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9625
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
9626
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9627
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9628
|
-
] })
|
|
9629
|
-
}
|
|
9630
|
-
) }),
|
|
9631
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9632
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9633
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9634
|
-
] }) })
|
|
9635
|
-
]
|
|
9636
|
-
}
|
|
9637
|
-
) });
|
|
9638
|
-
};
|
|
9639
|
-
const schema$5 = objectType({
|
|
9640
|
-
email: stringType().email()
|
|
9641
|
-
});
|
|
9642
9574
|
const BillingAddress = () => {
|
|
9643
9575
|
const { id } = reactRouterDom.useParams();
|
|
9644
9576
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9671,7 +9603,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9671
9603
|
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9672
9604
|
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9673
9605
|
},
|
|
9674
|
-
resolver: zod.zodResolver(schema$
|
|
9606
|
+
resolver: zod.zodResolver(schema$5)
|
|
9675
9607
|
});
|
|
9676
9608
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9677
9609
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9828,7 +9760,28 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9828
9760
|
}
|
|
9829
9761
|
) });
|
|
9830
9762
|
};
|
|
9831
|
-
const schema$
|
|
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
|
+
});
|
|
9832
9785
|
const NumberInput = React.forwardRef(
|
|
9833
9786
|
({
|
|
9834
9787
|
value,
|
|
@@ -10803,54 +10756,10 @@ const customItemSchema = objectType({
|
|
|
10803
10756
|
quantity: numberType(),
|
|
10804
10757
|
unit_price: unionType([numberType(), stringType()])
|
|
10805
10758
|
});
|
|
10806
|
-
const
|
|
10807
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10808
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10809
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10810
|
-
"div",
|
|
10811
|
-
{
|
|
10812
|
-
ref,
|
|
10813
|
-
className: ui.clx(
|
|
10814
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10815
|
-
className
|
|
10816
|
-
),
|
|
10817
|
-
...props,
|
|
10818
|
-
children: [
|
|
10819
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10820
|
-
"div",
|
|
10821
|
-
{
|
|
10822
|
-
role: "presentation",
|
|
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 = () => {
|
|
10759
|
+
const Email = () => {
|
|
10851
10760
|
const { id } = reactRouterDom.useParams();
|
|
10852
10761
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
10853
|
-
fields: "
|
|
10762
|
+
fields: "+email"
|
|
10854
10763
|
});
|
|
10855
10764
|
if (isError) {
|
|
10856
10765
|
throw error;
|
|
@@ -10858,33 +10767,26 @@ const Metadata = () => {
|
|
|
10858
10767
|
const isReady = !isPending && !!order;
|
|
10859
10768
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10860
10769
|
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
10861
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "
|
|
10862
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "
|
|
10770
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
10771
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
10863
10772
|
] }),
|
|
10864
|
-
|
|
10773
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
10865
10774
|
] });
|
|
10866
10775
|
};
|
|
10867
|
-
const
|
|
10868
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10869
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
10870
|
-
const { handleSuccess } = useRouteModal();
|
|
10871
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10872
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10776
|
+
const EmailForm = ({ order }) => {
|
|
10873
10777
|
const form = reactHookForm.useForm({
|
|
10874
10778
|
defaultValues: {
|
|
10875
|
-
|
|
10779
|
+
email: order.email ?? ""
|
|
10876
10780
|
},
|
|
10877
|
-
resolver: zod.zodResolver(
|
|
10781
|
+
resolver: zod.zodResolver(schema$3)
|
|
10878
10782
|
});
|
|
10879
|
-
const
|
|
10880
|
-
|
|
10783
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10784
|
+
const { handleSuccess } = useRouteModal();
|
|
10785
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10881
10786
|
await mutateAsync(
|
|
10882
|
-
{
|
|
10883
|
-
metadata: parsedData
|
|
10884
|
-
},
|
|
10787
|
+
{ email: data.email },
|
|
10885
10788
|
{
|
|
10886
10789
|
onSuccess: () => {
|
|
10887
|
-
ui.toast.success("Metadata updated");
|
|
10888
10790
|
handleSuccess();
|
|
10889
10791
|
},
|
|
10890
10792
|
onError: (error) => {
|
|
@@ -10893,266 +10795,35 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
10893
10795
|
}
|
|
10894
10796
|
);
|
|
10895
10797
|
});
|
|
10896
|
-
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
10897
|
-
control: form.control,
|
|
10898
|
-
name: "metadata"
|
|
10899
|
-
});
|
|
10900
|
-
function deleteRow(index) {
|
|
10901
|
-
remove(index);
|
|
10902
|
-
if (fields.length === 1) {
|
|
10903
|
-
insert(0, {
|
|
10904
|
-
key: "",
|
|
10905
|
-
value: "",
|
|
10906
|
-
disabled: false
|
|
10907
|
-
});
|
|
10908
|
-
}
|
|
10909
|
-
}
|
|
10910
|
-
function insertRow(index, position) {
|
|
10911
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
10912
|
-
key: "",
|
|
10913
|
-
value: "",
|
|
10914
|
-
disabled: false
|
|
10915
|
-
});
|
|
10916
|
-
}
|
|
10917
10798
|
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10918
10799
|
KeyboundForm,
|
|
10919
10800
|
{
|
|
10920
|
-
onSubmit: handleSubmit,
|
|
10921
10801
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
10802
|
+
onSubmit,
|
|
10922
10803
|
children: [
|
|
10923
|
-
/* @__PURE__ */ jsxRuntime.
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
|
|
10936
|
-
|
|
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" }) }),
|
|
10804
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10805
|
+
Form$2.Field,
|
|
10806
|
+
{
|
|
10807
|
+
control: form.control,
|
|
10808
|
+
name: "email",
|
|
10809
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
10810
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
10811
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
10812
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
10813
|
+
] })
|
|
10814
|
+
}
|
|
10815
|
+
) }),
|
|
10816
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10817
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11053
10818
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11054
10819
|
] }) })
|
|
11055
10820
|
]
|
|
11056
10821
|
}
|
|
11057
10822
|
) });
|
|
11058
10823
|
};
|
|
11059
|
-
const
|
|
11060
|
-
|
|
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
|
-
);
|
|
10824
|
+
const schema$3 = objectType({
|
|
10825
|
+
email: stringType().email()
|
|
11072
10826
|
});
|
|
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
10827
|
const PROMOTION_QUERY_KEY = "promotions";
|
|
11157
10828
|
const promotionsQueryKeys = {
|
|
11158
10829
|
list: (query2) => [
|
|
@@ -11324,133 +10995,462 @@ const PromotionForm = ({ preview }) => {
|
|
|
11324
10995
|
] }) })
|
|
11325
10996
|
] });
|
|
11326
10997
|
};
|
|
11327
|
-
const PromotionItem = ({
|
|
11328
|
-
promotion,
|
|
11329
|
-
orderId,
|
|
11330
|
-
isLoading
|
|
11331
|
-
}) => {
|
|
11332
|
-
var _a;
|
|
11333
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11334
|
-
const onRemove = async () => {
|
|
11335
|
-
removePromotions(
|
|
11336
|
-
{
|
|
11337
|
-
promo_codes: [promotion.code]
|
|
11338
|
-
},
|
|
10998
|
+
const PromotionItem = ({
|
|
10999
|
+
promotion,
|
|
11000
|
+
orderId,
|
|
11001
|
+
isLoading
|
|
11002
|
+
}) => {
|
|
11003
|
+
var _a;
|
|
11004
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11005
|
+
const onRemove = async () => {
|
|
11006
|
+
removePromotions(
|
|
11007
|
+
{
|
|
11008
|
+
promo_codes: [promotion.code]
|
|
11009
|
+
},
|
|
11010
|
+
{
|
|
11011
|
+
onError: (e) => {
|
|
11012
|
+
ui.toast.error(e.message);
|
|
11013
|
+
}
|
|
11014
|
+
}
|
|
11015
|
+
);
|
|
11016
|
+
};
|
|
11017
|
+
const displayValue = getDisplayValue(promotion);
|
|
11018
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11019
|
+
"div",
|
|
11020
|
+
{
|
|
11021
|
+
className: ui.clx(
|
|
11022
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11023
|
+
{
|
|
11024
|
+
"animate-pulse": isLoading
|
|
11025
|
+
}
|
|
11026
|
+
),
|
|
11027
|
+
children: [
|
|
11028
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11029
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11030
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11031
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11032
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11033
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11034
|
+
] }),
|
|
11035
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11036
|
+
] })
|
|
11037
|
+
] }),
|
|
11038
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11039
|
+
ui.IconButton,
|
|
11040
|
+
{
|
|
11041
|
+
size: "small",
|
|
11042
|
+
type: "button",
|
|
11043
|
+
variant: "transparent",
|
|
11044
|
+
onClick: onRemove,
|
|
11045
|
+
isLoading: isPending || isLoading,
|
|
11046
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11047
|
+
}
|
|
11048
|
+
)
|
|
11049
|
+
]
|
|
11050
|
+
},
|
|
11051
|
+
promotion.id
|
|
11052
|
+
);
|
|
11053
|
+
};
|
|
11054
|
+
function getDisplayValue(promotion) {
|
|
11055
|
+
var _a, _b, _c, _d;
|
|
11056
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11057
|
+
if (!value) {
|
|
11058
|
+
return null;
|
|
11059
|
+
}
|
|
11060
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11061
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11062
|
+
if (!currency) {
|
|
11063
|
+
return null;
|
|
11064
|
+
}
|
|
11065
|
+
return getLocaleAmount(value, currency);
|
|
11066
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11067
|
+
return formatPercentage(value);
|
|
11068
|
+
}
|
|
11069
|
+
return null;
|
|
11070
|
+
}
|
|
11071
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11072
|
+
style: "percent",
|
|
11073
|
+
minimumFractionDigits: 2
|
|
11074
|
+
});
|
|
11075
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11076
|
+
let val = value || 0;
|
|
11077
|
+
if (!isPercentageValue) {
|
|
11078
|
+
val = val / 100;
|
|
11079
|
+
}
|
|
11080
|
+
return formatter.format(val);
|
|
11081
|
+
};
|
|
11082
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11083
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11084
|
+
for (const item of items) {
|
|
11085
|
+
if (item.adjustments) {
|
|
11086
|
+
for (const adjustment of item.adjustments) {
|
|
11087
|
+
if (adjustment.promotion_id) {
|
|
11088
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11089
|
+
}
|
|
11090
|
+
}
|
|
11091
|
+
}
|
|
11092
|
+
}
|
|
11093
|
+
for (const shippingMethod of shippingMethods) {
|
|
11094
|
+
if (shippingMethod.adjustments) {
|
|
11095
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11096
|
+
if (adjustment.promotion_id) {
|
|
11097
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11098
|
+
}
|
|
11099
|
+
}
|
|
11100
|
+
}
|
|
11101
|
+
}
|
|
11102
|
+
return Array.from(promotionIds);
|
|
11103
|
+
}
|
|
11104
|
+
const InlineTip = React.forwardRef(
|
|
11105
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11106
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11107
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11108
|
+
"div",
|
|
11109
|
+
{
|
|
11110
|
+
ref,
|
|
11111
|
+
className: ui.clx(
|
|
11112
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11113
|
+
className
|
|
11114
|
+
),
|
|
11115
|
+
...props,
|
|
11116
|
+
children: [
|
|
11117
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11118
|
+
"div",
|
|
11119
|
+
{
|
|
11120
|
+
role: "presentation",
|
|
11121
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11122
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11123
|
+
})
|
|
11124
|
+
}
|
|
11125
|
+
),
|
|
11126
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
11127
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11128
|
+
labelValue,
|
|
11129
|
+
":"
|
|
11130
|
+
] }),
|
|
11131
|
+
" ",
|
|
11132
|
+
children
|
|
11133
|
+
] })
|
|
11134
|
+
]
|
|
11135
|
+
}
|
|
11136
|
+
);
|
|
11137
|
+
}
|
|
11138
|
+
);
|
|
11139
|
+
InlineTip.displayName = "InlineTip";
|
|
11140
|
+
const MetadataFieldSchema = objectType({
|
|
11141
|
+
key: stringType(),
|
|
11142
|
+
disabled: booleanType().optional(),
|
|
11143
|
+
value: anyType()
|
|
11144
|
+
});
|
|
11145
|
+
const MetadataSchema = objectType({
|
|
11146
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
11147
|
+
});
|
|
11148
|
+
const Metadata = () => {
|
|
11149
|
+
const { id } = reactRouterDom.useParams();
|
|
11150
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11151
|
+
fields: "metadata"
|
|
11152
|
+
});
|
|
11153
|
+
if (isError) {
|
|
11154
|
+
throw error;
|
|
11155
|
+
}
|
|
11156
|
+
const isReady = !isPending && !!order;
|
|
11157
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11158
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11159
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
11160
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
11161
|
+
] }),
|
|
11162
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
11163
|
+
] });
|
|
11164
|
+
};
|
|
11165
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
11166
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11167
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
11168
|
+
const { handleSuccess } = useRouteModal();
|
|
11169
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11170
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11171
|
+
const form = reactHookForm.useForm({
|
|
11172
|
+
defaultValues: {
|
|
11173
|
+
metadata: getDefaultValues(metadata)
|
|
11174
|
+
},
|
|
11175
|
+
resolver: zod.zodResolver(MetadataSchema)
|
|
11176
|
+
});
|
|
11177
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11178
|
+
const parsedData = parseValues(data);
|
|
11179
|
+
await mutateAsync(
|
|
11180
|
+
{
|
|
11181
|
+
metadata: parsedData
|
|
11182
|
+
},
|
|
11183
|
+
{
|
|
11184
|
+
onSuccess: () => {
|
|
11185
|
+
ui.toast.success("Metadata updated");
|
|
11186
|
+
handleSuccess();
|
|
11187
|
+
},
|
|
11188
|
+
onError: (error) => {
|
|
11189
|
+
ui.toast.error(error.message);
|
|
11190
|
+
}
|
|
11191
|
+
}
|
|
11192
|
+
);
|
|
11193
|
+
});
|
|
11194
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
11195
|
+
control: form.control,
|
|
11196
|
+
name: "metadata"
|
|
11197
|
+
});
|
|
11198
|
+
function deleteRow(index) {
|
|
11199
|
+
remove(index);
|
|
11200
|
+
if (fields.length === 1) {
|
|
11201
|
+
insert(0, {
|
|
11202
|
+
key: "",
|
|
11203
|
+
value: "",
|
|
11204
|
+
disabled: false
|
|
11205
|
+
});
|
|
11206
|
+
}
|
|
11207
|
+
}
|
|
11208
|
+
function insertRow(index, position) {
|
|
11209
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
11210
|
+
key: "",
|
|
11211
|
+
value: "",
|
|
11212
|
+
disabled: false
|
|
11213
|
+
});
|
|
11214
|
+
}
|
|
11215
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11216
|
+
KeyboundForm,
|
|
11217
|
+
{
|
|
11218
|
+
onSubmit: handleSubmit,
|
|
11219
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11220
|
+
children: [
|
|
11221
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
11222
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
11223
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
11224
|
+
/* @__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" }) }),
|
|
11225
|
+
/* @__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" }) })
|
|
11226
|
+
] }),
|
|
11227
|
+
fields.map((field, index) => {
|
|
11228
|
+
const isDisabled = field.disabled || false;
|
|
11229
|
+
let placeholder = "-";
|
|
11230
|
+
if (typeof field.value === "object") {
|
|
11231
|
+
placeholder = "{ ... }";
|
|
11232
|
+
}
|
|
11233
|
+
if (Array.isArray(field.value)) {
|
|
11234
|
+
placeholder = "[ ... ]";
|
|
11235
|
+
}
|
|
11236
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11237
|
+
ConditionalTooltip,
|
|
11238
|
+
{
|
|
11239
|
+
showTooltip: isDisabled,
|
|
11240
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
11241
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
11242
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11243
|
+
"div",
|
|
11244
|
+
{
|
|
11245
|
+
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
11246
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
11247
|
+
}),
|
|
11248
|
+
children: [
|
|
11249
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11250
|
+
Form$2.Field,
|
|
11251
|
+
{
|
|
11252
|
+
control: form.control,
|
|
11253
|
+
name: `metadata.${index}.key`,
|
|
11254
|
+
render: ({ field: field2 }) => {
|
|
11255
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11256
|
+
GridInput,
|
|
11257
|
+
{
|
|
11258
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
11259
|
+
...field2,
|
|
11260
|
+
disabled: isDisabled,
|
|
11261
|
+
placeholder: "Key"
|
|
11262
|
+
}
|
|
11263
|
+
) }) });
|
|
11264
|
+
}
|
|
11265
|
+
}
|
|
11266
|
+
),
|
|
11267
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11268
|
+
Form$2.Field,
|
|
11269
|
+
{
|
|
11270
|
+
control: form.control,
|
|
11271
|
+
name: `metadata.${index}.value`,
|
|
11272
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
11273
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11274
|
+
GridInput,
|
|
11275
|
+
{
|
|
11276
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
11277
|
+
...field2,
|
|
11278
|
+
value: isDisabled ? placeholder : value,
|
|
11279
|
+
disabled: isDisabled,
|
|
11280
|
+
placeholder: "Value"
|
|
11281
|
+
}
|
|
11282
|
+
) }) });
|
|
11283
|
+
}
|
|
11284
|
+
}
|
|
11285
|
+
)
|
|
11286
|
+
]
|
|
11287
|
+
}
|
|
11288
|
+
),
|
|
11289
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
11290
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11291
|
+
ui.DropdownMenu.Trigger,
|
|
11292
|
+
{
|
|
11293
|
+
className: ui.clx(
|
|
11294
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11295
|
+
{
|
|
11296
|
+
hidden: isDisabled
|
|
11297
|
+
}
|
|
11298
|
+
),
|
|
11299
|
+
disabled: isDisabled,
|
|
11300
|
+
asChild: true,
|
|
11301
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
11302
|
+
}
|
|
11303
|
+
),
|
|
11304
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
11305
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11306
|
+
ui.DropdownMenu.Item,
|
|
11307
|
+
{
|
|
11308
|
+
className: "gap-x-2",
|
|
11309
|
+
onClick: () => insertRow(index, "above"),
|
|
11310
|
+
children: [
|
|
11311
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11312
|
+
"Insert row above"
|
|
11313
|
+
]
|
|
11314
|
+
}
|
|
11315
|
+
),
|
|
11316
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11317
|
+
ui.DropdownMenu.Item,
|
|
11318
|
+
{
|
|
11319
|
+
className: "gap-x-2",
|
|
11320
|
+
onClick: () => insertRow(index, "below"),
|
|
11321
|
+
children: [
|
|
11322
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11323
|
+
"Insert row below"
|
|
11324
|
+
]
|
|
11325
|
+
}
|
|
11326
|
+
),
|
|
11327
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
11328
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11329
|
+
ui.DropdownMenu.Item,
|
|
11330
|
+
{
|
|
11331
|
+
className: "gap-x-2",
|
|
11332
|
+
onClick: () => deleteRow(index),
|
|
11333
|
+
children: [
|
|
11334
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
11335
|
+
"Delete row"
|
|
11336
|
+
]
|
|
11337
|
+
}
|
|
11338
|
+
)
|
|
11339
|
+
] })
|
|
11340
|
+
] })
|
|
11341
|
+
] })
|
|
11342
|
+
},
|
|
11343
|
+
field.id
|
|
11344
|
+
);
|
|
11345
|
+
})
|
|
11346
|
+
] }),
|
|
11347
|
+
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." })
|
|
11348
|
+
] }),
|
|
11349
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11350
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11351
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11352
|
+
] }) })
|
|
11353
|
+
]
|
|
11354
|
+
}
|
|
11355
|
+
) });
|
|
11356
|
+
};
|
|
11357
|
+
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
11358
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11359
|
+
"input",
|
|
11360
|
+
{
|
|
11361
|
+
ref,
|
|
11362
|
+
...props,
|
|
11363
|
+
autoComplete: "off",
|
|
11364
|
+
className: ui.clx(
|
|
11365
|
+
"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",
|
|
11366
|
+
className
|
|
11367
|
+
)
|
|
11368
|
+
}
|
|
11369
|
+
);
|
|
11370
|
+
});
|
|
11371
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11372
|
+
const PlaceholderInner = () => {
|
|
11373
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11374
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11375
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11376
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11377
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11378
|
+
] }) })
|
|
11379
|
+
] });
|
|
11380
|
+
};
|
|
11381
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11382
|
+
function getDefaultValues(metadata) {
|
|
11383
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
11384
|
+
return [
|
|
11339
11385
|
{
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11386
|
+
key: "",
|
|
11387
|
+
value: "",
|
|
11388
|
+
disabled: false
|
|
11343
11389
|
}
|
|
11344
|
-
|
|
11345
|
-
};
|
|
11346
|
-
const displayValue = getDisplayValue(promotion);
|
|
11347
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11348
|
-
"div",
|
|
11349
|
-
{
|
|
11350
|
-
className: ui.clx(
|
|
11351
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11352
|
-
{
|
|
11353
|
-
"animate-pulse": isLoading
|
|
11354
|
-
}
|
|
11355
|
-
),
|
|
11356
|
-
children: [
|
|
11357
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11358
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11359
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11360
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11361
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11362
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11363
|
-
] }),
|
|
11364
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11365
|
-
] })
|
|
11366
|
-
] }),
|
|
11367
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11368
|
-
ui.IconButton,
|
|
11369
|
-
{
|
|
11370
|
-
size: "small",
|
|
11371
|
-
type: "button",
|
|
11372
|
-
variant: "transparent",
|
|
11373
|
-
onClick: onRemove,
|
|
11374
|
-
isLoading: isPending || isLoading,
|
|
11375
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11376
|
-
}
|
|
11377
|
-
)
|
|
11378
|
-
]
|
|
11379
|
-
},
|
|
11380
|
-
promotion.id
|
|
11381
|
-
);
|
|
11382
|
-
};
|
|
11383
|
-
function getDisplayValue(promotion) {
|
|
11384
|
-
var _a, _b, _c, _d;
|
|
11385
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11386
|
-
if (!value) {
|
|
11387
|
-
return null;
|
|
11390
|
+
];
|
|
11388
11391
|
}
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
|
|
11392
|
-
|
|
11392
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11393
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11394
|
+
return {
|
|
11395
|
+
key,
|
|
11396
|
+
value,
|
|
11397
|
+
disabled: true
|
|
11398
|
+
};
|
|
11393
11399
|
}
|
|
11394
|
-
|
|
11395
|
-
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11400
|
+
let stringValue = value;
|
|
11401
|
+
if (typeof value !== "string") {
|
|
11402
|
+
stringValue = JSON.stringify(value);
|
|
11403
|
+
}
|
|
11404
|
+
return {
|
|
11405
|
+
key,
|
|
11406
|
+
value: stringValue,
|
|
11407
|
+
original_key: key
|
|
11408
|
+
};
|
|
11409
|
+
});
|
|
11399
11410
|
}
|
|
11400
|
-
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11405
|
-
let val = value || 0;
|
|
11406
|
-
if (!isPercentageValue) {
|
|
11407
|
-
val = val / 100;
|
|
11411
|
+
function parseValues(values) {
|
|
11412
|
+
const metadata = values.metadata;
|
|
11413
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11414
|
+
if (isEmpty) {
|
|
11415
|
+
return null;
|
|
11408
11416
|
}
|
|
11409
|
-
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
|
|
11413
|
-
|
|
11414
|
-
if (
|
|
11415
|
-
|
|
11416
|
-
if (adjustment.promotion_id) {
|
|
11417
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11418
|
-
}
|
|
11419
|
-
}
|
|
11417
|
+
const update = {};
|
|
11418
|
+
metadata.forEach((field) => {
|
|
11419
|
+
let key = field.key;
|
|
11420
|
+
let value = field.value;
|
|
11421
|
+
const disabled = field.disabled;
|
|
11422
|
+
if (!key || !value) {
|
|
11423
|
+
return;
|
|
11420
11424
|
}
|
|
11421
|
-
|
|
11422
|
-
|
|
11423
|
-
|
|
11424
|
-
|
|
11425
|
-
|
|
11426
|
-
|
|
11427
|
-
|
|
11425
|
+
if (disabled) {
|
|
11426
|
+
update[key] = value;
|
|
11427
|
+
return;
|
|
11428
|
+
}
|
|
11429
|
+
key = key.trim();
|
|
11430
|
+
value = value.trim();
|
|
11431
|
+
if (value === "true") {
|
|
11432
|
+
update[key] = true;
|
|
11433
|
+
} else if (value === "false") {
|
|
11434
|
+
update[key] = false;
|
|
11435
|
+
} else {
|
|
11436
|
+
const parsedNumber = parseFloat(value);
|
|
11437
|
+
if (!isNaN(parsedNumber)) {
|
|
11438
|
+
update[key] = parsedNumber;
|
|
11439
|
+
} else {
|
|
11440
|
+
update[key] = value;
|
|
11428
11441
|
}
|
|
11429
11442
|
}
|
|
11443
|
+
});
|
|
11444
|
+
return update;
|
|
11445
|
+
}
|
|
11446
|
+
function getHasUneditableRows(metadata) {
|
|
11447
|
+
if (!metadata) {
|
|
11448
|
+
return false;
|
|
11430
11449
|
}
|
|
11431
|
-
return
|
|
11450
|
+
return Object.values(metadata).some(
|
|
11451
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11452
|
+
);
|
|
11432
11453
|
}
|
|
11433
|
-
const CustomItems = () => {
|
|
11434
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11435
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
11436
|
-
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
11437
|
-
] });
|
|
11438
|
-
};
|
|
11439
|
-
const CustomItemsForm = () => {
|
|
11440
|
-
const form = reactHookForm.useForm({
|
|
11441
|
-
resolver: zod.zodResolver(schema$3)
|
|
11442
|
-
});
|
|
11443
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
11444
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
11445
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11446
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11447
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
11448
|
-
] }) })
|
|
11449
|
-
] }) });
|
|
11450
|
-
};
|
|
11451
|
-
const schema$3 = objectType({
|
|
11452
|
-
email: stringType().email()
|
|
11453
|
-
});
|
|
11454
11454
|
const SalesChannel = () => {
|
|
11455
11455
|
const { id } = reactRouterDom.useParams();
|
|
11456
11456
|
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
@@ -13063,29 +13063,29 @@ const routeModule = {
|
|
|
13063
13063
|
handle,
|
|
13064
13064
|
loader,
|
|
13065
13065
|
children: [
|
|
13066
|
-
{
|
|
13067
|
-
Component: Email,
|
|
13068
|
-
path: "/draft-orders/:id/email"
|
|
13069
|
-
},
|
|
13070
13066
|
{
|
|
13071
13067
|
Component: BillingAddress,
|
|
13072
13068
|
path: "/draft-orders/:id/billing-address"
|
|
13073
13069
|
},
|
|
13070
|
+
{
|
|
13071
|
+
Component: CustomItems,
|
|
13072
|
+
path: "/draft-orders/:id/custom-items"
|
|
13073
|
+
},
|
|
13074
13074
|
{
|
|
13075
13075
|
Component: Items,
|
|
13076
13076
|
path: "/draft-orders/:id/items"
|
|
13077
13077
|
},
|
|
13078
13078
|
{
|
|
13079
|
-
Component:
|
|
13080
|
-
path: "/draft-orders/:id/
|
|
13079
|
+
Component: Email,
|
|
13080
|
+
path: "/draft-orders/:id/email"
|
|
13081
13081
|
},
|
|
13082
13082
|
{
|
|
13083
13083
|
Component: Promotions,
|
|
13084
13084
|
path: "/draft-orders/:id/promotions"
|
|
13085
13085
|
},
|
|
13086
13086
|
{
|
|
13087
|
-
Component:
|
|
13088
|
-
path: "/draft-orders/:id/
|
|
13087
|
+
Component: Metadata,
|
|
13088
|
+
path: "/draft-orders/:id/metadata"
|
|
13089
13089
|
},
|
|
13090
13090
|
{
|
|
13091
13091
|
Component: SalesChannel,
|