import { useEffect, useState } from "react"; import { getConsent } from "@probo/cookie-banner/consent"; import type { ConsentData } from "@probo/cookie-banner/consent"; import { useConfig } from "../hooks/useConfig"; interface ConsentSnapshot { ready: boolean; hasResponse: boolean; data: ConsentData; } function readSnapshot(): ConsentSnapshot { const mgr = getConsent(); return { ready: mgr.ready, hasResponse: mgr.hasResponse, data: mgr.getAll(), }; } function readVisitorId(bannerId: string): string | null { if (!bannerId) return null; try { return localStorage.getItem(`probo_consent:${bannerId}:vid`); } catch { return null; } } function readCookie(): string | null { try { const prefix = "probo_consent="; const entry = document.cookie .split("; ") .find((c) => c.startsWith(prefix)); if (!entry) return null; return decodeURIComponent(entry.substring(prefix.length)); } catch { return null; } } export function DebugTab() { const [config] = useConfig(); const [snapshot, setSnapshot] = useState(readSnapshot); const [visitorId, setVisitorId] = useState(() => readVisitorId(config.bannerId), ); const [cookie, setCookie] = useState(readCookie); useEffect(() => { const mgr = getConsent(); return mgr.subscribe(() => { setSnapshot(readSnapshot()); setVisitorId(readVisitorId(config.bannerId)); setCookie(readCookie()); }); }, [config.bannerId]); useEffect(() => { setVisitorId(readVisitorId(config.bannerId)); setCookie(readCookie()); }, [config.bannerId]); return (

Debug

getConsent() State

          {JSON.stringify(
            { ready: snapshot.ready, hasResponse: snapshot.hasResponse },
            null,
            2,
          )}
        
{Object.keys(snapshot.data).length === 0 ? (

No consent data yet. Interact with the banner to generate consent.

) : ( {Object.entries(snapshot.data).map(([cat, granted]) => ( ))}
Category has()
{cat} {String(granted)}
)}

Storage

Visitor ID{" "} (localStorage: probo_consent:{config.bannerId || "?"}:vid)
            {visitorId ?? "(not set)"}
          
probo_consent cookie
            {cookie
              ? JSON.stringify(JSON.parse(cookie), null, 2)
              : "(not set)"}
          
); }