Commit 61b30350 authored by Djordje's avatar Djordje

Integrate routing with sidemenu

parent 0f569607
...@@ -24,7 +24,7 @@ function App() { ...@@ -24,7 +24,7 @@ function App() {
<Route path='register/:buildingId' element={<EntryPage children={<RegisterForm />} />} /> <Route path='register/:buildingId' element={<EntryPage children={<RegisterForm />} />} />
<Route path='register/error' element={<EntryPage children={<div>Invalid invitational link - screen to be implemented</div>} />} /> <Route path='register/error' element={<EntryPage children={<div>Invalid invitational link - screen to be implemented</div>} />} />
<Route path='login' element={<EntryPage children={<LoginForm />} />} /> <Route path='login' element={<EntryPage children={<LoginForm />} />} />
<Route path='tenant' element={<Application />} /> <Route path='tenant/*' element={<Application />} />
<Route path='*' element={<Navigate replace to="login" />} /> <Route path='*' element={<Navigate replace to="login" />} />
</Routes> </Routes>
</Router> </Router>
......
import { Box } from "@mui/material" import { Box } from "@mui/material"
import { Navigate, Route, Routes } from "react-router-dom";
const classes = { const classes = {
wrapper: { wrapper: {
...@@ -11,6 +12,17 @@ const classes = { ...@@ -11,6 +12,17 @@ const classes = {
export const ApplicationTab = () => { export const ApplicationTab = () => {
return ( return (
<Box sx={classes.wrapper}></Box> <Box sx={classes.wrapper}>
<Routes>
<Route path='overview' element={<div>Hello from overview</div>} />
<Route path='notifications' element={<div>Hello from notifications</div>} />
<Route path='issues' element={<div>Hello from issues</div>} />
<Route path='voting' element={<div>Hello from voting</div>} />
<Route path='invoices' element={<div>Hello from invoices</div>} />
<Route path='building-invoices' element={<div>Hello from building invoices</div>} />
<Route path='documents' element={<div>Hello from documents</div>} />
<Route path='*' element={<Navigate replace to="overview" />} />
</Routes>
</Box>
) )
} }
\ No newline at end of file
...@@ -89,7 +89,7 @@ export const LoginForm = () => { ...@@ -89,7 +89,7 @@ export const LoginForm = () => {
} }
localStorage.setItem(JWT_TENANT, res); localStorage.setItem(JWT_TENANT, res);
navigate('../tenant'); navigate('../tenant/overview');
} }
const handleKeyUp = (event: React.KeyboardEvent<HTMLDivElement>): void => { const handleKeyUp = (event: React.KeyboardEvent<HTMLDivElement>): void => {
......
...@@ -6,6 +6,7 @@ import { UserIcon } from "../icons/UserIcon"; ...@@ -6,6 +6,7 @@ import { UserIcon } from "../icons/UserIcon";
import { SideMenuItem } from "../SideMenuItem"; import { SideMenuItem } from "../SideMenuItem";
import { subMenu } from "./SideMenuData"; import { subMenu } from "./SideMenuData";
import "./SideMenu.css"; import "./SideMenu.css";
import { useLocation } from "react-router-dom";
const classes = { const classes = {
logo: { logo: {
...@@ -39,6 +40,13 @@ const classes = { ...@@ -39,6 +40,13 @@ const classes = {
export const SideMenu = ({ active, toggleSideMenu }: { active: boolean, toggleSideMenu: (open: boolean) => void }) => { export const SideMenu = ({ active, toggleSideMenu }: { active: boolean, toggleSideMenu: (open: boolean) => void }) => {
const [tenantInfo, setTenantInfo] = useState<any>(); const [tenantInfo, setTenantInfo] = useState<any>();
const location = useLocation();
const [selectedItem, setSelectedItem] = useState(location.pathname.split('/').at(-1)!);
const changeSelectedItem = (item: string) => {
setSelectedItem(item);
toggleSideMenu(false);
};
useEffect(() => { useEffect(() => {
getTenantInfo((err: any, data: any) => { getTenantInfo((err: any, data: any) => {
...@@ -64,10 +72,10 @@ export const SideMenu = ({ active, toggleSideMenu }: { active: boolean, toggleSi ...@@ -64,10 +72,10 @@ export const SideMenu = ({ active, toggleSideMenu }: { active: boolean, toggleSi
</Box> </Box>
</Box> </Box>
{subMenu.map((menu, index) => ( {subMenu.map((menu, index) => (
<SideMenuItem key={index} content={menu} /> <SideMenuItem key={index} content={menu} selectedItem={selectedItem} changeSelectedItem={changeSelectedItem} />
))} ))}
</div> </div>
<div className="transparent" onClick={() => {toggleSideMenu(false)}}></div> <div className="transparent" onClick={() => { toggleSideMenu(false) }}></div>
</div> </div>
} }
</> </>
......
...@@ -14,18 +14,18 @@ export const subMenu: SubMenu[] = [ ...@@ -14,18 +14,18 @@ export const subMenu: SubMenu[] = [
{ {
title: 'Glavni meni', title: 'Glavni meni',
items: [ items: [
{ title: 'Pregled', icon: <HomeIcon /> }, { title: 'Pregled', icon: <HomeIcon />, path: 'overview' },
{ title: 'Obaveštenja', icon: <NotificationIcon /> }, { title: 'Obaveštenja', icon: <NotificationIcon />, path: 'notifications' },
{ title: 'Aktivnosti', icon: <ActivityIcon /> }, { title: 'Aktivnosti', icon: <ActivityIcon />, path: 'issues' },
{ title: 'Glasanje', icon: <VotingIcon /> } { title: 'Glasanje', icon: <VotingIcon />, path: 'voting' }
] ]
}, },
{ {
title: 'Računi/Finansije', title: 'Računi/Finansije',
items: [ items: [
{ title: 'Moj Račun', icon: <InvoicesIcon /> }, { title: 'Moj Račun', icon: <InvoicesIcon />, path: 'invoices' },
{ title: 'Finansije zgrade', icon: <BuidlingInvoicesIcon /> }, { title: 'Finansije zgrade', icon: <BuidlingInvoicesIcon />, path: 'building-invoices' },
{ title: 'Dokumenta', icon: <DocumentIcon /> }] { title: 'Dokumenta', icon: <DocumentIcon />, path: 'documents' }]
}, },
{ {
title: 'Aplikacija', title: 'Aplikacija',
......
import { Box, Typography } from "@mui/material"; import { Box, Typography } from "@mui/material";
import { useLocation, useNavigate } from "react-router-dom";
import { SubMenu } from "../internal-types"; import { SubMenu } from "../internal-types";
const classes = { const classes = {
wrapper : { wrapper: {
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
color: 'white', color: 'white',
gap: '10px' gap: '5px'
}, },
itemTitle: { itemTitle: {
color: 'rgb(24, 95, 167)', color: 'rgb(24, 95, 167)',
...@@ -18,19 +19,43 @@ const classes = { ...@@ -18,19 +19,43 @@ const classes = {
gap: '15px', gap: '15px',
alignItems: 'center', alignItems: 'center',
paddingInline: '10%', paddingInline: '10%',
// boxSizing: 'border-box', paddingBlock: '2.5px',
boxSizing: 'border-box',
// backgroundColor: 'red', // backgroundColor: 'red',
borderRadius: '5px' borderRadius: '5px',
userSelect: 'none',
':hover': {
backgroundColor: 'rgba(150, 150, 150, 0.2)'
}
},
selectedItem: {
backgroundColor: 'rgba(200, 200, 200, 0.3)',
'& .MuiTypography-root': {
fontWeight: 'bold'
},
'&:hover': {
backgroundColor: 'rgba(200, 200, 200, 0.3)'
},
'& .icons-stroke': {
stroke: 'white'
}
} }
} as const; } as const;
export const SideMenuItem = ({ content }: { content: SubMenu }) => { export const SideMenuItem = ({ content, selectedItem, changeSelectedItem }: { content: SubMenu, selectedItem: string, changeSelectedItem: (item: string) => void }) => {
const navigate = useNavigate();
return ( return (
<Box sx={classes.wrapper}> <Box sx={classes.wrapper}>
<Typography sx={classes.itemTitle}> {content.title.toUpperCase()}</Typography> <Typography sx={classes.itemTitle}> {content.title.toUpperCase()}</Typography>
{content.items.map((item, ind) => ( {content.items.map((item, ind) => (
<Box sx={classes.itemsWrapper} key={ind}> <Box sx={selectedItem === item.path ? { ...classes.itemsWrapper, ...classes.selectedItem } : classes.itemsWrapper} key={ind} onClick={() => {
if (item.path) {
navigate(item.path);
changeSelectedItem(item.path);
}
}}>
{!!item.icon && item.icon} {!!item.icon && item.icon}
<Typography>{item.title}</Typography> <Typography>{item.title}</Typography>
</Box> </Box>
......
...@@ -25,5 +25,6 @@ export type SubMenu = { ...@@ -25,5 +25,6 @@ export type SubMenu = {
export type SubMenuItem = { export type SubMenuItem = {
icon?: ReactElement, icon?: ReactElement,
title: string title: string,
path?: string
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment