'use client' import React, {useEffect, useState} from 'react'; import {CheckCircle, AlertCircle, Info, AlertTriangle, X, LucideIcon} from 'lucide-react'; interface StaticAlertProps { type: 'success' | 'error' | 'info' | 'warning'; message: string; onClose: () => void; } const iconMap: Record = { success: CheckCircle, error: AlertCircle, info: Info, warning: AlertTriangle, }; const accentColorMap: Record = { success: 'text-success border-l-success', error: 'text-error border-l-error', info: 'text-info border-l-info', warning: 'text-warning border-l-warning', }; export default function StaticAlert({type, message, onClose}: StaticAlertProps) { const [visible, setVisible] = useState(false); const onCloseRef = React.useRef(onClose); useEffect((): void => { onCloseRef.current = onClose; }, [onClose]); useEffect((): (() => void) => { setVisible(true); const timer: ReturnType = setTimeout((): void => { setVisible(false); setTimeout((): void => onCloseRef.current(), 300); }, 4800); return (): void => { clearTimeout(timer); }; }, []); function handleClose(): void { setVisible(false); setTimeout((): void => onCloseRef.current(), 300); } const AlertIcon: LucideIcon = iconMap[type]; const accentClasses: string = accentColorMap[type]; return (
{typeof message === 'string' ? message : String(message ?? 'Une erreur est survenue')}
); }