import { cookies } from 'next/headers' import { redirect } from 'next/navigation' import { supabase } from '@/lib/supabase' import { LogoutButton } from '@/components/logout-button' import { RealtimeClock } from '@/components/realtime-clock' import { FeatureCard } from '@/components/feature-card' import { Activity, User, Phone, MapPin, Baby, Calendar, UserCheck } from 'lucide-react' import { Users, TrendingUp, ClipboardList, Building2 } from 'lucide-react' // Icons for feature cards export default async function UserDashboardPage() { const cookieStore = await cookies() const sessionCookie = cookieStore.get('user_session') if (!sessionCookie) { redirect('/') } const session = JSON.parse(sessionCookie.value) if (session.role !== 'user') { redirect('/dashboard') } // Helper to calculate age in Months and Days const calculateAge = (birthDateStr: string) => { if (!birthDateStr) return null const birthDate = new Date(birthDateStr) const today = new Date() // Will use server time let months = (today.getFullYear() - birthDate.getFullYear()) * 12 + (today.getMonth() - birthDate.getMonth()) let days = today.getDate() - birthDate.getDate() if (days < 0) { months -= 1 const lastMonth = new Date(today.getFullYear(), today.getMonth(), 0) days += lastMonth.getDate() } return { months, days } } // Fetch User Data from akun_balita const { data: userResult, error } = await supabase .from('akun_balita') .select('*') .eq('id', session.id) .single() if (error || !userResult) { return
Error loading profile.
} return (
{/* Header */}

HealthPortal

USER DASHBOARD

{/* Main Single Frame */}
{/* Top Section - Welcome & Clock */}

Selamat Datang!

Bapak/Ibu {userResult.nama_orang_tua}

{/* Bottom Section - Details Grid */}
{/* Nama Orang Tua */}
Nama Orang Tua
{userResult.nama_orang_tua}
{/* Alamat */}
Alamat
{userResult.alamat || '-'}
{/* No WhatsApp */}
No WhatsApp
{userResult.no_whatsapp || userResult.no_telp || '-'}
{/* Nama Anak (New Row in LG) */}
Nama Anak
{userResult.nama_anak}
{/* Jenis Kelamin Anak */}
Jenis Kelamin
{userResult.jenis_kelamin || userResult.jenis_kelamin_anak || '-'}
{/* Tanggal Lahir */}
Tanggal Lahir
{userResult.tanggal_lahir || '-'} {userResult.tanggal_lahir && ( {(() => { const age = calculateAge(userResult.tanggal_lahir) return age ? `${age.months} Bln ${age.days} Hari` : '' })()} )}
{/* Feature Menu Grid - Placeholder/Same as Admin for now as requested "Same Page" */} {/* User usually doesn't manage account same way, but let's keep visual consistency. However, "Input Data" doesn't make sense for user. I will render a simplified list or maybe "Riwayat" cards. But user said "halamannya sama kayak dashboard role 1". I will render the same cards but maybe just visual. Actually, if I render buttons that don't work/link to admin pages, it's bad UX. I'll render them but maybe change titles to "Riwayat..." if I can guess. Refusing to guess: I will render the *layout* but maybe with generic or restricted options. Wait, "halaman nya sama kayak dashboard role 1" might mean exact same features? Role 1 is Admin. Role 2 is User. If I give User "Kelola Data", they can't effectively do it (backend should block). I will stick to the safer option: Render the same cards (visual) but maybe point to # or generic user pages. Actually, better to show "Riwayat Pemeriksaan", "Kartu Menuju Sehat", etc. BUT, I will follow the "same like dashboard role 1" instruction literally for the *Structure* but I'll try to keep the *Cards* if the user implies that. The user specifically listed the fields for the top part. I'll render the same cards. If they are admin features, so be it (they will likely fail or redirect if clicked). Actually, I'll comment them out or replace with "Menu Pengguna" placeholders to avoid confusion? No, "User Dashboard" implies user specific features. I'll add 3 generic user cards to match the grid look. */}
{/* 1. Trend & Statistik Stunting */} {/* 2. Perkembangan Balita */} {/* 3. Lokasi Posyandu */} {/* 4. Artikel Stunting */}
) }