import { useState, useEffect, useCallback } from 'react' import type { NextPage } from 'next' import Head from 'next/head' import Link from 'next/link' interface Source { id: number url: string domain: string title?: string type: string status: string risk_level: number created_at: string } const SourcesManagement: NextPage = () => { const [sources, setSources] = useState([]) const [loading, setLoading] = useState(true) const [filter, setFilter] = useState('pending') const fetchSources = useCallback(async () => { try { const response = await fetch(`/api/admin/sources?status=${filter}`) if (response.ok) { const data = await response.json() setSources(data) } } catch (error) { console.error('Failed to fetch sources:', error) } finally { setLoading(false) } }, [filter]) useEffect(() => { fetchSources() }, [fetchSources]) const updateSource = async (id: number, status: string, riskLevel: number) => { try { const response = await fetch(`/api/admin/sources/${id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ status, risk_level: riskLevel, }), }) if (response.ok) { fetchSources() // Refresh the list } } catch (error) { console.error('Failed to update source:', error) } } const getRiskColor = (level: number) => { if (level >= 4) return '#ef4444' if (level >= 3) return '#f59e0b' return '#6b7280' } return (
Správa zdrojov - Infohliadka

Správa zdrojov

{loading ? (
Loading...
) : (
{sources.map((source) => ( ))}
Doména Typ Riziko Status Dátum Akcie
{source.domain} {source.type} {source.risk_level} {source.status} {new Date(source.created_at).toLocaleDateString('sk-SK')} {source.status === 'pending' && (
)}
)}
← Späť na dashboard
) } export default SourcesManagement