3
3
*/
4
4
import React , { useEffect , useState } from 'react' ;
5
5
import PT from 'prop-types' ;
6
+ import { connect } from 'react-redux' ;
6
7
8
+ import { actions } from 'topcoder-react-lib' ;
7
9
import { isomorphy } from 'topcoder-react-utils' ;
8
10
9
- // import VerifiedBadge from 'assets/images/profile/verified-badge.svg';
10
- // import InfoIcon from 'assets/images/profile/ico-info.svg';
11
- // import Tooltip from 'components/Tooltip';
11
+ import VerifiedBadge from 'assets/images/profile/verified-badge.svg' ;
12
+ import InfoIcon from 'assets/images/profile/ico-info.svg' ;
13
+ import Tooltip from 'components/Tooltip' ;
12
14
13
15
import './styles.scss' ;
14
16
15
- const ProfileHeader = ( { info } ) => {
17
+ const verifiedBadgeLookerId = '3322' ;
18
+
19
+ const ProfileHeader = ( { getLookerDone, lookerInfo, info } ) => {
16
20
const [ imageUrl , setimageUrl ] = useState ( ) ;
21
+ const [ isMemberVerified , setIsMemberVerified ] = useState ( false ) ;
22
+ const { handle } = info ;
17
23
18
24
useEffect ( ( ) => {
19
25
let url = '' ;
@@ -25,16 +31,29 @@ const ProfileHeader = ({ info }) => {
25
31
setimageUrl ( url ) ;
26
32
} , [ ] ) ;
27
33
34
+ useEffect ( ( ) => {
35
+ if ( ! lookerInfo || lookerInfo . error ) {
36
+ getLookerDone ( verifiedBadgeLookerId ) ;
37
+ }
38
+ } , [ ] ) ;
39
+
40
+ useEffect ( ( ) => {
41
+ if ( ! lookerInfo || lookerInfo . error ) {
42
+ return ;
43
+ }
44
+ const { lookerData } = lookerInfo ;
45
+ const currentUserData = lookerData . find ( x => x [ 'user.handle' ] === handle ) ;
46
+ setIsMemberVerified ( currentUserData && currentUserData [ 'member_verification.status' ] === 'Verified' ) ;
47
+ } , [ lookerInfo ] ) ;
48
+
28
49
const loadImageError = ( ) => {
29
50
setimageUrl ( null ) ;
30
51
} ;
31
52
32
- // const tooltipContent = (
33
- // <div styleName="tooltip-content">verified member</div>
34
- // );
53
+ const tooltipContent = (
54
+ < div styleName = "tooltip-content" > verified member</ div >
55
+ ) ;
35
56
36
- const { handle } = info ;
37
- // const isMemberVerified = true;
38
57
39
58
return (
40
59
< div styleName = "container" >
@@ -55,24 +74,22 @@ const ProfileHeader = ({ info }) => {
55
74
{ handle }
56
75
</ div >
57
76
58
- { /* { */ }
59
- { /* isMemberVerified && ( */ }
60
- { /* <div styleName="verified-member"> */ }
61
- { /* <VerifiedBadge /> */ }
62
-
63
- { /* <span>verified member</span> */ }
64
-
65
- { /* <div styleName="info"> */ }
66
- { /* <Tooltip */ }
67
- { /* content={tooltipContent} */ }
68
- { /* trigger={['hover', 'focus']} */ }
69
- { /* > */ }
70
- { /* <InfoIcon /> */ }
71
- { /* </Tooltip> */ }
72
- { /* </div> */ }
73
- { /* </div> */ }
74
- { /* ) */ }
75
- { /* } */ }
77
+ { isMemberVerified && (
78
+ < div styleName = "verified-member" >
79
+ < VerifiedBadge />
80
+
81
+ < span > verified member</ span >
82
+
83
+ < div styleName = "info" >
84
+ < Tooltip
85
+ content = { tooltipContent }
86
+ trigger = { [ 'hover' , 'focus' ] }
87
+ >
88
+ < InfoIcon />
89
+ </ Tooltip >
90
+ </ div >
91
+ </ div >
92
+ ) }
76
93
</ div >
77
94
78
95
</ div >
@@ -85,8 +102,34 @@ ProfileHeader.defaultProps = {
85
102
info : { } ,
86
103
} ;
87
104
105
+ function mapStateToProps ( state ) {
106
+ const {
107
+ looker : {
108
+ dataSet,
109
+ } ,
110
+ } = state ;
111
+ return {
112
+ lookerInfo : dataSet [ verifiedBadgeLookerId ] ,
113
+ } ;
114
+ }
115
+
116
+ function mapDispatchToProps ( dispatch ) {
117
+ return {
118
+ getLookerDone : ( lookerId ) => {
119
+ dispatch ( actions . looker . getLookerDone ( lookerId ) ) ;
120
+ } ,
121
+ } ;
122
+ }
123
+
88
124
ProfileHeader . propTypes = {
89
125
info : PT . shape ( ) ,
126
+ lookerInfo : PT . shape ( ) . isRequired ,
127
+ getLookerDone : PT . func . isRequired ,
90
128
} ;
91
129
92
- export default ProfileHeader ;
130
+ const Container = connect (
131
+ mapStateToProps ,
132
+ mapDispatchToProps ,
133
+ ) ( ProfileHeader ) ;
134
+
135
+ export default Container ;
0 commit comments