import React, { useState, useEffect, useCallback } from 'react'; import { Button } from '@/components/ui/index'; import { Input } from '@/components/ui/index'; import { RefreshCw } from 'lucide-react'; import { BackupJobList } from '@/components/Proxmox'; import { listProxmoxClusters, listProxmoxBackupJobs } from '@/lib/proxmoxClient'; import type { ClusterInfo } from '@/lib/domain'; import { toast } from 'sonner'; export function ProxmoxBackupPage() { const [clusters, setClusters] = useState([]); const [selectedClusterId, setSelectedClusterId] = useState(''); const [nodeInputValue, setNodeInputValue] = useState('localhost'); const [nodeId, setNodeId] = useState('localhost'); // eslint-disable-next-line @typescript-eslint/no-explicit-any const [jobs, setJobs] = useState([]); const [isLoading, setIsLoading] = useState(false); useEffect(() => { listProxmoxClusters() .then((cls) => { setClusters(cls); if (cls.length > 0) setSelectedClusterId(cls[0].id); }) .catch((err) => { console.error('Failed to load clusters:', err); toast.error('Failed to load clusters'); }); }, []); const loadJobs = useCallback(async (clusterId: string, nId: string) => { if (!clusterId) return; setIsLoading(true); try { const data = await listProxmoxBackupJobs(clusterId, nId); setJobs(data); } catch (err) { console.error('Failed to load backup jobs:', err); toast.error('Failed to load backup jobs'); } finally { setIsLoading(false); } }, []); useEffect(() => { if (selectedClusterId) loadJobs(selectedClusterId, nodeId); }, [selectedClusterId, nodeId, loadJobs]); const applyNodeId = () => { setNodeId(nodeInputValue.trim() || 'localhost'); }; if (clusters.length === 0 && !isLoading) { return (

Backup Jobs

Manage Proxmox Backup Server jobs

No Proxmox clusters configured.

Add a remote connection first.

); } return (

Backup Jobs

Manage Proxmox Backup Server jobs

{clusters.length > 0 && (
Cluster:
)}
Node: setNodeInputValue(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') applyNodeId(); }} placeholder="localhost" />
loadJobs(selectedClusterId, nodeId)} />
); }