react-query

This commit is contained in:
2025-12-21 01:45:17 +01:00
parent 22f28728ce
commit 13d8563feb
13 changed files with 324 additions and 296 deletions

View File

@@ -1,59 +1,25 @@
'use client';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { Loader2 } from 'lucide-react';
import { useRouter } from 'next/navigation';
import OnboardingWizard from '@/components/onboarding/OnboardingWizard';
import { useCurrentDriver } from '@/hooks/useDriverService';
import { useAuth } from '@/lib/auth/AuthContext';
import { useServices } from '@/lib/services/ServiceProvider';
export default function OnboardingPage() {
const router = useRouter();
const { session } = useAuth();
const { driverService } = useServices();
const [checking, setChecking] = useState(true);
const { data: driver, isLoading } = useCurrentDriver();
useEffect(() => {
// If user is not authenticated, redirect to login
if (!session) {
router.replace('/auth/login?returnTo=/onboarding');
return;
}
// If user is not authenticated, redirect to login
if (!session) {
router.replace('/auth/login?returnTo=/onboarding');
return null;
}
let cancelled = false;
const checkOnboarding = async () => {
try {
const driver = await driverService.getCurrentDriver();
if (cancelled) return;
// If driver profile exists, onboarding is complete go to dashboard
if (driver) {
router.replace('/dashboard');
return;
}
// Otherwise allow onboarding wizard to render
setChecking(false);
} catch {
// On error, allow onboarding to proceed so user isn't blocked
if (!cancelled) {
setChecking(false);
}
}
};
checkOnboarding();
return () => {
cancelled = true;
};
}, [session, driverService, router]);
// Show loading while checking auth/onboarding status
if (checking) {
// Show loading while checking driver data
if (isLoading) {
return (
<main className="min-h-screen bg-deep-graphite flex items-center justify-center">
<Loader2 className="w-8 h-8 text-primary-blue animate-spin" />
@@ -61,6 +27,12 @@ export default function OnboardingPage() {
);
}
// If driver profile exists, onboarding is complete go to dashboard
if (driver) {
router.replace('/dashboard');
return null;
}
return (
<main className="min-h-screen bg-deep-graphite">
<OnboardingWizard />