'use client'; import { useState } from 'react'; interface Group { id: string; name: string; platform: string; } interface Route { id: string; sourceGroupId: string; targetGroupId: string; sourceGroup: { name: string }; targetGroup: { name: string }; } export function RouteManager({ groups, initialRoutes, }: { groups: Group[]; initialRoutes: Route[]; }) { const [routes, setRoutes] = useState(initialRoutes); const [sourceId, setSourceId] = useState(''); const [targetId, setTargetId] = useState(''); const [busy, setBusy] = useState(false); async function addRoute() { if (!sourceId || !targetId) return; setBusy(true); try { const res = await fetch('/api/routes', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sourceGroupId: sourceId, targetGroupId: targetId }), }); if (!res.ok) return; const created: Route = await res.json(); setRoutes((prev) => [created, ...prev]); setSourceId(''); setTargetId(''); } finally { setBusy(false); } } async function deleteRoute(id: string) { const res = await fetch(`/api/routes/${id}`, { method: 'DELETE' }); if (res.ok) setRoutes((prev) => prev.filter((r) => r.id !== id)); } return (

Active sync routes

{routes.length === 0 ? (

No routes configured.

) : (
    {routes.map((route) => (
  • {route.sourceGroup.name} {route.targetGroup.name}
  • ))}
)}

Add route

); }