Skip to content

Commit

Permalink
fix: update side navigation for administrator and resident per Unlock…
Browse files Browse the repository at this point in the history
  • Loading branch information
carddev81 committed Jan 30, 2025
1 parent 134addd commit c68484e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 87 deletions.
130 changes: 63 additions & 67 deletions frontend/src/Components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ import {
RssIcon,
RectangleStackIcon,
CogIcon,
LightBulbIcon
LightBulbIcon,
RocketLaunchIcon,
ArrowTrendingUpIcon
} from '@heroicons/react/24/solid';
import {
getDashboardLink,
handleLogout,
hasFeature,
isAdministrator,
useAuth
} from '@/useAuth';
import { handleLogout, hasFeature, isAdministrator, useAuth } from '@/useAuth';
import Modal from '@/Components/Modal';
import ULIComponent from './ULIComponent';
import { Link } from 'react-router-dom';
Expand Down Expand Up @@ -52,12 +48,6 @@ export default function Navbar({
const confirmSeedModal = useRef<HTMLDialogElement | null>(null);
const [seedInProgress, setSeedInProgress] = useState<boolean>(false);

const dashboardTitleStudent = new Map([
['/trending-content', 'Trending Content'],
['/learning-path', 'Learning Path'],
['/program-tracker', 'Program Tracker']
]);

const handleSeedDemoData = async () => {
setSeedInProgress(true);
const resp = await API.post<null, object>(`auth/demo-seed`, {});
Expand Down Expand Up @@ -134,18 +124,29 @@ export default function Navbar({
Operational Insights
</Link>
</li>
{hasFeature(
user,
FeatureAccess.OpenContentAccess
) && (
<li>
<Link to="/knowledge-center-management/libraries">
<ULIComponent icon={BookOpenIcon} />
Knowledge Center
</Link>
</li>
)}
{hasFeature(user, FeatureAccess.ProviderAccess) && (
<>
<li>
<Link to="/course-catalog-admin">
<Link to="/learning-platforms">
<ULIComponent icon={CloudIcon} />
Course Catalog
Learning Platforms
</Link>
</li>
<li>
<Link to="/learning-platforms">
<Link to="/course-catalog-admin">
<ULIComponent icon={CloudIcon} />
Learning Platforms
Course Catalog
</Link>
</li>
</>
Expand All @@ -158,17 +159,6 @@ export default function Navbar({
</Link>
</li>
)}
{hasFeature(
user,
FeatureAccess.OpenContentAccess
) && (
<li>
<Link to="/knowledge-center-management/libraries">
<ULIComponent icon={BookOpenIcon} />
Knowledge Center
</Link>
</li>
)}
<li>
<Link to="/residents">
<ULIComponent icon={AcademicCapIcon} />
Expand All @@ -192,25 +182,54 @@ export default function Navbar({
</>
) : (
<>
<li>
<Link to={getDashboardLink(user)}>
<ULIComponent icon={HomeIcon} />
{dashboardTitleStudent.get(
getDashboardLink(user)
) ?? 'Home'}
</Link>
</li>
{hasFeature(user, FeatureAccess.ProviderAccess) && (
<>
{getDashboardLink(user) !==
'/learning-path' && (
{!hasFeature(
user,
FeatureAccess.OpenContentAccess
) &&
!hasFeature(
user,
FeatureAccess.ProviderAccess
) &&
!hasFeature(
user,
FeatureAccess.ProgramAccess
) && (
<>
<li>
<Link to="/learning-path">
<Link to="/home">
<ULIComponent icon={HomeIcon} />
My Learning
Home
</Link>
</li>
)}
</>
)}
{hasFeature(
user,
FeatureAccess.OpenContentAccess
) && (
<>
<li>
<Link to="/trending-content">
<ULIComponent icon={ArrowTrendingUpIcon} />
Trending Content
</Link>
</li>
<li>
<Link to="/knowledge-center/libraries">
<ULIComponent icon={BookOpenIcon} />
Knowledge Center
</Link>
</li>
</>
)}
{hasFeature(user, FeatureAccess.ProviderAccess) && (
<>
<li>
<Link to="/learning-path">
<ULIComponent icon={RocketLaunchIcon} />
Learning Path
</Link>
</li>
<li>
<Link to="/my-courses">
<ULIComponent
Expand All @@ -229,29 +248,6 @@ export default function Navbar({
</li>
</>
)}
{hasFeature(
user,
FeatureAccess.OpenContentAccess
) && (
<>
{user.feature_access.length > 1 && (
<li>
<Link to="/trending-content">
<ULIComponent
icon={BookOpenIcon}
/>
Trending Content
</Link>
</li>
)}
<li>
<Link to="/knowledge-center/libraries">
<ULIComponent icon={BookOpenIcon} />
Knowledge Center
</Link>
</li>
</>
)}
{hasFeature(user, FeatureAccess.ProgramAccess) && (
<li>
<Link to="/programs">
Expand Down
31 changes: 11 additions & 20 deletions frontend/src/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,11 @@ export async function handleLogout(): Promise<void> {
}
}

const accessValues = new Map<FeatureAccess, number>([
[FeatureAccess.OpenContentAccess, 1],
[FeatureAccess.ProviderAccess, 2],
[FeatureAccess.ProgramAccess, 3]
]);

export const studentAccessLinks = [
'/home', // temporary layer 0 until implemented
'/trending-content',
'/learning-path', // temporary until layer 3 is implemented
'/learning-path' // temporary until layer 3 is implemented
];

export const getDashboardLink = (user?: User) => {
if (!user) return '/';

const maxFeature =
user?.feature_access
.map((ax) => accessValues.get(ax) ?? 0)
.sort((a, b) => a - b)
.pop() ?? 0;
return isAdministrator(user)
? getAdminLink(user)
: studentAccessLinks[maxFeature];
: getResidentLink(user);
};

const getAdminLink = (user: User): string => {
Expand All @@ -187,4 +168,14 @@ const getAdminLink = (user: User): string => {
return "/learning-insights";
}
return "/operational-insights";
};

const getResidentLink = (user: User): string => {
if (user.feature_access.includes(FeatureAccess.OpenContentAccess)) {
return "/trending-content";
}
if (user.feature_access.includes(FeatureAccess.ProviderAccess)) {
return "/learning-path";
}
return "/home";
};

0 comments on commit c68484e

Please sign in to comment.