29 lines
924 B
TypeScript
29 lines
924 B
TypeScript
import { useToastContext } from '@/components/feedback/ToastProvider';
|
|
import type { UseToastReturn } from './types';
|
|
|
|
export interface Toast {
|
|
id: string;
|
|
message: string;
|
|
type?: 'success' | 'error' | 'warning' | 'info';
|
|
duration?: number;
|
|
}
|
|
|
|
/**
|
|
* Hook pour afficher des toasts.
|
|
* FE-TYPE-012: Fully typed hook return
|
|
*/
|
|
export function useToast(): UseToastReturn {
|
|
const { addToast } = useToastContext();
|
|
|
|
return {
|
|
success: (message: string, duration?: number) =>
|
|
addToast({ message, type: 'success', duration }),
|
|
error: (message: string, duration?: number) =>
|
|
addToast({ message, type: 'error', duration }),
|
|
warning: (message: string, duration?: number) =>
|
|
addToast({ message, type: 'warning', duration }),
|
|
info: (message: string, duration?: number) =>
|
|
addToast({ message, type: 'info', duration }),
|
|
toast: (toast: Omit<Toast, 'id'>) => addToast(toast),
|
|
};
|
|
}
|