feat(presence): dashboard Who's-here panel + /attendance + /me history + nav

Dashboard right column gets a 'Who's here' panel: present members with
Host badges + your own Check in / Check in as host / Check out with an
optional note (router.refresh after). New /attendance page (all members)
lists recent visits with status + duration + notes. /me gains a 'My
recent visits' section. Sidebar 'Attendance' link under People.
This commit is contained in:
Moheeb Zara
2026-05-16 22:17:17 -07:00
parent 8a77b1d301
commit c6b3306a71
5 changed files with 264 additions and 4 deletions
+8 -2
View File
@@ -4,8 +4,9 @@ import { redirect } from 'next/navigation'
import type { Tables } from '@/types/database'
import { PageTitle } from '@/components/ui/page-title'
import { Empty, EmptyHeader, EmptyMedia, EmptyTitle, EmptyDescription } from '@/components/ui/empty'
import { listSelfEntryDoors } from '@/lib/actions'
import { listSelfEntryDoors, listPresentNow } from '@/lib/actions'
import { DoorSelfEntry } from './door-self-entry'
import { PresencePanel } from './presence-panel'
function IcoUsers({ className }: { className?: string }) {
return <svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" /></svg>
@@ -158,8 +159,11 @@ export default async function DashboardPage() {
)
}
const selfEntryRes = await listSelfEntryDoors()
const [selfEntryRes, presentRes] = await Promise.all([listSelfEntryDoors(), listPresentNow()])
const selfEntryDoors = ('data' in selfEntryRes ? selfEntryRes.data : []) as { id: string; name: string }[]
const present = ('data' in presentRes ? presentRes.data : []) as {
id: string; name: string; isHost: boolean; isMe: boolean; checkedInAt: string; note: string | null
}[]
return (
<div className="min-h-screen bg-background">
@@ -329,6 +333,8 @@ export default async function DashboardPage() {
</div>
<div className="space-y-6">
<PresencePanel present={present} />
{selfEntryDoors.length > 0 && (
<div>
<p className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase mb-3 flex items-center gap-1.5">
+112
View File
@@ -0,0 +1,112 @@
'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 (
<div>
<div className="flex items-center justify-between mb-3">
<p className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase">
Who&apos;s here ({present.length}{hostCount > 0 ? ` · ${hostCount} hosting` : ''})
</p>
</div>
<div className="bg-card rounded border border-border">
{present.length === 0 ? (
<p className="px-4 py-4 font-sans text-xs text-muted-foreground text-center">
Nobody is checked in right now.
</p>
) : (
<ul className="divide-y divide-border">
{present.map(p => (
<li key={p.id} className="flex items-center justify-between gap-3 px-4 py-2.5">
<span className="font-sans text-sm text-foreground truncate">
{p.name}{p.isMe ? ' (you)' : ''}
{p.note && <span className="font-mono text-[10px] text-muted-foreground ml-2">{p.note}</span>}
</span>
<span className="flex items-center gap-2 shrink-0">
{p.isHost && <Badge variant="default">Host</Badge>}
<span className="font-mono text-[10px] text-muted-foreground/70">
{new Date(p.checkedInAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
</span>
</span>
</li>
))}
</ul>
)}
<div className="border-t border-border p-3 space-y-2">
{showNote && (
<input
className="w-full bg-background border border-border text-foreground font-sans text-sm rounded px-3 py-2 focus:outline-none focus:border-primary"
placeholder={amHere ? 'Check-out note (optional)' : 'Check-in note (optional)'}
maxLength={500}
value={note}
onChange={e => setNote(e.target.value)}
/>
)}
<div className="flex items-center gap-1.5 flex-wrap">
{amHere ? (
<Button size="sm" disabled={busy} onClick={doCheckOut}>
Check out{me?.isHost ? ' (hosting)' : ''}
</Button>
) : (
<>
<Button size="sm" disabled={busy} onClick={() => doCheckIn(false)}>Check in</Button>
<Button size="sm" variant="outline" disabled={busy} onClick={() => doCheckIn(true)}>Check in as host</Button>
</>
)}
<Button size="sm" variant="outline" onClick={() => setShowNote(v => !v)}>
{showNote ? 'Hide note' : 'Add note'}
</Button>
</div>
</div>
</div>
</div>
)
}