add notification context

This commit is contained in:
smanylov
2026-05-14 14:30:20 +07:00
parent 9c011b6416
commit 13a5db6313
6 changed files with 162 additions and 15 deletions
+2 -1
View File
@@ -8,7 +8,8 @@ export interface NotificationBody {
id: number,
message: string,
status: string | null,
type: string
type: string,
context: Record<string, string>
}
export async function fetchActiveNotifications() {
@@ -0,0 +1,103 @@
'use client'
import { useTranslations } from 'next-intl'
interface NotificationTextHandlerProps {
notificationType: string
notificationMessage: string
notificationContext: Record<string, string>
}
export function NotificationTextHandler({
notificationType,
notificationMessage,
notificationContext
}: NotificationTextHandlerProps) {
const t = useTranslations('Notifications');
const getNotificationText = () => {
if (!notificationType) {
return t.has(notificationMessage) ? t(notificationMessage) : notificationMessage
}
switch (notificationType) {
case 'USER_VERIFIED':
return t('user-verified', {
status: notificationContext?.status || t('not-specified'),
updateDate: notificationContext?.update_date || t('not-specified-date')
});
case 'MONITORING_RESULT':
return t('monitoring-result', {
message: notificationContext?.message || t('message-missing')
});
case 'COMPLAINT_STATUS_CHANGED':
return t('complaint-status-changed', {
newStatus: notificationContext?.new_status || t('not-specified'),
oldStatus: notificationContext?.old_status || t('not-specified'),
violation: notificationContext?.violation || t('not-specified'),
file: notificationContext?.file || t('not-specified')
});
case 'FILE_ADDED_TO_SYSTEM':
return t('file-added-to-system', {
status: notificationContext?.status || t('not-specified'),
fileName: notificationContext?.file_name || t('not-specified-file-name')
});
case 'FILE_MODERATION_EVENT':
return t('file-moderation-event', {
fileName: notificationContext?.file_name || t('not-specified-file-name'),
oldStatus: notificationContext?.old_status || t('not-specified'),
newStatus: notificationContext?.new_status || t('not-specified'),
comment: notificationContext?.comment || t('no-comment')
});
case 'PAYMENT_RESULT':
return t('payment-result', {
status: notificationContext?.status || t('not-specified'),
amount: notificationContext?.amount || '0'
});
case 'REFERRAL_REGISTERED':
return t('referral-registered', {
referralUser: notificationContext?.referral_user || t('unknown-user')
});
case 'SEARCH_RESULT':
return t('search-result', {
startDate: notificationContext?.start_date || t('not-specified-date'),
endDate: notificationContext?.end_date || t('not-specified-date'),
searchType: notificationContext?.search_type || t('not-specified'),
count: notificationContext?.count || '0'
});
case 'SEARCH_OPERATION_FAILED':
return t('search-operation-failed', {
status: notificationContext?.status || t('not-specified'),
errorMessage: notificationContext?.error_message || t('error-not-described'),
message: notificationContext?.message || t('message-missing'),
reason: notificationContext?.reason || t('reason-not-specified'),
nextRun: notificationContext?.next_run || t('not-scheduled')
});
case 'TOKEN_NOT_FOUND':
return t('token-not-found', {
currentTokens: notificationContext?.current_tokens || '0',
needTokens: notificationContext?.need_tokens || t('not-specified'),
message: notificationContext?.message || t('message-missing'),
nextRun: notificationContext?.next_run || t('not-scheduled')
});
default:
return notificationMessage || t('notification-without-text');
}
};
return (
<div>
{getNotificationText()}
</div>
);
}
+4 -3
View File
@@ -6,9 +6,10 @@ import { useTranslations } from 'next-intl';
import Link from 'next/link';
import { IconInfoMessage, IconPolicy, IconFiles, IconAccountBalanceWallet, IconCheckbook, IconGavel } from '@/app/ui/icons/icons';
import { useActiveNotifications } from '@/app/hooks/react-query/useActiveNotificationsList';
import { NotificationBody, notificationsMarkAsRead } from '@/app/actions/notificationActions';
import { notificationsMarkAsRead } from '@/app/actions/notificationActions';
import { useQueryClient } from '@tanstack/react-query';
import { formatDate } from '@/app/lib/formatDate';
import { NotificationTextHandler } from '@/app/components/NotificationTextHandler';
export default function NotificationsButton() {
const t = useTranslations('Global');
@@ -220,7 +221,7 @@ export default function NotificationsButton() {
className="notification-item-header"
>
<div className="notification-title">
{norificationTranslate.has(item.type) ? norificationTranslate(item.type) : item.type}
{norificationTranslate.has(item.message) ? norificationTranslate(item.message) : item.message}
</div>
<div className="notification-data">
@@ -229,7 +230,7 @@ export default function NotificationsButton() {
</div>
<div className="notification-text">
{norificationTranslate.has(item.message) ? norificationTranslate(item.message) : item.message}
<NotificationTextHandler notificationType={item.type} notificationMessage={item.message} notificationContext={item.context} />
</div>
@@ -16,7 +16,7 @@ import {
createColumnHelper,
RowSelectionState,
} from '@tanstack/react-table';
import { NotificationTextHandler } from '@/app/components/NotificationTextHandler';
export function NotificationsList() {
const t = useTranslations('Global');
@@ -137,18 +137,22 @@ export function NotificationsList() {
}),
columnHelper.accessor('message', {
id: 'message',
header: () => null, // No header text, using custom header above
header: () => null,
cell: ({ row }) => {
const item = row.original;
return (
<div className="notification-body">
<div className="notification-header">
{/* Optional header content */}
<div
className="notification-title"
>
{norificationTranslate.has(item.message)
? norificationTranslate(item.message)
: item.message} ({item.id})
</div>
</div>
<div className="notification-text">
{norificationTranslate.has(item.message)
? norificationTranslate(item.message)
: item.message} ({item.id})
<NotificationTextHandler notificationType={item.type} notificationMessage={item.message} notificationContext={item.context} />
</div>
<div className="notification-footer">
<div className="notification-date">