Coerce toast descriptions to strings (lib)
cgen-a45f9e187907479d95483cb2d5598451
This commit is contained in:
parent
0c052636e5
commit
4764de3e0e
1 changed files with 14 additions and 1 deletions
|
|
@ -8,9 +8,22 @@ interface AethexToastOptions {
|
||||||
|
|
||||||
export const aethexToast = {
|
export const aethexToast = {
|
||||||
success: (options: AethexToastOptions) => {
|
success: (options: AethexToastOptions) => {
|
||||||
|
const normalize = (d?: any) => {
|
||||||
|
if (d == null) return undefined;
|
||||||
|
if (typeof d === "string") return d;
|
||||||
|
if (typeof d === "object") {
|
||||||
|
if ((d as any).message) return String((d as any).message);
|
||||||
|
try {
|
||||||
|
return JSON.stringify(d);
|
||||||
|
} catch (e) {
|
||||||
|
return String(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String(d);
|
||||||
|
};
|
||||||
return toast({
|
return toast({
|
||||||
title: `✅ ${options.title || "Success"}`,
|
title: `✅ ${options.title || "Success"}`,
|
||||||
description: options.description,
|
description: normalize(options.description),
|
||||||
duration: options.duration || 5000,
|
duration: options.duration || 5000,
|
||||||
variant: "success" as any,
|
variant: "success" as any,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue