34 lines
635 B
TypeScript
34 lines
635 B
TypeScript
import { useState } from 'react'
|
|
import type { Notification } from '@/types/notifications'
|
|
|
|
export function useNotificationCenter(
|
|
markAsRead: (id: string) => void,
|
|
onClose?: () => void
|
|
) {
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
const handleToggle = () => {
|
|
setIsOpen((prev) => !prev)
|
|
}
|
|
|
|
const handleClose = () => {
|
|
setIsOpen(false)
|
|
onClose?.()
|
|
}
|
|
|
|
const handleNotificationClick = (notification: Notification) => {
|
|
if (!notification.read) {
|
|
markAsRead(notification.id)
|
|
}
|
|
handleClose()
|
|
}
|
|
|
|
return {
|
|
isOpen,
|
|
handleToggle,
|
|
handleClose,
|
|
handleNotificationClick,
|
|
}
|
|
}
|
|
|