'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { toast } from 'sonner' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { checkIn, checkOut } from '@/lib/actions' type Present = { id: string name: string isHost: boolean isMe: boolean checkedInAt: string note: string | null } export function PresencePanel({ present }: { present: Present[] }) { const router = useRouter() const [busy, setBusy] = useState(false) const [note, setNote] = useState('') const [showNote, setShowNote] = useState(false) const me = present.find(p => p.isMe) const amHere = !!me const hostCount = present.filter(p => p.isHost).length async function doCheckIn(asHost: boolean) { setBusy(true) const res = await checkIn({ asHost, note: note.trim() || null }) setBusy(false) if ('error' in res && res.error) return toast.error(res.error) setNote('') setShowNote(false) toast.success(asHost ? 'Checked in as host' : 'Checked in') router.refresh() } async function doCheckOut() { setBusy(true) const res = await checkOut({ note: note.trim() || null }) setBusy(false) if ('error' in res && res.error) return toast.error(res.error) setNote('') setShowNote(false) toast.success('Checked out') router.refresh() } return (
Who's here ({present.length}{hostCount > 0 ? ` ยท ${hostCount} hosting` : ''})
Nobody is checked in right now.
) : (