feat: implement complex selection flow

This commit is contained in:
Jose Selesan
2026-04-20 15:47:47 -03:00
parent a5e39c94c5
commit 28fd51f926
17 changed files with 453 additions and 38 deletions

View File

@@ -0,0 +1,50 @@
import { useEffect } from 'react';
import { apiClient } from '@/lib/api-client';
import { useAuth } from '@/lib/auth';
import { createFileRoute, useNavigate } from '@tanstack/react-router';
function AuthCallbackPage() {
const navigate = useNavigate();
const { isAuthenticated } = useAuth();
useEffect(() => {
async function handleCallback() {
if (!isAuthenticated) {
navigate({ to: '/login' });
return;
}
try {
const complexes = await apiClient.complexes.listMine();
if (complexes.length === 1) {
await apiClient.complexes.select({ complexId: complexes[0].id });
navigate({ to: '/' });
} else if (complexes.length > 1) {
const current = await apiClient.complexes.getCurrent();
if (current) {
navigate({ to: '/' });
} else {
navigate({ to: '/select-complex' });
}
} else {
navigate({ to: '/' });
}
} catch {
navigate({ to: '/login' });
}
}
handleCallback();
}, [isAuthenticated, navigate]);
return (
<main className="flex min-h-screen w-full items-center justify-center px-6">
<p className="text-sm text-muted-foreground">Completando sesión...</p>
</main>
);
}
export const Route = createFileRoute('/auth-callback')({
component: AuthCallbackPage,
});