Added fullWidth variant for navigation routes
This commit is contained in:
parent
ffd4b829f6
commit
88a3f85635
@ -1,6 +1,6 @@
|
|||||||
// components/layout/BackstoryLayout.tsx
|
// components/layout/BackstoryLayout.tsx
|
||||||
import React, { JSX, ReactElement, useEffect, useState } from 'react';
|
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 { Box, Container, Paper } from '@mui/material';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { SxProps, Theme } from '@mui/material';
|
import { SxProps, Theme } from '@mui/material';
|
||||||
@ -24,10 +24,12 @@ export type NavigationLinkType = {
|
|||||||
interface BackstoryPageContainerProps {
|
interface BackstoryPageContainerProps {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
sx?: SxProps<Theme>;
|
sx?: SxProps<Theme>;
|
||||||
|
variant?: 'normal' | 'fullWidth';
|
||||||
}
|
}
|
||||||
|
|
||||||
const BackstoryPageContainer = (props: BackstoryPageContainerProps): JSX.Element => {
|
const BackstoryPageContainer = (props: BackstoryPageContainerProps): JSX.Element => {
|
||||||
const { children, sx } = props;
|
const { children, sx, variant = 'normal' } = props;
|
||||||
|
console.log({ variant });
|
||||||
return (
|
return (
|
||||||
<Container
|
<Container
|
||||||
className="BackstoryPageContainer"
|
className="BackstoryPageContainer"
|
||||||
@ -37,7 +39,8 @@ const BackstoryPageContainer = (props: BackstoryPageContainerProps): JSX.Element
|
|||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
p: '0 !important',
|
p: '0 !important',
|
||||||
m: '0 auto !important',
|
m: '0 auto !important',
|
||||||
maxWidth: '1024px',
|
minWidth: variant === 'normal' ? '1024px' : '100%',
|
||||||
|
maxWidth: variant === 'normal' ? '1024px' : '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
minHeight: 0,
|
minHeight: 0,
|
||||||
...sx,
|
...sx,
|
||||||
@ -83,6 +86,9 @@ const BackstoryLayout: React.FC<BackstoryLayoutProps> = (props: BackstoryLayoutP
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { guest, user } = useAuth();
|
const { guest, user } = useAuth();
|
||||||
const [navigationItems, setNavigationItems] = useState<NavigationItem[]>([]);
|
const [navigationItems, setNavigationItems] = useState<NavigationItem[]>([]);
|
||||||
|
const userType = user?.userType || null;
|
||||||
|
const isAdmin = user?.isAdmin ? true : false;
|
||||||
|
const routes = getAllRoutes(userType, isAdmin);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const userType = user?.userType || null;
|
const userType = user?.userType || null;
|
||||||
@ -93,10 +99,6 @@ const BackstoryLayout: React.FC<BackstoryLayoutProps> = (props: BackstoryLayoutP
|
|||||||
const generateRoutes = (): React.ReactNode | null => {
|
const generateRoutes = (): React.ReactNode | null => {
|
||||||
if (!guest && !user) return null;
|
if (!guest && !user) return null;
|
||||||
|
|
||||||
const userType = user?.userType || null;
|
|
||||||
const isAdmin = user?.isAdmin ? true : false;
|
|
||||||
const routes = getAllRoutes(userType, isAdmin);
|
|
||||||
|
|
||||||
return routes
|
return routes
|
||||||
.map((route, index) => {
|
.map((route, index) => {
|
||||||
if (!route.path || !route.component) return null;
|
if (!route.path || !route.component) return null;
|
||||||
@ -114,6 +116,31 @@ const BackstoryLayout: React.FC<BackstoryLayoutProps> = (props: BackstoryLayoutP
|
|||||||
.filter(Boolean);
|
.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 (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -152,7 +179,7 @@ const BackstoryLayout: React.FC<BackstoryLayoutProps> = (props: BackstoryLayoutP
|
|||||||
minWidth: 'min-content',
|
minWidth: 'min-content',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<BackstoryPageContainer>
|
<BackstoryPageContainer variant={variant}>
|
||||||
{!guest && !user && (
|
{!guest && !user && (
|
||||||
<Box>
|
<Box>
|
||||||
<LoadingComponent
|
<LoadingComponent
|
||||||
|
@ -222,6 +222,7 @@ export const navigationConfig: NavigationConfig = {
|
|||||||
path: '/candidate/resumes/:resumeId?',
|
path: '/candidate/resumes/:resumeId?',
|
||||||
icon: <EditDocumentIcon />,
|
icon: <EditDocumentIcon />,
|
||||||
component: <ResumeViewer />,
|
component: <ResumeViewer />,
|
||||||
|
variant: 'fullWidth',
|
||||||
userTypes: ['candidate', 'guest', 'employer'],
|
userTypes: ['candidate', 'guest', 'employer'],
|
||||||
showInNavigation: false,
|
showInNavigation: false,
|
||||||
showInUserMenu: true,
|
showInUserMenu: true,
|
||||||
|
@ -8,6 +8,7 @@ export interface NavigationItem {
|
|||||||
children?: NavigationItem[];
|
children?: NavigationItem[];
|
||||||
component?: ReactElement;
|
component?: ReactElement;
|
||||||
userTypes?: ('candidate' | 'employer' | 'guest' | 'admin')[];
|
userTypes?: ('candidate' | 'employer' | 'guest' | 'admin')[];
|
||||||
|
variant?: 'normal' | 'fullWidth';
|
||||||
exact?: boolean;
|
exact?: boolean;
|
||||||
divider?: boolean;
|
divider?: boolean;
|
||||||
showInNavigation?: boolean; // Controls if item appears in main navigation
|
showInNavigation?: boolean; // Controls if item appears in main navigation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user