import React, { useEffect, useState } from 'react' import { Plus, Trash2, RefreshCw, ToggleLeft, ToggleRight } from 'lucide-react' import { api } from '../api/client' interface CronJob { id: number; schedule: string; command: string; comment: string | null; enabled: boolean } const PRESETS = [ { label: 'Every minute', value: '* * * * *' }, { label: 'Every hour', value: '0 * * * *' }, { label: 'Daily at midnight', value: '0 0 * * *' }, { label: 'Weekly (Sunday)', value: '0 0 * * 0' }, { label: 'Monthly (1st)', value: '0 0 1 * *' }, ] export default function CronJobs() { const [jobs, setJobs] = useState([]) const [loading, setLoading] = useState(false) const [showModal, setShowModal] = useState(false) const [saving, setSaving] = useState(false) const [error, setError] = useState('') const [form, setForm] = useState({ schedule: '0 * * * *', command: '', comment: '', enabled: true }) const fetch = async () => { setLoading(true) try { const r = await api.get('/nixclient/cron'); setJobs(r.data.data) } finally { setLoading(false) } } useEffect(() => { fetch() }, []) const save = async (e: React.FormEvent) => { e.preventDefault(); setSaving(true); setError('') try { await api.post('/nixclient/cron', form); setShowModal(false); setForm({ schedule: '0 * * * *', command: '', comment: '', enabled: true }); fetch() } catch (err: unknown) { setError((err as { response?: { data?: { error?: string } } })?.response?.data?.error ?? 'Failed') } finally { setSaving(false) } } const del = async (id: number) => { if (!confirm('Delete this cron job?')) return try { await api.delete(`/nixclient/cron/${id}`); fetch() } catch {} } const toggle = async (job: CronJob) => { try { await api.put(`/nixclient/cron/${job.id}`, { enabled: !job.enabled }); fetch() } catch {} } return (

Cron Jobs

{jobs.length} jobs

{['Schedule', 'Command', 'Comment', 'Status', ''].map(h => )} {jobs.map(j => ( ))} {!loading && jobs.length === 0 && }
{h}
{j.schedule} {j.command} {j.comment ?? '—'}
No cron jobs
{showModal && (

New Cron Job

{error &&
{error}
}
setForm(f => ({ ...f, schedule: e.target.value }))} required placeholder="* * * * *" className="w-full bg-[#0a0f1a] border border-[#1e2d45] text-white font-mono text-sm rounded px-3 py-2 focus:outline-none focus:border-sky-500" />

minute hour day month weekday

setForm(f => ({ ...f, command: e.target.value }))} required placeholder="/usr/bin/php /home/user/public_html/cron.php" className="w-full bg-[#0a0f1a] border border-[#1e2d45] text-white font-mono text-sm rounded px-3 py-2 focus:outline-none focus:border-sky-500" />
setForm(f => ({ ...f, comment: e.target.value }))} placeholder="What this job does" className="w-full bg-[#0a0f1a] border border-[#1e2d45] text-white text-sm rounded px-3 py-2 focus:outline-none focus:border-sky-500" />
)}
) }