@medusajs/draft-order 2.12.0 → 2.12.2-snapshot-20251203100938
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 +743 -743
- package/.medusa/server/src/admin/index.mjs +743 -743
- package/package.json +16 -16
|
@@ -9762,6 +9762,95 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9762
9762
|
) });
|
|
9763
9763
|
};
|
|
9764
9764
|
const schema$5 = addressSchema;
|
|
9765
|
+
const Email = () => {
|
|
9766
|
+
const { id } = reactRouterDom.useParams();
|
|
9767
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9768
|
+
fields: "+email"
|
|
9769
|
+
});
|
|
9770
|
+
if (isError) {
|
|
9771
|
+
throw error;
|
|
9772
|
+
}
|
|
9773
|
+
const isReady = !isPending && !!order;
|
|
9774
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9775
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9776
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
9777
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9778
|
+
] }),
|
|
9779
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
9780
|
+
] });
|
|
9781
|
+
};
|
|
9782
|
+
const EmailForm = ({ order }) => {
|
|
9783
|
+
const form = reactHookForm.useForm({
|
|
9784
|
+
defaultValues: {
|
|
9785
|
+
email: order.email ?? ""
|
|
9786
|
+
},
|
|
9787
|
+
resolver: zod.zodResolver(schema$4)
|
|
9788
|
+
});
|
|
9789
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9790
|
+
const { handleSuccess } = useRouteModal();
|
|
9791
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9792
|
+
await mutateAsync(
|
|
9793
|
+
{ email: data.email },
|
|
9794
|
+
{
|
|
9795
|
+
onSuccess: () => {
|
|
9796
|
+
handleSuccess();
|
|
9797
|
+
},
|
|
9798
|
+
onError: (error) => {
|
|
9799
|
+
ui.toast.error(error.message);
|
|
9800
|
+
}
|
|
9801
|
+
}
|
|
9802
|
+
);
|
|
9803
|
+
});
|
|
9804
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9805
|
+
KeyboundForm,
|
|
9806
|
+
{
|
|
9807
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9808
|
+
onSubmit,
|
|
9809
|
+
children: [
|
|
9810
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9811
|
+
Form$2.Field,
|
|
9812
|
+
{
|
|
9813
|
+
control: form.control,
|
|
9814
|
+
name: "email",
|
|
9815
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9816
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
9817
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9818
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9819
|
+
] })
|
|
9820
|
+
}
|
|
9821
|
+
) }),
|
|
9822
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9823
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9824
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9825
|
+
] }) })
|
|
9826
|
+
]
|
|
9827
|
+
}
|
|
9828
|
+
) });
|
|
9829
|
+
};
|
|
9830
|
+
const schema$4 = objectType({
|
|
9831
|
+
email: stringType().email()
|
|
9832
|
+
});
|
|
9833
|
+
const CustomItems = () => {
|
|
9834
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9835
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
9836
|
+
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
9837
|
+
] });
|
|
9838
|
+
};
|
|
9839
|
+
const CustomItemsForm = () => {
|
|
9840
|
+
const form = reactHookForm.useForm({
|
|
9841
|
+
resolver: zod.zodResolver(schema$3)
|
|
9842
|
+
});
|
|
9843
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9844
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
9845
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9846
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9847
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
9848
|
+
] }) })
|
|
9849
|
+
] }) });
|
|
9850
|
+
};
|
|
9851
|
+
const schema$3 = objectType({
|
|
9852
|
+
email: stringType().email()
|
|
9853
|
+
});
|
|
9765
9854
|
const NumberInput = React.forwardRef(
|
|
9766
9855
|
({
|
|
9767
9856
|
value,
|
|
@@ -10736,193 +10825,543 @@ const customItemSchema = objectType({
|
|
|
10736
10825
|
quantity: numberType(),
|
|
10737
10826
|
unit_price: unionType([numberType(), stringType()])
|
|
10738
10827
|
});
|
|
10739
|
-
const
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
|
|
10745
|
-
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
}
|
|
10759
|
-
|
|
10828
|
+
const InlineTip = React.forwardRef(
|
|
10829
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10830
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10831
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10832
|
+
"div",
|
|
10833
|
+
{
|
|
10834
|
+
ref,
|
|
10835
|
+
className: ui.clx(
|
|
10836
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10837
|
+
className
|
|
10838
|
+
),
|
|
10839
|
+
...props,
|
|
10840
|
+
children: [
|
|
10841
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10842
|
+
"div",
|
|
10843
|
+
{
|
|
10844
|
+
role: "presentation",
|
|
10845
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10846
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10847
|
+
})
|
|
10848
|
+
}
|
|
10849
|
+
),
|
|
10850
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
10851
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10852
|
+
labelValue,
|
|
10853
|
+
":"
|
|
10854
|
+
] }),
|
|
10855
|
+
" ",
|
|
10856
|
+
children
|
|
10857
|
+
] })
|
|
10858
|
+
]
|
|
10859
|
+
}
|
|
10860
|
+
);
|
|
10861
|
+
}
|
|
10862
|
+
);
|
|
10863
|
+
InlineTip.displayName = "InlineTip";
|
|
10864
|
+
const MetadataFieldSchema = objectType({
|
|
10865
|
+
key: stringType(),
|
|
10866
|
+
disabled: booleanType().optional(),
|
|
10867
|
+
value: anyType()
|
|
10868
|
+
});
|
|
10869
|
+
const MetadataSchema = objectType({
|
|
10870
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10871
|
+
});
|
|
10872
|
+
const Metadata = () => {
|
|
10760
10873
|
const { id } = reactRouterDom.useParams();
|
|
10761
|
-
const {
|
|
10762
|
-
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
useInitiateOrderEdit({ preview });
|
|
10767
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10768
|
-
if (isPreviewError) {
|
|
10769
|
-
throw previewError;
|
|
10874
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10875
|
+
fields: "metadata"
|
|
10876
|
+
});
|
|
10877
|
+
if (isError) {
|
|
10878
|
+
throw error;
|
|
10770
10879
|
}
|
|
10771
|
-
const isReady = !!
|
|
10772
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, {
|
|
10773
|
-
/* @__PURE__ */ jsxRuntime.
|
|
10774
|
-
|
|
10880
|
+
const isReady = !isPending && !!order;
|
|
10881
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10882
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
10883
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
10884
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10885
|
+
] }),
|
|
10886
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10775
10887
|
] });
|
|
10776
10888
|
};
|
|
10777
|
-
const
|
|
10778
|
-
|
|
10779
|
-
|
|
10780
|
-
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
10889
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10890
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10891
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10781
10892
|
const { handleSuccess } = useRouteModal();
|
|
10782
|
-
const
|
|
10783
|
-
const
|
|
10784
|
-
const
|
|
10785
|
-
{
|
|
10786
|
-
|
|
10787
|
-
},
|
|
10788
|
-
{
|
|
10789
|
-
enabled: !!promoIds.length
|
|
10790
|
-
}
|
|
10791
|
-
);
|
|
10792
|
-
const comboboxData = useComboboxData({
|
|
10793
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
10794
|
-
queryFn: async (params) => {
|
|
10795
|
-
return await sdk.admin.promotion.list({
|
|
10796
|
-
...params,
|
|
10797
|
-
id: {
|
|
10798
|
-
$nin: promoIds
|
|
10799
|
-
}
|
|
10800
|
-
});
|
|
10893
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10894
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10895
|
+
const form = reactHookForm.useForm({
|
|
10896
|
+
defaultValues: {
|
|
10897
|
+
metadata: getDefaultValues(metadata)
|
|
10801
10898
|
},
|
|
10802
|
-
|
|
10803
|
-
return data.promotions.map((promotion) => ({
|
|
10804
|
-
label: promotion.code,
|
|
10805
|
-
value: promotion.code
|
|
10806
|
-
}));
|
|
10807
|
-
}
|
|
10899
|
+
resolver: zod.zodResolver(MetadataSchema)
|
|
10808
10900
|
});
|
|
10809
|
-
const
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
}
|
|
10813
|
-
addPromotions(
|
|
10901
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10902
|
+
const parsedData = parseValues(data);
|
|
10903
|
+
await mutateAsync(
|
|
10814
10904
|
{
|
|
10815
|
-
|
|
10905
|
+
metadata: parsedData
|
|
10816
10906
|
},
|
|
10817
10907
|
{
|
|
10818
|
-
onError: (e) => {
|
|
10819
|
-
ui.toast.error(e.message);
|
|
10820
|
-
comboboxData.onSearchValueChange("");
|
|
10821
|
-
setComboboxValue("");
|
|
10822
|
-
},
|
|
10823
10908
|
onSuccess: () => {
|
|
10824
|
-
|
|
10825
|
-
|
|
10909
|
+
ui.toast.success("Metadata updated");
|
|
10910
|
+
handleSuccess();
|
|
10911
|
+
},
|
|
10912
|
+
onError: (error) => {
|
|
10913
|
+
ui.toast.error(error.message);
|
|
10826
10914
|
}
|
|
10827
10915
|
}
|
|
10828
10916
|
);
|
|
10829
|
-
};
|
|
10830
|
-
const {
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
}
|
|
10842
|
-
});
|
|
10843
|
-
if (!requestSucceeded) {
|
|
10844
|
-
setIsSubmitting(false);
|
|
10845
|
-
return;
|
|
10917
|
+
});
|
|
10918
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
10919
|
+
control: form.control,
|
|
10920
|
+
name: "metadata"
|
|
10921
|
+
});
|
|
10922
|
+
function deleteRow(index) {
|
|
10923
|
+
remove(index);
|
|
10924
|
+
if (fields.length === 1) {
|
|
10925
|
+
insert(0, {
|
|
10926
|
+
key: "",
|
|
10927
|
+
value: "",
|
|
10928
|
+
disabled: false
|
|
10929
|
+
});
|
|
10846
10930
|
}
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
},
|
|
10854
|
-
onSettled: () => {
|
|
10855
|
-
setIsSubmitting(false);
|
|
10856
|
-
}
|
|
10931
|
+
}
|
|
10932
|
+
function insertRow(index, position) {
|
|
10933
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10934
|
+
key: "",
|
|
10935
|
+
value: "",
|
|
10936
|
+
disabled: false
|
|
10857
10937
|
});
|
|
10858
|
-
};
|
|
10859
|
-
if (isError) {
|
|
10860
|
-
throw error;
|
|
10861
10938
|
}
|
|
10862
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10939
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10940
|
+
KeyboundForm,
|
|
10941
|
+
{
|
|
10942
|
+
onSubmit: handleSubmit,
|
|
10943
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10944
|
+
children: [
|
|
10945
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10946
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10947
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10948
|
+
/* @__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" }) }),
|
|
10949
|
+
/* @__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" }) })
|
|
10950
|
+
] }),
|
|
10951
|
+
fields.map((field, index) => {
|
|
10952
|
+
const isDisabled = field.disabled || false;
|
|
10953
|
+
let placeholder = "-";
|
|
10954
|
+
if (typeof field.value === "object") {
|
|
10955
|
+
placeholder = "{ ... }";
|
|
10956
|
+
}
|
|
10957
|
+
if (Array.isArray(field.value)) {
|
|
10958
|
+
placeholder = "[ ... ]";
|
|
10959
|
+
}
|
|
10960
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10961
|
+
ConditionalTooltip,
|
|
10962
|
+
{
|
|
10963
|
+
showTooltip: isDisabled,
|
|
10964
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
10965
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
10966
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
10967
|
+
"div",
|
|
10968
|
+
{
|
|
10969
|
+
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
10970
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10971
|
+
}),
|
|
10972
|
+
children: [
|
|
10973
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10974
|
+
Form$2.Field,
|
|
10975
|
+
{
|
|
10976
|
+
control: form.control,
|
|
10977
|
+
name: `metadata.${index}.key`,
|
|
10978
|
+
render: ({ field: field2 }) => {
|
|
10979
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10980
|
+
GridInput,
|
|
10981
|
+
{
|
|
10982
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10983
|
+
...field2,
|
|
10984
|
+
disabled: isDisabled,
|
|
10985
|
+
placeholder: "Key"
|
|
10986
|
+
}
|
|
10987
|
+
) }) });
|
|
10988
|
+
}
|
|
10989
|
+
}
|
|
10990
|
+
),
|
|
10991
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10992
|
+
Form$2.Field,
|
|
10993
|
+
{
|
|
10994
|
+
control: form.control,
|
|
10995
|
+
name: `metadata.${index}.value`,
|
|
10996
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
10997
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10998
|
+
GridInput,
|
|
10999
|
+
{
|
|
11000
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
11001
|
+
...field2,
|
|
11002
|
+
value: isDisabled ? placeholder : value,
|
|
11003
|
+
disabled: isDisabled,
|
|
11004
|
+
placeholder: "Value"
|
|
11005
|
+
}
|
|
11006
|
+
) }) });
|
|
11007
|
+
}
|
|
11008
|
+
}
|
|
11009
|
+
)
|
|
11010
|
+
]
|
|
11011
|
+
}
|
|
11012
|
+
),
|
|
11013
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
11014
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11015
|
+
ui.DropdownMenu.Trigger,
|
|
11016
|
+
{
|
|
11017
|
+
className: ui.clx(
|
|
11018
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11019
|
+
{
|
|
11020
|
+
hidden: isDisabled
|
|
11021
|
+
}
|
|
11022
|
+
),
|
|
11023
|
+
disabled: isDisabled,
|
|
11024
|
+
asChild: true,
|
|
11025
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
11026
|
+
}
|
|
11027
|
+
),
|
|
11028
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
11029
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11030
|
+
ui.DropdownMenu.Item,
|
|
11031
|
+
{
|
|
11032
|
+
className: "gap-x-2",
|
|
11033
|
+
onClick: () => insertRow(index, "above"),
|
|
11034
|
+
children: [
|
|
11035
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11036
|
+
"Insert row above"
|
|
11037
|
+
]
|
|
11038
|
+
}
|
|
11039
|
+
),
|
|
11040
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11041
|
+
ui.DropdownMenu.Item,
|
|
11042
|
+
{
|
|
11043
|
+
className: "gap-x-2",
|
|
11044
|
+
onClick: () => insertRow(index, "below"),
|
|
11045
|
+
children: [
|
|
11046
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11047
|
+
"Insert row below"
|
|
11048
|
+
]
|
|
11049
|
+
}
|
|
11050
|
+
),
|
|
11051
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
11052
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11053
|
+
ui.DropdownMenu.Item,
|
|
11054
|
+
{
|
|
11055
|
+
className: "gap-x-2",
|
|
11056
|
+
onClick: () => deleteRow(index),
|
|
11057
|
+
children: [
|
|
11058
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
11059
|
+
"Delete row"
|
|
11060
|
+
]
|
|
11061
|
+
}
|
|
11062
|
+
)
|
|
11063
|
+
] })
|
|
11064
|
+
] })
|
|
11065
|
+
] })
|
|
11066
|
+
},
|
|
11067
|
+
field.id
|
|
11068
|
+
);
|
|
11069
|
+
})
|
|
11070
|
+
] }),
|
|
11071
|
+
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." })
|
|
10868
11072
|
] }),
|
|
10869
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10870
|
-
|
|
10871
|
-
{
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
PromotionItem,
|
|
10888
|
-
{
|
|
10889
|
-
promotion,
|
|
10890
|
-
orderId: preview.id,
|
|
10891
|
-
isLoading: isPending
|
|
10892
|
-
},
|
|
10893
|
-
promotion.id
|
|
10894
|
-
)) })
|
|
10895
|
-
] }) }),
|
|
10896
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10897
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10898
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10899
|
-
ui.Button,
|
|
10900
|
-
{
|
|
10901
|
-
size: "small",
|
|
10902
|
-
type: "submit",
|
|
10903
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
10904
|
-
children: "Save"
|
|
10905
|
-
}
|
|
11073
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11074
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11075
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11076
|
+
] }) })
|
|
11077
|
+
]
|
|
11078
|
+
}
|
|
11079
|
+
) });
|
|
11080
|
+
};
|
|
11081
|
+
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
11082
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11083
|
+
"input",
|
|
11084
|
+
{
|
|
11085
|
+
ref,
|
|
11086
|
+
...props,
|
|
11087
|
+
autoComplete: "off",
|
|
11088
|
+
className: ui.clx(
|
|
11089
|
+
"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",
|
|
11090
|
+
className
|
|
10906
11091
|
)
|
|
11092
|
+
}
|
|
11093
|
+
);
|
|
11094
|
+
});
|
|
11095
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11096
|
+
const PlaceholderInner = () => {
|
|
11097
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11098
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11099
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11100
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11101
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
10907
11102
|
] }) })
|
|
10908
11103
|
] });
|
|
10909
11104
|
};
|
|
10910
|
-
const
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
}) => {
|
|
10915
|
-
var _a;
|
|
10916
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10917
|
-
const onRemove = async () => {
|
|
10918
|
-
removePromotions(
|
|
10919
|
-
{
|
|
10920
|
-
promo_codes: [promotion.code]
|
|
10921
|
-
},
|
|
11105
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11106
|
+
function getDefaultValues(metadata) {
|
|
11107
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
11108
|
+
return [
|
|
10922
11109
|
{
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
11110
|
+
key: "",
|
|
11111
|
+
value: "",
|
|
11112
|
+
disabled: false
|
|
11113
|
+
}
|
|
11114
|
+
];
|
|
11115
|
+
}
|
|
11116
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11117
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11118
|
+
return {
|
|
11119
|
+
key,
|
|
11120
|
+
value,
|
|
11121
|
+
disabled: true
|
|
11122
|
+
};
|
|
11123
|
+
}
|
|
11124
|
+
let stringValue = value;
|
|
11125
|
+
if (typeof value !== "string") {
|
|
11126
|
+
stringValue = JSON.stringify(value);
|
|
11127
|
+
}
|
|
11128
|
+
return {
|
|
11129
|
+
key,
|
|
11130
|
+
value: stringValue,
|
|
11131
|
+
original_key: key
|
|
11132
|
+
};
|
|
11133
|
+
});
|
|
11134
|
+
}
|
|
11135
|
+
function parseValues(values) {
|
|
11136
|
+
const metadata = values.metadata;
|
|
11137
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11138
|
+
if (isEmpty) {
|
|
11139
|
+
return null;
|
|
11140
|
+
}
|
|
11141
|
+
const update = {};
|
|
11142
|
+
metadata.forEach((field) => {
|
|
11143
|
+
let key = field.key;
|
|
11144
|
+
let value = field.value;
|
|
11145
|
+
const disabled = field.disabled;
|
|
11146
|
+
if (!key || !value) {
|
|
11147
|
+
return;
|
|
11148
|
+
}
|
|
11149
|
+
if (disabled) {
|
|
11150
|
+
update[key] = value;
|
|
11151
|
+
return;
|
|
11152
|
+
}
|
|
11153
|
+
key = key.trim();
|
|
11154
|
+
value = value.trim();
|
|
11155
|
+
if (value === "true") {
|
|
11156
|
+
update[key] = true;
|
|
11157
|
+
} else if (value === "false") {
|
|
11158
|
+
update[key] = false;
|
|
11159
|
+
} else {
|
|
11160
|
+
const parsedNumber = parseFloat(value);
|
|
11161
|
+
if (!isNaN(parsedNumber)) {
|
|
11162
|
+
update[key] = parsedNumber;
|
|
11163
|
+
} else {
|
|
11164
|
+
update[key] = value;
|
|
11165
|
+
}
|
|
11166
|
+
}
|
|
11167
|
+
});
|
|
11168
|
+
return update;
|
|
11169
|
+
}
|
|
11170
|
+
function getHasUneditableRows(metadata) {
|
|
11171
|
+
if (!metadata) {
|
|
11172
|
+
return false;
|
|
11173
|
+
}
|
|
11174
|
+
return Object.values(metadata).some(
|
|
11175
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11176
|
+
);
|
|
11177
|
+
}
|
|
11178
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11179
|
+
const promotionsQueryKeys = {
|
|
11180
|
+
list: (query2) => [
|
|
11181
|
+
PROMOTION_QUERY_KEY,
|
|
11182
|
+
query2 ? query2 : void 0
|
|
11183
|
+
],
|
|
11184
|
+
detail: (id, query2) => [
|
|
11185
|
+
PROMOTION_QUERY_KEY,
|
|
11186
|
+
id,
|
|
11187
|
+
query2 ? query2 : void 0
|
|
11188
|
+
]
|
|
11189
|
+
};
|
|
11190
|
+
const usePromotions = (query2, options) => {
|
|
11191
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
11192
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11193
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11194
|
+
...options
|
|
11195
|
+
});
|
|
11196
|
+
return { ...data, ...rest };
|
|
11197
|
+
};
|
|
11198
|
+
const Promotions = () => {
|
|
11199
|
+
const { id } = reactRouterDom.useParams();
|
|
11200
|
+
const {
|
|
11201
|
+
order: preview,
|
|
11202
|
+
isError: isPreviewError,
|
|
11203
|
+
error: previewError
|
|
11204
|
+
} = useOrderPreview(id, void 0);
|
|
11205
|
+
useInitiateOrderEdit({ preview });
|
|
11206
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11207
|
+
if (isPreviewError) {
|
|
11208
|
+
throw previewError;
|
|
11209
|
+
}
|
|
11210
|
+
const isReady = !!preview;
|
|
11211
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11212
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11213
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11214
|
+
] });
|
|
11215
|
+
};
|
|
11216
|
+
const PromotionForm = ({ preview }) => {
|
|
11217
|
+
const { items, shipping_methods } = preview;
|
|
11218
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11219
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11220
|
+
const { handleSuccess } = useRouteModal();
|
|
11221
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11222
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11223
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11224
|
+
{
|
|
11225
|
+
id: promoIds
|
|
11226
|
+
},
|
|
11227
|
+
{
|
|
11228
|
+
enabled: !!promoIds.length
|
|
11229
|
+
}
|
|
11230
|
+
);
|
|
11231
|
+
const comboboxData = useComboboxData({
|
|
11232
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11233
|
+
queryFn: async (params) => {
|
|
11234
|
+
return await sdk.admin.promotion.list({
|
|
11235
|
+
...params,
|
|
11236
|
+
id: {
|
|
11237
|
+
$nin: promoIds
|
|
11238
|
+
}
|
|
11239
|
+
});
|
|
11240
|
+
},
|
|
11241
|
+
getOptions: (data) => {
|
|
11242
|
+
return data.promotions.map((promotion) => ({
|
|
11243
|
+
label: promotion.code,
|
|
11244
|
+
value: promotion.code
|
|
11245
|
+
}));
|
|
11246
|
+
}
|
|
11247
|
+
});
|
|
11248
|
+
const add = async (value) => {
|
|
11249
|
+
if (!value) {
|
|
11250
|
+
return;
|
|
11251
|
+
}
|
|
11252
|
+
addPromotions(
|
|
11253
|
+
{
|
|
11254
|
+
promo_codes: [value]
|
|
11255
|
+
},
|
|
11256
|
+
{
|
|
11257
|
+
onError: (e) => {
|
|
11258
|
+
ui.toast.error(e.message);
|
|
11259
|
+
comboboxData.onSearchValueChange("");
|
|
11260
|
+
setComboboxValue("");
|
|
11261
|
+
},
|
|
11262
|
+
onSuccess: () => {
|
|
11263
|
+
comboboxData.onSearchValueChange("");
|
|
11264
|
+
setComboboxValue("");
|
|
11265
|
+
}
|
|
11266
|
+
}
|
|
11267
|
+
);
|
|
11268
|
+
};
|
|
11269
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11270
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11271
|
+
const onSubmit = async () => {
|
|
11272
|
+
setIsSubmitting(true);
|
|
11273
|
+
let requestSucceeded = false;
|
|
11274
|
+
await requestOrderEdit(void 0, {
|
|
11275
|
+
onError: (e) => {
|
|
11276
|
+
ui.toast.error(e.message);
|
|
11277
|
+
},
|
|
11278
|
+
onSuccess: () => {
|
|
11279
|
+
requestSucceeded = true;
|
|
11280
|
+
}
|
|
11281
|
+
});
|
|
11282
|
+
if (!requestSucceeded) {
|
|
11283
|
+
setIsSubmitting(false);
|
|
11284
|
+
return;
|
|
11285
|
+
}
|
|
11286
|
+
await confirmOrderEdit(void 0, {
|
|
11287
|
+
onError: (e) => {
|
|
11288
|
+
ui.toast.error(e.message);
|
|
11289
|
+
},
|
|
11290
|
+
onSuccess: () => {
|
|
11291
|
+
handleSuccess();
|
|
11292
|
+
},
|
|
11293
|
+
onSettled: () => {
|
|
11294
|
+
setIsSubmitting(false);
|
|
11295
|
+
}
|
|
11296
|
+
});
|
|
11297
|
+
};
|
|
11298
|
+
if (isError) {
|
|
11299
|
+
throw error;
|
|
11300
|
+
}
|
|
11301
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11302
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11303
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11304
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11305
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11306
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11307
|
+
] }),
|
|
11308
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11309
|
+
Combobox,
|
|
11310
|
+
{
|
|
11311
|
+
id: "promotion-combobox",
|
|
11312
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11313
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11314
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11315
|
+
options: comboboxData.options,
|
|
11316
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11317
|
+
searchValue: comboboxData.searchValue,
|
|
11318
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11319
|
+
onChange: add,
|
|
11320
|
+
value: comboboxValue
|
|
11321
|
+
}
|
|
11322
|
+
)
|
|
11323
|
+
] }),
|
|
11324
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11325
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
11326
|
+
PromotionItem,
|
|
11327
|
+
{
|
|
11328
|
+
promotion,
|
|
11329
|
+
orderId: preview.id,
|
|
11330
|
+
isLoading: isPending
|
|
11331
|
+
},
|
|
11332
|
+
promotion.id
|
|
11333
|
+
)) })
|
|
11334
|
+
] }) }),
|
|
11335
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11336
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11337
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11338
|
+
ui.Button,
|
|
11339
|
+
{
|
|
11340
|
+
size: "small",
|
|
11341
|
+
type: "submit",
|
|
11342
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11343
|
+
children: "Save"
|
|
11344
|
+
}
|
|
11345
|
+
)
|
|
11346
|
+
] }) })
|
|
11347
|
+
] });
|
|
11348
|
+
};
|
|
11349
|
+
const PromotionItem = ({
|
|
11350
|
+
promotion,
|
|
11351
|
+
orderId,
|
|
11352
|
+
isLoading
|
|
11353
|
+
}) => {
|
|
11354
|
+
var _a;
|
|
11355
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11356
|
+
const onRemove = async () => {
|
|
11357
|
+
removePromotions(
|
|
11358
|
+
{
|
|
11359
|
+
promo_codes: [promotion.code]
|
|
11360
|
+
},
|
|
11361
|
+
{
|
|
11362
|
+
onError: (e) => {
|
|
11363
|
+
ui.toast.error(e.message);
|
|
11364
|
+
}
|
|
10926
11365
|
}
|
|
10927
11366
|
);
|
|
10928
11367
|
};
|
|
@@ -11013,74 +11452,6 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
11013
11452
|
}
|
|
11014
11453
|
return Array.from(promotionIds);
|
|
11015
11454
|
}
|
|
11016
|
-
const Email = () => {
|
|
11017
|
-
const { id } = reactRouterDom.useParams();
|
|
11018
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11019
|
-
fields: "+email"
|
|
11020
|
-
});
|
|
11021
|
-
if (isError) {
|
|
11022
|
-
throw error;
|
|
11023
|
-
}
|
|
11024
|
-
const isReady = !isPending && !!order;
|
|
11025
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11026
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11027
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
11028
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
11029
|
-
] }),
|
|
11030
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
11031
|
-
] });
|
|
11032
|
-
};
|
|
11033
|
-
const EmailForm = ({ order }) => {
|
|
11034
|
-
const form = reactHookForm.useForm({
|
|
11035
|
-
defaultValues: {
|
|
11036
|
-
email: order.email ?? ""
|
|
11037
|
-
},
|
|
11038
|
-
resolver: zod.zodResolver(schema$4)
|
|
11039
|
-
});
|
|
11040
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11041
|
-
const { handleSuccess } = useRouteModal();
|
|
11042
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11043
|
-
await mutateAsync(
|
|
11044
|
-
{ email: data.email },
|
|
11045
|
-
{
|
|
11046
|
-
onSuccess: () => {
|
|
11047
|
-
handleSuccess();
|
|
11048
|
-
},
|
|
11049
|
-
onError: (error) => {
|
|
11050
|
-
ui.toast.error(error.message);
|
|
11051
|
-
}
|
|
11052
|
-
}
|
|
11053
|
-
);
|
|
11054
|
-
});
|
|
11055
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11056
|
-
KeyboundForm,
|
|
11057
|
-
{
|
|
11058
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11059
|
-
onSubmit,
|
|
11060
|
-
children: [
|
|
11061
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11062
|
-
Form$2.Field,
|
|
11063
|
-
{
|
|
11064
|
-
control: form.control,
|
|
11065
|
-
name: "email",
|
|
11066
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11067
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
11068
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11069
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11070
|
-
] })
|
|
11071
|
-
}
|
|
11072
|
-
) }),
|
|
11073
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11074
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11075
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11076
|
-
] }) })
|
|
11077
|
-
]
|
|
11078
|
-
}
|
|
11079
|
-
) });
|
|
11080
|
-
};
|
|
11081
|
-
const schema$4 = objectType({
|
|
11082
|
-
email: stringType().email()
|
|
11083
|
-
});
|
|
11084
11455
|
const SalesChannel = () => {
|
|
11085
11456
|
const { id } = reactRouterDom.useParams();
|
|
11086
11457
|
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
@@ -11109,7 +11480,7 @@ const SalesChannelForm = ({ order }) => {
|
|
|
11109
11480
|
defaultValues: {
|
|
11110
11481
|
sales_channel_id: order.sales_channel_id || ""
|
|
11111
11482
|
},
|
|
11112
|
-
resolver: zod.zodResolver(schema$
|
|
11483
|
+
resolver: zod.zodResolver(schema$2)
|
|
11113
11484
|
});
|
|
11114
11485
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11115
11486
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11184,7 +11555,7 @@ const SalesChannelField = ({ control, order }) => {
|
|
|
11184
11555
|
}
|
|
11185
11556
|
);
|
|
11186
11557
|
};
|
|
11187
|
-
const schema$
|
|
11558
|
+
const schema$2 = objectType({
|
|
11188
11559
|
sales_channel_id: stringType().min(1)
|
|
11189
11560
|
});
|
|
11190
11561
|
const ShippingAddress = () => {
|
|
@@ -11219,7 +11590,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
11219
11590
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
11220
11591
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
11221
11592
|
},
|
|
11222
|
-
resolver: zod.zodResolver(schema$
|
|
11593
|
+
resolver: zod.zodResolver(schema$1)
|
|
11223
11594
|
});
|
|
11224
11595
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11225
11596
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11389,7 +11760,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
11389
11760
|
}
|
|
11390
11761
|
) });
|
|
11391
11762
|
};
|
|
11392
|
-
const schema$
|
|
11763
|
+
const schema$1 = addressSchema;
|
|
11393
11764
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11394
11765
|
const Shipping = () => {
|
|
11395
11766
|
var _a;
|
|
@@ -12062,512 +12433,141 @@ const LocationField = ({ control, setValue }) => {
|
|
|
12062
12433
|
value: location.id
|
|
12063
12434
|
}));
|
|
12064
12435
|
}
|
|
12065
|
-
});
|
|
12066
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12067
|
-
Form$2.Field,
|
|
12068
|
-
{
|
|
12069
|
-
control,
|
|
12070
|
-
name: "location_id",
|
|
12071
|
-
render: ({ field: { onChange, ...field } }) => {
|
|
12072
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12073
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
12074
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
|
|
12075
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
|
|
12076
|
-
] }),
|
|
12077
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12078
|
-
Combobox,
|
|
12079
|
-
{
|
|
12080
|
-
options: locations.options,
|
|
12081
|
-
fetchNextPage: locations.fetchNextPage,
|
|
12082
|
-
isFetchingNextPage: locations.isFetchingNextPage,
|
|
12083
|
-
searchValue: locations.searchValue,
|
|
12084
|
-
onSearchValueChange: locations.onSearchValueChange,
|
|
12085
|
-
placeholder: "Select location",
|
|
12086
|
-
onChange: (value) => {
|
|
12087
|
-
setValue("shipping_option_id", "", {
|
|
12088
|
-
shouldDirty: true,
|
|
12089
|
-
shouldTouch: true
|
|
12090
|
-
});
|
|
12091
|
-
onChange(value);
|
|
12092
|
-
},
|
|
12093
|
-
...field
|
|
12094
|
-
}
|
|
12095
|
-
) })
|
|
12096
|
-
] }) });
|
|
12097
|
-
}
|
|
12098
|
-
}
|
|
12099
|
-
);
|
|
12100
|
-
};
|
|
12101
|
-
const ShippingOptionField = ({
|
|
12102
|
-
shippingProfileId,
|
|
12103
|
-
preview,
|
|
12104
|
-
control
|
|
12105
|
-
}) => {
|
|
12106
|
-
var _a;
|
|
12107
|
-
const locationId = reactHookForm.useWatch({ control, name: "location_id" });
|
|
12108
|
-
const shippingOptions = useComboboxData({
|
|
12109
|
-
queryKey: ["shipping_options", locationId, shippingProfileId],
|
|
12110
|
-
queryFn: async (params) => {
|
|
12111
|
-
return await sdk.admin.shippingOption.list({
|
|
12112
|
-
...params,
|
|
12113
|
-
stock_location_id: locationId,
|
|
12114
|
-
shipping_profile_id: shippingProfileId
|
|
12115
|
-
});
|
|
12116
|
-
},
|
|
12117
|
-
getOptions: (data) => {
|
|
12118
|
-
return data.shipping_options.map((option) => {
|
|
12119
|
-
var _a2;
|
|
12120
|
-
if ((_a2 = option.rules) == null ? void 0 : _a2.find(
|
|
12121
|
-
(r) => r.attribute === "is_return" && r.value === "true"
|
|
12122
|
-
)) {
|
|
12123
|
-
return void 0;
|
|
12124
|
-
}
|
|
12125
|
-
return {
|
|
12126
|
-
label: option.name,
|
|
12127
|
-
value: option.id
|
|
12128
|
-
};
|
|
12129
|
-
}).filter(Boolean);
|
|
12130
|
-
},
|
|
12131
|
-
enabled: !!locationId && !!shippingProfileId,
|
|
12132
|
-
defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
|
|
12133
|
-
});
|
|
12134
|
-
const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
|
|
12135
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12136
|
-
Form$2.Field,
|
|
12137
|
-
{
|
|
12138
|
-
control,
|
|
12139
|
-
name: "shipping_option_id",
|
|
12140
|
-
render: ({ field }) => {
|
|
12141
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12142
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
12143
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
|
|
12144
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
|
|
12145
|
-
] }),
|
|
12146
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12147
|
-
ConditionalTooltip,
|
|
12148
|
-
{
|
|
12149
|
-
content: tooltipContent,
|
|
12150
|
-
showTooltip: !locationId || !shippingProfileId,
|
|
12151
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12152
|
-
Combobox,
|
|
12153
|
-
{
|
|
12154
|
-
options: shippingOptions.options,
|
|
12155
|
-
fetchNextPage: shippingOptions.fetchNextPage,
|
|
12156
|
-
isFetchingNextPage: shippingOptions.isFetchingNextPage,
|
|
12157
|
-
searchValue: shippingOptions.searchValue,
|
|
12158
|
-
onSearchValueChange: shippingOptions.onSearchValueChange,
|
|
12159
|
-
placeholder: "Select shipping option",
|
|
12160
|
-
...field,
|
|
12161
|
-
disabled: !locationId || !shippingProfileId
|
|
12162
|
-
}
|
|
12163
|
-
) }) })
|
|
12164
|
-
}
|
|
12165
|
-
)
|
|
12166
|
-
] }) });
|
|
12167
|
-
}
|
|
12168
|
-
}
|
|
12169
|
-
);
|
|
12170
|
-
};
|
|
12171
|
-
const CustomAmountField = ({
|
|
12172
|
-
control,
|
|
12173
|
-
currencyCode
|
|
12174
|
-
}) => {
|
|
12175
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12176
|
-
Form$2.Field,
|
|
12177
|
-
{
|
|
12178
|
-
control,
|
|
12179
|
-
name: "custom_amount",
|
|
12180
|
-
render: ({ field: { onChange, ...field } }) => {
|
|
12181
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12182
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
12183
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
|
|
12184
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
|
|
12185
|
-
] }),
|
|
12186
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12187
|
-
ui.CurrencyInput,
|
|
12188
|
-
{
|
|
12189
|
-
...field,
|
|
12190
|
-
onValueChange: (value) => onChange(value),
|
|
12191
|
-
symbol: getNativeSymbol(currencyCode),
|
|
12192
|
-
code: currencyCode
|
|
12193
|
-
}
|
|
12194
|
-
) })
|
|
12195
|
-
] });
|
|
12196
|
-
}
|
|
12197
|
-
}
|
|
12198
|
-
);
|
|
12199
|
-
};
|
|
12200
|
-
const InlineTip = React.forwardRef(
|
|
12201
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
12202
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
12203
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12204
|
-
"div",
|
|
12205
|
-
{
|
|
12206
|
-
ref,
|
|
12207
|
-
className: ui.clx(
|
|
12208
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
12209
|
-
className
|
|
12210
|
-
),
|
|
12211
|
-
...props,
|
|
12212
|
-
children: [
|
|
12213
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12214
|
-
"div",
|
|
12215
|
-
{
|
|
12216
|
-
role: "presentation",
|
|
12217
|
-
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
12218
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
12219
|
-
})
|
|
12220
|
-
}
|
|
12221
|
-
),
|
|
12222
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
12223
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
12224
|
-
labelValue,
|
|
12225
|
-
":"
|
|
12226
|
-
] }),
|
|
12227
|
-
" ",
|
|
12228
|
-
children
|
|
12229
|
-
] })
|
|
12230
|
-
]
|
|
12231
|
-
}
|
|
12232
|
-
);
|
|
12233
|
-
}
|
|
12234
|
-
);
|
|
12235
|
-
InlineTip.displayName = "InlineTip";
|
|
12236
|
-
const MetadataFieldSchema = objectType({
|
|
12237
|
-
key: stringType(),
|
|
12238
|
-
disabled: booleanType().optional(),
|
|
12239
|
-
value: anyType()
|
|
12240
|
-
});
|
|
12241
|
-
const MetadataSchema = objectType({
|
|
12242
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
12243
|
-
});
|
|
12244
|
-
const Metadata = () => {
|
|
12245
|
-
const { id } = reactRouterDom.useParams();
|
|
12246
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
12247
|
-
fields: "metadata"
|
|
12248
|
-
});
|
|
12249
|
-
if (isError) {
|
|
12250
|
-
throw error;
|
|
12251
|
-
}
|
|
12252
|
-
const isReady = !isPending && !!order;
|
|
12253
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12254
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12255
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
12256
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
12257
|
-
] }),
|
|
12258
|
-
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
12259
|
-
] });
|
|
12260
|
-
};
|
|
12261
|
-
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
12262
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
12263
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
12264
|
-
const { handleSuccess } = useRouteModal();
|
|
12265
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
12266
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
12267
|
-
const form = reactHookForm.useForm({
|
|
12268
|
-
defaultValues: {
|
|
12269
|
-
metadata: getDefaultValues(metadata)
|
|
12270
|
-
},
|
|
12271
|
-
resolver: zod.zodResolver(MetadataSchema)
|
|
12272
|
-
});
|
|
12273
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
12274
|
-
const parsedData = parseValues(data);
|
|
12275
|
-
await mutateAsync(
|
|
12276
|
-
{
|
|
12277
|
-
metadata: parsedData
|
|
12278
|
-
},
|
|
12279
|
-
{
|
|
12280
|
-
onSuccess: () => {
|
|
12281
|
-
ui.toast.success("Metadata updated");
|
|
12282
|
-
handleSuccess();
|
|
12283
|
-
},
|
|
12284
|
-
onError: (error) => {
|
|
12285
|
-
ui.toast.error(error.message);
|
|
12286
|
-
}
|
|
12287
|
-
}
|
|
12288
|
-
);
|
|
12289
|
-
});
|
|
12290
|
-
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
12291
|
-
control: form.control,
|
|
12292
|
-
name: "metadata"
|
|
12293
|
-
});
|
|
12294
|
-
function deleteRow(index) {
|
|
12295
|
-
remove(index);
|
|
12296
|
-
if (fields.length === 1) {
|
|
12297
|
-
insert(0, {
|
|
12298
|
-
key: "",
|
|
12299
|
-
value: "",
|
|
12300
|
-
disabled: false
|
|
12301
|
-
});
|
|
12302
|
-
}
|
|
12303
|
-
}
|
|
12304
|
-
function insertRow(index, position) {
|
|
12305
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
12306
|
-
key: "",
|
|
12307
|
-
value: "",
|
|
12308
|
-
disabled: false
|
|
12309
|
-
});
|
|
12310
|
-
}
|
|
12311
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12312
|
-
KeyboundForm,
|
|
12313
|
-
{
|
|
12314
|
-
onSubmit: handleSubmit,
|
|
12315
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12316
|
-
children: [
|
|
12317
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
12318
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
12319
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
12320
|
-
/* @__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" }) }),
|
|
12321
|
-
/* @__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" }) })
|
|
12322
|
-
] }),
|
|
12323
|
-
fields.map((field, index) => {
|
|
12324
|
-
const isDisabled = field.disabled || false;
|
|
12325
|
-
let placeholder = "-";
|
|
12326
|
-
if (typeof field.value === "object") {
|
|
12327
|
-
placeholder = "{ ... }";
|
|
12328
|
-
}
|
|
12329
|
-
if (Array.isArray(field.value)) {
|
|
12330
|
-
placeholder = "[ ... ]";
|
|
12331
|
-
}
|
|
12332
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12333
|
-
ConditionalTooltip,
|
|
12334
|
-
{
|
|
12335
|
-
showTooltip: isDisabled,
|
|
12336
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
12337
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
12338
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12339
|
-
"div",
|
|
12340
|
-
{
|
|
12341
|
-
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
12342
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
12343
|
-
}),
|
|
12344
|
-
children: [
|
|
12345
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12346
|
-
Form$2.Field,
|
|
12347
|
-
{
|
|
12348
|
-
control: form.control,
|
|
12349
|
-
name: `metadata.${index}.key`,
|
|
12350
|
-
render: ({ field: field2 }) => {
|
|
12351
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12352
|
-
GridInput,
|
|
12353
|
-
{
|
|
12354
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
12355
|
-
...field2,
|
|
12356
|
-
disabled: isDisabled,
|
|
12357
|
-
placeholder: "Key"
|
|
12358
|
-
}
|
|
12359
|
-
) }) });
|
|
12360
|
-
}
|
|
12361
|
-
}
|
|
12362
|
-
),
|
|
12363
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12364
|
-
Form$2.Field,
|
|
12365
|
-
{
|
|
12366
|
-
control: form.control,
|
|
12367
|
-
name: `metadata.${index}.value`,
|
|
12368
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
12369
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12370
|
-
GridInput,
|
|
12371
|
-
{
|
|
12372
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
12373
|
-
...field2,
|
|
12374
|
-
value: isDisabled ? placeholder : value,
|
|
12375
|
-
disabled: isDisabled,
|
|
12376
|
-
placeholder: "Value"
|
|
12377
|
-
}
|
|
12378
|
-
) }) });
|
|
12379
|
-
}
|
|
12380
|
-
}
|
|
12381
|
-
)
|
|
12382
|
-
]
|
|
12383
|
-
}
|
|
12384
|
-
),
|
|
12385
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
12386
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12387
|
-
ui.DropdownMenu.Trigger,
|
|
12388
|
-
{
|
|
12389
|
-
className: ui.clx(
|
|
12390
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
12391
|
-
{
|
|
12392
|
-
hidden: isDisabled
|
|
12393
|
-
}
|
|
12394
|
-
),
|
|
12395
|
-
disabled: isDisabled,
|
|
12396
|
-
asChild: true,
|
|
12397
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
12398
|
-
}
|
|
12399
|
-
),
|
|
12400
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
12401
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12402
|
-
ui.DropdownMenu.Item,
|
|
12403
|
-
{
|
|
12404
|
-
className: "gap-x-2",
|
|
12405
|
-
onClick: () => insertRow(index, "above"),
|
|
12406
|
-
children: [
|
|
12407
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
12408
|
-
"Insert row above"
|
|
12409
|
-
]
|
|
12410
|
-
}
|
|
12411
|
-
),
|
|
12412
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12413
|
-
ui.DropdownMenu.Item,
|
|
12414
|
-
{
|
|
12415
|
-
className: "gap-x-2",
|
|
12416
|
-
onClick: () => insertRow(index, "below"),
|
|
12417
|
-
children: [
|
|
12418
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
12419
|
-
"Insert row below"
|
|
12420
|
-
]
|
|
12421
|
-
}
|
|
12422
|
-
),
|
|
12423
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
12424
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12425
|
-
ui.DropdownMenu.Item,
|
|
12426
|
-
{
|
|
12427
|
-
className: "gap-x-2",
|
|
12428
|
-
onClick: () => deleteRow(index),
|
|
12429
|
-
children: [
|
|
12430
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
12431
|
-
"Delete row"
|
|
12432
|
-
]
|
|
12433
|
-
}
|
|
12434
|
-
)
|
|
12435
|
-
] })
|
|
12436
|
-
] })
|
|
12437
|
-
] })
|
|
12438
|
-
},
|
|
12439
|
-
field.id
|
|
12440
|
-
);
|
|
12441
|
-
})
|
|
12442
|
-
] }),
|
|
12443
|
-
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." })
|
|
12444
|
-
] }),
|
|
12445
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12446
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12447
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12448
|
-
] }) })
|
|
12449
|
-
]
|
|
12450
|
-
}
|
|
12451
|
-
) });
|
|
12452
|
-
};
|
|
12453
|
-
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
12436
|
+
});
|
|
12454
12437
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12455
|
-
|
|
12438
|
+
Form$2.Field,
|
|
12456
12439
|
{
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12440
|
+
control,
|
|
12441
|
+
name: "location_id",
|
|
12442
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
12443
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12444
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
12445
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
|
|
12446
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
|
|
12447
|
+
] }),
|
|
12448
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12449
|
+
Combobox,
|
|
12450
|
+
{
|
|
12451
|
+
options: locations.options,
|
|
12452
|
+
fetchNextPage: locations.fetchNextPage,
|
|
12453
|
+
isFetchingNextPage: locations.isFetchingNextPage,
|
|
12454
|
+
searchValue: locations.searchValue,
|
|
12455
|
+
onSearchValueChange: locations.onSearchValueChange,
|
|
12456
|
+
placeholder: "Select location",
|
|
12457
|
+
onChange: (value) => {
|
|
12458
|
+
setValue("shipping_option_id", "", {
|
|
12459
|
+
shouldDirty: true,
|
|
12460
|
+
shouldTouch: true
|
|
12461
|
+
});
|
|
12462
|
+
onChange(value);
|
|
12463
|
+
},
|
|
12464
|
+
...field
|
|
12465
|
+
}
|
|
12466
|
+
) })
|
|
12467
|
+
] }) });
|
|
12468
|
+
}
|
|
12464
12469
|
}
|
|
12465
12470
|
);
|
|
12466
|
-
});
|
|
12467
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
12468
|
-
const PlaceholderInner = () => {
|
|
12469
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
12470
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
12471
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12472
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
12473
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
12474
|
-
] }) })
|
|
12475
|
-
] });
|
|
12476
12471
|
};
|
|
12477
|
-
const
|
|
12478
|
-
|
|
12479
|
-
|
|
12480
|
-
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
|
|
12486
|
-
|
|
12487
|
-
|
|
12488
|
-
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
|
|
12498
|
-
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12472
|
+
const ShippingOptionField = ({
|
|
12473
|
+
shippingProfileId,
|
|
12474
|
+
preview,
|
|
12475
|
+
control
|
|
12476
|
+
}) => {
|
|
12477
|
+
var _a;
|
|
12478
|
+
const locationId = reactHookForm.useWatch({ control, name: "location_id" });
|
|
12479
|
+
const shippingOptions = useComboboxData({
|
|
12480
|
+
queryKey: ["shipping_options", locationId, shippingProfileId],
|
|
12481
|
+
queryFn: async (params) => {
|
|
12482
|
+
return await sdk.admin.shippingOption.list({
|
|
12483
|
+
...params,
|
|
12484
|
+
stock_location_id: locationId,
|
|
12485
|
+
shipping_profile_id: shippingProfileId
|
|
12486
|
+
});
|
|
12487
|
+
},
|
|
12488
|
+
getOptions: (data) => {
|
|
12489
|
+
return data.shipping_options.map((option) => {
|
|
12490
|
+
var _a2;
|
|
12491
|
+
if ((_a2 = option.rules) == null ? void 0 : _a2.find(
|
|
12492
|
+
(r) => r.attribute === "is_return" && r.value === "true"
|
|
12493
|
+
)) {
|
|
12494
|
+
return void 0;
|
|
12495
|
+
}
|
|
12496
|
+
return {
|
|
12497
|
+
label: option.name,
|
|
12498
|
+
value: option.id
|
|
12499
|
+
};
|
|
12500
|
+
}).filter(Boolean);
|
|
12501
|
+
},
|
|
12502
|
+
enabled: !!locationId && !!shippingProfileId,
|
|
12503
|
+
defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
|
|
12505
12504
|
});
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12505
|
+
const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
|
|
12506
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12507
|
+
Form$2.Field,
|
|
12508
|
+
{
|
|
12509
|
+
control,
|
|
12510
|
+
name: "shipping_option_id",
|
|
12511
|
+
render: ({ field }) => {
|
|
12512
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12513
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
12514
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
|
|
12515
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
|
|
12516
|
+
] }),
|
|
12517
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12518
|
+
ConditionalTooltip,
|
|
12519
|
+
{
|
|
12520
|
+
content: tooltipContent,
|
|
12521
|
+
showTooltip: !locationId || !shippingProfileId,
|
|
12522
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12523
|
+
Combobox,
|
|
12524
|
+
{
|
|
12525
|
+
options: shippingOptions.options,
|
|
12526
|
+
fetchNextPage: shippingOptions.fetchNextPage,
|
|
12527
|
+
isFetchingNextPage: shippingOptions.isFetchingNextPage,
|
|
12528
|
+
searchValue: shippingOptions.searchValue,
|
|
12529
|
+
onSearchValueChange: shippingOptions.onSearchValueChange,
|
|
12530
|
+
placeholder: "Select shipping option",
|
|
12531
|
+
...field,
|
|
12532
|
+
disabled: !locationId || !shippingProfileId
|
|
12533
|
+
}
|
|
12534
|
+
) }) })
|
|
12535
|
+
}
|
|
12536
|
+
)
|
|
12537
|
+
] }) });
|
|
12537
12538
|
}
|
|
12538
12539
|
}
|
|
12539
|
-
});
|
|
12540
|
-
return update;
|
|
12541
|
-
}
|
|
12542
|
-
function getHasUneditableRows(metadata) {
|
|
12543
|
-
if (!metadata) {
|
|
12544
|
-
return false;
|
|
12545
|
-
}
|
|
12546
|
-
return Object.values(metadata).some(
|
|
12547
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
12548
12540
|
);
|
|
12549
|
-
}
|
|
12550
|
-
const CustomItems = () => {
|
|
12551
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12552
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
12553
|
-
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
12554
|
-
] });
|
|
12555
12541
|
};
|
|
12556
|
-
const
|
|
12557
|
-
|
|
12558
|
-
|
|
12559
|
-
|
|
12560
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
|
|
12565
|
-
|
|
12566
|
-
|
|
12542
|
+
const CustomAmountField = ({
|
|
12543
|
+
control,
|
|
12544
|
+
currencyCode
|
|
12545
|
+
}) => {
|
|
12546
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12547
|
+
Form$2.Field,
|
|
12548
|
+
{
|
|
12549
|
+
control,
|
|
12550
|
+
name: "custom_amount",
|
|
12551
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
12552
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12553
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
12554
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
|
|
12555
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
|
|
12556
|
+
] }),
|
|
12557
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12558
|
+
ui.CurrencyInput,
|
|
12559
|
+
{
|
|
12560
|
+
...field,
|
|
12561
|
+
onValueChange: (value) => onChange(value),
|
|
12562
|
+
symbol: getNativeSymbol(currencyCode),
|
|
12563
|
+
code: currencyCode
|
|
12564
|
+
}
|
|
12565
|
+
) })
|
|
12566
|
+
] });
|
|
12567
|
+
}
|
|
12568
|
+
}
|
|
12569
|
+
);
|
|
12567
12570
|
};
|
|
12568
|
-
const schema$1 = objectType({
|
|
12569
|
-
email: stringType().email()
|
|
12570
|
-
});
|
|
12571
12571
|
const TransferOwnership = () => {
|
|
12572
12572
|
const { id } = reactRouterDom.useParams();
|
|
12573
12573
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -13068,17 +13068,25 @@ const routeModule = {
|
|
|
13068
13068
|
Component: BillingAddress,
|
|
13069
13069
|
path: "/draft-orders/:id/billing-address"
|
|
13070
13070
|
},
|
|
13071
|
+
{
|
|
13072
|
+
Component: Email,
|
|
13073
|
+
path: "/draft-orders/:id/email"
|
|
13074
|
+
},
|
|
13075
|
+
{
|
|
13076
|
+
Component: CustomItems,
|
|
13077
|
+
path: "/draft-orders/:id/custom-items"
|
|
13078
|
+
},
|
|
13071
13079
|
{
|
|
13072
13080
|
Component: Items,
|
|
13073
13081
|
path: "/draft-orders/:id/items"
|
|
13074
13082
|
},
|
|
13075
13083
|
{
|
|
13076
|
-
Component:
|
|
13077
|
-
path: "/draft-orders/:id/
|
|
13084
|
+
Component: Metadata,
|
|
13085
|
+
path: "/draft-orders/:id/metadata"
|
|
13078
13086
|
},
|
|
13079
13087
|
{
|
|
13080
|
-
Component:
|
|
13081
|
-
path: "/draft-orders/:id/
|
|
13088
|
+
Component: Promotions,
|
|
13089
|
+
path: "/draft-orders/:id/promotions"
|
|
13082
13090
|
},
|
|
13083
13091
|
{
|
|
13084
13092
|
Component: SalesChannel,
|
|
@@ -13092,14 +13100,6 @@ const routeModule = {
|
|
|
13092
13100
|
Component: Shipping,
|
|
13093
13101
|
path: "/draft-orders/:id/shipping"
|
|
13094
13102
|
},
|
|
13095
|
-
{
|
|
13096
|
-
Component: Metadata,
|
|
13097
|
-
path: "/draft-orders/:id/metadata"
|
|
13098
|
-
},
|
|
13099
|
-
{
|
|
13100
|
-
Component: CustomItems,
|
|
13101
|
-
path: "/draft-orders/:id/custom-items"
|
|
13102
|
-
},
|
|
13103
13103
|
{
|
|
13104
13104
|
Component: TransferOwnership,
|
|
13105
13105
|
path: "/draft-orders/:id/transfer-ownership"
|