@medusajs/draft-order 2.11.4-preview-20251110120148 → 2.11.4-preview-20251110180138
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 +486 -486
- package/.medusa/server/src/admin/index.mjs +486 -486
- package/package.json +16 -16
|
@@ -9561,6 +9561,27 @@ const ID = () => {
|
|
|
9561
9561
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9562
9562
|
] });
|
|
9563
9563
|
};
|
|
9564
|
+
const CustomItems = () => {
|
|
9565
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9566
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9567
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9568
|
+
] });
|
|
9569
|
+
};
|
|
9570
|
+
const CustomItemsForm = () => {
|
|
9571
|
+
const form = useForm({
|
|
9572
|
+
resolver: zodResolver(schema$5)
|
|
9573
|
+
});
|
|
9574
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9575
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9576
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9577
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9578
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9579
|
+
] }) })
|
|
9580
|
+
] }) });
|
|
9581
|
+
};
|
|
9582
|
+
const schema$5 = objectType({
|
|
9583
|
+
email: stringType().email()
|
|
9584
|
+
});
|
|
9564
9585
|
const BillingAddress = () => {
|
|
9565
9586
|
const { id } = useParams();
|
|
9566
9587
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9593,7 +9614,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9593
9614
|
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9594
9615
|
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9595
9616
|
},
|
|
9596
|
-
resolver: zodResolver(schema$
|
|
9617
|
+
resolver: zodResolver(schema$4)
|
|
9597
9618
|
});
|
|
9598
9619
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9599
9620
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9750,28 +9771,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9750
9771
|
}
|
|
9751
9772
|
) });
|
|
9752
9773
|
};
|
|
9753
|
-
const schema$
|
|
9754
|
-
const CustomItems = () => {
|
|
9755
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9756
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9757
|
-
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9758
|
-
] });
|
|
9759
|
-
};
|
|
9760
|
-
const CustomItemsForm = () => {
|
|
9761
|
-
const form = useForm({
|
|
9762
|
-
resolver: zodResolver(schema$4)
|
|
9763
|
-
});
|
|
9764
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9765
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9766
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9767
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9768
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9769
|
-
] }) })
|
|
9770
|
-
] }) });
|
|
9771
|
-
};
|
|
9772
|
-
const schema$4 = objectType({
|
|
9773
|
-
email: stringType().email()
|
|
9774
|
-
});
|
|
9774
|
+
const schema$4 = addressSchema;
|
|
9775
9775
|
const Email = () => {
|
|
9776
9776
|
const { id } = useParams();
|
|
9777
9777
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -10814,392 +10814,115 @@ const customItemSchema = objectType({
|
|
|
10814
10814
|
quantity: numberType(),
|
|
10815
10815
|
unit_price: unionType([numberType(), stringType()])
|
|
10816
10816
|
});
|
|
10817
|
-
const
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
}
|
|
10837
|
-
|
|
10817
|
+
const InlineTip = forwardRef(
|
|
10818
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10819
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10820
|
+
return /* @__PURE__ */ jsxs(
|
|
10821
|
+
"div",
|
|
10822
|
+
{
|
|
10823
|
+
ref,
|
|
10824
|
+
className: clx(
|
|
10825
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10826
|
+
className
|
|
10827
|
+
),
|
|
10828
|
+
...props,
|
|
10829
|
+
children: [
|
|
10830
|
+
/* @__PURE__ */ jsx(
|
|
10831
|
+
"div",
|
|
10832
|
+
{
|
|
10833
|
+
role: "presentation",
|
|
10834
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10835
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10836
|
+
})
|
|
10837
|
+
}
|
|
10838
|
+
),
|
|
10839
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10840
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10841
|
+
labelValue,
|
|
10842
|
+
":"
|
|
10843
|
+
] }),
|
|
10844
|
+
" ",
|
|
10845
|
+
children
|
|
10846
|
+
] })
|
|
10847
|
+
]
|
|
10848
|
+
}
|
|
10849
|
+
);
|
|
10850
|
+
}
|
|
10851
|
+
);
|
|
10852
|
+
InlineTip.displayName = "InlineTip";
|
|
10853
|
+
const MetadataFieldSchema = objectType({
|
|
10854
|
+
key: stringType(),
|
|
10855
|
+
disabled: booleanType().optional(),
|
|
10856
|
+
value: anyType()
|
|
10857
|
+
});
|
|
10858
|
+
const MetadataSchema = objectType({
|
|
10859
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10860
|
+
});
|
|
10861
|
+
const Metadata = () => {
|
|
10838
10862
|
const { id } = useParams();
|
|
10839
|
-
const {
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
useInitiateOrderEdit({ preview });
|
|
10845
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10846
|
-
if (isPreviewError) {
|
|
10847
|
-
throw previewError;
|
|
10863
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10864
|
+
fields: "metadata"
|
|
10865
|
+
});
|
|
10866
|
+
if (isError) {
|
|
10867
|
+
throw error;
|
|
10848
10868
|
}
|
|
10849
|
-
const isReady = !!
|
|
10850
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, {
|
|
10851
|
-
/* @__PURE__ */
|
|
10852
|
-
|
|
10869
|
+
const isReady = !isPending && !!order;
|
|
10870
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10871
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10872
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10873
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10874
|
+
] }),
|
|
10875
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10853
10876
|
] });
|
|
10854
10877
|
};
|
|
10855
|
-
const
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
const [comboboxValue, setComboboxValue] = useState("");
|
|
10878
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10879
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10880
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10859
10881
|
const { handleSuccess } = useRouteModal();
|
|
10860
|
-
const
|
|
10861
|
-
const
|
|
10862
|
-
const
|
|
10863
|
-
{
|
|
10864
|
-
|
|
10865
|
-
},
|
|
10866
|
-
{
|
|
10867
|
-
enabled: !!promoIds.length
|
|
10868
|
-
}
|
|
10869
|
-
);
|
|
10870
|
-
const comboboxData = useComboboxData({
|
|
10871
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
10872
|
-
queryFn: async (params) => {
|
|
10873
|
-
return await sdk.admin.promotion.list({
|
|
10874
|
-
...params,
|
|
10875
|
-
id: {
|
|
10876
|
-
$nin: promoIds
|
|
10877
|
-
}
|
|
10878
|
-
});
|
|
10882
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10883
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10884
|
+
const form = useForm({
|
|
10885
|
+
defaultValues: {
|
|
10886
|
+
metadata: getDefaultValues(metadata)
|
|
10879
10887
|
},
|
|
10880
|
-
|
|
10881
|
-
return data.promotions.map((promotion) => ({
|
|
10882
|
-
label: promotion.code,
|
|
10883
|
-
value: promotion.code
|
|
10884
|
-
}));
|
|
10885
|
-
}
|
|
10888
|
+
resolver: zodResolver(MetadataSchema)
|
|
10886
10889
|
});
|
|
10887
|
-
const
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
}
|
|
10891
|
-
addPromotions(
|
|
10890
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10891
|
+
const parsedData = parseValues(data);
|
|
10892
|
+
await mutateAsync(
|
|
10892
10893
|
{
|
|
10893
|
-
|
|
10894
|
+
metadata: parsedData
|
|
10894
10895
|
},
|
|
10895
10896
|
{
|
|
10896
|
-
onError: (e) => {
|
|
10897
|
-
toast.error(e.message);
|
|
10898
|
-
comboboxData.onSearchValueChange("");
|
|
10899
|
-
setComboboxValue("");
|
|
10900
|
-
},
|
|
10901
10897
|
onSuccess: () => {
|
|
10902
|
-
|
|
10903
|
-
|
|
10898
|
+
toast.success("Metadata updated");
|
|
10899
|
+
handleSuccess();
|
|
10900
|
+
},
|
|
10901
|
+
onError: (error) => {
|
|
10902
|
+
toast.error(error.message);
|
|
10904
10903
|
}
|
|
10905
10904
|
}
|
|
10906
10905
|
);
|
|
10907
|
-
};
|
|
10908
|
-
const {
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
}
|
|
10920
|
-
});
|
|
10921
|
-
if (!requestSucceeded) {
|
|
10922
|
-
setIsSubmitting(false);
|
|
10923
|
-
return;
|
|
10906
|
+
});
|
|
10907
|
+
const { fields, insert, remove } = useFieldArray({
|
|
10908
|
+
control: form.control,
|
|
10909
|
+
name: "metadata"
|
|
10910
|
+
});
|
|
10911
|
+
function deleteRow(index) {
|
|
10912
|
+
remove(index);
|
|
10913
|
+
if (fields.length === 1) {
|
|
10914
|
+
insert(0, {
|
|
10915
|
+
key: "",
|
|
10916
|
+
value: "",
|
|
10917
|
+
disabled: false
|
|
10918
|
+
});
|
|
10924
10919
|
}
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
},
|
|
10932
|
-
onSettled: () => {
|
|
10933
|
-
setIsSubmitting(false);
|
|
10934
|
-
}
|
|
10935
|
-
});
|
|
10936
|
-
};
|
|
10937
|
-
if (isError) {
|
|
10938
|
-
throw error;
|
|
10939
|
-
}
|
|
10940
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10941
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10942
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10943
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10944
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10945
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10946
|
-
] }),
|
|
10947
|
-
/* @__PURE__ */ jsx(
|
|
10948
|
-
Combobox,
|
|
10949
|
-
{
|
|
10950
|
-
id: "promotion-combobox",
|
|
10951
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
10952
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10953
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
10954
|
-
options: comboboxData.options,
|
|
10955
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10956
|
-
searchValue: comboboxData.searchValue,
|
|
10957
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10958
|
-
onChange: add,
|
|
10959
|
-
value: comboboxValue
|
|
10960
|
-
}
|
|
10961
|
-
)
|
|
10962
|
-
] }),
|
|
10963
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10964
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
10965
|
-
PromotionItem,
|
|
10966
|
-
{
|
|
10967
|
-
promotion,
|
|
10968
|
-
orderId: preview.id,
|
|
10969
|
-
isLoading: isPending
|
|
10970
|
-
},
|
|
10971
|
-
promotion.id
|
|
10972
|
-
)) })
|
|
10973
|
-
] }) }),
|
|
10974
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10975
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10976
|
-
/* @__PURE__ */ jsx(
|
|
10977
|
-
Button,
|
|
10978
|
-
{
|
|
10979
|
-
size: "small",
|
|
10980
|
-
type: "submit",
|
|
10981
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
10982
|
-
children: "Save"
|
|
10983
|
-
}
|
|
10984
|
-
)
|
|
10985
|
-
] }) })
|
|
10986
|
-
] });
|
|
10987
|
-
};
|
|
10988
|
-
const PromotionItem = ({
|
|
10989
|
-
promotion,
|
|
10990
|
-
orderId,
|
|
10991
|
-
isLoading
|
|
10992
|
-
}) => {
|
|
10993
|
-
var _a;
|
|
10994
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10995
|
-
const onRemove = async () => {
|
|
10996
|
-
removePromotions(
|
|
10997
|
-
{
|
|
10998
|
-
promo_codes: [promotion.code]
|
|
10999
|
-
},
|
|
11000
|
-
{
|
|
11001
|
-
onError: (e) => {
|
|
11002
|
-
toast.error(e.message);
|
|
11003
|
-
}
|
|
11004
|
-
}
|
|
11005
|
-
);
|
|
11006
|
-
};
|
|
11007
|
-
const displayValue = getDisplayValue(promotion);
|
|
11008
|
-
return /* @__PURE__ */ jsxs(
|
|
11009
|
-
"div",
|
|
11010
|
-
{
|
|
11011
|
-
className: clx(
|
|
11012
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11013
|
-
{
|
|
11014
|
-
"animate-pulse": isLoading
|
|
11015
|
-
}
|
|
11016
|
-
),
|
|
11017
|
-
children: [
|
|
11018
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11019
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11020
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11021
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11022
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11023
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11024
|
-
] }),
|
|
11025
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11026
|
-
] })
|
|
11027
|
-
] }),
|
|
11028
|
-
/* @__PURE__ */ jsx(
|
|
11029
|
-
IconButton,
|
|
11030
|
-
{
|
|
11031
|
-
size: "small",
|
|
11032
|
-
type: "button",
|
|
11033
|
-
variant: "transparent",
|
|
11034
|
-
onClick: onRemove,
|
|
11035
|
-
isLoading: isPending || isLoading,
|
|
11036
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11037
|
-
}
|
|
11038
|
-
)
|
|
11039
|
-
]
|
|
11040
|
-
},
|
|
11041
|
-
promotion.id
|
|
11042
|
-
);
|
|
11043
|
-
};
|
|
11044
|
-
function getDisplayValue(promotion) {
|
|
11045
|
-
var _a, _b, _c, _d;
|
|
11046
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11047
|
-
if (!value) {
|
|
11048
|
-
return null;
|
|
11049
|
-
}
|
|
11050
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11051
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11052
|
-
if (!currency) {
|
|
11053
|
-
return null;
|
|
11054
|
-
}
|
|
11055
|
-
return getLocaleAmount(value, currency);
|
|
11056
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11057
|
-
return formatPercentage(value);
|
|
11058
|
-
}
|
|
11059
|
-
return null;
|
|
11060
|
-
}
|
|
11061
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11062
|
-
style: "percent",
|
|
11063
|
-
minimumFractionDigits: 2
|
|
11064
|
-
});
|
|
11065
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11066
|
-
let val = value || 0;
|
|
11067
|
-
if (!isPercentageValue) {
|
|
11068
|
-
val = val / 100;
|
|
11069
|
-
}
|
|
11070
|
-
return formatter.format(val);
|
|
11071
|
-
};
|
|
11072
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11073
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11074
|
-
for (const item of items) {
|
|
11075
|
-
if (item.adjustments) {
|
|
11076
|
-
for (const adjustment of item.adjustments) {
|
|
11077
|
-
if (adjustment.promotion_id) {
|
|
11078
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11079
|
-
}
|
|
11080
|
-
}
|
|
11081
|
-
}
|
|
11082
|
-
}
|
|
11083
|
-
for (const shippingMethod of shippingMethods) {
|
|
11084
|
-
if (shippingMethod.adjustments) {
|
|
11085
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11086
|
-
if (adjustment.promotion_id) {
|
|
11087
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11088
|
-
}
|
|
11089
|
-
}
|
|
11090
|
-
}
|
|
11091
|
-
}
|
|
11092
|
-
return Array.from(promotionIds);
|
|
11093
|
-
}
|
|
11094
|
-
const InlineTip = forwardRef(
|
|
11095
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11096
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11097
|
-
return /* @__PURE__ */ jsxs(
|
|
11098
|
-
"div",
|
|
11099
|
-
{
|
|
11100
|
-
ref,
|
|
11101
|
-
className: clx(
|
|
11102
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11103
|
-
className
|
|
11104
|
-
),
|
|
11105
|
-
...props,
|
|
11106
|
-
children: [
|
|
11107
|
-
/* @__PURE__ */ jsx(
|
|
11108
|
-
"div",
|
|
11109
|
-
{
|
|
11110
|
-
role: "presentation",
|
|
11111
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11112
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11113
|
-
})
|
|
11114
|
-
}
|
|
11115
|
-
),
|
|
11116
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
11117
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11118
|
-
labelValue,
|
|
11119
|
-
":"
|
|
11120
|
-
] }),
|
|
11121
|
-
" ",
|
|
11122
|
-
children
|
|
11123
|
-
] })
|
|
11124
|
-
]
|
|
11125
|
-
}
|
|
11126
|
-
);
|
|
11127
|
-
}
|
|
11128
|
-
);
|
|
11129
|
-
InlineTip.displayName = "InlineTip";
|
|
11130
|
-
const MetadataFieldSchema = objectType({
|
|
11131
|
-
key: stringType(),
|
|
11132
|
-
disabled: booleanType().optional(),
|
|
11133
|
-
value: anyType()
|
|
11134
|
-
});
|
|
11135
|
-
const MetadataSchema = objectType({
|
|
11136
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
11137
|
-
});
|
|
11138
|
-
const Metadata = () => {
|
|
11139
|
-
const { id } = useParams();
|
|
11140
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11141
|
-
fields: "metadata"
|
|
11142
|
-
});
|
|
11143
|
-
if (isError) {
|
|
11144
|
-
throw error;
|
|
11145
|
-
}
|
|
11146
|
-
const isReady = !isPending && !!order;
|
|
11147
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11148
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11149
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
11150
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
11151
|
-
] }),
|
|
11152
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
11153
|
-
] });
|
|
11154
|
-
};
|
|
11155
|
-
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
11156
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11157
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
11158
|
-
const { handleSuccess } = useRouteModal();
|
|
11159
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11160
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11161
|
-
const form = useForm({
|
|
11162
|
-
defaultValues: {
|
|
11163
|
-
metadata: getDefaultValues(metadata)
|
|
11164
|
-
},
|
|
11165
|
-
resolver: zodResolver(MetadataSchema)
|
|
11166
|
-
});
|
|
11167
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11168
|
-
const parsedData = parseValues(data);
|
|
11169
|
-
await mutateAsync(
|
|
11170
|
-
{
|
|
11171
|
-
metadata: parsedData
|
|
11172
|
-
},
|
|
11173
|
-
{
|
|
11174
|
-
onSuccess: () => {
|
|
11175
|
-
toast.success("Metadata updated");
|
|
11176
|
-
handleSuccess();
|
|
11177
|
-
},
|
|
11178
|
-
onError: (error) => {
|
|
11179
|
-
toast.error(error.message);
|
|
11180
|
-
}
|
|
11181
|
-
}
|
|
11182
|
-
);
|
|
11183
|
-
});
|
|
11184
|
-
const { fields, insert, remove } = useFieldArray({
|
|
11185
|
-
control: form.control,
|
|
11186
|
-
name: "metadata"
|
|
11187
|
-
});
|
|
11188
|
-
function deleteRow(index) {
|
|
11189
|
-
remove(index);
|
|
11190
|
-
if (fields.length === 1) {
|
|
11191
|
-
insert(0, {
|
|
11192
|
-
key: "",
|
|
11193
|
-
value: "",
|
|
11194
|
-
disabled: false
|
|
11195
|
-
});
|
|
11196
|
-
}
|
|
11197
|
-
}
|
|
11198
|
-
function insertRow(index, position) {
|
|
11199
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
11200
|
-
key: "",
|
|
11201
|
-
value: "",
|
|
11202
|
-
disabled: false
|
|
10920
|
+
}
|
|
10921
|
+
function insertRow(index, position) {
|
|
10922
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10923
|
+
key: "",
|
|
10924
|
+
value: "",
|
|
10925
|
+
disabled: false
|
|
11203
10926
|
});
|
|
11204
10927
|
}
|
|
11205
10928
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
@@ -11342,104 +11065,381 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
11342
11065
|
] }) })
|
|
11343
11066
|
]
|
|
11344
11067
|
}
|
|
11345
|
-
) });
|
|
11346
|
-
};
|
|
11347
|
-
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11348
|
-
return /* @__PURE__ */ jsx(
|
|
11349
|
-
"input",
|
|
11350
|
-
{
|
|
11351
|
-
ref,
|
|
11352
|
-
...props,
|
|
11353
|
-
autoComplete: "off",
|
|
11354
|
-
className: clx(
|
|
11355
|
-
"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",
|
|
11356
|
-
className
|
|
11068
|
+
) });
|
|
11069
|
+
};
|
|
11070
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11071
|
+
return /* @__PURE__ */ jsx(
|
|
11072
|
+
"input",
|
|
11073
|
+
{
|
|
11074
|
+
ref,
|
|
11075
|
+
...props,
|
|
11076
|
+
autoComplete: "off",
|
|
11077
|
+
className: clx(
|
|
11078
|
+
"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",
|
|
11079
|
+
className
|
|
11080
|
+
)
|
|
11081
|
+
}
|
|
11082
|
+
);
|
|
11083
|
+
});
|
|
11084
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11085
|
+
const PlaceholderInner = () => {
|
|
11086
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11087
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11088
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11089
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11090
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11091
|
+
] }) })
|
|
11092
|
+
] });
|
|
11093
|
+
};
|
|
11094
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11095
|
+
function getDefaultValues(metadata) {
|
|
11096
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
11097
|
+
return [
|
|
11098
|
+
{
|
|
11099
|
+
key: "",
|
|
11100
|
+
value: "",
|
|
11101
|
+
disabled: false
|
|
11102
|
+
}
|
|
11103
|
+
];
|
|
11104
|
+
}
|
|
11105
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11106
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11107
|
+
return {
|
|
11108
|
+
key,
|
|
11109
|
+
value,
|
|
11110
|
+
disabled: true
|
|
11111
|
+
};
|
|
11112
|
+
}
|
|
11113
|
+
let stringValue = value;
|
|
11114
|
+
if (typeof value !== "string") {
|
|
11115
|
+
stringValue = JSON.stringify(value);
|
|
11116
|
+
}
|
|
11117
|
+
return {
|
|
11118
|
+
key,
|
|
11119
|
+
value: stringValue,
|
|
11120
|
+
original_key: key
|
|
11121
|
+
};
|
|
11122
|
+
});
|
|
11123
|
+
}
|
|
11124
|
+
function parseValues(values) {
|
|
11125
|
+
const metadata = values.metadata;
|
|
11126
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11127
|
+
if (isEmpty) {
|
|
11128
|
+
return null;
|
|
11129
|
+
}
|
|
11130
|
+
const update = {};
|
|
11131
|
+
metadata.forEach((field) => {
|
|
11132
|
+
let key = field.key;
|
|
11133
|
+
let value = field.value;
|
|
11134
|
+
const disabled = field.disabled;
|
|
11135
|
+
if (!key || !value) {
|
|
11136
|
+
return;
|
|
11137
|
+
}
|
|
11138
|
+
if (disabled) {
|
|
11139
|
+
update[key] = value;
|
|
11140
|
+
return;
|
|
11141
|
+
}
|
|
11142
|
+
key = key.trim();
|
|
11143
|
+
value = value.trim();
|
|
11144
|
+
if (value === "true") {
|
|
11145
|
+
update[key] = true;
|
|
11146
|
+
} else if (value === "false") {
|
|
11147
|
+
update[key] = false;
|
|
11148
|
+
} else {
|
|
11149
|
+
const parsedNumber = parseFloat(value);
|
|
11150
|
+
if (!isNaN(parsedNumber)) {
|
|
11151
|
+
update[key] = parsedNumber;
|
|
11152
|
+
} else {
|
|
11153
|
+
update[key] = value;
|
|
11154
|
+
}
|
|
11155
|
+
}
|
|
11156
|
+
});
|
|
11157
|
+
return update;
|
|
11158
|
+
}
|
|
11159
|
+
function getHasUneditableRows(metadata) {
|
|
11160
|
+
if (!metadata) {
|
|
11161
|
+
return false;
|
|
11162
|
+
}
|
|
11163
|
+
return Object.values(metadata).some(
|
|
11164
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11165
|
+
);
|
|
11166
|
+
}
|
|
11167
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11168
|
+
const promotionsQueryKeys = {
|
|
11169
|
+
list: (query2) => [
|
|
11170
|
+
PROMOTION_QUERY_KEY,
|
|
11171
|
+
query2 ? query2 : void 0
|
|
11172
|
+
],
|
|
11173
|
+
detail: (id, query2) => [
|
|
11174
|
+
PROMOTION_QUERY_KEY,
|
|
11175
|
+
id,
|
|
11176
|
+
query2 ? query2 : void 0
|
|
11177
|
+
]
|
|
11178
|
+
};
|
|
11179
|
+
const usePromotions = (query2, options) => {
|
|
11180
|
+
const { data, ...rest } = useQuery({
|
|
11181
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11182
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11183
|
+
...options
|
|
11184
|
+
});
|
|
11185
|
+
return { ...data, ...rest };
|
|
11186
|
+
};
|
|
11187
|
+
const Promotions = () => {
|
|
11188
|
+
const { id } = useParams();
|
|
11189
|
+
const {
|
|
11190
|
+
order: preview,
|
|
11191
|
+
isError: isPreviewError,
|
|
11192
|
+
error: previewError
|
|
11193
|
+
} = useOrderPreview(id, void 0);
|
|
11194
|
+
useInitiateOrderEdit({ preview });
|
|
11195
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11196
|
+
if (isPreviewError) {
|
|
11197
|
+
throw previewError;
|
|
11198
|
+
}
|
|
11199
|
+
const isReady = !!preview;
|
|
11200
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11201
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
11202
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
11203
|
+
] });
|
|
11204
|
+
};
|
|
11205
|
+
const PromotionForm = ({ preview }) => {
|
|
11206
|
+
const { items, shipping_methods } = preview;
|
|
11207
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11208
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
11209
|
+
const { handleSuccess } = useRouteModal();
|
|
11210
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11211
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11212
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11213
|
+
{
|
|
11214
|
+
id: promoIds
|
|
11215
|
+
},
|
|
11216
|
+
{
|
|
11217
|
+
enabled: !!promoIds.length
|
|
11218
|
+
}
|
|
11219
|
+
);
|
|
11220
|
+
const comboboxData = useComboboxData({
|
|
11221
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11222
|
+
queryFn: async (params) => {
|
|
11223
|
+
return await sdk.admin.promotion.list({
|
|
11224
|
+
...params,
|
|
11225
|
+
id: {
|
|
11226
|
+
$nin: promoIds
|
|
11227
|
+
}
|
|
11228
|
+
});
|
|
11229
|
+
},
|
|
11230
|
+
getOptions: (data) => {
|
|
11231
|
+
return data.promotions.map((promotion) => ({
|
|
11232
|
+
label: promotion.code,
|
|
11233
|
+
value: promotion.code
|
|
11234
|
+
}));
|
|
11235
|
+
}
|
|
11236
|
+
});
|
|
11237
|
+
const add = async (value) => {
|
|
11238
|
+
if (!value) {
|
|
11239
|
+
return;
|
|
11240
|
+
}
|
|
11241
|
+
addPromotions(
|
|
11242
|
+
{
|
|
11243
|
+
promo_codes: [value]
|
|
11244
|
+
},
|
|
11245
|
+
{
|
|
11246
|
+
onError: (e) => {
|
|
11247
|
+
toast.error(e.message);
|
|
11248
|
+
comboboxData.onSearchValueChange("");
|
|
11249
|
+
setComboboxValue("");
|
|
11250
|
+
},
|
|
11251
|
+
onSuccess: () => {
|
|
11252
|
+
comboboxData.onSearchValueChange("");
|
|
11253
|
+
setComboboxValue("");
|
|
11254
|
+
}
|
|
11255
|
+
}
|
|
11256
|
+
);
|
|
11257
|
+
};
|
|
11258
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11259
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11260
|
+
const onSubmit = async () => {
|
|
11261
|
+
setIsSubmitting(true);
|
|
11262
|
+
let requestSucceeded = false;
|
|
11263
|
+
await requestOrderEdit(void 0, {
|
|
11264
|
+
onError: (e) => {
|
|
11265
|
+
toast.error(e.message);
|
|
11266
|
+
},
|
|
11267
|
+
onSuccess: () => {
|
|
11268
|
+
requestSucceeded = true;
|
|
11269
|
+
}
|
|
11270
|
+
});
|
|
11271
|
+
if (!requestSucceeded) {
|
|
11272
|
+
setIsSubmitting(false);
|
|
11273
|
+
return;
|
|
11274
|
+
}
|
|
11275
|
+
await confirmOrderEdit(void 0, {
|
|
11276
|
+
onError: (e) => {
|
|
11277
|
+
toast.error(e.message);
|
|
11278
|
+
},
|
|
11279
|
+
onSuccess: () => {
|
|
11280
|
+
handleSuccess();
|
|
11281
|
+
},
|
|
11282
|
+
onSettled: () => {
|
|
11283
|
+
setIsSubmitting(false);
|
|
11284
|
+
}
|
|
11285
|
+
});
|
|
11286
|
+
};
|
|
11287
|
+
if (isError) {
|
|
11288
|
+
throw error;
|
|
11289
|
+
}
|
|
11290
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11291
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11292
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11293
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11294
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11295
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11296
|
+
] }),
|
|
11297
|
+
/* @__PURE__ */ jsx(
|
|
11298
|
+
Combobox,
|
|
11299
|
+
{
|
|
11300
|
+
id: "promotion-combobox",
|
|
11301
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11302
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11303
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11304
|
+
options: comboboxData.options,
|
|
11305
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11306
|
+
searchValue: comboboxData.searchValue,
|
|
11307
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11308
|
+
onChange: add,
|
|
11309
|
+
value: comboboxValue
|
|
11310
|
+
}
|
|
11311
|
+
)
|
|
11312
|
+
] }),
|
|
11313
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11314
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11315
|
+
PromotionItem,
|
|
11316
|
+
{
|
|
11317
|
+
promotion,
|
|
11318
|
+
orderId: preview.id,
|
|
11319
|
+
isLoading: isPending
|
|
11320
|
+
},
|
|
11321
|
+
promotion.id
|
|
11322
|
+
)) })
|
|
11323
|
+
] }) }),
|
|
11324
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11325
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11326
|
+
/* @__PURE__ */ jsx(
|
|
11327
|
+
Button,
|
|
11328
|
+
{
|
|
11329
|
+
size: "small",
|
|
11330
|
+
type: "submit",
|
|
11331
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11332
|
+
children: "Save"
|
|
11333
|
+
}
|
|
11357
11334
|
)
|
|
11358
|
-
}
|
|
11359
|
-
);
|
|
11360
|
-
});
|
|
11361
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
11362
|
-
const PlaceholderInner = () => {
|
|
11363
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11364
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11365
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11366
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11367
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11368
11335
|
] }) })
|
|
11369
11336
|
] });
|
|
11370
11337
|
};
|
|
11371
|
-
const
|
|
11372
|
-
|
|
11373
|
-
|
|
11374
|
-
|
|
11338
|
+
const PromotionItem = ({
|
|
11339
|
+
promotion,
|
|
11340
|
+
orderId,
|
|
11341
|
+
isLoading
|
|
11342
|
+
}) => {
|
|
11343
|
+
var _a;
|
|
11344
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11345
|
+
const onRemove = async () => {
|
|
11346
|
+
removePromotions(
|
|
11375
11347
|
{
|
|
11376
|
-
|
|
11377
|
-
|
|
11378
|
-
|
|
11348
|
+
promo_codes: [promotion.code]
|
|
11349
|
+
},
|
|
11350
|
+
{
|
|
11351
|
+
onError: (e) => {
|
|
11352
|
+
toast.error(e.message);
|
|
11353
|
+
}
|
|
11379
11354
|
}
|
|
11380
|
-
|
|
11355
|
+
);
|
|
11356
|
+
};
|
|
11357
|
+
const displayValue = getDisplayValue(promotion);
|
|
11358
|
+
return /* @__PURE__ */ jsxs(
|
|
11359
|
+
"div",
|
|
11360
|
+
{
|
|
11361
|
+
className: clx(
|
|
11362
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11363
|
+
{
|
|
11364
|
+
"animate-pulse": isLoading
|
|
11365
|
+
}
|
|
11366
|
+
),
|
|
11367
|
+
children: [
|
|
11368
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11369
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11370
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11371
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11372
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11373
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11374
|
+
] }),
|
|
11375
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11376
|
+
] })
|
|
11377
|
+
] }),
|
|
11378
|
+
/* @__PURE__ */ jsx(
|
|
11379
|
+
IconButton,
|
|
11380
|
+
{
|
|
11381
|
+
size: "small",
|
|
11382
|
+
type: "button",
|
|
11383
|
+
variant: "transparent",
|
|
11384
|
+
onClick: onRemove,
|
|
11385
|
+
isLoading: isPending || isLoading,
|
|
11386
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11387
|
+
}
|
|
11388
|
+
)
|
|
11389
|
+
]
|
|
11390
|
+
},
|
|
11391
|
+
promotion.id
|
|
11392
|
+
);
|
|
11393
|
+
};
|
|
11394
|
+
function getDisplayValue(promotion) {
|
|
11395
|
+
var _a, _b, _c, _d;
|
|
11396
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11397
|
+
if (!value) {
|
|
11398
|
+
return null;
|
|
11381
11399
|
}
|
|
11382
|
-
|
|
11383
|
-
|
|
11384
|
-
|
|
11385
|
-
|
|
11386
|
-
value,
|
|
11387
|
-
disabled: true
|
|
11388
|
-
};
|
|
11389
|
-
}
|
|
11390
|
-
let stringValue = value;
|
|
11391
|
-
if (typeof value !== "string") {
|
|
11392
|
-
stringValue = JSON.stringify(value);
|
|
11400
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11401
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11402
|
+
if (!currency) {
|
|
11403
|
+
return null;
|
|
11393
11404
|
}
|
|
11394
|
-
return
|
|
11395
|
-
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11399
|
-
});
|
|
11405
|
+
return getLocaleAmount(value, currency);
|
|
11406
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11407
|
+
return formatPercentage(value);
|
|
11408
|
+
}
|
|
11409
|
+
return null;
|
|
11400
11410
|
}
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11405
|
-
|
|
11411
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11412
|
+
style: "percent",
|
|
11413
|
+
minimumFractionDigits: 2
|
|
11414
|
+
});
|
|
11415
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11416
|
+
let val = value || 0;
|
|
11417
|
+
if (!isPercentageValue) {
|
|
11418
|
+
val = val / 100;
|
|
11406
11419
|
}
|
|
11407
|
-
|
|
11408
|
-
|
|
11409
|
-
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
if (
|
|
11413
|
-
|
|
11414
|
-
|
|
11415
|
-
|
|
11416
|
-
|
|
11417
|
-
|
|
11420
|
+
return formatter.format(val);
|
|
11421
|
+
};
|
|
11422
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11423
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11424
|
+
for (const item of items) {
|
|
11425
|
+
if (item.adjustments) {
|
|
11426
|
+
for (const adjustment of item.adjustments) {
|
|
11427
|
+
if (adjustment.promotion_id) {
|
|
11428
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11429
|
+
}
|
|
11430
|
+
}
|
|
11418
11431
|
}
|
|
11419
|
-
|
|
11420
|
-
|
|
11421
|
-
if (
|
|
11422
|
-
|
|
11423
|
-
|
|
11424
|
-
|
|
11425
|
-
|
|
11426
|
-
const parsedNumber = parseFloat(value);
|
|
11427
|
-
if (!isNaN(parsedNumber)) {
|
|
11428
|
-
update[key] = parsedNumber;
|
|
11429
|
-
} else {
|
|
11430
|
-
update[key] = value;
|
|
11432
|
+
}
|
|
11433
|
+
for (const shippingMethod of shippingMethods) {
|
|
11434
|
+
if (shippingMethod.adjustments) {
|
|
11435
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11436
|
+
if (adjustment.promotion_id) {
|
|
11437
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11438
|
+
}
|
|
11431
11439
|
}
|
|
11432
11440
|
}
|
|
11433
|
-
});
|
|
11434
|
-
return update;
|
|
11435
|
-
}
|
|
11436
|
-
function getHasUneditableRows(metadata) {
|
|
11437
|
-
if (!metadata) {
|
|
11438
|
-
return false;
|
|
11439
11441
|
}
|
|
11440
|
-
return
|
|
11441
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11442
|
-
);
|
|
11442
|
+
return Array.from(promotionIds);
|
|
11443
11443
|
}
|
|
11444
11444
|
const SalesChannel = () => {
|
|
11445
11445
|
const { id } = useParams();
|
|
@@ -13053,14 +13053,14 @@ const routeModule = {
|
|
|
13053
13053
|
handle,
|
|
13054
13054
|
loader,
|
|
13055
13055
|
children: [
|
|
13056
|
-
{
|
|
13057
|
-
Component: BillingAddress,
|
|
13058
|
-
path: "/draft-orders/:id/billing-address"
|
|
13059
|
-
},
|
|
13060
13056
|
{
|
|
13061
13057
|
Component: CustomItems,
|
|
13062
13058
|
path: "/draft-orders/:id/custom-items"
|
|
13063
13059
|
},
|
|
13060
|
+
{
|
|
13061
|
+
Component: BillingAddress,
|
|
13062
|
+
path: "/draft-orders/:id/billing-address"
|
|
13063
|
+
},
|
|
13064
13064
|
{
|
|
13065
13065
|
Component: Email,
|
|
13066
13066
|
path: "/draft-orders/:id/email"
|
|
@@ -13069,14 +13069,14 @@ const routeModule = {
|
|
|
13069
13069
|
Component: Items,
|
|
13070
13070
|
path: "/draft-orders/:id/items"
|
|
13071
13071
|
},
|
|
13072
|
-
{
|
|
13073
|
-
Component: Promotions,
|
|
13074
|
-
path: "/draft-orders/:id/promotions"
|
|
13075
|
-
},
|
|
13076
13072
|
{
|
|
13077
13073
|
Component: Metadata,
|
|
13078
13074
|
path: "/draft-orders/:id/metadata"
|
|
13079
13075
|
},
|
|
13076
|
+
{
|
|
13077
|
+
Component: Promotions,
|
|
13078
|
+
path: "/draft-orders/:id/promotions"
|
|
13079
|
+
},
|
|
13080
13080
|
{
|
|
13081
13081
|
Component: SalesChannel,
|
|
13082
13082
|
path: "/draft-orders/:id/sales-channel"
|