2026-08-17 22:24:24 +02:00
|
|
|
import { asError } from '@/utils/errorTypes';
|
2026-06-29 07:55:47 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
|
|
import { AppRouter } from '@/routes';
|
|
|
|
|
import { setUnauthorizedHandler } from '@/api/client';
|
|
|
|
|
import { useAuthStore } from '@/store/authStore';
|
2026-07-23 08:42:26 +02:00
|
|
|
import { useThemeStore } from '@/store/themeStore';
|
2026-07-26 12:18:52 +02:00
|
|
|
import { ErrorBoundary } from '@/components/common/ErrorBoundary';
|
2026-07-26 12:49:39 +02:00
|
|
|
import { useToast } from '@/components/ui/Toast';
|
|
|
|
|
import { useOnlineStatus } from '@/hooks/useOnlineStatus';
|
2026-08-27 01:43:06 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2026-08-16 13:50:39 +02:00
|
|
|
|
2026-06-29 07:55:47 +02:00
|
|
|
|
2026-07-26 12:49:39 +02:00
|
|
|
function QueryClientWrapper({ children }: { children: React.ReactNode }) {
|
2026-08-27 01:43:06 +02:00
|
|
|
const { t } = useTranslation();
|
2026-07-26 12:49:39 +02:00
|
|
|
const toast = useToast();
|
|
|
|
|
|
|
|
|
|
const [queryClient] = React.useState(() => new QueryClient({
|
|
|
|
|
defaultOptions: {
|
|
|
|
|
queries: {
|
|
|
|
|
retry: 1,
|
|
|
|
|
staleTime: 5 * 60 * 1000,
|
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
|
},
|
|
|
|
|
mutations: {
|
|
|
|
|
retry: 0,
|
2026-08-17 22:24:24 +02:00
|
|
|
onError: (error: unknown) => { const errObj = asError(error);
|
2026-07-26 12:49:39 +02:00
|
|
|
// Don't show toast for 401 (handled by auth)
|
2026-08-17 22:24:24 +02:00
|
|
|
if (errObj?.status === 401) return;
|
|
|
|
|
const msg = errObj?.detail || errObj?.message || 'Ein Fehler ist aufgetreten';
|
2026-07-26 12:49:39 +02:00
|
|
|
toast.error(msg);
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-06-29 07:55:47 +02:00
|
|
|
},
|
2026-07-26 12:49:39 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
|
{children}
|
|
|
|
|
</QueryClientProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function OfflineBanner() {
|
2026-08-27 01:43:06 +02:00
|
|
|
const { t } = useTranslation();
|
2026-07-26 12:49:39 +02:00
|
|
|
const isOnline = useOnlineStatus();
|
|
|
|
|
|
|
|
|
|
if (isOnline) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="fixed top-0 left-0 right-0 z-[200] bg-warning-500 text-white text-center py-2 px-4 text-sm font-medium shadow-md">
|
2026-08-27 01:43:06 +02:00
|
|
|
{t('app.siesindofflineänderungenwerdengespeicher')}
|
2026-07-26 12:49:39 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-29 07:55:47 +02:00
|
|
|
|
|
|
|
|
export default function App() {
|
2026-08-27 01:43:06 +02:00
|
|
|
const { t } = useTranslation();
|
2026-06-29 07:55:47 +02:00
|
|
|
const { logout } = useAuthStore();
|
2026-07-23 08:42:26 +02:00
|
|
|
const loadThemeFromStorage = useThemeStore((s) => s.loadFromStorage);
|
2026-07-26 12:49:39 +02:00
|
|
|
const toast = useToast();
|
2026-06-29 07:55:47 +02:00
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
setUnauthorizedHandler(() => {
|
2026-07-26 12:49:39 +02:00
|
|
|
toast.warning('Ihre Sitzung ist abgelaufen. Sie werden zur Anmeldung weitergeleitet.');
|
2026-06-29 07:55:47 +02:00
|
|
|
logout();
|
2026-07-26 12:49:39 +02:00
|
|
|
setTimeout(() => { window.location.href = '/login'; }, 1500);
|
2026-06-29 07:55:47 +02:00
|
|
|
});
|
2026-07-26 12:49:39 +02:00
|
|
|
}, [logout, toast]);
|
2026-06-29 07:55:47 +02:00
|
|
|
|
2026-07-23 08:42:26 +02:00
|
|
|
// Load theme from localStorage on app start
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
loadThemeFromStorage();
|
|
|
|
|
}, [loadThemeFromStorage]);
|
|
|
|
|
|
2026-06-29 07:55:47 +02:00
|
|
|
return (
|
2026-07-26 12:49:39 +02:00
|
|
|
<QueryClientWrapper>
|
|
|
|
|
<OfflineBanner />
|
2026-07-31 00:58:05 +02:00
|
|
|
<a
|
|
|
|
|
href="#main-content"
|
|
|
|
|
className="sr-only focus:not-sr-only focus:absolute focus:top-2 focus:left-2 focus:z-[300] focus:px-4 focus:py-2 focus:bg-primary-600 focus:text-white focus:rounded-md"
|
|
|
|
|
>
|
2026-08-27 01:43:06 +02:00
|
|
|
{t('app.zumhauptinhaltspringen')}
|
2026-07-31 00:58:05 +02:00
|
|
|
</a>
|
2026-07-26 12:18:52 +02:00
|
|
|
<ErrorBoundary>
|
|
|
|
|
<AppRouter />
|
|
|
|
|
</ErrorBoundary>
|
2026-07-26 12:49:39 +02:00
|
|
|
</QueryClientWrapper>
|
2026-06-29 07:55:47 +02:00
|
|
|
);
|
|
|
|
|
}
|