"use client"; import { useAuthQuery } from "@/hooks/use-auth-query"; import { Activity, Coins } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { api } from "@/convex/_generated/api"; import { formatEurFromCents, cn } from "@/lib/utils"; import { formatRelativeTime } from "@/lib/format-time"; // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- function statusBadge(status: string) { switch (status) { case "committed": return Abgeschlossen; case "reserved": return ( Reserviert ); case "released": return ( Rückerstattet ); case "failed": return Fehlgeschlagen; default: return Unbekannt; } } function truncatedDescription(text: string, maxLen = 40) { if (text.length <= maxLen) return text; return text.slice(0, maxLen) + "…"; } // --------------------------------------------------------------------------- // Component // --------------------------------------------------------------------------- export function RecentTransactions() { const transactions = useAuthQuery(api.credits.getRecentTransactions, { limit: 10, }); // ── Loading State ────────────────────────────────────────────────────── if (transactions === undefined) { return (
Letzte Aktivität
{Array.from({ length: 5 }).map((_, i) => (
))}
); } // ── Empty State ──────────────────────────────────────────────────────── if (transactions.length === 0) { return (
Letzte Aktivität

Noch keine Aktivität

Erstelle dein erstes Bild im Canvas (Prompt-Knoten)

); } // ── Transaction List ─────────────────────────────────────────────────── return (
Letzte Aktivität
{transactions.map((t) => { const isCredit = t.amount > 0; return (
{/* Status Indicator */}
{statusBadge(t.status)}
{/* Description */}

{truncatedDescription(t.description)}

{formatRelativeTime(t._creationTime)}

{/* Credits */}
{isCredit ? "+" : "−"} {formatEurFromCents(Math.abs(t.amount))}
); })}
); }