Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1202 | Rev 1562 | 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'
1202 stevensc 3
import { Container } from '@mui/material'
4
 
1197 stevensc 5
import { addNotification } from '../../redux/notification/notification.actions'
6
import { ButtonPrimary } from '@buttons'
7
 
8
class ErrorBoundary extends React.Component {
9
  constructor(props) {
10
    super(props)
11
    this.state = { hasError: false }
12
  }
13
 
1200 stevensc 14
  static getDerivedStateFromError() {
15
    return { hasError: true }
16
  }
17
 
1197 stevensc 18
  componentDidCatch(error, errorInfo) {
19
    console.error('ErrorBoundary caught an error: ', error, errorInfo)
20
    this.props.addNotification({ style: 'danger', msg: error.message })
21
  }
22
 
23
  render() {
24
    if (this.state.hasError) {
25
      return (
26
        <Container>
1202 stevensc 27
          <h1>Something went wrong, please reload the page</h1>
1197 stevensc 28
 
29
          <ButtonPrimary
30
            className='mt-3'
1219 stevensc 31
            onClick={() => window.location.reload(true)}
1198 stevensc 32
            label='Reload'
1197 stevensc 33
          />
34
        </Container>
35
      )
36
    }
37
 
38
    return this.props.children
39
  }
40
}
41
 
42
const mapDispatchToProps = {
43
  addNotification: (notification) => addNotification(notification)
44
}
45
 
46
export default connect(null, mapDispatchToProps)(ErrorBoundary)