2026-03-30 19:11:48 +07:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import { useTranslations } from 'next-intl';
|
|
|
|
|
import { IconCheck } from '@/app/ui/icons/icons';
|
2026-04-04 16:14:56 +07:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { useAllNotifications } from '@/app/hooks/react-query/useAllNotificationsList';
|
2026-03-30 19:11:48 +07:00
|
|
|
|
|
|
|
|
export function NotificationsList() {
|
|
|
|
|
const t = useTranslations('Global');
|
2026-04-04 16:14:56 +07:00
|
|
|
const [selectedFiles, setSelectedFiles] = useState<Set<number>>(new Set());
|
|
|
|
|
const { data: allNotifications } = useAllNotifications();
|
2026-03-30 19:11:48 +07:00
|
|
|
|
2026-04-04 16:14:56 +07:00
|
|
|
useEffect(() => {
|
|
|
|
|
console.log(allNotifications);
|
|
|
|
|
}, [allNotifications])
|
|
|
|
|
|
|
|
|
|
function selectHandler(fileId: number) {
|
2026-03-30 19:11:48 +07:00
|
|
|
setSelectedFiles((prev) => {
|
2026-03-31 13:47:27 +07:00
|
|
|
const newSet = new Set(prev);
|
|
|
|
|
|
2026-03-30 19:11:48 +07:00
|
|
|
if (newSet.has(fileId)) {
|
|
|
|
|
newSet.delete(fileId)
|
|
|
|
|
} else {
|
|
|
|
|
newSet.add(fileId)
|
|
|
|
|
}
|
|
|
|
|
return newSet;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearHandler() {
|
|
|
|
|
setSelectedFiles(new Set());
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 13:47:27 +07:00
|
|
|
function selectAllHandler() {
|
2026-04-04 16:14:56 +07:00
|
|
|
setSelectedFiles(new Set(allNotifications?.notifications.map(item => item.id)));
|
2026-03-31 13:47:27 +07:00
|
|
|
}
|
|
|
|
|
|
2026-03-30 19:11:48 +07:00
|
|
|
return (
|
|
|
|
|
<div
|
2026-03-31 13:47:27 +07:00
|
|
|
className="notifications-list-wrapper"
|
2026-03-30 19:11:48 +07:00
|
|
|
>
|
|
|
|
|
<div
|
2026-03-31 13:47:27 +07:00
|
|
|
className="notifications-list-header"
|
2026-03-30 19:11:48 +07:00
|
|
|
>
|
2026-03-31 13:47:27 +07:00
|
|
|
<h4>
|
|
|
|
|
{t('all-notifications')}
|
|
|
|
|
</h4>
|
2026-03-30 19:11:48 +07:00
|
|
|
|
|
|
|
|
<div
|
2026-03-31 13:47:27 +07:00
|
|
|
className="notifications-list-action"
|
2026-03-30 19:11:48 +07:00
|
|
|
>
|
2026-03-31 13:47:27 +07:00
|
|
|
{(selectedFiles.size !== 0) && (
|
2026-03-31 14:00:51 +07:00
|
|
|
<>
|
|
|
|
|
<button
|
|
|
|
|
className="btn btn-primary"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
clearHandler();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t('deselect')}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
className="btn btn-primary"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
clearHandler();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t('mark-all-as-read')}
|
|
|
|
|
</button>
|
|
|
|
|
</>
|
2026-03-31 13:47:27 +07:00
|
|
|
)}
|
|
|
|
|
<button
|
|
|
|
|
className="btn btn-primary"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
selectAllHandler();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t('select-all')}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className="notifications-list-body"
|
|
|
|
|
>
|
2026-04-04 16:14:56 +07:00
|
|
|
{(allNotifications?.notifications.length !== 0) && (
|
|
|
|
|
allNotifications?.notifications.map(item => {
|
2026-03-31 13:47:27 +07:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className="notification-item"
|
|
|
|
|
key={item.id}
|
|
|
|
|
>
|
2026-03-30 19:11:48 +07:00
|
|
|
<div
|
2026-03-31 13:47:27 +07:00
|
|
|
className="notification-check"
|
|
|
|
|
>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
selectHandler(item.id);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{selectedFiles.has(item.id) && (
|
|
|
|
|
<IconCheck />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
className="notification-body"
|
2026-03-30 19:11:48 +07:00
|
|
|
>
|
|
|
|
|
<div
|
2026-03-31 13:47:27 +07:00
|
|
|
className="notification-header"
|
2026-03-30 19:11:48 +07:00
|
|
|
>
|
2026-03-31 13:47:27 +07:00
|
|
|
<div
|
|
|
|
|
className="notification-title"
|
2026-03-30 19:11:48 +07:00
|
|
|
>
|
2026-04-04 16:14:56 +07:00
|
|
|
{item.type}
|
2026-03-31 13:47:27 +07:00
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className="notification-status"
|
|
|
|
|
>
|
|
|
|
|
{item.status}
|
|
|
|
|
</div>
|
2026-03-30 19:11:48 +07:00
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className="notification-text"
|
|
|
|
|
>
|
2026-04-04 16:14:56 +07:00
|
|
|
{item.message}
|
2026-03-30 19:11:48 +07:00
|
|
|
</div>
|
2026-03-31 13:47:27 +07:00
|
|
|
<div
|
|
|
|
|
className="notification-footer"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
className="notification-date"
|
|
|
|
|
>
|
2026-04-04 16:14:56 +07:00
|
|
|
{item.createdAt}
|
2026-03-31 13:47:27 +07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
className="btn btn-remove"
|
|
|
|
|
>
|
|
|
|
|
{t('remove')}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-03-30 19:11:48 +07:00
|
|
|
</div>
|
2026-03-31 13:47:27 +07:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
)}
|
2026-03-30 19:11:48 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|