'use client'; import Alert from '@/components/Alert'; import Button from '@/components/Button'; import { cn } from '@/lib/helper'; import { Icon } from '@iconify/react'; import { useEffect, useRef } from 'react'; /** * Alert Unique Error List * @param formErrorList - Array of error messages * @param onClose - Function to close the alert */ const AlertErrorList = ({ formErrorList, className, onClose, title, }: { formErrorList: string[]; className?: { alert?: string; button?: string; headerWrapper?: string; headerIcon?: string; headerText?: string; titleWrapper?: string; ul?: string; li?: string; }; onClose: () => void; title?: string; }) => { const alertRef = useRef(null); useEffect(() => { if (formErrorList.length > 0) { alertRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start', }); } }, [formErrorList.length]); if (formErrorList.length === 0) return null; return (
{title || `Terdapat ${formErrorList.length} error pada form:`}
); }; export default AlertErrorList;