import { useState, useEffect } from 'react' import { Sidebar } from './Sidebar' import { DashboardHome } from './DashboardHome' import { UserManagement } from './UserManagement' import { userManagement, type User } from '../lib/supabase' interface DashboardLayoutProps { onLogout: () => void } export function DashboardLayout({ onLogout }: DashboardLayoutProps) { const [user, setUser] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [currentView, setCurrentView] = useState('dashboard') useEffect(() => { fetchUserProfile() }, []) const fetchUserProfile = async () => { try { setLoading(true) setError(null) const currentUser = await userManagement.getCurrentUser() if (currentUser) { setUser(currentUser) } else { setError('No authenticated user found') } } catch (err) { setError('Failed to fetch user profile') console.error('Profile fetch error:', err) } finally { setLoading(false) } } const handleLogout = async () => { // Navigate to signout route which will handle the actual logout window.history.pushState({}, '', '/signout') window.dispatchEvent(new PopStateEvent('popstate')) } const renderCurrentView = () => { if (!user) return null switch (currentView) { case 'dashboard': return case 'user-management': if (user.roles.includes('admin')) { return } else { return (
Access denied. You need admin privileges to access user management.
) } case 'experiments': return (

Experiments

Experiments module coming soon...
) case 'analytics': return (

Analytics

Analytics module coming soon...
) case 'data-entry': return (

Data Entry

Data entry module coming soon...
) default: return } } if (loading) { return (

Loading dashboard...

) } if (error) { return (
{error}
) } if (!user) { return (
No user data available
) } return (
{renderCurrentView()}
) }