FactuGES_ERP/packages/rdx-ui/src/helpers/toast-utils.ts

65 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-03-17 17:49:54 +00:00
import { toast } from "sonner";
2025-09-24 10:34:04 +00:00
/**
* Muestra un toast de aviso
*/
2025-10-23 17:29:52 +00:00
export function showInfoToast(title: string, description?: string, id?: number | string) {
2025-09-24 10:34:04 +00:00
toast.info(title, {
description,
2025-10-23 17:29:52 +00:00
id,
2025-09-24 10:34:04 +00:00
});
}
/**
* Muestra un toast de aviso
*/
2025-10-23 17:29:52 +00:00
export function showWarningToast(title: string, description?: string, id?: number | string) {
2025-09-24 10:34:04 +00:00
toast.warning(title, {
description,
2025-10-23 17:29:52 +00:00
id,
2025-09-24 10:34:04 +00:00
});
}
/**
* Muestra un toast de éxito
*/
2025-10-23 17:29:52 +00:00
export function showSuccessToast(title: string, description?: string, id?: number | string) {
2025-09-24 10:34:04 +00:00
toast.success(title, {
description,
2025-10-23 17:29:52 +00:00
id,
2025-09-24 10:34:04 +00:00
});
}
/**
* Muestra un toast de error
*/
2025-10-23 17:29:52 +00:00
export function showErrorToast(title: string, description?: string, id?: number | string) {
2025-09-24 10:34:04 +00:00
toast.error(title, {
description,
2025-10-23 17:29:52 +00:00
id,
});
}
/**
* Toast con opción "Undo" (deshacer)
* @param message
* @param onUndo
* @returns
*/
export function showUndoToast(
message: string,
onUndo: () => void,
id?: number | string
): number | string {
return toast(message, {
id,
description: "",
action: {
label: "Undo",
onClick: onUndo,
},
duration: 5000,
2025-09-24 10:34:04 +00:00
});
}