Home.js 11 KB
Newer Older
d.arizona's avatar
d.arizona committed
1
import React from 'react';
d.arizona's avatar
d.arizona committed
2 3 4 5 6 7 8 9 10 11 12
import clsx from 'clsx';
import { makeStyles, useTheme } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import List from '@material-ui/core/List';
import CssBaseline from '@material-ui/core/CssBaseline';
import Typography from '@material-ui/core/Typography';
import Divider from '@material-ui/core/Divider';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
d.arizona's avatar
d.arizona committed
13 14
import ExpandMore from '@material-ui/icons/ExpandMore'
import ExpandLess from '@material-ui/icons/ExpandLess'
d.arizona's avatar
d.arizona committed
15 16 17 18 19 20 21
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import InboxIcon from '@material-ui/icons/MoveToInbox';
import MailIcon from '@material-ui/icons/Mail';
d.arizona's avatar
d.arizona committed
22
import Collapse from '@material-ui/core/Collapse';
d.arizona's avatar
d.arizona committed
23

d.arizona's avatar
d.arizona committed
24
import {
Deni Rinaldi's avatar
Deni Rinaldi committed
25 26 27 28 29
  BrowserRouter as Router,
  Switch,
  Route,
  Link,
  useParams,
d.arizona's avatar
d.arizona committed
30
  useRouteMatch
Deni Rinaldi's avatar
Deni Rinaldi committed
31 32
} from "react-router-dom";
import Images from '../assets/Images';
Deni Rinaldi's avatar
Deni Rinaldi committed
33
import { FadeMenu, Footer, UseWindowDimensions } from '../Utils/Index';
Deni Rinaldi's avatar
Deni Rinaldi committed
34
import Beranda from './Beranda';
d.arizona's avatar
d.arizona committed
35 36
import { Avatar } from '@material-ui/core';
import HomeRoutes from '../router/homeRoutes'
d.arizona's avatar
d.arizona committed
37
import ArraySide from '../library/Array'
d.arizona's avatar
d.arizona committed
38

Deni Rinaldi's avatar
Deni Rinaldi committed
39
const drawerWidth = 307;
d.arizona's avatar
d.arizona committed
40

Deni Rinaldi's avatar
Deni Rinaldi committed
41

d.arizona's avatar
d.arizona committed
42
const useStyles = makeStyles((theme) => ({
d.arizona's avatar
d.arizona committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  root: {
    display: 'flex',
  },
  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,
  },
  hide: {
    display: 'none',
  },
  drawer: {
    width: drawerWidth,
    flexShrink: 0,
    whiteSpace: 'nowrap',
  },
  drawerOpen: {
    width: drawerWidth,
    transition: theme.transitions.create('width', {
      easing: theme.transitions.easing.sharp,
      duration: theme.transitions.duration.enteringScreen,
    }),
Deni Rinaldi's avatar
Deni Rinaldi committed
78
    backgroundColor: '#0d2846'
d.arizona's avatar
d.arizona committed
79 80 81 82 83 84 85 86 87 88 89
  },
  drawerClose: {
    transition: theme.transitions.create('width', {
      easing: theme.transitions.easing.sharp,
      duration: theme.transitions.duration.leavingScreen,
    }),
    overflowX: 'hidden',
    width: theme.spacing(7) + 1,
    [theme.breakpoints.up('sm')]: {
      width: theme.spacing(9) + 1,
    },
Deni Rinaldi's avatar
Deni Rinaldi committed
90
    backgroundColor: '#0d2846'
d.arizona's avatar
d.arizona committed
91 92 93 94 95 96 97 98 99
  },
  toolbar: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'flex-end',
    padding: theme.spacing(0, 1),
    // necessary for content to be below app bar
    ...theme.mixins.toolbar,
  },
Deni Rinaldi's avatar
Deni Rinaldi committed
100 101 102 103 104 105 106
  toolbarDrawer: {
    alignItems: 'center',
    justifyContent: 'flex-end',
    padding: theme.spacing(0, 1),
    // necessary for content to be below app bar
    // ...theme.mixins.toolbar
  },
d.arizona's avatar
d.arizona committed
107 108 109 110
  content: {
    flexGrow: 1,
    padding: theme.spacing(3),
  },
Deni Rinaldi's avatar
Deni Rinaldi committed
111 112 113 114 115
  orangeAvatar: {
    margin: 10,
    color: '#fff',
    backgroundColor: 'black',
  },
d.arizona's avatar
d.arizona committed
116 117
}));

