1
- import React from 'react' ;
1
+ import React , { useCallback } from 'react' ;
2
2
import errorImg from '@app/static/images/errorBoundary.png' ;
3
- import intl from 'react-intl-universal ' ;
3
+ import { I18nContext , useI18n } from '@vesoft-inc/i18n ' ;
4
4
import { CopyToClipboard } from 'react-copy-to-clipboard' ;
5
5
import { Button , message } from 'antd' ;
6
6
import { withRouter , RouteComponentProps } from 'react-router-dom' ;
@@ -10,13 +10,41 @@ interface IProps extends RouteComponentProps {}
10
10
interface IState {
11
11
errInfo : string ;
12
12
}
13
+
14
+ function ErrorPanel ( props : { errInfo : string } ) {
15
+ const { errInfo } = props ;
16
+ const { intl } = useI18n ( ) ;
17
+ const handleCopy = useCallback ( ( ) => {
18
+ message . success ( intl . get ( 'common.copySuccess' ) ) ;
19
+ } , [ ] ) ;
20
+ return < div className = { styles . errPage } >
21
+ < img src = { errorImg } className = { styles . errImg } />
22
+ < p className = { styles . errText } > { intl . get ( 'warning.crashPage' ) } </ p >
23
+ < p className = { styles . errTip } > { intl . get ( 'warning.crashPageTip' ) } </ p >
24
+ < div className = { styles . btns } >
25
+ < Button type = "primary" onClick = { ( ) => window . location . reload ( ) } > { intl . get ( 'warning.refreshPage' ) } </ Button >
26
+ < Button onClick = { ( ) => window . open ( intl . get ( 'link.forumHref' ) , '_blank' ) } > { intl . get ( 'warning.contactStaff' ) } </ Button >
27
+ </ div >
28
+ < div className = { styles . errContainer } >
29
+ < div className = { styles . header } >
30
+ < span > { intl . get ( 'warning.errorMessage' ) } </ span >
31
+ < CopyToClipboard key = { 1 } text = { errInfo } onCopy = { handleCopy } >
32
+ < Button > { intl . get ( 'common.copy' ) } </ Button >
33
+ </ CopyToClipboard >
34
+ </ div >
35
+ < p className = { styles . errMsg } > { errInfo . toString ( ) } </ p >
36
+ </ div >
37
+ </ div > ;
38
+ }
39
+
13
40
class ErrorBoundary extends React . PureComponent < IProps , IState > {
14
41
constructor ( props ) {
15
42
super ( props ) ;
16
43
this . state = {
17
44
errInfo : null ,
18
45
} ;
19
46
}
47
+ static contextType = I18nContext ;
20
48
componentDidCatch ( error ) {
21
49
this . setState ( {
22
50
errInfo : error ?. stack ?. toString ( ) ,
@@ -30,31 +58,10 @@ class ErrorBoundary extends React.PureComponent<IProps, IState> {
30
58
}
31
59
}
32
60
33
- handleCopy = ( ) => {
34
- message . success ( intl . get ( 'common.copySuccess' ) ) ;
35
- } ;
36
-
37
61
render ( ) {
38
62
const { errInfo } = this . state ;
39
63
if ( ! errInfo ) return this . props . children ;
40
- return < div className = { styles . errPage } >
41
- < img src = { errorImg } className = { styles . errImg } />
42
- < p className = { styles . errText } > { intl . get ( 'warning.crashPage' ) } </ p >
43
- < p className = { styles . errTip } > { intl . get ( 'warning.crashPageTip' ) } </ p >
44
- < div className = { styles . btns } >
45
- < Button type = "primary" onClick = { ( ) => window . location . reload ( ) } > { intl . get ( 'warning.refreshPage' ) } </ Button >
46
- < Button onClick = { ( ) => window . open ( intl . get ( 'link.forumHref' ) , '_blank' ) } > { intl . get ( 'warning.contactStaff' ) } </ Button >
47
- </ div >
48
- < div className = { styles . errContainer } >
49
- < div className = { styles . header } >
50
- < span > { intl . get ( 'warning.errorMessage' ) } </ span >
51
- < CopyToClipboard key = { 1 } text = { errInfo } onCopy = { this . handleCopy } >
52
- < Button > { intl . get ( 'common.copy' ) } </ Button >
53
- </ CopyToClipboard >
54
- </ div >
55
- < p className = { styles . errMsg } > { errInfo . toString ( ) } </ p >
56
- </ div >
57
- </ div > ;
64
+ return < ErrorPanel errInfo = { errInfo } /> ;
58
65
}
59
66
}
60
67
0 commit comments