Advertisement
materialblock

UserHealthDashboard.js

Nov 17th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState } from "react";
  2. import clsx from "clsx";
  3. import axios from "axios";
  4. //Auth Kit
  5. import { useAuthUser, useSignOut } from "react-auth-kit";
  6.  
  7. //Core MaterialUi
  8. import {
  9.   makeStyles,
  10.   CssBaseline,
  11.   Switch,
  12.   Drawer,
  13.   Box,
  14.   AppBar,
  15.   Toolbar,
  16.   List,
  17.   Typography,
  18.   Divider,
  19.   IconButton,
  20.   Container,
  21.   Grid,
  22.   Paper,
  23.   Link,
  24.   Button,
  25. } from "@material-ui/core";
  26. //Icons
  27. import MenuIcon from "@material-ui/icons/Menu";
  28. import ChevronLeftIcon from "@material-ui/icons/ChevronLeft";
  29. import ExitToAppIcon from "@material-ui/icons/ExitToApp";
  30. import PersonIcon from "@material-ui/icons/Person";
  31. import NoteIcon from "@material-ui/icons/Note";
  32.  
  33. //Colors
  34. import {
  35.   orange,
  36.   lightBlue,
  37.   deepPurple,
  38.   deepOrange,
  39. } from "@material-ui/core/colors";
  40. //Components
  41. import { mainListItems } from "../interface/NavList";
  42. // For Switch Theming
  43. import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
  44. import Chart from "./ChartHealth";
  45. import BarHealth from "./BarHealth";
  46. import TableHealth from "./TableHealth";
  47. import { Link as RouteLink } from "react-router-dom";
  48. function Copyright() {
  49.   return (
  50.     <Typography variant="body2" color="textSecondary" align="center">
  51.       {"Copyright © "}
  52.       <Link color="inherit" href="https://github.com/falcon-group">
  53.         falcon-group
  54.       </Link>{" "}
  55.       {new Date().getFullYear()}
  56.       {"."}
  57.     </Typography>
  58.   );
  59. }
  60.  
  61. const drawerWidth = 240;
  62.  
  63. const useStyles = makeStyles(theme => ({
  64.   root: {
  65.     display: "flex",
  66.   },
  67.   toolbar: {
  68.     paddingRight: 24, // keep right padding when drawer closed
  69.   },
  70.   toolbarIcon: {
  71.     display: "flex",
  72.     alignItems: "center",
  73.     justifyContent: "flex-end",
  74.     padding: "0 8px",
  75.     ...theme.mixins.toolbar,
  76.   },
  77.   appBar: {
  78.     zIndex: theme.zIndex.drawer + 1,
  79.     transition: theme.transitions.create(["width", "margin"], {
  80.       easing: theme.transitions.easing.sharp,
  81.       duration: theme.transitions.duration.leavingScreen,
  82.     }),
  83.   },
  84.   appBarShift: {
  85.     marginLeft: drawerWidth,
  86.     width: `calc(100% - ${drawerWidth}px)`,
  87.     transition: theme.transitions.create(["width", "margin"], {
  88.       easing: theme.transitions.easing.sharp,
  89.       duration: theme.transitions.duration.enteringScreen,
  90.     }),
  91.   },
  92.   menuButton: {
  93.     marginRight: 36,
  94.   },
  95.   menuButtonHidden: {
  96.     display: "none",
  97.   },
  98.   title: {
  99.     flexGrow: 1,
  100.   },
  101.   drawerPaper: {
  102.     position: "relative",
  103.     whiteSpace: "nowrap",
  104.     width: drawerWidth,
  105.     transition: theme.transitions.create("width", {
  106.       easing: theme.transitions.easing.sharp,
  107.       duration: theme.transitions.duration.enteringScreen,
  108.     }),
  109.   },
  110.   drawerPaperClose: {
  111.     overflowX: "hidden",
  112.     transition: theme.transitions.create("width", {
  113.       easing: theme.transitions.easing.sharp,
  114.       duration: theme.transitions.duration.leavingScreen,
  115.     }),
  116.     width: theme.spacing(7),
  117.     [theme.breakpoints.up("sm")]: {
  118.       width: theme.spacing(9),
  119.     },
  120.   },
  121.   appBarSpacer: theme.mixins.toolbar,
  122.   content: {
  123.     flexGrow: 1,
  124.     height: "100vh",
  125.     overflow: "auto",
  126.   },
  127.   container: {
  128.     paddingTop: theme.spacing(4),
  129.     paddingBottom: theme.spacing(4),
  130.   },
  131.   paper: {
  132.     padding: theme.spacing(2),
  133.     display: "flex",
  134.     overflow: "auto",
  135.     flexDirection: "column",
  136.   },
  137.   fixedHeight: {
  138.     height: 240,
  139.   },
  140. }));
  141.  
  142. const UserHealthDashboard = props => {
  143.   const [open, setOpen] = useState(true);
  144.   const [darkState, setDarkState] = useState(false);
  145.   const palletType = darkState ? "dark" : "light";
  146.   const signOut = useSignOut();
  147.   const authUser = useAuthUser();
  148.   const mainPrimaryColor = darkState ? orange[500] : lightBlue[800];
  149.   const mainSecondaryColor = darkState ? deepOrange[900] : deepPurple[500];
  150.   const darkTheme = createMuiTheme({
  151.     palette: {
  152.       type: palletType,
  153.       primary: {
  154.         main: mainPrimaryColor,
  155.       },
  156.       secondary: {
  157.         main: mainSecondaryColor,
  158.       },
  159.     },
  160.   });
  161.   const classes = useStyles();
  162.  
  163.   const id = props.match.params.id;
  164.   let notesLinkId = `/notes-user/${id}`;
  165.  
  166.   const handleThemeChange = () => {
  167.     setDarkState(!darkState);
  168.   };
  169.   const handleDrawerOpen = () => {
  170.     setOpen(true);
  171.   };
  172.   const handleDrawerClose = () => {
  173.     setOpen(false);
  174.   };
  175.   const fixedHeightPaper = clsx(classes.paper, classes.fixedHeight);
  176.  
  177.   return (
  178.     <ThemeProvider theme={darkTheme}>
  179.       <div className={classes.root}>
  180.         <CssBaseline />
  181.         <AppBar
  182.           position="absolute"
  183.           className={clsx(classes.appBar, open && classes.appBarShift)}
  184.         >
  185.           <Toolbar className={classes.toolbar}>
  186.             <IconButton
  187.               edge="start"
  188.               color="inherit"
  189.               aria-label="open drawer"
  190.               onClick={handleDrawerOpen}
  191.               className={clsx(
  192.                 classes.menuButton,
  193.                 open && classes.menuButtonHidden
  194.               )}
  195.             >
  196.               <MenuIcon />
  197.             </IconButton>
  198.             <Typography
  199.               component="h1"
  200.               variant="h6"
  201.               color="inherit"
  202.               noWrap
  203.               className={classes.title}
  204.             >
  205.               Состояние пациента
  206.             </Typography>
  207.  
  208.             <Switch checked={darkState} onChange={handleThemeChange} />
  209.             <IconButton color="inherit">
  210.               <PersonIcon />
  211.             </IconButton>
  212.             <Typography component="h" variant="subtitle2">
  213.               {`${authUser().name}`}
  214.             </Typography>
  215.             <IconButton color="inherit" onClick={() => signOut()}>
  216.               <ExitToAppIcon />
  217.             </IconButton>
  218.           </Toolbar>
  219.         </AppBar>
  220.         <Drawer
  221.           variant="permanent"
  222.           classes={{
  223.             paper: clsx(classes.drawerPaper, !open && classes.drawerPaperClose),
  224.           }}
  225.           open={open}
  226.         >
  227.           <div className={classes.toolbarIcon}>
  228.             <IconButton onClick={handleDrawerClose}>
  229.               <ChevronLeftIcon />
  230.             </IconButton>
  231.           </div>
  232.           <Divider />
  233.           <List>{mainListItems}</List>
  234.           <Divider />
  235.         </Drawer>
  236.  
  237.         <main className={classes.content}>
  238.           <div className={classes.appBarSpacer} />
  239.           <Container maxWidth="lg" className={classes.container}>
  240.             <RouteLink
  241.               to={notesLinkId}
  242.               style={{
  243.                 textDecoration: "none",
  244.                 color: "inherit",
  245.               }}
  246.             >
  247.               <Button
  248.                 size="medium"
  249.                 variant="contained"
  250.                 color="primary"
  251.                 startIcon={<NoteIcon />}
  252.                 style={{ marginBottom: "20px" }}
  253.               >
  254.                 Заметки
  255.               </Button>
  256.             </RouteLink>
  257.  
  258.             <Grid container spacing={3}>
  259.               <Grid item xs={12} md={8} lg={9}>
  260.                 <Paper className={fixedHeightPaper}>
  261.                   <Chart />
  262.                 </Paper>
  263.               </Grid>
  264.               <Grid item xs={3} md={4} lg={3}>
  265.                 <Paper className={fixedHeightPaper}>
  266.                   <BarHealth />
  267.                 </Paper>
  268.               </Grid>
  269.               <Grid item xs={12}>
  270.                 <Paper className={classes.paper}>
  271.                   <TableHealth />
  272.                 </Paper>
  273.               </Grid>
  274.             </Grid>
  275.  
  276.             <Box pt={4}>
  277.               <Copyright />
  278.             </Box>
  279.           </Container>
  280.         </main>
  281.       </div>
  282.     </ThemeProvider>
  283.   );
  284. };
  285. export default UserHealthDashboard;
  286.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement