From 6db7532a4e8e86257bdb1f8507c624058689478c Mon Sep 17 00:00:00 2001 From: ayush00git Date: Wed, 2 Sep 2026 13:36:37 +0530 Subject: [PATCH] fix(profile): handle admin profile redirection issues --- app/src/pages/Landing.tsx | 18 ++++++++++++++++-- app/src/pages/profile/Profile.tsx | 9 ++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/pages/Landing.tsx b/app/src/pages/Landing.tsx index 4b0abb2..65a7f00 100644 --- a/app/src/pages/Landing.tsx +++ b/app/src/pages/Landing.tsx @@ -3,6 +3,7 @@ import { ArrowRight } from 'lucide-react'; import { Link, useNavigate } from 'react-router-dom'; import { MainLayout } from '../components/layout/MainLayout'; import { useAuth } from '../context/auth-context'; +import { adminDashboardFor } from '../constants/adminDashboard'; type Profile = { department?: string; hostel?: string; building?: string } | null; @@ -34,10 +35,14 @@ export function Landing() { return () => document.removeEventListener('mousedown', handleClick); }, []); + // admins (profile carries a position) get a dashboard button instead of + // the complaint-lodging flow + const isAdmin = Boolean(profile?.position); + function handleComplaintClick() { if (isAuth === null) return; if (isAuth && profile) { - navigate(getPostRoute(profile)); + navigate(isAdmin ? adminDashboardFor(profile.position!) : getPostRoute(profile)); } else { setShowLoginMenu(prev => !prev); } @@ -63,7 +68,7 @@ export function Landing() { onClick={handleComplaintClick} className="inline-flex items-center gap-2 bg-[#16a34a] hover:bg-[#15803d] text-white text-sm font-semibold px-6 py-3 rounded-lg transition-colors duration-200 cursor-pointer" > - Lodge a Complaint + {isAdmin ? 'Dashboard' : 'Lodge a Complaint'}
)} + + {isAuth !== true && ( + + Admin Logins (XEN, AE, JE) + + )} diff --git a/app/src/pages/profile/Profile.tsx b/app/src/pages/profile/Profile.tsx index 93f2110..1cd88dd 100644 --- a/app/src/pages/profile/Profile.tsx +++ b/app/src/pages/profile/Profile.tsx @@ -1,5 +1,5 @@ import { useCallback, useEffect, useState } from 'react'; -import { useNavigate, Link } from 'react-router-dom'; +import { useNavigate, Link, Navigate } from 'react-router-dom'; import { ShieldCheck, LogOut, PlusCircle, AlertCircle, Pencil, Inbox, ServerCrash, Info, X, Clock, @@ -10,6 +10,7 @@ import type { ComplaintPost, EditForm, Role } from '../../components/ComplaintCa import { Loader } from '../../components/Loader'; import { BUILDINGS, HOSTELS, DEPARTMENTS, BLOCK_LABELS, BLOCK_TYPES } from '../../constants/models'; import { useAuth } from '../../context/auth-context'; +import { adminDashboardFor } from '../../constants/adminDashboard'; export function Profile() { const { profile, status, errorMessage, patchProfile } = useAuth(); @@ -116,6 +117,12 @@ export function Profile() { if (!profile) return null; + // admins (role "admin" — their profile carries a position) have no profile + // page; send them to their XEN / AE / JE dashboard instead + if (profile.position) { + return ; + } + const isFaculty = 'department' in profile; const isWarden = 'hostel' in profile; const isCentreHead = 'building' in profile;