1
1
import PropTypes from 'prop-types' ;
2
2
import React from 'react' ;
3
3
import { Link } from 'react-router' ;
4
- import { withTranslation } from 'react-i18next' ;
4
+ import { useTranslation } from 'react-i18next' ;
5
5
6
- class ErrorModal extends React . Component {
7
- forceAuthentication ( ) {
6
+ const ErrorModal = ( { type, service, closeModal } ) => {
7
+ const { t } = useTranslation ( ) ;
8
+
9
+ function forceAuthentication ( ) {
8
10
return (
9
11
< p >
10
- { this . props . t ( 'ErrorModal.MessageLogin' ) }
11
- < Link to = "/login" onClick = { this . props . closeModal } >
12
+ { t ( 'ErrorModal.MessageLogin' ) }
13
+ < Link to = "/login" onClick = { closeModal } >
12
14
{ ' ' }
13
- { this . props . t ( 'ErrorModal.Login' ) }
15
+ { t ( 'ErrorModal.Login' ) }
14
16
</ Link >
15
- { this . props . t ( 'ErrorModal.LoginOr' ) }
16
- < Link to = "/signup" onClick = { this . props . closeModal } >
17
- { this . props . t ( 'ErrorModal.SignUp' ) }
17
+ { t ( 'ErrorModal.LoginOr' ) }
18
+ < Link to = "/signup" onClick = { closeModal } >
19
+ { t ( 'ErrorModal.SignUp' ) }
18
20
</ Link >
19
21
.
20
22
</ p >
21
23
) ;
22
24
}
23
25
24
- oauthError ( ) {
25
- const { t, service } = this . props ;
26
+ function oauthError ( ) {
26
27
const serviceLabels = {
27
28
github : 'GitHub' ,
28
29
google : 'Google'
@@ -34,50 +35,47 @@ class ErrorModal extends React.Component {
34
35
) ;
35
36
}
36
37
37
- staleSession ( ) {
38
+ function staleSession ( ) {
38
39
return (
39
40
< p >
40
- { this . props . t ( 'ErrorModal.MessageLoggedOut' ) }
41
- < Link to = "/login" onClick = { this . props . closeModal } >
42
- { this . props . t ( 'ErrorModal.LogIn' ) }
41
+ { t ( 'ErrorModal.MessageLoggedOut' ) }
42
+ < Link to = "/login" onClick = { closeModal } >
43
+ { t ( 'ErrorModal.LogIn' ) }
43
44
</ Link >
44
45
.
45
46
</ p >
46
47
) ;
47
48
}
48
49
49
- staleProject ( ) {
50
- return < p > { this . props . t ( 'ErrorModal.SavedDifferentWindow' ) } </ p > ;
50
+ function staleProject ( ) {
51
+ return < p > { t ( 'ErrorModal.SavedDifferentWindow' ) } </ p > ;
51
52
}
52
53
53
- render ( ) {
54
- return (
55
- < div className = "error-modal__content" >
56
- { ( ( ) => { // eslint-disable-line
57
- if ( this . props . type === 'forceAuthentication' ) {
58
- return this . forceAuthentication ( ) ;
59
- } else if ( this . props . type === 'staleSession' ) {
60
- return this . staleSession ( ) ;
61
- } else if ( this . props . type === 'staleProject' ) {
62
- return this . staleProject ( ) ;
63
- } else if ( this . props . type === 'oauthError' ) {
64
- return this . oauthError ( ) ;
65
- }
66
- } ) ( ) }
67
- </ div >
68
- ) ;
69
- }
70
- }
54
+ return (
55
+ < div className = "error-modal__content" >
56
+ { ( ( ) => { // eslint-disable-line
57
+ if ( type === 'forceAuthentication' ) {
58
+ return forceAuthentication ( ) ;
59
+ } else if ( type === 'staleSession' ) {
60
+ return staleSession ( ) ;
61
+ } else if ( type === 'staleProject' ) {
62
+ return staleProject ( ) ;
63
+ } else if ( type === 'oauthError' ) {
64
+ return oauthError ( ) ;
65
+ }
66
+ } ) ( ) }
67
+ </ div >
68
+ ) ;
69
+ } ;
71
70
72
71
ErrorModal . propTypes = {
73
72
type : PropTypes . string . isRequired ,
74
73
closeModal : PropTypes . func . isRequired ,
75
- t : PropTypes . func . isRequired ,
76
74
service : PropTypes . string
77
75
} ;
78
76
79
77
ErrorModal . defaultProps = {
80
78
service : ''
81
79
} ;
82
80
83
- export default withTranslation ( ) ( ErrorModal ) ;
81
+ export default ErrorModal ;
0 commit comments