import { useState, useEffect } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { Header } from '@/components/layout/Header'; import { Sidebar } from '@/components/layout/Sidebar'; import { UsersSettings } from '@/components/settings/UsersSettings'; import { TufSettings } from '@/components/settings/TufSettings'; import { TokenSettings } from '@/components/settings/TokenSettings'; type SettingsPage = 'users' | 'tokens' | 'tuf'; // Determine current page from URL or default to 'users' const getCurrentPage = (pathname: string): SettingsPage => { if (pathname === '/settings/tuf') { return 'tuf'; } if (pathname === '/settings/tokens') { return 'tokens'; } return 'users'; }; export const SettingsPage = () => { const [isSidebarOpen, setIsSidebarOpen] = useState(false); const navigate = useNavigate(); const location = useLocation(); const [currentPage, setCurrentPage] = useState(getCurrentPage(location.pathname)); // Update current page when location changes useEffect(() => { const page = getCurrentPage(location.pathname); setCurrentPage(page); }, [location.pathname]); const menuItems = [ { id: 'users' as SettingsPage, label: 'Users', icon: 'fa-users' }, { id: 'tokens' as SettingsPage, label: 'CI/CD Tokens', icon: 'fa-key' }, { id: 'tuf' as SettingsPage, label: 'TUF', icon: 'fa-shield-alt' }, ]; const handlePageChange = (page: SettingsPage) => { setCurrentPage(page); if (page === 'tuf') { navigate('/settings/tuf'); } else if (page === 'tokens') { navigate('/settings/tokens'); } else { navigate('/settings'); } }; return (
setIsSidebarOpen(false)} />
setIsSidebarOpen(true)} onCreateClick={() => {}} createButtonText="" hideSearch={true} />
{/* Navigation Tabs */}
{/* Content */}
{currentPage === 'users' && } {currentPage === 'tokens' && } {currentPage === 'tuf' && }
); };