import { useEffect, useState, lazy, Suspense } from 'react'; import { Routes, Route, Navigate } from 'react-router-dom'; import { useAuthStore } from '@/stores/auth'; import { useAppStore } from '@/stores/app'; import { authApi } from '@/api/endpoints/auth'; import AppShell from '@/components/layout/AppShell'; import { Loader2, Lock } from 'lucide-react'; // Lazy-loaded pages (code splitting) const LoginPage = lazy(() => import('@/pages/LoginPage')); const ChatPage = lazy(() => import('@/pages/ChatPage')); const TerraformPage = lazy(() => import('@/pages/TerraformPage')); const PromptGeneratorPage = lazy(() => import('@/pages/PromptGeneratorPage')); const WorkspacesPage = lazy(() => import('@/pages/WorkspacesPage')); const ExplorerPage = lazy(() => import('@/pages/ExplorerPage')); const OciServicesPage = lazy(() => import('@/pages/OciServicesPage')); const ReportsPage = lazy(() => import('@/pages/ReportsPage')); const OciConfigPage = lazy(() => import('@/pages/config/OciConfigPage')); const GenAiConfigPage = lazy(() => import('@/pages/config/GenAiConfigPage')); const McpServersPage = lazy(() => import('@/pages/config/McpServersPage')); const AdbConfigPage = lazy(() => import('@/pages/config/AdbConfigPage')); const EmbeddingsPage = lazy(() => import('@/pages/config/EmbeddingsPage')); const EmbConsultPage = lazy(() => import('@/pages/config/EmbConsultPage')); const TerminalPage = lazy(() => import('@/pages/TerminalPage')); const UsersPage = lazy(() => import('@/pages/admin/UsersPage')); const MySettingsPage = lazy(() => import('@/pages/admin/MySettingsPage')); const OracleIamPage = lazy(() => import('@/pages/admin/OracleIamPage')); const AuditPage = lazy(() => import('@/pages/admin/AuditPage')); function PageLoader() { return (
); } function ForcePasswordModal() { const [curPw, setCurPw] = useState(''); const [newPw, setNewPw] = useState(''); const [confirmPw, setConfirmPw] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const clearMustChangePassword = useAuthStore((s) => s.clearMustChangePassword); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); if (newPw.length < 8) { setError('A nova senha deve ter no minimo 8 caracteres'); return; } if (newPw !== confirmPw) { setError('As senhas nao coincidem'); return; } if (newPw === curPw) { setError('A nova senha deve ser diferente da atual'); return; } setLoading(true); try { await authApi.changePassword(curPw, newPw); clearMustChangePassword(); } catch (err) { setError(err instanceof Error ? err.message : 'Erro ao alterar senha'); } finally { setLoading(false); } }; return (

Alterar Senha

Por seguranca, altere sua senha antes de continuar.

setCurPw(e.target.value)} className="w-full px-3 py-2.5 rounded-lg text-sm outline-none" style={{ background: 'var(--bg2)', border: '1px solid var(--bd)', color: 'var(--t1)' }} autoFocus /> setNewPw(e.target.value)} className="w-full px-3 py-2.5 rounded-lg text-sm outline-none" style={{ background: 'var(--bg2)', border: '1px solid var(--bd)', color: 'var(--t1)' }} /> setConfirmPw(e.target.value)} className="w-full px-3 py-2.5 rounded-lg text-sm outline-none" style={{ background: 'var(--bg2)', border: '1px solid var(--bd)', color: 'var(--t1)' }} /> {error && (
{error}
)}
); } export default function App() { const checkAuth = useAuthStore((s) => s.checkAuth); const loadData = useAppStore((s) => s.loadData); const user = useAuthStore((s) => s.user); const mustChangePassword = useAuthStore((s) => s.mustChangePassword); useEffect(() => { checkAuth().then(() => { if (useAuthStore.getState().user) loadData(); }); }, [checkAuth, loadData]); useEffect(() => { if (user) loadData(); }, [user, loadData]); return ( }> {user && mustChangePassword && } } /> }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ); }