import EasyModal, { useModal } from "ez-modal-react"; import { useQuery } from "@tanstack/react-query"; import { Modal, Button, Table, Spinner, Badge } from "react-bootstrap"; import { getWgClientLogs } from "src/api/backend"; import { IconNotes } from "@tabler/icons-react"; interface Props { clientId: number; clientName: string; } const WireGuardClientLogsModal = EasyModal.create(({ clientId, clientName }: Props) => { const modal = useModal(); const { data: logs, isLoading } = useQuery({ queryKey: ["wg-client-logs", clientId], queryFn: () => getWgClientLogs(clientId), refetchInterval: 5000 }); const handleClose = () => { modal.resolve(null); modal.hide(); }; const formatDate = (dateString: string) => { const d = new Date(dateString); return d.toLocaleString(); }; const getActionBadge = (action: string) => { switch (action) { case "connected": return Connected; case "disconnected": return Disconnected; case "uploaded-file": return File Upload; case "deleted-file": return File Deleted; default: return {action}; } }; return ( Event Logs: {clientName} {isLoading ? (
) : (
{logs && logs.length > 0 ? ( logs.map((log: any) => ( )) ) : ( )}
Date / Time Event Details
{formatDate(log.created_on)} {getActionBadge(log.action)} {log.meta && log.meta.message ? log.meta.message : JSON.stringify(log.meta)}
No events recorded for this client yet.
)}
); }); export default WireGuardClientLogsModal;