| import { useEffect } from 'react';
|
| import { useState } from 'react';
|
| import { useRouter } from '@tanstack/react-router';
|
| import { Skeleton } from '@/components/ui/skeleton';
|
| import { useSystemStatus } from '@/features/auth/data/initialization';
|
|
|
| interface InitializationGuardProps {
|
| children: React.ReactNode;
|
| }
|
|
|
| export function InitializationGuard({ children }: InitializationGuardProps) {
|
| const router = useRouter();
|
| const { data: systemStatus, isLoading, error } = useSystemStatus();
|
| const [isNavigating, setIsNavigating] = useState(false);
|
|
|
| useEffect(() => {
|
|
|
| if (systemStatus && !systemStatus.isInitialized) {
|
|
|
| const currentPath = window.location.pathname;
|
| if (currentPath !== '/initialization') {
|
| setIsNavigating(true);
|
|
|
| router.navigate({ to: '/initialization' }).finally(() => {
|
| setIsNavigating(false);
|
| });
|
| }
|
| }
|
| }, [systemStatus, router]);
|
|
|
|
|
| if (isLoading) {
|
| return (
|
| <div className='flex h-screen items-center justify-center'>
|
| <div className='space-y-4'>
|
| <Skeleton className='h-8 w-48' />
|
| <Skeleton className='h-4 w-32' />
|
| </div>
|
| </div>
|
| );
|
| }
|
|
|
|
|
| if (error) {
|
| return (
|
| <div className='flex h-screen items-center justify-center'>
|
| <div className='text-center'>
|
| <h1 className='text-2xl font-bold text-red-600'>System Error</h1>
|
| <p className='text-muted-foreground'>Failed to check system status</p>
|
| </div>
|
| </div>
|
| );
|
| }
|
|
|
|
|
|
|
| if ((systemStatus && !systemStatus.isInitialized && window.location.pathname !== '/initialization') || isNavigating) {
|
|
|
|
|
| return (
|
| <div className='flex h-screen items-center justify-center'>
|
| <div className='space-y-4'>
|
| <Skeleton className='h-8 w-48' />
|
| <Skeleton className='h-4 w-32' />
|
| </div>
|
| </div>
|
| );
|
| }
|
|
|
| return <>{children}</>;
|
| }
|
|
|