"use client" import { useEffect, useRef, useState } from "react"; import { BiBell } from "react-icons/bi" const NotificationsButton = () => { const [isOpen, setIsOpen] = useState(false); const [loading, setLoading] = useState(true); const [notifications, setNotifications] = useState([]); const dropdownRef = useRef(null); const toggleModal = () => { setIsOpen(!isOpen); }; const handleClickOutside = (event : any) => { if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { setIsOpen(false); } }; useEffect(() => { if (isOpen) { document.addEventListener('mousedown', handleClickOutside); } else { document.removeEventListener('mousedown', handleClickOutside); } return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [isOpen]); useEffect(() => { const timer = setTimeout(() => { setLoading(false); setNotifications([ { avatarURL: "https://via.placeholder.com/50", title: "Notification 1", timestamp: "15/4/24", description: "This is notification 1", }, { avatarURL: "https://via.placeholder.com/50", title: "Notification 2", timestamp: "15/4/24", description: "This is notification 2", }, { avatarURL: "https://via.placeholder.com/50", title: "Notification 3", timestamp: "15/4/24", description: "This is notification 3", }, ]); }, 2000); return () => clearTimeout(timer); }, []); return (
{isOpen && (

Notifications

{loading ? ( <>
) : ( notifications.map((notification : any, index : number) => (
Avatar
{notification.title}
{notification.timestamp}
{notification.description}
)) )}
)}
); } export default NotificationsButton