import { useLocation, useNavigate, useSearch } from '@tanstack/react-router'; import { useAdminSettings } from '@/api/admin/settings/queries'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import Spinner from '@/components/elements/Spinner'; import AdvancedSettingsForm from '@/components/admin/settings/AdvancedSettingsForm'; import GeneralSettingsForm from '@/components/admin/settings/GeneralSettingsForm'; import MailSettingsForm from '@/components/admin/settings/MailSettingsForm'; import SettingsTabButton from '@/components/admin/settings/SettingsTabButton'; import { httpErrorToHuman } from '@/api/http'; import { ServerError } from '@/components/elements/ScreenBlock'; import { Alert } from '@/components/elements/alert'; type Tab = 'general' | 'mail' | 'advanced'; type SettingsSearch = { tab?: string; }; const tabs: { key: Tab; label: string }[] = [ { key: 'general', label: 'General' }, { key: 'mail', label: 'Mail' }, { key: 'advanced', label: 'Advanced' }, ]; const parseTab = (tab: string | undefined): Tab => tab === 'mail' || tab === 'advanced' || tab === 'general' ? tab : 'general'; export default function SettingsContainer() { const navigate = useNavigate(); const location = useLocation(); const search = useSearch({ strict: false }) as SettingsSearch; const pathTab = location.pathname.endsWith('/mail') ? 'mail' : location.pathname.endsWith('/advanced') ? 'advanced' : undefined; const tab = parseTab(pathTab ?? search.tab); const { data: settings, error, isFetching, refetch } = useAdminSettings(); if (error && !settings) { return refetch()} />; } return ( {settings?.meta.load_environment_only && ( This Panel reads settings from the environment only. Set APP_ENVIRONMENT_ONLY=false{' '} in your environment file to load settings dynamically. )}
{tabs.map((item) => ( navigate({ to: item.key === 'general' ? '/panel/settings' : item.key === 'mail' ? '/panel/settings/mail' : '/panel/settings/advanced', replace: true, viewTransition: false, }) } > {item.label} ))}
{!settings ? ( ) : (
{tab === 'general' && } {tab === 'mail' && } {tab === 'advanced' && }
)}
); }