import { useEffect, useState, type FormEvent } from 'react' import { createTask, deleteTask, listEndpoints, listTasks, type Endpoint, type Task } from '../api' import { StatusBadge } from '../components/StatusBadge' export function Tasks() { const [tasks, setTasks] = useState(null) const [endpoints, setEndpoints] = useState([]) const [name, setName] = useState('') const [srcId, setSrcId] = useState('') const [dstId, setDstId] = useState('') const [error, setError] = useState(null) const [busy, setBusy] = useState(false) function reload() { listTasks() .then((t) => setTasks(t ?? [])) .catch((e: unknown) => setError(e instanceof Error ? e.message : 'Failed to load tasks')) } useEffect(() => { reload() listEndpoints().then((e) => setEndpoints(e ?? [])).catch(() => {}) }, []) async function onDeleteTask(id: number, taskName: string) { if (!confirm(`Delete task "${taskName}" and all its accounts?`)) return setError(null) try { await deleteTask(id) reload() } catch (e: unknown) { setError(e instanceof Error ? e.message : 'Failed to delete task') } } async function submit(e: FormEvent) { e.preventDefault() setBusy(true) setError(null) try { const res = await createTask({ name, src_endpoint_id: Number(srcId), dst_endpoint_id: Number(dstId), }) setName('') setSrcId('') setDstId('') reload() location.hash = `#/tasks/${res.id}` } catch (err) { setError(err instanceof Error ? err.message : 'Failed to create task') } finally { setBusy(false) } } const canSubmit = name.trim() !== '' && srcId !== '' && dstId !== '' && srcId !== dstId return ( <>

Migration tasks /// mailbox copy jobs

New task {endpoints.length < 2 ? (

Register at least two endpoints (source & destination) on the{' '} Endpoints {' '} screen before creating a task.

) : (
setName(e.target.value)} placeholder="q3-office365-migration" required />
{error &&
{error}
}
)}
All tasks ({tasks?.length ?? 0})
{tasks === null ? ( ) : tasks.length === 0 ? ( ) : ( tasks.map((t) => ( )) )}
ID Name Route Status
loading…
no tasks yet — create one above
{t.id} {t.name} #{t.src_endpoint_id} → #{t.dst_endpoint_id}
) }