// components/account/SupporterBadges.tsx "use client"; import { useEffect, useState } from "react"; type SupportBadge = { provider: "kofi" | "patreon" | "mighty" | string; active: boolean; // currently entitled (status==="active" && renews_at >= now) kind: "member" | "one_time" | "inactive"; label: string; // e.g., "Ko-fi • Bronze" or "Ko-fi Supporter" tier?: string | null; renews_at?: string | null; started_at?: string | null; }; function providerIcon(p: string) { // Swap these for real icons later if you want if (p === "kofi") return "☕"; if (p === "patreon") return "🅿️"; if (p === "mighty") return "💬"; return "🎖️"; } export default function SupporterBadges({ email, userId, }: { email?: string | null; userId?: string | null; }) { const [badges, setBadges] = useState(null); const [error, setError] = useState(null); useEffect(() => { let url = "/api/support/badges"; const params = new URLSearchParams(); if (email) params.set("email", String(email)); if (userId) params.set("userId", String(userId)); const qs = params.toString(); if (qs) url += `?${qs}`; fetch(url, { cache: "no-store" }) .then((r) => (r.ok ? r.json() : Promise.reject(r))) .then((json) => setBadges(Array.isArray(json?.badges) ? json.badges : [])) .catch(async (e) => { try { const t = await e.text(); setError(t || String(e)); } catch { setError(String(e)); } }); }, [email, userId]); if (error) { return (
Couldn’t load supporter badges.
); } if (!badges) { return (
Loading supporter badges…
); } if (badges.length === 0) { return (
No supporter badges yet.
); } return (
Supporter Badges
{badges.map((b, i) => ( {providerIcon(b.provider)} {b.label} ))}
); }