Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app/src/pages/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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 <ArrowRight className="w-4 h-4" />
{isAdmin ? 'Dashboard' : 'Lodge a Complaint'} <ArrowRight className="w-4 h-4" />
</button>
<div
className={`absolute top-full left-1/2 -translate-x-1/2 mt-2 bg-[#222222] border border-[#333333] rounded-lg shadow-xl overflow-hidden z-50 min-w-[190px] transition-all duration-200 origin-top ${
Expand Down Expand Up @@ -107,6 +112,15 @@ export function Landing() {
</div>
</div>
)}

{isAuth !== true && (
<Link
to="/staff/login"
className="inline-flex items-center gap-2 bg-[#111111] hover:bg-[#000000] text-white text-sm font-semibold px-6 py-3 rounded-lg transition-colors duration-200 cursor-pointer"
>
Admin Logins (XEN, AE, JE)
</Link>
)}
</div>
</div>
</section>
Expand Down
9 changes: 8 additions & 1 deletion app/src/pages/profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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 <Navigate to={adminDashboardFor(profile.position)} replace />;
}

const isFaculty = 'department' in profile;
const isWarden = 'hostel' in profile;
const isCentreHead = 'building' in profile;
Expand Down
Loading