d.arizona's avatar
d.arizona committed
118 119 120 121
export default function MiniDrawer() {
  const classes = useStyles();
  const theme = useTheme();
  const [open, setOpen] = React.useState(false);
d.arizona's avatar
d.arizona committed
122
  const [selectedIndex, setSelectedIndex] = React.useState([]);
d.arizona's avatar
d.arizona committed
123

d.arizona's avatar
d.arizona committed
124 125 126
  React.useEffect(() => {
    // alert(ArraySide)
  })
d.arizona's avatar
d.arizona committed
127 128
  const handleDrawerOpen = () => {
    setOpen(true);
d.arizona's avatar
d.arizona committed
129 130
  };

d.arizona's avatar
d.arizona committed
131 132
  const handleDrawerClose = () => {
    setOpen(false);
d.arizona's avatar
d.arizona committed
133 134
  };

d.arizona's avatar
d.arizona committed
135
  let { path, url } = useRouteMatch();
d.arizona's avatar
d.arizona committed
136

Deni Rinaldi's avatar
Deni Rinaldi committed
137 138
  const { height, width } = UseWindowDimensions();

d.arizona's avatar
d.arizona committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
  return (
    <div className={classes.root}>
      <CssBaseline />
      <AppBar
        position="fixed"
        className={clsx(classes.appBar, {
          [classes.appBarShift]: open,
        })}
      >
        <Toolbar style={{ flex: 1, backgroundColor: '#51c6ea' }}>
          <IconButton
            color="inherit"
            aria-label="open drawer"
            onClick={handleDrawerOpen}
            edge="start"
            className={clsx(classes.menuButton, {
              [classes.hide]: open,
            })}
          >
            <MenuIcon />
          </IconButton>
          <div style={{ backgroundColor: '#51c6ea', height: '70px', display: 'flex', flex: 1, placeContent: 'flex-end' }}>
            <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', paddingRight: 20, paddingLeft: 20 }}>
              <div style={{ width: 44, height: 44, backgroundColor: '#354960', borderRadius: 30, marginRight: 10 }} />
              <Typography style={{ color: 'white' }}>Tommy</Typography>
              {/* <img src={require('./assets/dropdown-white.svg')} alt="React Logo" style={{ marginLeft: 15 }} /> */}
              <FadeMenu />
Deni Rinaldi's avatar
Deni Rinaldi committed
166
            </div>
d.arizona's avatar
d.arizona committed
167 168 169 170 171 172
            <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', paddingRight: 20, paddingLeft: 20, borderLeftColor: '#c2c2c2', borderLeftWidth: .2, borderLeftStyle: 'solid' }}>
              <img src={Images.search} alt="React Logo" style={{ height: 18, width: 18 }} />
            </div>
            <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', paddingRight: 20, paddingLeft: 20, borderLeftColor: '#c2c2c2', borderLeftWidth: .2, borderLeftStyle: 'solid' }}>
              <img src={Images.flagEnglish} alt="React Logo" style={{ height: 32, width: 32 }} />
              <Typography style={{ color: 'white' }}>EN</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
173 174
            </div>
          </div>
d.arizona's avatar
d.arizona committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
        </Toolbar>
      </AppBar>
      <Drawer
        variant="permanent"
        className={clsx(classes.drawer, {
          [classes.drawerOpen]: open,
          [classes.drawerClose]: !open,
        })}
        classes={{
          paper: clsx({
            [classes.drawerOpen]: open,
            [classes.drawerClose]: !open,
          }),
        }}
      >
        <div className={classes.toolbarDrawer} style={{
          backgroundColor: '#51c6ea',
          height: open ? 152 : 68
        }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', flex: 1, padding: 10 }}>
            <img src={Images.triputra} alt="React Logo" style={{ height: 31, width: 151, alignSelf: 'center' }} />
            <IconButton onClick={handleDrawerClose}>
197
              <ChevronLeftIcon style={{ fill: 'white' }} />
d.arizona's avatar
d.arizona committed
198 199 200 201
            </IconButton>
          </div>
          {open &&
            <div style={{ width: '100%' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
202 203
              <Typography style={{ fontSize: 12, color: '#fff', textAlign: 'center', fontWeight: 'bold' }}>John Doe</Typography>
              <Typography style={{ fontSize: 12, color: '#fff', textAlign: 'center', marginTop: 10 }}>john@tia.com</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
204
            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
205
          }
d.arizona's avatar
d.arizona committed
206 207 208 209 210 211 212 213 214 215 216
        </div>
        <Divider />
        {open &&
          <div style={{ width: '100%', textAlign: '-webkit-center', marginTop: -15 }}>
            <div style={{ width: 86, height: 86, backgroundColor: '#0d2846', borderRadius: 50, display: 'flex', justifyContent: 'center' }}>
              <div style={{ width: 72, height: 72, backgroundColor: 'white', borderRadius: 50, alignSelf: 'center' }}>
              </div>

            </div>
          </div>
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
217 218 219
        {open &&
          <div style={{ marginLeft: 25, marginTop: 20, marginBottom: 20 }}>
            <Typography style={{ color: 'white', fontSize: 12 }}>APLIKASI</Typography>
d.arizona's avatar
d.arizona committed
220 221
          </div>
        }
d.arizona's avatar
d.arizona committed
222
        <List>
d.arizona's avatar
d.arizona committed
223
          {ArraySide.map((item, index) => (
Deni Rinaldi's avatar
Deni Rinaldi committed
224 225 226 227
            <div>
              {item.subItem != null ?
                <div style={{ justifyContent: 'space-between', flexDirection: 'row', display: 'flex', paddingRight: 10 }} onClick={() => selectedIndex == 0 ? setSelectedIndex(index) : setSelectedIndex(0)}>
                  <ListItem button key={item.label}>
228
                    <ListItemIcon><img src={item.img} /></ListItemIcon>
Deni Rinaldi's avatar
Deni Rinaldi committed
229 230 231 232
                    <Typography style={{ color: 'white', fontSize: 12 }}>{item.label}</Typography>
                  </ListItem>
                  {item.subItem != null ? (index === selectedIndex ? <ExpandLess style={{ color: "white", marginLeft: 50, alignSelf: 'center' }} /> : <ExpandMore style={{ color: "white", marginLeft: 50, alignSelf: 'center' }} />) : null}
                </div>
d.arizona's avatar
d.arizona committed
233
                :
234 235 236 237 238 239 240 241 242 243 244 245 246 247

                item.label === 'PENGATURAN' ?
                  open ?
                    <Link to={`${url}/${item.path}`}>
                      <ListItem button key={item.label} onClick={() => null}>
                        <Typography style={{ color: 'white', fontSize: 12 }}>{item.label}</Typography>
                      </ListItem>
                    </Link> : null :
                  <Link to={`${url}/${item.path}`}>
                    <ListItem button key={item.label} onClick={() => setSelectedIndex(index)}>
                      <ListItemIcon><img src={item.img} /></ListItemIcon>
                      <Typography style={{ color: 'white', fontSize: 12 }}>{item.label}</Typography>
                    </ListItem>
                  </Link>
Deni Rinaldi's avatar
Deni Rinaldi committed
248 249
              }
              {item.subItem != null &&
d.arizona's avatar
d.arizona committed
250 251 252 253 254 255
                <div>
                  <Collapse in={index === selectedIndex} timeout="auto" unmountOnExit>
                    <List component="div" disablePadding>
                      {item.subItem.map((sub, index) => {
                        return (
                          <Link to={`${url}/${sub.path}`}>
Deni Rinaldi's avatar
Deni Rinaldi committed
256 257
                            <ListItem style={{ paddingLeft: 72 }}>
                              <Typography style={{ color: 'white', fontSize: 12 }}>{sub.label}</Typography>
d.arizona's avatar
d.arizona committed
258 259 260 261 262 263 264
                            </ListItem>
                          </Link>
                        )
                      })}
                    </List>
                  </Collapse>
                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
265 266
              }
            </div>
d.arizona's avatar
d.arizona committed
267 268 269
          ))}
        </List>
      </Drawer>
d.arizona's avatar
d.arizona committed
270
      <div className={classes.content} style={{ justifyContent: 'space-between', padding: 0, backgroundColor: '#f8f8f8' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
271 272
        <div>
          <div className={classes.toolbar} />
d.arizona's avatar
d.arizona committed
273 274 275 276 277 278 279 280 281 282 283 284 285
          <Switch>
            {HomeRoutes.map((route, index) => (
              // You can render a <Route> in as many places
              // as you want in your app. It will render along
              // with any other <Route>s that also match the URL.
              // So, a sidebar or breadcrumbs or anything else
              // that requires you to render multiple things
              // in multiple places at the same URL is nothing
              // more than multiple <Route>s.
              <Route
                key={index}
                path={route.path}
                // exact={route.exact}
Deni Rinaldi's avatar
Deni Rinaldi committed
286
                children={<route.main height={height} />}
d.arizona's avatar
d.arizona committed
287 288 289
              />
            ))}
          </Switch>
Deni Rinaldi's avatar
Deni Rinaldi committed
290 291 292
          <Footer>
            <Typography style={{ fontSize: '12px' }}>© EKSAD Technology. All rights reserved.</Typography>
          </Footer>
d.arizona's avatar
d.arizona committed
293
        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
294

Deni Rinaldi's avatar
Deni Rinaldi committed
295
      </div>
d.arizona's avatar
d.arizona committed
296 297 298
    </div>
  );
}