import { useState, useEffect } from 'react'; import { Dashboard } from './components/Dashboard'; import { Inventory } from './components/Inventory'; import { ProtocolChecker } from './components/ProtocolChecker'; import { Onboarding } from './components/Onboarding'; import { ProfileSettings } from './components/ProfileSettings'; import { LoginForm } from './components/auth/LoginForm'; import { SignUpForm } from './components/auth/SignUpForm'; import { EmailVerification } from './components/auth/EmailVerification'; import { ForgotPassword } from './components/auth/ForgotPassword'; import { ResetPassword } from './components/auth/ResetPassword'; import { PrivacyPolicy } from './components/PrivacyPolicy'; import { useSession, signOut } from './lib/auth-client'; import { LayoutDashboard, Package, FileCheck, LogOut, UserCircle } from 'lucide-react'; const logo = '/logo.png'; type AppView = | 'loading' | 'login' | 'signup' | 'verify-email' | 'forgot-password' | 'reset-password' | 'onboarding' | 'app'; type Tab = 'dashboard' | 'inventory' | 'protocol' | 'profile'; function isPrivacyRoute() { return window.location.pathname === '/privacy'; } function isResetPasswordRoute() { return ( window.location.pathname === '/reset-password' && Boolean(new URLSearchParams(window.location.search).get('token')) ); } export default function App() { const { data: session, isPending } = useSession(); const [isPrivacy] = useState(isPrivacyRoute); const [view, setView] = useState( isResetPasswordRoute() ? 'reset-password' : 'loading' ); const [activeTab, setActiveTab] = useState('dashboard'); const [sidebarName, setSidebarName] = useState(undefined); useEffect(() => { if (view === 'reset-password') return; if (isPending) return; if (!session) { if (view !== 'signup' && view !== 'forgot-password') setView('login'); return; } if (!session.user.emailVerified) { setView('verify-email'); return; } // Check if lab profile exists fetch('/api/profile', { credentials: 'include' }).then(r => { setView(r.ok ? 'app' : 'onboarding'); }); }, [session, isPending, view]); if (isPrivacy) return ; if (view === 'reset-password') { return ( { window.history.replaceState({}, '', '/'); setView('login'); }} /> ); } if (view === 'loading') { return (
LabWise
); } if (!session) { if (view === 'signup') return ( setView('login')} onVerify={() => setView('verify-email')} /> ); if (view === 'forgot-password') return setView('login')} />; return ( setView('signup')} onForgotPassword={() => setView('forgot-password')} /> ); } if (view === 'verify-email') return ; if (view === 'onboarding') return setView('app')} />; if (view !== 'app') return null; const navItems = [ { id: 'dashboard' as Tab, label: 'Dashboard', icon: LayoutDashboard }, { id: 'inventory' as Tab, label: 'Inventory', icon: Package }, { id: 'protocol' as Tab, label: 'Protocol Checker', icon: FileCheck }, ]; return (
{activeTab === 'dashboard' && } {activeTab === 'inventory' && } {activeTab === 'protocol' && } {activeTab === 'profile' && }
); }