import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import CloseIcon from "@mui/icons-material/Close"; import PersonAddIcon from "@mui/icons-material/PersonAdd"; import { useAuth } from "@app/auth/UseSession"; import { isUserAnonymous } from "@app/auth/supabase"; import { withBasePath } from "@app/constants/app"; import "@app/components/auth/GuestUserBanner.css"; interface GuestUserBannerProps { className?: string; } // Ensure the toast only appears once per full page load, not on re-hydration let hasShownThisLoad = false; /** * Guest user toast encouraging account creation. * Appears 2s after load, top-right of the viewport. */ export function GuestUserBanner({ className = "" }: GuestUserBannerProps) { const { t } = useTranslation(); const { session } = useAuth(); const [isDismissed, setIsDismissed] = useState(false); const [visible, setVisible] = useState(false); const isAnon = Boolean(session?.user && isUserAnonymous(session.user)); useEffect(() => { if (!isAnon || hasShownThisLoad) return; const timer = setTimeout(() => { setVisible(true); hasShownThisLoad = true; }, 2000); return () => clearTimeout(timer); }, [isAnon]); if (!isAnon || isDismissed || !visible) { return null; } const handleSignUp = () => { window.location.href = withBasePath("/signup"); }; const handleDismiss = () => { setIsDismissed(true); }; return (
{t("guestBanner.title", "You're using Stirling PDF as a guest!")}
{t( "guestBanner.message", "Create a free account to save your work, access more features, and support the project.", )}
); } export default GuestUserBanner;