Skip to content

Commit 7ce9e14

Browse files
committed
fixing routes
1 parent e1e2c00 commit 7ce9e14

File tree

8 files changed

+58
-50
lines changed

8 files changed

+58
-50
lines changed

public/styles/links.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.router-link{
2+
text-decoration:none;
3+
color:black;
4+
}

src/App.jsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import Inter from "../public/static/fonts/Inter.ttf";
22
import { ThemeProvider, CssBaseline, createTheme } from "@mui/material";
33
import RootComponent from "./components/RootComponent";
4+
import RootPage from "./components/RootPage";
5+
import {
6+
Route,
7+
createBrowserRouter,
8+
createRoutesFromElements,
9+
RouterProvider,
10+
} from "react-router-dom";
11+
import Home from "./components/bodyComponents/Home/Home";
412
function App() {
513
const theme = createTheme({
614
spacing: 4,
@@ -40,9 +48,25 @@ function App() {
4048
},
4149
//here we customize our typographi and in the variant prop we can use out myVar value
4250
});
51+
const router = createBrowserRouter(
52+
createRoutesFromElements(
53+
<Route path="/" element={<RootComponent />}>
54+
<Route index element={<RootPage />}></Route>
55+
<Route path="/home" element={<Home />}></Route>
56+
<Route path="/inventory"></Route>
57+
<Route path="/orders"></Route>
58+
<Route path="/customers"></Route>
59+
<Route path="/revenue"></Route>
60+
<Route path="/growth"></Route>
61+
<Route path="/reports"></Route>
62+
<Route path="/settings"></Route>
63+
</Route>
64+
)
65+
);
66+
4367
return (
4468
<ThemeProvider theme={theme}>
45-
<RootComponent />
69+
<RouterProvider router={router} />
4670
<CssBaseline />
4771
</ThemeProvider>
4872
);

src/components/BodyComponent.jsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/components/RootComponent.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import NavBarComponent from "./NavBarComponent";
33
import { Box, Grid } from "@mui/material";
44
import SideBarComponent from "./SideBarComponent";
5-
import BodyComponent from "./BodyComponent";
5+
import { Outlet } from "react-router-dom";
66

77
export default function RootComponent() {
88
return (
@@ -15,7 +15,7 @@ export default function RootComponent() {
1515
<SideBarComponent />
1616
</Grid>
1717
<Grid item md={10}>
18-
<BodyComponent />
18+
<Outlet />
1919
</Grid>
2020
</Grid>
2121
</Box>

src/components/RootPage.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
export default function RootPage() {
4+
return <div>RootPage</div>;
5+
}

src/components/SideBarComponent.jsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState } from "react";
2+
import "../../public/styles/links.css";
23
import {
34
List,
45
ListItem,
@@ -9,6 +10,7 @@ import {
910
Box,
1011
Snackbar,
1112
Alert,
13+
Button,
1214
} from "@mui/material";
1315
import {
1416
HomeOutlined,
@@ -20,8 +22,13 @@ import {
2022
TrendingUpOutlined,
2123
PeopleAltOutlined,
2224
} from "@mui/icons-material";
25+
import { Link, NavLink, useNavigate } from "react-router-dom";
2326

2427
export default function SideBarComponent() {
28+
const navigate = useNavigate();
29+
const navigateTo = (to) => {
30+
navigate(to);
31+
};
2532
// const styles = theme => ({
2633
// listItemText:{
2734
// fontSize:'0.7em',//Insert your required size
@@ -41,7 +48,7 @@ export default function SideBarComponent() {
4148
component: <CardTravelOutlined fontSize="medium" color="primary" />,
4249
},
4350
{
44-
title: "Customer",
51+
title: "Customers",
4552
component: <PeopleAltOutlined fontSize="medium" color="primary" />,
4653
},
4754
{
@@ -53,7 +60,7 @@ export default function SideBarComponent() {
5360
component: <TrendingUpOutlined fontSize="medium" color="primary" />,
5461
},
5562
{
56-
title: "Report",
63+
title: "Reports",
5764
component: <DescriptionOutlined fontSize="medium" color="primary" />,
5865
},
5966
{
@@ -74,6 +81,7 @@ export default function SideBarComponent() {
7481
<ListItemButton
7582
onClick={(event) => {
7683
handlSelectedComponent(event, index);
84+
navigateTo(comp.title.toLocaleLowerCase());
7785
}}
7886
selected={index === selected}
7987
sx={{
@@ -86,6 +94,10 @@ export default function SideBarComponent() {
8694
<ListItemIcon>
8795
<IconButton>{comp.component}</IconButton>
8896
</ListItemIcon>
97+
{/* <Link
98+
to={"" + comp.title.toLocaleLowerCase()}
99+
className="router-link"
100+
> */}
89101
<ListItemText
90102
primary={comp.title}
91103
primaryTypographyProps={{
@@ -94,6 +106,7 @@ export default function SideBarComponent() {
94106
color: selected === index ? "primary.main" : "inherit",
95107
}}
96108
/>
109+
{/* </Link> */}
97110
</ListItemButton>
98111
</Box>
99112
</ListItem>

src/components/bodyComponents/Home/Home.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ export default class Home extends Component {
6969
}}
7070
>
7171
{cardComponent.map((card, index) => (
72-
<Grid item md={"3"} key={index}>
72+
<Grid item md={3} key={index}>
7373
<InfoCard card={card} />
7474
</Grid>
7575
))}
7676
</Grid>
7777
<Grid container sx={{ marginX: 3 }}>
78-
<Grid item md={"8"}>
78+
<Grid item md={8}>
7979
<TotalSales data={data} />
8080
</Grid>
81-
<Grid item md={"4"}>
81+
<Grid item md={4}>
8282
<SalesByCity data={data} />
8383
</Grid>
8484
</Grid>
8585

8686
<Grid container sx={{ margin: 3 }}>
87-
<Grid item md={"6"}>
87+
<Grid item md={6}>
8888
<Channels />
8989
</Grid>
90-
<Grid item md={"6"}>
90+
<Grid item md={6}>
9191
<TopSellingProduct />
9292
</Grid>
9393
</Grid>

src/components/bodyComponents/Home/TopSellingProduct.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ export default function TopSellingProduct() {
4646
</TableRow>
4747
</TableHead>
4848
<TableBody>
49-
{products.map((product) => {
49+
{products.map((product, id) => {
5050
return (
51-
<TableRow>
51+
<TableRow key={id}>
5252
<TableCell>{product.name}</TableCell>
5353
<TableCell>{product.price}</TableCell>
5454
<TableCell>{product.quantity}</TableCell>

0 commit comments

Comments
 (0)