import { redirect } from 'next/navigation' import { createClient } from '@/lib/supabase/server' import { PageHeader, PageTitle } from '@/components/ui/page-title' import { Badge } from '@/components/ui/badge' import { Empty, EmptyHeader, EmptyMedia, EmptyTitle, EmptyDescription } from '@/components/ui/empty' import { DoorClosed } from 'lucide-react' import { listSelfEntryDoors, getMyCards, listMyDoorActivity } from '@/lib/actions' import { DoorSelfEntry } from '../dashboard/door-self-entry' export const dynamic = 'force-dynamic' type Card = { id: string; card_type: string; label: string | null; is_active: boolean; last4: string } type Activity = { id: string; action: string; success: boolean; detail: string | null; occurred_at: string } const ACTION_LABEL: Record = { self_entry: 'Self-entry', grant: 'Card granted', revoke: 'Card revoked', open: 'Open', unlock: 'Unlock', lock: 'Lock', test: 'Connection test', } export default async function DoorsPage() { const supabase = await createClient() const { data: { user } } = await supabase.auth.getUser() if (!user) redirect('/login') const [doorsRes, cardsRes, activityRes] = await Promise.all([ listSelfEntryDoors(), getMyCards(), listMyDoorActivity(), ]) const doors = ('data' in doorsRes ? doorsRes.data : []) as { id: string; name: string }[] const cards = ('data' in cardsRes ? cardsRes.data : []) as Card[] const activity = ('data' in activityRes ? activityRes.data : []) as Activity[] const nothing = doors.length === 0 && cards.length === 0 && activity.length === 0 return ( <> Doors
{nothing && ( No door access yet When a door manager adds you an access card or enables member self-entry on a door, it will show up here. )} {doors.length > 0 && (

Open a door

Only use this when you are physically at the door and authorized to enter. Every attempt is logged.

)} {cards.length > 0 && (

My access cards

{cards.map(c => (
{c.label || `${c.card_type.toUpperCase()} card`} ••••{c.last4} {c.is_active ? 'Active' : 'Inactive'}
))}

Only the last 4 characters are shown. The full card ID is a credential and is never displayed.

)} {activity.length > 0 && (

My recent door activity

    {activity.map(a => (
  • {a.success ? 'ok' : 'fail'} {' · '}{ACTION_LABEL[a.action] ?? a.action} {new Date(a.occurred_at).toLocaleString()}
  • ))}
)}
) }