Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1197 | Rev 1199 | 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
      // You can render any custom fallback UI
23
      return (
24
        <Container>
1198 stevensc 25
          <Title>Something went wrong, please reload the page</Title>
1197 stevensc 26
 
27
          <ButtonPrimary
28
            className='mt-3'
29
            onClick={() => window.location.reload()}
1198 stevensc 30
            label='Reload'
1197 stevensc 31
          />
32
        </Container>
33
      )
34
    }
35
 
36
    return this.props.children
37
  }
38
}
39
 
40
const mapDispatchToProps = {
41
  addNotification: (notification) => addNotification(notification)
42
}
43
 
44
export default connect(null, mapDispatchToProps)(ErrorBoundary)