feat(registratura): add manual toggle for monitoring (Opreste/Reactiveaza)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-30 09:52:59 +03:00
parent 5bcf65ff02
commit 4d1883b459
@@ -948,6 +948,7 @@ function ExternalStatusSection({
if (!tracking) return null; if (!tracking) return null;
const [checking, setChecking] = useState(false); const [checking, setChecking] = useState(false);
const [toggling, setToggling] = useState(false);
const [checkResult, setCheckResult] = useState<{ const [checkResult, setCheckResult] = useState<{
changed: boolean; changed: boolean;
error: string | null; error: string | null;
@@ -1001,6 +1002,26 @@ function ExternalStatusSection({
return `acum ${days}z`; return `acum ${days}z`;
}; };
const handleToggleActive = useCallback(async () => {
setToggling(true);
try {
const updated = { ...liveTracking, active: !liveTracking.active };
await fetch("/api/registratura", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: entry.id,
updates: { externalStatusTracking: updated },
}),
});
setLiveTracking(updated);
} catch {
// Best effort
} finally {
setToggling(false);
}
}, [entry.id, liveTracking]);
const t = liveTracking; const t = liveTracking;
return ( return (
@@ -1022,6 +1043,19 @@ function ExternalStatusSection({
<Pencil className="h-3 w-3 mr-1" /> <Pencil className="h-3 w-3 mr-1" />
Modifica Modifica
</Button> </Button>
<Button
variant="ghost"
size="sm"
className={cn("h-6 px-2 text-xs", !t.active && "text-green-600")}
onClick={handleToggleActive}
disabled={toggling}
>
{t.active ? (
<><BellOff className="h-3 w-3 mr-1" />Opreste</>
) : (
<><Bell className="h-3 w-3 mr-1" />Reactiveaza</>
)}
</Button>
{t.active && ( {t.active && (
<Button <Button
variant="ghost" variant="ghost"