Skip to content

Commit

Permalink
♻️(frontend) menu item activation on multiple path
Browse files Browse the repository at this point in the history
certificate entry on learner sidebar menu can render multiple routes:
* order certificate
* enrollment certificate

our menu item must be selected when any of theses two route is active.
  • Loading branch information
rlecellier committed Apr 25, 2024
1 parent 3cea1f5 commit 7e6e527
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ interface MenuNavLinkProps {

const MenuNavLink = ({ link, badgeCount }: MenuNavLinkProps) => {
const location = useLocation();
const activePaths = [...(link.activePaths || []), link.to];
const isMenuNavLinkActive = activePaths.some((path) => isMenuLinkActive(path, location));

return (
<li
className={classNames('dashboard-sidebar__container__nav__item', {
active: isMenuLinkActive(link.to, location),
active: isMenuNavLinkActive,
})}
>
<NavLink to={link.to} end>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface MenuLink {
to: string;
label: string;
component?: ReactNode;
activePaths?: string[];
}

export interface DashboardSidebarProps extends PropsWithChildren {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export const LearnerDashboardSidebar = (props: Partial<DashboardSidebarProps>) =
].map((path) => ({
to: generatePath(path),
label: getRouteLabel(path),
activePaths:
path === LearnerDashboardPaths.CERTIFICATES
? [
LearnerDashboardPaths.ORDER_CERTIFICATES,
LearnerDashboardPaths.ENROLLMENT_CERTIFICATES,
]
: undefined,
})),
[],
);
Expand Down

0 comments on commit 7e6e527

Please sign in to comment.