import * as React from "react"; import { X } from "lucide-react"; import { googleAuthErrorCopy } from "./googleAuthErrorCopy"; import { clearGoogleLinkError, getGoogleLinkError, reportGoogleLinkErrorOnce, type GoogleLinkProvider, } from "./googleLinkError"; const PROVIDER_LABELS: Record = { gsc: "Search Console", ga4: "Google Analytics", }; /** * Inline error shown on a connect surface after a failed Google link flow. * startGoogleLink sends OAuth failures back to the page that started the * connect (see its errorCallbackURL); googleLinkError.ts captures the params * before the router can redirect them away, and this renders the explanation * next to the Connect button that retries it. Persists until dismissed or the * user navigates. */ export function GoogleLinkErrorAlert({ provider, className, }: { provider: GoogleLinkProvider; className?: string; }) { const [error] = React.useState(() => getGoogleLinkError(provider)); const [dismissed, setDismissed] = React.useState(false); React.useEffect(() => { if (error) reportGoogleLinkErrorOnce(); }, [error]); if (!error || dismissed) return null; const copy = googleAuthErrorCopy(error.code, PROVIDER_LABELS[provider]); return (

{copy.title}

{copy.description}

); }