Linked backend data to detectors' meshes.
This commit is contained in:
@@ -109,6 +109,26 @@ const AlertsPage: React.FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleAcknowledgeToggle = async (alertId: number) => {
|
||||
try {
|
||||
const res = await fetch(`/api/update-alert/${alertId}`, { method: 'PATCH' })
|
||||
const payload = await res.json().catch(() => null)
|
||||
console.log('[AlertsPage] PATCH /api/update-alert', { id: alertId, status: res.status, payload })
|
||||
if (!res.ok) {
|
||||
throw new Error(typeof payload?.error === 'string' ? payload.error : `Update failed (${res.status})`)
|
||||
}
|
||||
// Обновить алерты
|
||||
const params = new URLSearchParams()
|
||||
if (currentObject.id) params.set('objectId', currentObject.id)
|
||||
const listRes = await fetch(`/api/get-alerts?${params.toString()}`, { cache: 'no-store' })
|
||||
const listPayload = await listRes.json().catch(() => null)
|
||||
const data = Array.isArray(listPayload?.data) ? listPayload.data : (listPayload?.data?.alerts || [])
|
||||
setAlerts(data as AlertItem[])
|
||||
} catch (e) {
|
||||
console.error('Failed to update alert:', e)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-screen bg-[#0e111a]">
|
||||
<Sidebar
|
||||
@@ -218,6 +238,12 @@ const AlertsPage: React.FC = () => {
|
||||
}`}>
|
||||
{item.acknowledged ? 'Да' : 'Нет'}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => handleAcknowledgeToggle(item.id)}
|
||||
className="ml-2 inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-[#2a2e3e] text-white hover:bg-[#353a4d]"
|
||||
>
|
||||
{item.acknowledged ? 'Снять' : 'Подтвердить'}
|
||||
</button>
|
||||
</td>
|
||||
<td className="py-4">
|
||||
<div className="text-sm text-gray-300">{new Date(item.timestamp).toLocaleString('ru-RU')}</div>
|
||||
|
||||
Reference in New Issue
Block a user