import { useState, useEffect } from "react"; import { FiAlertCircle, FiMail } from "react-icons/fi"; import { useAuth } from "@/hooks/useAuth"; import { privateApi } from "@/api/privateClient"; export const BANNER_H = "40px"; export default function TopBanner() { const { user, isLoading } = useAuth(); const [sending, setSending] = useState(false); const [sent, setSent] = useState(false); const [cooldown, setCooldown] = useState(0); const show = !isLoading && !!user && user.email_verified === false; useEffect(() => { document.documentElement.style.setProperty("--top-banner-h", show ? BANNER_H : "0px"); }, [show]); useEffect(() => { if (cooldown <= 0) return; const t = setTimeout(() => setCooldown((s) => s - 1), 1000); return () => clearTimeout(t); }, [cooldown]); async function handleResend() { setSending(true); try { await privateApi.post("/api/account/resend-verification/"); setSent(true); } catch (err: any) { const secs = err?.response?.data?.seconds_remaining; if (secs) setCooldown(secs); } finally { setSending(false); } } if (!show) return null; return (
Tvůj e-mail ještě není ověřen. {sent ? ( E-mail odeslán! ) : ( )}
); }