2026-09-03 21:01:52 +03:30
|
|
|
import { Navigate } from 'react-router-dom';
|
|
|
|
|
import { useAuth } from '@/hooks/useAuth';
|
|
|
|
|
import { useLearningJourney } from '@/hooks/useLearningJourney';
|
2026-09-09 01:31:24 +03:30
|
|
|
import { PageSkeleton } from '@/components/skeletons';
|
2026-09-03 21:01:52 +03:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Entry router at "/".
|
|
|
|
|
* Routes the learner to the correct step of the single product journey.
|
|
|
|
|
*/
|
|
|
|
|
export function HomeRedirect() {
|
|
|
|
|
const { effectiveUserId, guestSessionHydrated } = useAuth();
|
|
|
|
|
const { progress, loading } = useLearningJourney(effectiveUserId ?? undefined);
|
|
|
|
|
|
|
|
|
|
if (!guestSessionHydrated || (effectiveUserId && loading)) {
|
2026-09-09 01:31:24 +03:30
|
|
|
return <PageSkeleton />;
|
2026-09-03 21:01:52 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!effectiveUserId) {
|
|
|
|
|
return <Navigate to="/login" replace />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!progress?.pre_test_completed_at) {
|
|
|
|
|
return <Navigate to="/assessment/pre" replace />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!progress?.training_completed_at) {
|
|
|
|
|
return <Navigate to="/chat" replace />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!progress?.post_test_completed_at) {
|
|
|
|
|
return <Navigate to="/assessment/post" replace />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <Navigate to="/finished" replace />;
|
|
|
|
|
}
|