Snippets
Created by
David Macias
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | import React, { Component } from 'react';
import axios from 'axios';
import Account from './components/account';
import Menu from './components/menu';
import Trigger from './components/trigger';
import Drawer from '@material-ui/core/Drawer';
import AppBar from '@material-ui/core/AppBar';
import CssBaseline from '@material-ui/core/CssBaseline';
import Toolbar from '@material-ui/core/Toolbar';
import List from '@material-ui/core/List';
import Typography from '@material-ui/core/Typography';
import Divider from '@material-ui/core/Divider';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import withStyles from '@material-ui/core/styles/withStyles';
import AccountBoxIcon from '@material-ui/icons/AccountBox';
import NotesIcon from '@material-ui/icons/Notes';
import CalendarIcon from '@material-ui/icons/CalendarToday';
import TriggerIcon from '@material-ui/icons/TrackChanges';
import ExitToAppIcon from '@material-ui/icons/ExitToApp';
import CircularProgress from '@material-ui/core/CircularProgress';
import { authMiddleWare } from './utils/auth'
const drawerWidth = 240;
const styles = (theme) => ({
root: {
display: 'flex'
},
appBar: {
zIndex: theme.zIndex.drawer + 1
},
drawer: {
width: drawerWidth,
flexShrink: 0
},
drawerPaper: {
width: drawerWidth
},
content: {
flexGrow: 1,
padding: theme.spacing(3)
},
avatar: {
height: 110,
width: 100,
flexShrink: 0,
flexGrow: 0,
marginTop: 20
},
uiProgess: {
position: 'fixed',
zIndex: '1000',
height: '31px',
width: '31px',
left: '50%',
top: '35%'
},
toolbar: theme.mixins.toolbar
});
class home extends Component {
state = {
render: false
};
loadAccountPage = (event) => {
this.setState({ render: true });
};
loadMenuPage = (event) => {
this.setState({ render: false });
};
loadTriggerPage = (event) => {
this.setState({ render: false });
};
logoutHandler = (event) => {
localStorage.removeItem('AuthToken');
this.props.history.push('/login');
};
constructor(props) {
super(props);
this.state = {
firstName: '',
lastName: '',
uiLoading: true
};
}
componentWillMount = () => {
authMiddleWare(this.props.history);
const authToken = localStorage.getItem('AuthToken');
axios.defaults.headers.common = { Authorization: `${authToken}` };
axios
.get('/user')
.then((response) => {
console.log(response.data);
this.setState({
firstName: response.data.userCredentials.firstName,
lastName: response.data.userCredentials.lastName,
email: response.data.userCredentials.email,
organization: response.data.userCredentials.organization,
username: response.data.userCredentials.username,
uiLoading: false
});
})
.catch((error) => {
if (error.response.status === 403) {
this.props.history.push('/login')
}
console.log(error);
this.setState({ errorMsg: 'Error in retrieving the data' });
});
};
render() {
const { classes } = this.props;
if (this.state.uiLoading === true) {
return (
<div className={classes.root}>
{this.state.uiLoading && <CircularProgress size={150} className={classes.uiProgess} />}
</div>
);
} else {
return (
<div className={classes.root}>
<CssBaseline />
<AppBar position="fixed" className={classes.appBar}>
<Toolbar>
<Typography variant="h6" noWrap>
CC Shift: Management
</Typography>
</Toolbar>
</AppBar>
<Drawer
className={classes.drawer}
variant="permanent"
classes={{
paper: classes.drawerPaper
}}
>
<div className={classes.toolbar} />
<Divider />
<center>
<p>
{' '}
{this.state.firstName} {this.state.lastName}
</p>
</center>
<Divider />
<List>
<ListItem button key="Menu" onClick={this.loadMenuPage}>
<ListItemIcon>
{' '}
<NotesIcon />{' '}
</ListItemIcon>
<ListItemText primary="Menus" />
</ListItem>
<ListItem button key="Calendars" onClick={this.loadMenuPage}>
<ListItemIcon>
{' '}
<CalendarIcon />{' '}
</ListItemIcon>
<ListItemText primary="Calendars" />
</ListItem>
<ListItem button key="Trigger" onClick={this.loadTriggerPage}>
<ListItemIcon>
{' '}
<TriggerIcon />{' '}
</ListItemIcon>
<ListItemText primary="Triggers" />
</ListItem>
<ListItem button key="Account" onClick={this.loadAccountPage}>
<ListItemIcon>
{' '}
<AccountBoxIcon />{' '}
</ListItemIcon>
<ListItemText primary="Account" />
</ListItem>
<ListItem button key="Logout" onClick={this.logoutHandler}>
<ListItemIcon>
{' '}
<ExitToAppIcon />{' '}
</ListItemIcon>
<ListItemText primary="Logout" />
</ListItem>
</List>
</Drawer>
<div>{this.state.render ? <Account /> : <Menu />}</div>
</div>
);
}
}
}
export default withStyles(styles)(home);
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.