add translate, add remove notification function
This commit is contained in:
@@ -128,3 +128,46 @@ export async function notificationsMarkAsRead(ids: number[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function notificationsDelete(ids: number[]) {
|
||||
const token = await getSessionData('token');
|
||||
console.log('notificationsDelete');
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
version: 1,
|
||||
msg_id: 30015,
|
||||
message_body: {
|
||||
action: 'delete',
|
||||
authToken: token,
|
||||
notificationIds: ids
|
||||
}
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (response.ok) {
|
||||
let parsed = await response.json();
|
||||
console.log('parsed');
|
||||
console.log(parsed);
|
||||
|
||||
if (parsed?.message_code === 0) {
|
||||
return parsed?.message_body
|
||||
} else {
|
||||
throw parsed;
|
||||
}
|
||||
} else {
|
||||
throw (`${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useTranslations } from 'next-intl';
|
||||
import { IconCheck, IconArrowLeft, IconArrowRight, IconDoubleArrowLeft, IconDoubleArrowRight } from '@/app/ui/icons/icons';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useAllNotifications } from '@/app/hooks/react-query/useAllNotificationsList';
|
||||
import { notificationsMarkAsRead } from '@/app/actions/notificationActions';
|
||||
import { notificationsMarkAsRead, notificationsDelete } from '@/app/actions/notificationActions';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { formatDate, formatDateTime } from '@/app/lib/formatDate';
|
||||
|
||||
@@ -81,7 +81,7 @@ export function NotificationsList() {
|
||||
setSelectedFiles(new Set(allNotifications?.notifications.map(item => item.id)));
|
||||
}
|
||||
|
||||
async function markAsReadHandler(ids: number[]) {
|
||||
async function notificationActionHandler(ids: number[], action: 'remove' | 'mark-as-read') {
|
||||
setLoadingIds(prev => {
|
||||
const newSet = new Set(prev);
|
||||
ids.forEach(id => newSet.add(id));
|
||||
@@ -89,14 +89,21 @@ export function NotificationsList() {
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await notificationsMarkAsRead(ids);
|
||||
let response;
|
||||
|
||||
if (response.success) {
|
||||
if (action === 'mark-as-read') {
|
||||
response = await notificationsMarkAsRead(ids);
|
||||
} else if (action === 'remove') {
|
||||
response = await notificationsDelete(ids);
|
||||
}
|
||||
|
||||
if (response?.success) {
|
||||
await queryClient.invalidateQueries({ queryKey: ['activeNotifications'] });
|
||||
await queryClient.invalidateQueries({ queryKey: ['allNotifications'] });
|
||||
}
|
||||
} catch (error) {
|
||||
setError(error instanceof Error ? error.message : 'Failed to mark as read');
|
||||
const errorMessage = action === 'mark-as-read' ? 'Failed to mark as read' : 'Failed to remove';
|
||||
setError(errorMessage);
|
||||
} finally {
|
||||
setLoadingIds(prev => {
|
||||
const newSet = new Set(prev);
|
||||
@@ -112,15 +119,6 @@ export function NotificationsList() {
|
||||
}
|
||||
}
|
||||
|
||||
function removeHandler(id: number) {
|
||||
console.log(id);
|
||||
|
||||
setSelectedFiles(prev => {
|
||||
prev.delete(id)
|
||||
return new Set(prev);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="notifications-list-wrapper"
|
||||
@@ -150,10 +148,10 @@ export function NotificationsList() {
|
||||
className="btn btn-primary"
|
||||
onClick={() => {
|
||||
const array = Array.from(selectedFiles);
|
||||
markAsReadHandler(array);
|
||||
notificationActionHandler(array, 'mark-as-read');
|
||||
}}
|
||||
>
|
||||
{t('mark-all-as-read')}
|
||||
{t('mark-as-read')}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
@@ -225,7 +223,7 @@ export function NotificationsList() {
|
||||
<button
|
||||
className="btn btn-remove"
|
||||
onClick={() => {
|
||||
removeHandler(item.id);
|
||||
notificationActionHandler([item.id], 'remove');
|
||||
}}
|
||||
disabled={loadingIds.has(item.id)}
|
||||
>
|
||||
|
||||
@@ -513,5 +513,25 @@
|
||||
"COMPLAINT_AND_LEGAL_IN_WORK": "Complaint and legal in work",
|
||||
"AUTHORIZED_USE": "Authorized use",
|
||||
"CREATED": "New"
|
||||
},
|
||||
"Notifications": {
|
||||
"notification-search-result": "Search result",
|
||||
"notification-monitoring-result": "Monitoring result",
|
||||
"notification-operation-impossible": "Operation impossible",
|
||||
"notification-start-failed-now": "Failed to start now",
|
||||
"notification-start-failed-next": "Failed to start later",
|
||||
"notification-payout-result": "Payout result",
|
||||
"notification-payment-result": "Payment result",
|
||||
"notification-referral-deposit": "Referral deposit",
|
||||
"notification-referral-registered": "Referral registered",
|
||||
"notification-referral-activated": "Referral activated",
|
||||
"notification-complaint-status": "Complaint status changed",
|
||||
"notification-case-status": "Case status changed",
|
||||
"notification-incoming-message": "Incoming message",
|
||||
"notification-tariff-expiring": "Tariff expiring",
|
||||
"notification-token-not-found": "Token not found",
|
||||
"notification-file-moderation": "File moderation event",
|
||||
"notification-file-added": "File added to system",
|
||||
"notification-search-operation-filed": "Search operation failed"
|
||||
}
|
||||
}
|
||||
@@ -513,5 +513,25 @@
|
||||
"COMPLAINT_AND_LEGAL_IN_WORK": "Дело и жалоба в работе",
|
||||
"AUTHORIZED_USE": "Разрешенное использование",
|
||||
"CREATED": "Новый"
|
||||
},
|
||||
"Notifications": {
|
||||
"notification-search-result": "Результат поиска",
|
||||
"notification-monitoring-result": "Результат мониторинга",
|
||||
"notification-operation-impossible": "Операция невозможна",
|
||||
"notification-start-failed-now": "Не удалось запустить сейчас",
|
||||
"notification-start-failed-next": "Не удалось запустить позднее",
|
||||
"notification-payout-result": "Результат выплаты",
|
||||
"notification-payment-result": "Результат платежа",
|
||||
"notification-referral-deposit": "Депозит реферала",
|
||||
"notification-referral-registered": "Реферал зарегистрирован",
|
||||
"notification-referral-activated": "Реферал активирован",
|
||||
"notification-complaint-status": "Статус жалобы изменён",
|
||||
"notification-case-status": "Статус обращения изменён",
|
||||
"notification-incoming-message": "Входящее сообщение",
|
||||
"notification-tariff-expiring": "Истечение тарифа",
|
||||
"notification-token-not-found": "Токен не найден",
|
||||
"notification-file-moderation": "Модерация файла",
|
||||
"notification-file-added": "Файл добавлен в систему",
|
||||
"notification-search-operation-filed": "Ошибка операции поиска"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user