import { Notification } from 'iconsax-react'; import { FC, useState } from 'react'; import XIcon from '../../assets/images/close-circle.svg'; import { useTranslation } from 'react-i18next'; import { clx } from '../../helpers/utils'; import StatusCircle from '../../components/StatusCircle'; import { useOutsideClick } from '../../hooks/useOutSideClick'; import { useGetNotification, useReadAll } from './hooks/useNotificationData'; import { NotificationItemType } from './types/NotificationTypes'; import { timeAgo } from '../../config/func'; import InfiniteScroll from 'react-infinite-scroll-component'; import MoonLoader from "react-spinners/MoonLoader" import Button from '../../components/Button'; import { toast } from 'react-toastify'; import { useGetDashboardSummary } from '../home/hooks/useHomeData'; const Notifications: FC = () => { const { t } = useTranslation('global'); const ref = useOutsideClick(() => setShowModal(false)); const [activeTab, setActiveTab] = useState<'all' | 'read' | 'unread'>('all'); const [showModal, setShowModal] = useState(false); const { data, fetchNextPage, hasNextPage, refetch } = useGetNotification(activeTab); const readAll = useReadAll() const posts = data?.pages.flatMap((page) => page.data?.notifications) || []; const getDashboard = useGetDashboardSummary() const handleAllRead = () => { readAll.mutate(undefined, { onSuccess: () => { getDashboard.refetch() refetch() toast.success(t('success')) } }) } return (
setShowModal(!showModal)} className='relative cursor-pointer'>
{getDashboard.data?.data?.notificationCount}
{showModal && (
{t('notif.natification')}
close setShowModal(false)} />
setActiveTab('all')} className={clx( 'flex-1 border-l cursor-pointer text-white border-white border-opacity-70 flex justify-center items-center', activeTab === 'all' ? 'bg-white bg-opacity-70 text-black' : '' )} > همه
setActiveTab('unread')} className={clx( 'flex-1 border-l cursor-pointer text-white border-white border-opacity-70 bg-transparent flex justify-center items-center', activeTab === 'unread' ? 'bg-white bg-opacity-70 text-black' : '' )} > خوانده نشده
setActiveTab('read')} className={clx( 'flex-1 cursor-pointer text-white border-white bg-transparent flex justify-center items-center', activeTab === 'read' ? 'bg-white bg-opacity-70 text-black' : '' )} > خوانده شده
} scrollableTarget="notificationsContainer" > { posts.map((item: NotificationItemType) => (
{item.message}
{timeAgo(item.createdAt)}
{item.title}
)) }
)} ); }; export default Notifications;