|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import classNames from 'classnames'; |
| 3 | +import { withStyles } from '@material-ui/core'; |
| 4 | +import { withTranslation } from 'react-i18next'; |
| 5 | +import { withRouter } from 'react-router'; |
| 6 | +import Typography from '@material-ui/core/Typography'; |
| 7 | +import CssBaseline from '@material-ui/core/CssBaseline'; |
| 8 | +import AppBar from '@material-ui/core/AppBar'; |
| 9 | +import Toolbar from '@material-ui/core/Toolbar'; |
| 10 | +import IconButton from '@material-ui/core/IconButton'; |
| 11 | +import MenuIcon from '@material-ui/icons/Menu'; |
| 12 | +import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'; |
| 13 | +import ChevronRightIcon from '@material-ui/icons/ChevronRight'; |
| 14 | +import Drawer from '@material-ui/core/Drawer'; |
| 15 | +import Divider from '@material-ui/core/Divider'; |
| 16 | +import PropTypes from 'prop-types'; |
| 17 | +import MainMenu from '../common/MainMenu'; |
| 18 | +import ActionEditor from './ActionEditor'; |
| 19 | +import Styles from '../../Styles'; |
| 20 | +import Banner from '../common/Banner'; |
| 21 | + |
| 22 | +export class ActionDashboard extends Component { |
| 23 | + state = { |
| 24 | + open: false, |
| 25 | + }; |
| 26 | + |
| 27 | + static propTypes = { |
| 28 | + t: PropTypes.func.isRequired, |
| 29 | + classes: PropTypes.shape({ |
| 30 | + root: PropTypes.string.isRequired, |
| 31 | + appBar: PropTypes.string.isRequired, |
| 32 | + appBarShift: PropTypes.string.isRequired, |
| 33 | + menuButton: PropTypes.string.isRequired, |
| 34 | + hide: PropTypes.string.isRequired, |
| 35 | + drawer: PropTypes.string.isRequired, |
| 36 | + drawerPaper: PropTypes.string.isRequired, |
| 37 | + drawerHeader: PropTypes.string.isRequired, |
| 38 | + content: PropTypes.string.isRequired, |
| 39 | + contentShift: PropTypes.string.isRequired, |
| 40 | + developer: PropTypes.string.isRequired, |
| 41 | + screenTitle: PropTypes.string.isRequired, |
| 42 | + }).isRequired, |
| 43 | + theme: PropTypes.shape({ |
| 44 | + direction: PropTypes.string.isRequired, |
| 45 | + }).isRequired, |
| 46 | + history: PropTypes.shape({ |
| 47 | + replace: PropTypes.func.isRequired, |
| 48 | + }).isRequired, |
| 49 | + i18n: PropTypes.shape({ |
| 50 | + changeLanguage: PropTypes.func.isRequired, |
| 51 | + }).isRequired, |
| 52 | + }; |
| 53 | + |
| 54 | + handleDrawerOpen = () => { |
| 55 | + this.setState({ open: true }); |
| 56 | + }; |
| 57 | + |
| 58 | + handleDrawerClose = () => { |
| 59 | + this.setState({ open: false }); |
| 60 | + }; |
| 61 | + |
| 62 | + render() { |
| 63 | + const { classes, theme, t } = this.props; |
| 64 | + const { open } = this.state; |
| 65 | + |
| 66 | + return ( |
| 67 | + <div className={classes.root}> |
| 68 | + <CssBaseline /> |
| 69 | + <AppBar |
| 70 | + position="fixed" |
| 71 | + className={classNames(classes.appBar, { |
| 72 | + [classes.appBarShift]: open, |
| 73 | + })} |
| 74 | + > |
| 75 | + <Toolbar disableGutters={!open}> |
| 76 | + <IconButton |
| 77 | + color="inherit" |
| 78 | + aria-label="Open drawer" |
| 79 | + onClick={this.handleDrawerOpen} |
| 80 | + className={classNames(classes.menuButton, open && classes.hide)} |
| 81 | + > |
| 82 | + <MenuIcon /> |
| 83 | + </IconButton> |
| 84 | + </Toolbar> |
| 85 | + </AppBar> |
| 86 | + <Drawer |
| 87 | + className={classes.drawer} |
| 88 | + variant="persistent" |
| 89 | + anchor="left" |
| 90 | + open={open} |
| 91 | + classes={{ |
| 92 | + paper: classes.drawerPaper, |
| 93 | + }} |
| 94 | + > |
| 95 | + <div className={classes.drawerHeader}> |
| 96 | + <IconButton onClick={this.handleDrawerClose}> |
| 97 | + {theme.direction === 'ltr' ? ( |
| 98 | + <ChevronLeftIcon /> |
| 99 | + ) : ( |
| 100 | + <ChevronRightIcon /> |
| 101 | + )} |
| 102 | + </IconButton> |
| 103 | + </div> |
| 104 | + <Divider /> |
| 105 | + <MainMenu /> |
| 106 | + </Drawer> |
| 107 | + <main |
| 108 | + className={classNames(classes.content, { |
| 109 | + [classes.contentShift]: open, |
| 110 | + })} |
| 111 | + > |
| 112 | + <div className={classes.drawerHeader} /> |
| 113 | + <div className={classes.developer}> |
| 114 | + <Typography variant="h4" className={classes.screenTitle}> |
| 115 | + {t('Action Dashboard')} |
| 116 | + </Typography> |
| 117 | + <br /> |
| 118 | + <Banner |
| 119 | + text={t( |
| 120 | + 'Danger Zone! Proceed with caution as changes to this section might lead to data loss.' |
| 121 | + )} |
| 122 | + type="error" |
| 123 | + /> |
| 124 | + <ActionEditor /> |
| 125 | + </div> |
| 126 | + </main> |
| 127 | + </div> |
| 128 | + ); |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +const StyledComponent = withStyles(Styles, { withTheme: true })( |
| 133 | + ActionDashboard |
| 134 | +); |
| 135 | + |
| 136 | +const TranslatedComponent = withTranslation()(StyledComponent); |
| 137 | + |
| 138 | +export default withRouter(TranslatedComponent); |
0 commit comments