103 lines
3.4 KiB
TypeScript
103 lines
3.4 KiB
TypeScript
'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>
|
||
|
|
);
|
||
|
|
}
|