Skip to content

Commit a90c9f0

Browse files
updated
1 parent 86a4c4f commit a90c9f0

File tree

14 files changed

+410
-17
lines changed

14 files changed

+410
-17
lines changed

chapter-6/db.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"sales": [
3+
{
4+
"id": "sgacus86fov",
5+
"name": "This week",
6+
"data": [30, 40, 25, 50, 49, 21, 70, 51]
7+
},
8+
{
9+
"id": "saftyaf56",
10+
"name": "Last week",
11+
"data": [23, 12, 54, 61, 32, 56, 81, 19]
12+
}
13+
]
14+
}

chapter-6/package-lock.json

+93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chapter-6/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@types/testing-library__jest-dom": "5.9.5",
2525
"@types/webpack-env": "1.15.3",
2626
"@types/yup": "0.29.9",
27+
"apexcharts": "3.22.3",
2728
"axios": "0.21.0",
2829
"clsx": "1.1.1",
2930
"cross-env": "7.0.2",
@@ -40,8 +41,10 @@
4041
"plop": "2.7.4",
4142
"prettier": "2.2.0",
4243
"react": "16.13.0",
44+
"react-apexcharts": "1.3.7",
4345
"react-app-polyfill": "1.0.6",
4446
"react-dom": "16.13.0",
47+
"react-feather": "2.0.9",
4548
"react-helmet-async": "1.0.7",
4649
"react-i18next": "11.7.3",
4750
"react-redux": "7.2.2",
@@ -77,7 +80,8 @@
7780
"lint:fix": "npm run eslint -- --fix src",
7881
"lint:css": "stylelint src/**/*.css",
7982
"generate": "cross-env TS_NODE_PROJECT='./internals/ts-node.tsconfig.json' plop --plopfile internals/generators/plopfile.ts",
80-
"prettify": "prettier --write"
83+
"prettify": "prettier --write",
84+
"backend": "json-server --watch db.json --port 5000 --delay=1000"
8185
},
8286
"browserslist": {
8387
"production": [

chapter-6/src/api/axios.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import axios from 'axios';
2+
3+
/*create an instance of axios with a default base URI when sending HTTP requests*/
4+
/*JSON Server has CORS Policy by default*/
5+
export const api = axios.create({
6+
baseURL: `http://localhost:5000/`,
7+
});
8+
9+
export default api;
10+
11+
export const EndPoints = {
12+
sales: 'sales',
13+
};

chapter-6/src/app/components/page.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React, { forwardRef } from 'react';
2+
import type { HTMLProps, ReactNode } from 'react';
3+
import { Helmet } from 'react-helmet-async';
4+
5+
type PageProps = {
6+
children?: ReactNode;
7+
title?: string;
8+
} & HTMLProps<HTMLDivElement>;
9+
10+
const Page = forwardRef<HTMLDivElement, PageProps>(
11+
({ children, title = '', ...rest }, ref) => {
12+
return (
13+
<div ref={ref as any} {...rest}>
14+
<Helmet>
15+
<title>{title}</title>
16+
</Helmet>
17+
{children}
18+
</div>
19+
);
20+
},
21+
);
22+
23+
export default Page;

chapter-6/src/app/index.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
* contain code that should be seen on all pages. (e.g. navigation bar)
77
*/
88

9-
import { Container } from '@material-ui/core';
109
import * as React from 'react';
1110
import { Helmet } from 'react-helmet-async';
12-
import { Switch, Route, BrowserRouter } from 'react-router-dom';
11+
import { BrowserRouter } from 'react-router-dom';
1312

1413
import { GlobalStyle } from 'styles/global-styles';
15-
import NavigationBar from './components/navigation-bar';
14+
import MainLayout from './layouts/main-layout';
1615
import { Routes } from './routes';
1716

1817
export function App() {
@@ -24,10 +23,9 @@ export function App() {
2423
>
2524
<meta name="description" content="A React Boilerplate application" />
2625
</Helmet>
27-
<NavigationBar />
28-
<Container>
26+
<MainLayout>
2927
<Routes />
30-
</Container>
28+
</MainLayout>
3129
<GlobalStyle />
3230
</BrowserRouter>
3331
);

chapter-6/src/app/layouts/dashboard-layout/dashboard-sidebar-navigation.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import SettingsIcon from '@material-ui/icons/Settings';
1010
import ExitToAppIcon from '@material-ui/icons/ExitToApp';
1111
import Toolbar from '@material-ui/core/Toolbar';
1212
import { useRouteMatch } from 'react-router';
13+
import { Divider, ListSubheader } from '@material-ui/core';
14+
15+
import { PieChart as PieChartIcon } from 'react-feather';
1316

1417
const DashboardSidebarNavigation = () => {
1518
const classes = useStyles();
@@ -36,8 +39,18 @@ const DashboardSidebarNavigation = () => {
3639
Logo
3740
</Link>
3841
</Toolbar>
42+
<Divider />
3943
<div className={classes.drawerContainer}>
4044
<List>
45+
<ListSubheader>Reports</ListSubheader>
46+
<Link className={classes.link} to={`${url}`}>
47+
<ListItem button>
48+
<ListItemIcon>
49+
<PieChartIcon />
50+
</ListItemIcon>
51+
<ListItemText primary={'Dashboard'} />
52+
</ListItem>
53+
</Link>
4154
<Link className={classes.link} to={`${url}/settings-and-privacy`}>
4255
<ListItem button>
4356
<ListItemIcon>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { Grid } from '@material-ui/core';
3+
import { makeStyles } from '@material-ui/core/styles';
34

45
import DashboardSidebarNavigation from './dashboard-sidebar-navigation';
56

@@ -8,16 +9,51 @@ type Props = {
89
};
910

1011
const Dashboard = ({ children }: Props) => {
12+
const classes = useStyles();
13+
1114
return (
1215
<Grid
1316
container
1417
direction="row"
1518
justify="flex-start"
1619
alignItems="flex-start"
1720
>
18-
<DashboardSidebarNavigation /> {children}
21+
<DashboardSidebarNavigation />{' '}
22+
<div className={classes.wrapper}>
23+
<div className={classes.contentContainer}>
24+
<div className={classes.content}>{children}</div>
25+
</div>
26+
</div>
1927
</Grid>
2028
);
2129
};
2230

2331
export default Dashboard;
32+
33+
const useStyles = makeStyles(theme => ({
34+
root: {
35+
display: 'flex',
36+
height: '100%',
37+
overflow: 'hidden',
38+
width: '100%',
39+
},
40+
wrapper: {
41+
display: 'flex',
42+
flex: '1 1 auto',
43+
overflow: 'hidden',
44+
paddingTop: 64,
45+
[theme.breakpoints.up('lg')]: {
46+
paddingLeft: 256,
47+
},
48+
},
49+
contentContainer: {
50+
display: 'flex',
51+
flex: '1 1 auto',
52+
overflow: 'hidden',
53+
},
54+
content: {
55+
flex: '1 1 auto',
56+
height: '100%',
57+
overflow: 'auto',
58+
},
59+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React from 'react';
2+
import type { ReactNode } from 'react';
3+
import { makeStyles } from '@material-ui/core';
4+
5+
import NavigationBar from './navigation-bar';
6+
7+
type Props = {
8+
children?: ReactNode;
9+
};
10+
11+
const MainLayout = ({ children }: Props) => {
12+
const classes = useStyles();
13+
14+
return (
15+
<>
16+
<NavigationBar />
17+
<div className={classes.root}>
18+
<div className={classes.wrapper}>
19+
<div className={classes.contentContainer}>
20+
<div className={classes.content}>{children}</div>
21+
</div>
22+
</div>
23+
</div>
24+
</>
25+
);
26+
};
27+
28+
const useStyles = makeStyles(theme => ({
29+
root: {
30+
backgroundColor: theme.palette.background.default,
31+
display: 'flex',
32+
height: '100%',
33+
overflow: 'hidden',
34+
width: '100%',
35+
},
36+
wrapper: {
37+
display: 'flex',
38+
flex: '1 1 auto',
39+
overflow: 'hidden',
40+
paddingTop: 64,
41+
},
42+
contentContainer: {
43+
display: 'flex',
44+
flex: '1 1 auto',
45+
overflow: 'hidden',
46+
},
47+
content: {
48+
flex: '1 1 auto',
49+
height: '100%',
50+
overflow: 'auto',
51+
},
52+
}));
53+
54+
export default MainLayout;

0 commit comments

Comments
 (0)