diff --git a/src/components/dashboard/DashboardLayout.tsx b/src/components/dashboard/DashboardLayout.tsx index 5d2ed22..7929557 100644 --- a/src/components/dashboard/DashboardLayout.tsx +++ b/src/components/dashboard/DashboardLayout.tsx @@ -1,6 +1,6 @@ -import { Component, Show, createEffect, For } from 'solid-js'; +import { Component, Show, createEffect, For, createSignal } from 'solid-js'; import { useNavigate, A } from '@solidjs/router'; -import { authState, fetchRuntimeConfig, logout, hasModule } from '~/lib/auth'; +import { authState, logout, switchRole } from '~/lib/auth'; // ── Icons (inline SVGs for zero deps) ───────────────────────────────────────── @@ -86,7 +86,7 @@ const MODULE_NAV_MAP: Record { const s = authState(); @@ -101,6 +101,8 @@ export default function DashboardLayout(props: { children: any }) { }); const rc = () => authState().runtime_config; + const roleOptions = () => rc()?.user?.roles ?? []; + const activeRole = () => rc()?.user?.active_role ?? rc()?.role ?? ''; const navItems = () => { if (rc()?.role === 'USER') { @@ -127,6 +129,18 @@ export default function DashboardLayout(props: { children: any }) { navigate('/auth/login', { replace: true }); } + async function handleRoleSwitch(nextRole: string) { + const normalized = String(nextRole || '').trim().toUpperCase(); + if (!normalized || normalized === activeRole()) return; + setSwitchingRole(true); + try { + await switchRole(normalized); + navigate('/dashboard', { replace: true }); + } finally { + setSwitchingRole(false); + } + } + return (
{/* ── Sidebar ── */} @@ -166,6 +180,23 @@ export default function DashboardLayout(props: { children: any }) {
 
+ 1}> + + + + Choose What You Need + diff --git a/src/lib/auth.ts b/src/lib/auth.ts index a9ae5bd..3040caa 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -108,7 +108,7 @@ export async function switchRole(roleKey: string): Promise { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, - body: JSON.stringify({ requested_role: roleKey }), + body: JSON.stringify({ role_key: roleKey }), credentials: 'include', }); diff --git a/src/routes/choose-role.tsx b/src/routes/choose-role.tsx index bfd0c6c..8f718c7 100644 --- a/src/routes/choose-role.tsx +++ b/src/routes/choose-role.tsx @@ -1,6 +1,6 @@ -import { createSignal, Show, For } from 'solid-js'; +import { createMemo, createSignal, Show, For } from 'solid-js'; import { useNavigate } from '@solidjs/router'; -import { authState } from '~/lib/auth'; +import { authState, switchRole } from '~/lib/auth'; const ALL_ROLES = [ { key: 'COMPANY', label: 'Company', icon: '🏢', desc: 'Post jobs and hire talent' }, @@ -21,11 +21,18 @@ export default function ChooseRole() { const navigate = useNavigate(); const [loading, setLoading] = createSignal(false); const [error, setError] = createSignal(''); + const registeredRoles = createMemo(() => new Set(authState().runtime_config?.user?.roles ?? [])); - async function selectRole(roleKey: string) { + async function selectRole(roleKey: string, alreadyRegistered: boolean) { setLoading(true); setError(''); try { + if (alreadyRegistered) { + await switchRole(roleKey); + navigate('/dashboard', { replace: true }); + return; + } + // Register for the role then redirect to onboarding const token = authState().access_token; const res = await fetch(`${import.meta.env.VITE_API_URL ?? 'http://localhost:8000'}/api/me/roles/register`, { @@ -56,7 +63,7 @@ export default function ChooseRole() {
NXTGAUGE

What brings you here?

-

Choose your role to get started. You can add more roles later.

+

Choose a role to continue onboarding. You can register multiple roles and switch between them anytime.

@@ -66,15 +73,23 @@ export default function ChooseRole() {
{(role) => ( + (() => { + const alreadyRegistered = registeredRoles().has(role.key); + return ( + ); + })() )}
diff --git a/src/routes/dashboard/explore.tsx b/src/routes/dashboard/explore.tsx index 2e0c7d9..5d15db1 100644 --- a/src/routes/dashboard/explore.tsx +++ b/src/routes/dashboard/explore.tsx @@ -3,12 +3,12 @@ import { A } from '@solidjs/router'; export default function DashboardExplorePage() { return (
-

Explore Nxtgauge

+

Choose What You Want to Do

- Add an additional role to unlock more modules in your dashboard. + Tell us how you want to use Nxtgauge next. Each path has a quick onboarding and review step.

- Go to Choose Role to register another role. + Go to Choose Your Path to continue. If you unlock more than one path, you can switch from the dashboard top bar.

);