"use client"; import { useState, useEffect } from "react"; import { Eye, ArrowLeft, Loader2 } from "lucide-react"; import { getViewAsStatusSync, stopViewAs, type ViewAsStatus } from "@/lib/admin-api"; import { useRouter } from "next/navigation"; export default function ViewAsAgentBanner() { const router = useRouter(); const [status, setStatus] = useState({ active: false }); const [isLeaving, setIsLeaving] = useState(false); useEffect(() => { // Baca dari localStorage (sync) karena token disimpan di sana const current = getViewAsStatusSync(); setStatus(current); }, []); if (!status.active) return null; const handleLeave = async () => { setIsLeaving(true); try { await stopViewAs(); // Hapus dari localStorage setStatus({ active: false }); // Force reload agar semua data di-refresh tanpa view-as filter window.location.reload(); } catch { setIsLeaving(false); } }; return (
Melihat sebagai:{" "} {status.agent_label} ({status.agent_uuid})
); }