import { useState } from 'react' import { useLocation, useNavigate } from 'react-router-dom' import { fetchDashboardRoute } from '../api/session' import { useAuth } from '../auth/AuthProvider' import { spaPathFromCiUrl } from '../lib/ciSpaPaths' export function RoleSelectPage() { const { user, roles, selectedRole, setSelectedRole } = useAuth() const navigate = useNavigate() const location = useLocation() const [pickedRole, setPickedRole] = useState(selectedRole) const [busy, setBusy] = useState(false) const [error, setError] = useState(null) const from = (location.state as { from?: string } | null)?.from ?? '/app/home' async function continueLogin() { if (!pickedRole) { setError('Please select a role to continue.') return } setBusy(true) setError(null) setSelectedRole(pickedRole) let target = from.startsWith('/app') ? from : '/app/home' if (pickedRole.toLowerCase() === 'parent' && target === '/app/home') { target = '/app/parent/home' } try { const dash = await fetchDashboardRoute() const route = dash.data?.dashboard?.route const mapped = spaPathFromCiUrl(route) if (mapped) target = mapped } catch { /* keep fallback target */ } navigate(target, { replace: true }) } return (

Select role

{user?.name ? `Signed in as ${user.name}.` : 'Signed in successfully.'} Choose a role to continue.

{roles.map((role) => ( ))}
{error ? (
{error}
) : null}
) }