Base.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, { Component } from 'react'
  2. import { connect } from 'react-redux'
  3. import { Helmet } from 'react-helmet'
  4. import Topbar from './Topbar'
  5. import Sidebar from './Sidebar'
  6. import Typography from 'material-ui/Typography'
  7. import Snackbar from 'material-ui/Snackbar'
  8. import Spinner from './Spinner'
  9. import { withStyles } from 'material-ui/styles'
  10. import { notify } from '../../actions'
  11. const styles = theme => ({
  12. root: {
  13. flexGrow: 1,
  14. zIndex: 1,
  15. overflow: 'hidden',
  16. position: 'relative',
  17. display: 'flex'
  18. },
  19. content: {
  20. flexGrow: 1,
  21. backgroundColor: theme.palette.background.default,
  22. padding: theme.spacing.unit * 3,
  23. minWidth: 0
  24. },
  25. toolbar: theme.mixins.toolbar,
  26. header: {
  27. marginBottom: 25
  28. }
  29. })
  30. class Base extends Component {
  31. render() {
  32. const { classes, app, onHideNotification } = this.props
  33. return (
  34. <div className={classes.root}>
  35. <Helmet>
  36. <title>{this.props.title}</title>
  37. </Helmet>
  38. <Topbar />
  39. <Sidebar />
  40. <main className={classes.content}>
  41. <div className={classes.toolbar}></div>
  42. <Typography
  43. variant='headline'
  44. color='primary'
  45. className={classes.header}
  46. children={this.props.title}
  47. />
  48. {this.props.children}
  49. </main>
  50. <Snackbar
  51. open={app.notification.isOpen}
  52. autoHideDuration={2000}
  53. onClose={onHideNotification}
  54. message={app.notification.message}
  55. />
  56. <Spinner
  57. open={app.spinner.isOpen}
  58. message={app.spinner.message || 'Cargando, espere...'}
  59. />
  60. </div>
  61. )
  62. }
  63. }
  64. /**
  65. *
  66. * @param {*} state
  67. * @param {*} props
  68. */
  69. const mapStateToProps = (state, props) => {
  70. return {
  71. app: state.app
  72. }
  73. }
  74. /**
  75. *
  76. * @param {*} state
  77. * @param {*} props
  78. */
  79. const mapDispatchToProps = (dispatch, props) => ({
  80. /**
  81. *
  82. */
  83. onHideNotification() {
  84. dispatch(notify(null))
  85. },
  86. /**
  87. *
  88. */
  89. onHideDialog() {
  90. console.log('hide dialog')
  91. }
  92. })
  93. export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(Base))