Files
no-copy-frontend/src/app/ui/notifications/notifications-list.tsx
T

152 lines
3.1 KiB
TypeScript
Raw Normal View History

'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';
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-04-04 16:14:56 +07:00
useEffect(() => {
console.log(allNotifications);
}, [allNotifications])
function selectHandler(fileId: number) {
setSelectedFiles((prev) => {
2026-03-31 13:47:27 +07:00
const newSet = new Set(prev);
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
}
return (
<div
2026-03-31 13:47:27 +07:00
className="notifications-list-wrapper"
>
<div
2026-03-31 13:47:27 +07:00
className="notifications-list-header"
>
2026-03-31 13:47:27 +07:00
<h4>
{t('all-notifications')}
</h4>
<div
2026-03-31 13:47:27 +07:00
className="notifications-list-action"
>
2026-03-31 13:47:27 +07:00
{(selectedFiles.size !== 0) && (
<>
<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}
>
<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"
>
<div
2026-03-31 13:47:27 +07:00
className="notification-header"
>
2026-03-31 13:47:27 +07:00
<div
className="notification-title"
>
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>
</div>
<div
className="notification-text"
>
2026-04-04 16:14:56 +07:00
{item.message}
</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>
</div>
2026-03-31 13:47:27 +07:00
</div>
)
})
)}
</div>
</div>
)
}