47 lines
1.9 KiB
TypeScript
47 lines
1.9 KiB
TypeScript
export const dynamic = 'force-dynamic'
|
|
|
|
import Link from 'next/link'
|
|
import { redirect } from 'next/navigation'
|
|
import { createClient } from '@/lib/supabase/server'
|
|
import { UserManager, type AdminUser, type SiteOption } from '@/components/admin/user-manager'
|
|
import { SiteZoneManager, type SiteWithZones } from '@/components/admin/site-zone-manager'
|
|
|
|
export default async function AdminHome() {
|
|
const supabase = await createClient()
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
if (!user) redirect('/login')
|
|
|
|
const { data: profile } = await supabase
|
|
.from('users').select('role').eq('id', user.id).single()
|
|
if (!profile || profile.role !== 'admin') redirect('/login')
|
|
|
|
const [{ data: users }, { data: sites }] = await Promise.all([
|
|
supabase
|
|
.from('users')
|
|
.select('id, name, email, role, department, site_id, active')
|
|
.order('created_at', { ascending: false }),
|
|
supabase
|
|
.from('sites')
|
|
.select('id, name, address, zones (id, name, qr_code_token)')
|
|
.order('name'),
|
|
])
|
|
|
|
const siteOptions: SiteOption[] = (sites ?? []).map(s => ({ id: s.id, name: s.name }))
|
|
|
|
return (
|
|
<main className="max-w-4xl mx-auto px-4 py-6 space-y-6">
|
|
<div className="flex items-center justify-between">
|
|
<h1 className="text-2xl font-bold text-gray-900">Admin</h1>
|
|
<nav className="flex gap-3 text-sm">
|
|
<Link href="/hse/dashboard" className="text-blue-600 hover:underline">HSE Dashboard</Link>
|
|
<Link href="/hse/incidents" className="text-blue-600 hover:underline">Incidents</Link>
|
|
<Link href="/hse/capa" className="text-blue-600 hover:underline">CAPA</Link>
|
|
<Link href="/management" className="text-blue-600 hover:underline">Management</Link>
|
|
</nav>
|
|
</div>
|
|
<UserManager users={(users ?? []) as AdminUser[]} sites={siteOptions} />
|
|
<SiteZoneManager sites={(sites ?? []) as unknown as SiteWithZones[]} />
|
|
</main>
|
|
)
|
|
}
|