Proyectos de Subversion LeadersLinked - SPA

Rev

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