"use client"; import React, { useCallback, useState } from "react"; import Link from "next/link"; import { CalendarClock, ArrowRight, Baby, HandHeart, UserCheck, Banknote, Inbox, CheckCircle2 } from "lucide-react"; import { useAuth } from "@/hooks/useAuth"; import { useVisiblePolling } from "@/hooks/useVisiblePolling"; import { CampusBadge } from "@/components/shared/CampusFilter"; import type { Event } from "@/types"; import { apiV2Data } from "@/lib/apiV2"; import { useExternalEffect } from "@/lib/hooks"; type TodayEvent = { id: string; title: string; location: string | null; campus: Event["campus"]; isHidden: boolean; kidsCheckIn: boolean; startsAt: string; endsAt: string; sessionLabel: string | null; places: number; checkedIn: number; kidsIn: number | null; volunteers: { needed: number; rostered: number; checkedIn: number } | null; }; type Pending = { key: string; label: string; count: number; href: string; tone: string }; type Today = { events: TodayEvent[]; money: { today: number; todayCount: number; week: number } | null; pending: Pending[] }; const TONE: Record = { amber: "bg-amber-50 text-amber-800", rose: "bg-rose-50 text-rose-700", blue: "bg-blue-50 text-blue-700", violet: "bg-violet-50 text-violet-700", green: "bg-green-50 text-green-700", }; const time = (d: string) => new Date(d).toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" }); const rand = (n: number) => `R ${n.toFixed(2)}`; /** * The top of every staff dashboard (1.49.0): what's on today and how it's going, and — for * supervisors and admins — money in and what's waiting for someone, each linking to where it's * dealt with. Refreshes every 30 seconds while the tab is visible. */ export function TodayPanel({ supervisor }: { supervisor: boolean }) { const { token } = useAuth(); const [data, setData] = useState(null); const load = useCallback(async () => { if (!token) return; try { setData(await (apiV2Data("get", "/dashboard/today", { authToken: token }) as Promise)); } catch { /* keep what's shown */ } }, [token]); useExternalEffect(() => { load(); }, [load]); useVisiblePolling(load, 30000, !!token); if (!data) return null; return (

Today

{new Date().toLocaleDateString(undefined, { weekday: "long", day: "numeric", month: "long" })}
{data.events.length === 0 ? (

Nothing on today.

) : (
    {data.events.map(e => { const pct = e.places ? Math.min(100, Math.round((e.checkedIn / e.places) * 100)) : 0; return (
  • {e.title}{e.sessionLabel && · {e.sessionLabel}}
    {time(e.startsAt)}–{time(e.endsAt)}{e.location ? ` · ${e.location}` : ""}
    {e.kidsCheckIn ? "Kids desk" : "Scanner"}
    {!e.kidsCheckIn && ( {e.checkedIn} of {e.places} checked in )} {e.kidsIn !== null && {e.kidsIn} children in now} {e.volunteers && ( {e.volunteers.checkedIn} of {e.volunteers.rostered} volunteers here{e.volunteers.rostered < e.volunteers.needed ? ` (${e.volunteers.needed - e.volunteers.rostered} short)` : ""} )}
  • ); })}
)} {data.money && (
Today {rand(data.money.today)} ({data.money.todayCount} payment{data.money.todayCount === 1 ? "" : "s"}) Last 7 days {rand(data.money.week)}
)}
{supervisor && (

Waiting for you

{data.pending.length === 0 ? (

All caught up.

) : (
    {data.pending.map(p => (
  • {p.count} {p.label}
  • ))}
)}
)}
); }