From 6fe515a7019f48e041ad51bb16a47c3deaf7158e Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 5 Feb 2024 13:15:47 -0300 Subject: [PATCH] front(toast): add toast util success and error msg --- web/app/utils/toast.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 web/app/utils/toast.ts diff --git a/web/app/utils/toast.ts b/web/app/utils/toast.ts new file mode 100644 index 0000000..7520924 --- /dev/null +++ b/web/app/utils/toast.ts @@ -0,0 +1,23 @@ +import toast from 'react-hot-toast'; + +interface ToastOptions { + duration?: number; + centered?: boolean; + style?: React.CSSProperties; +} + +const createToast = (message: string, type: 'success' | 'error', options?: ToastOptions) => { + const { duration = 5000, centered = true, style } = options || {}; + + toast[type](message, { + duration, + style: { + textAlign: centered ? 'center' : 'justify', + ...style, + }, + }); +}; + +export const successToast = (message: string, options?: ToastOptions) => createToast(message, 'success', options); + +export const errorToast = (message: string, options?: ToastOptions) => createToast(message, 'error', options);