Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1565 | Rev 2195 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1197 stevensc 1
import React from 'react'
2
import { connect } from 'react-redux'
1606 stevensc 3
import { Container, Typography } from '@mui/material'
1202 stevensc 4
 
1565 stevensc 5
import { addNotification } from '@app/redux/notification/notification.actions'
1197 stevensc 6
 
1606 stevensc 7
import Button from '@app/components/UI/buttons/Buttons'
8
 
1197 stevensc 9
class ErrorBoundary extends React.Component {
1606 stevensc 10
  constructor(props) {
11
    super(props)
12
    this.state = { hasError: false }
13
  }
14
 
15
  static getDerivedStateFromError() {
16
    return { hasError: true }
17
  }
18
 
1197 stevensc 19
  componentDidCatch(error, errorInfo) {
20
    console.error('ErrorBoundary caught an error: ', error, errorInfo)
21
    this.props.addNotification({ style: 'danger', msg: error.message })
22
  }
23
 
24
  render() {
1606 stevensc 25
    if (this.state.hasError) {
26
      return (
27
        <Container>
28
          <Typography variant='h1'>
29
            Something went wrong, please reload the page
30
          </Typography>
31
 
32
          <Button
33
            variant='primary'
34
            onClick={() => window.location.reload(true)}
35
          >
36
            Reload
37
          </Button>
38
        </Container>
39
      )
40
    }
41
 
1197 stevensc 42
    return this.props.children
43
  }
44
}
45
 
46
const mapDispatchToProps = {
47
  addNotification: (notification) => addNotification(notification)
48
}
49
 
50
export default connect(null, mapDispatchToProps)(ErrorBoundary)