diff --git a/frontend/src/components/layout/BackstoryLayout.tsx b/frontend/src/components/layout/BackstoryLayout.tsx index 3c07021..bed6a01 100644 --- a/frontend/src/components/layout/BackstoryLayout.tsx +++ b/frontend/src/components/layout/BackstoryLayout.tsx @@ -1,6 +1,6 @@ // components/layout/BackstoryLayout.tsx import React, { JSX, ReactElement, useEffect, useState } from 'react'; -import { Outlet, useLocation, Routes, Route } from 'react-router-dom'; +import { Outlet, useLocation, Routes, Route, matchPath } from 'react-router-dom'; import { Box, Container, Paper } from '@mui/material'; import { useNavigate } from 'react-router-dom'; import { SxProps, Theme } from '@mui/material'; @@ -24,10 +24,12 @@ export type NavigationLinkType = { interface BackstoryPageContainerProps { children?: React.ReactNode; sx?: SxProps; + variant?: 'normal' | 'fullWidth'; } const BackstoryPageContainer = (props: BackstoryPageContainerProps): JSX.Element => { - const { children, sx } = props; + const { children, sx, variant = 'normal' } = props; + console.log({ variant }); return ( = (props: BackstoryLayoutP const location = useLocation(); const { guest, user } = useAuth(); const [navigationItems, setNavigationItems] = useState([]); + const userType = user?.userType || null; + const isAdmin = user?.isAdmin ? true : false; + const routes = getAllRoutes(userType, isAdmin); useEffect(() => { const userType = user?.userType || null; @@ -93,10 +99,6 @@ const BackstoryLayout: React.FC = (props: BackstoryLayoutP const generateRoutes = (): React.ReactNode | null => { if (!guest && !user) return null; - const userType = user?.userType || null; - const isAdmin = user?.isAdmin ? true : false; - const routes = getAllRoutes(userType, isAdmin); - return routes .map((route, index) => { if (!route.path || !route.component) return null; @@ -114,6 +116,31 @@ const BackstoryLayout: React.FC = (props: BackstoryLayoutP .filter(Boolean); }; + const findMatchingRoute = (currentPath: string, routes: any[]) => { + for (const route of routes) { + if (!route.path) continue; + + // Try to match the route path with the current path + const match = matchPath( + { + path: route.path, + exact: true, + caseSensitive: false + }, + currentPath + ); + + if (match) { + return route; + } + } + return null; + }; + + // Extract 'variant' from the current route + const currentRouteConfig = findMatchingRoute(location.pathname, routes); + const variant = currentRouteConfig?.variant || 'normal'; + return ( = (props: BackstoryLayoutP minWidth: 'min-content', }} > - + {!guest && !user && ( , component: , + variant: 'fullWidth', userTypes: ['candidate', 'guest', 'employer'], showInNavigation: false, showInUserMenu: true, diff --git a/frontend/src/types/navigation.ts b/frontend/src/types/navigation.ts index b208d41..bed1cd1 100644 --- a/frontend/src/types/navigation.ts +++ b/frontend/src/types/navigation.ts @@ -8,6 +8,7 @@ export interface NavigationItem { children?: NavigationItem[]; component?: ReactElement; userTypes?: ('candidate' | 'employer' | 'guest' | 'admin')[]; + variant?: 'normal' | 'fullWidth'; exact?: boolean; divider?: boolean; showInNavigation?: boolean; // Controls if item appears in main navigation