'use client'; import { useEffect, useState } from 'react'; import { useT, useLocale } from '@/i18n/I18nProvider'; import { getImpersonation, stopImpersonation, type ImpersonationInfo, } from '@/lib/impersonation'; import { UserCog, LogOut } from 'lucide-react'; /** * Persistent banner shown while an admin is impersonating a user. Reads the * impersonation marker from localStorage (only changes across full reloads). */ export function ImpersonationBanner() { const t = useT(); const locale = useLocale(); const det = t.dashboard.users.detail; const [info, setInfo] = useState(null); const [exiting, setExiting] = useState(false); useEffect(() => { setInfo(getImpersonation()); }, []); if (!info) return null; const exit = async () => { setExiting(true); const targetId = await stopImpersonation(); // Hard reload back into the admin session, landing on the user's detail page. window.location.href = targetId ? `/${locale}/dashboard/admin/users/${targetId}` : `/${locale}/dashboard/admin/users`; }; return (
{det.impersonatingBanner.replace('{name}', info.targetName || '—')}
); }