import { useQuery } from "@tanstack/react-query"; import { RefreshCw, AlertCircle, CheckCircle, Activity, Clock, TrendingUp, User, FileText, } from "lucide-react"; import { apiClient } from "../lib/api"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "./ui/card"; import { Alert, AlertDescription, AlertTitle } from "./ui/alert"; import { Button } from "./ui/button"; import { Badge } from "./ui/badge"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "./ui/dialog"; import { ScrollArea } from "./ui/scroll-area"; import type { SyncOperationsResponse, SyncOperation } from "../types/api"; // Component for viewing sync operation logs function LogsDialog({ operation }: { operation: SyncOperation }) { return ( View Logs Logs Sync Operation Logs Operation #{operation.id} - Started at{" "} {new Date(operation.started_at).toLocaleString()} {operation.logs.length === 0 ? ( No logs available ) : ( operation.logs.map((log, index) => ( {log} )) )} {operation.errors.length > 0 && ( <> Errors: {operation.errors.map((error, index) => ( {error} ))} > )} ); } export default function System() { const { data: syncOperations, isLoading: syncOperationsLoading, error: syncOperationsError, refetch: refetchSyncOperations, } = useQuery({ queryKey: ["syncOperations"], queryFn: () => apiClient.getSyncOperations(10, 0), // Get latest 10 operations }); if (syncOperationsLoading) { return ( Loading system status... ); } if (syncOperationsError) { return ( Failed to load system data Unable to connect to the Leggen API. Please check your configuration and ensure the API server is running. refetchSyncOperations()} variant="outline" size="sm" > Retry ); } return ( {/* Sync Operations Section */} Recent Sync Operations Latest synchronization activities and their status {!syncOperations || syncOperations.operations.length === 0 ? ( No sync operations yet Sync operations will appear here once you start syncing your accounts. ) : ( {syncOperations.operations.slice(0, 10).map((operation) => { const startedAt = new Date(operation.started_at); const isRunning = !operation.completed_at; const duration = operation.duration_seconds ? `${Math.round(operation.duration_seconds)}s` : ""; return ( {/* Desktop Layout */} {isRunning ? ( ) : operation.success ? ( ) : ( )} {isRunning ? "Sync Running" : operation.success ? "Sync Completed" : "Sync Failed"} {operation.trigger_type.charAt(0).toUpperCase() + operation.trigger_type.slice(1)} {startedAt.toLocaleDateString()}{" "} {startedAt.toLocaleTimeString()} {duration && Duration: {duration}} {operation.accounts_processed} accounts {operation.transactions_added} new transactions {/* Mobile Layout */} {isRunning ? ( ) : operation.success ? ( ) : ( )} {isRunning ? "Sync Running" : operation.success ? "Sync Completed" : "Sync Failed"} {operation.trigger_type.charAt(0).toUpperCase() + operation.trigger_type.slice(1)} {startedAt.toLocaleDateString()}{" "} {startedAt.toLocaleTimeString()} {duration && ( • {duration} )} {operation.accounts_processed} accounts {operation.transactions_added} new transactions ); })} )} {/* System Health Summary Card */} System Health Overall system status and performance {syncOperations?.operations.filter((op) => op.success).length || 0} Successful Syncs {syncOperations?.operations.filter( (op) => !op.success && op.completed_at, ).length || 0} Failed Syncs {syncOperations?.operations.filter((op) => !op.completed_at) .length || 0} Running Operations ); }
No logs available
Unable to connect to the Leggen API. Please check your configuration and ensure the API server is running.
Sync operations will appear here once you start syncing your accounts.