import SetupModeButton from './components/SetupModeButton'; import React, { useEffect, useState } from 'react'; import { useClientDelete } from './hooks/useClientDelete'; import { fetchClients, updateClient } from './apiClients'; import type { Client } from './apiClients'; import { GridComponent, ColumnsDirective, ColumnDirective, Page, Inject, Toolbar, Search, Sort, Edit, } from '@syncfusion/ej2-react-grids'; import { DialogComponent } from '@syncfusion/ej2-react-popups'; // Raumgruppen werden dynamisch aus der API geladen interface DetailsModalProps { open: boolean; client: Client | null; groupIdToName: Record; onClose: () => void; } function DetailsModal({ open, client, groupIdToName, onClose }: DetailsModalProps) { if (!open || !client) return null; return (

Client-Details

{Object.entries(client) .filter( ([key]) => ![ 'index', 'is_active', 'type', 'column', 'group_name', 'foreignKeyData', 'hardware_token', ].includes(key) ) .map(([key, value]) => ( ))}
{key === 'group_id' ? 'Raumgruppe' : key === 'ip' ? 'IP-Adresse' : key === 'registration_time' ? 'Registriert am' : key.charAt(0).toUpperCase() + key.slice(1)} : {key === 'group_id' ? value !== undefined ? groupIdToName[value as string | number] || value : '' : key === 'registration_time' && value ? new Date( (value as string).endsWith('Z') ? (value as string) : value + 'Z' ).toLocaleString() : key === 'last_alive' && value ? String(value) // Wert direkt anzeigen, nicht erneut parsen : String(value)}
); } const Clients: React.FC = () => { const [clients, setClients] = useState([]); const [groups, setGroups] = useState<{ id: number; name: string }[]>([]); const [detailsClient, setDetailsClient] = useState(null); const { showDialog, deleteClientId, handleDelete, confirmDelete, cancelDelete } = useClientDelete( uuid => setClients(prev => prev.filter(c => c.uuid !== uuid)) ); useEffect(() => { fetchClients().then(setClients); // Gruppen auslesen import('./apiGroups').then(mod => mod.fetchGroups()).then(setGroups); }, []); // Map group_id zu group_name const groupIdToName: Record = {}; groups.forEach(g => { groupIdToName[g.id] = g.name; }); // DataGrid data mit korrektem Gruppennamen und formatierten Zeitangaben const gridData = clients.map(c => ({ ...c, group_name: c.group_id !== undefined ? groupIdToName[c.group_id] || String(c.group_id) : '', last_alive: c.last_alive ? new Date( (c.last_alive as string).endsWith('Z') ? (c.last_alive as string) : c.last_alive + 'Z' ).toLocaleString() : '', })); // DataGrid row template für Details- und Entfernen-Button const detailsButtonTemplate = (props: Client) => (
); return (

Client-Übersicht

{groups.length > 0 ? ( <> ; }) => { if (args.requestType === 'save') { const { uuid, description, model } = args.data as { uuid: string; description: string; model: string; }; // API-Aufruf zum Speichern await updateClient(uuid, { description, model }); // Nach dem Speichern neu laden fetchClients().then(setClients); } }} > setDetailsClient(null)} /> ) : (
Raumgruppen werden geladen ...
)} {/* DialogComponent für Bestätigung */} {showDialog && deleteClientId && ( )}
); }; export default Clients;