Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState } from "react";
- import clsx from "clsx";
- import axios from "axios";
- //Auth Kit
- import { useAuthUser, useSignOut } from "react-auth-kit";
- //Core MaterialUi
- import {
- makeStyles,
- CssBaseline,
- Switch,
- Drawer,
- Box,
- AppBar,
- Toolbar,
- List,
- Typography,
- Divider,
- IconButton,
- Container,
- Grid,
- Paper,
- Link,
- Button,
- } from "@material-ui/core";
- //Icons
- import MenuIcon from "@material-ui/icons/Menu";
- import ChevronLeftIcon from "@material-ui/icons/ChevronLeft";
- import ExitToAppIcon from "@material-ui/icons/ExitToApp";
- import PersonIcon from "@material-ui/icons/Person";
- import NoteIcon from "@material-ui/icons/Note";
- //Colors
- import {
- orange,
- lightBlue,
- deepPurple,
- deepOrange,
- } from "@material-ui/core/colors";
- //Components
- import { mainListItems } from "../interface/NavList";
- // For Switch Theming
- import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
- import Chart from "./ChartHealth";
- import BarHealth from "./BarHealth";
- import TableHealth from "./TableHealth";
- import { Link as RouteLink } from "react-router-dom";
- function Copyright() {
- return (
- <Typography variant="body2" color="textSecondary" align="center">
- {"Copyright © "}
- <Link color="inherit" href="https://github.com/falcon-group">
- falcon-group
- </Link>{" "}
- {new Date().getFullYear()}
- {"."}
- </Typography>
- );
- }
- const drawerWidth = 240;
- const useStyles = makeStyles(theme => ({
- root: {
- display: "flex",
- },
- toolbar: {
- paddingRight: 24, // keep right padding when drawer closed
- },
- toolbarIcon: {
- display: "flex",
- alignItems: "center",
- justifyContent: "flex-end",
- padding: "0 8px",
- ...theme.mixins.toolbar,
- },
- appBar: {
- zIndex: theme.zIndex.drawer + 1,
- transition: theme.transitions.create(["width", "margin"], {
- easing: theme.transitions.easing.sharp,
- duration: theme.transitions.duration.leavingScreen,
- }),
- },
- appBarShift: {
- marginLeft: drawerWidth,
- width: `calc(100% - ${drawerWidth}px)`,
- transition: theme.transitions.create(["width", "margin"], {
- easing: theme.transitions.easing.sharp,
- duration: theme.transitions.duration.enteringScreen,
- }),
- },
- menuButton: {
- marginRight: 36,
- },
- menuButtonHidden: {
- display: "none",
- },
- title: {
- flexGrow: 1,
- },
- drawerPaper: {
- position: "relative",
- whiteSpace: "nowrap",
- width: drawerWidth,
- transition: theme.transitions.create("width", {
- easing: theme.transitions.easing.sharp,
- duration: theme.transitions.duration.enteringScreen,
- }),
- },
- drawerPaperClose: {
- overflowX: "hidden",
- transition: theme.transitions.create("width", {
- easing: theme.transitions.easing.sharp,
- duration: theme.transitions.duration.leavingScreen,
- }),
- width: theme.spacing(7),
- [theme.breakpoints.up("sm")]: {
- width: theme.spacing(9),
- },
- },
- appBarSpacer: theme.mixins.toolbar,
- content: {
- flexGrow: 1,
- height: "100vh",
- overflow: "auto",
- },
- container: {
- paddingTop: theme.spacing(4),
- paddingBottom: theme.spacing(4),
- },
- paper: {
- padding: theme.spacing(2),
- display: "flex",
- overflow: "auto",
- flexDirection: "column",
- },
- fixedHeight: {
- height: 240,
- },
- }));
- const UserHealthDashboard = props => {
- const [open, setOpen] = useState(true);
- const [darkState, setDarkState] = useState(false);
- const palletType = darkState ? "dark" : "light";
- const signOut = useSignOut();
- const authUser = useAuthUser();
- const mainPrimaryColor = darkState ? orange[500] : lightBlue[800];
- const mainSecondaryColor = darkState ? deepOrange[900] : deepPurple[500];
- const darkTheme = createMuiTheme({
- palette: {
- type: palletType,
- primary: {
- main: mainPrimaryColor,
- },
- secondary: {
- main: mainSecondaryColor,
- },
- },
- });
- const classes = useStyles();
- const id = props.match.params.id;
- let notesLinkId = `/notes-user/${id}`;
- const handleThemeChange = () => {
- setDarkState(!darkState);
- };
- const handleDrawerOpen = () => {
- setOpen(true);
- };
- const handleDrawerClose = () => {
- setOpen(false);
- };
- const fixedHeightPaper = clsx(classes.paper, classes.fixedHeight);
- return (
- <ThemeProvider theme={darkTheme}>
- <div className={classes.root}>
- <CssBaseline />
- <AppBar
- position="absolute"
- className={clsx(classes.appBar, open && classes.appBarShift)}
- >
- <Toolbar className={classes.toolbar}>
- <IconButton
- edge="start"
- color="inherit"
- aria-label="open drawer"
- onClick={handleDrawerOpen}
- className={clsx(
- classes.menuButton,
- open && classes.menuButtonHidden
- )}
- >
- <MenuIcon />
- </IconButton>
- <Typography
- component="h1"
- variant="h6"
- color="inherit"
- noWrap
- className={classes.title}
- >
- Состояние пациента
- </Typography>
- <Switch checked={darkState} onChange={handleThemeChange} />
- <IconButton color="inherit">
- <PersonIcon />
- </IconButton>
- <Typography component="h" variant="subtitle2">
- {`${authUser().name}`}
- </Typography>
- <IconButton color="inherit" onClick={() => signOut()}>
- <ExitToAppIcon />
- </IconButton>
- </Toolbar>
- </AppBar>
- <Drawer
- variant="permanent"
- classes={{
- paper: clsx(classes.drawerPaper, !open && classes.drawerPaperClose),
- }}
- open={open}
- >
- <div className={classes.toolbarIcon}>
- <IconButton onClick={handleDrawerClose}>
- <ChevronLeftIcon />
- </IconButton>
- </div>
- <Divider />
- <List>{mainListItems}</List>
- <Divider />
- </Drawer>
- <main className={classes.content}>
- <div className={classes.appBarSpacer} />
- <Container maxWidth="lg" className={classes.container}>
- <RouteLink
- to={notesLinkId}
- style={{
- textDecoration: "none",
- color: "inherit",
- }}
- >
- <Button
- size="medium"
- variant="contained"
- color="primary"
- startIcon={<NoteIcon />}
- style={{ marginBottom: "20px" }}
- >
- Заметки
- </Button>
- </RouteLink>
- <Grid container spacing={3}>
- <Grid item xs={12} md={8} lg={9}>
- <Paper className={fixedHeightPaper}>
- <Chart />
- </Paper>
- </Grid>
- <Grid item xs={3} md={4} lg={3}>
- <Paper className={fixedHeightPaper}>
- <BarHealth />
- </Paper>
- </Grid>
- <Grid item xs={12}>
- <Paper className={classes.paper}>
- <TableHealth />
- </Paper>
- </Grid>
- </Grid>
- <Box pt={4}>
- <Copyright />
- </Box>
- </Container>
- </main>
- </div>
- </ThemeProvider>
- );
- };
- export default UserHealthDashboard;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement