33 */
44import React , { useEffect , useState } from 'react' ;
55import PT from 'prop-types' ;
6+ import { connect } from 'react-redux' ;
67
8+ import { actions } from 'topcoder-react-lib' ;
79import { isomorphy } from 'topcoder-react-utils' ;
810
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' ;
1214
1315import './styles.scss' ;
1416
15- const ProfileHeader = ( { info } ) => {
17+ const verifiedBadgeLookerId = '3322' ;
18+
19+ const ProfileHeader = ( { getLookerDone, lookerInfo, info } ) => {
1620 const [ imageUrl , setimageUrl ] = useState ( ) ;
21+ const [ isMemberVerified , setIsMemberVerified ] = useState ( false ) ;
22+ const { handle } = info ;
1723
1824 useEffect ( ( ) => {
1925 let url = '' ;
@@ -25,16 +31,29 @@ const ProfileHeader = ({ info }) => {
2531 setimageUrl ( url ) ;
2632 } , [ ] ) ;
2733
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+
2849 const loadImageError = ( ) => {
2950 setimageUrl ( null ) ;
3051 } ;
3152
32- // const tooltipContent = (
33- // <div styleName="tooltip-content">verified member</div>
34- // );
53+ const tooltipContent = (
54+ < div styleName = "tooltip-content" > verified member</ div >
55+ ) ;
3556
36- const { handle } = info ;
37- // const isMemberVerified = true;
3857
3958 return (
4059 < div styleName = "container" >
@@ -55,24 +74,22 @@ const ProfileHeader = ({ info }) => {
5574 { handle }
5675 </ div >
5776
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+ ) }
7693 </ div >
7794
7895 </ div >
@@ -85,8 +102,34 @@ ProfileHeader.defaultProps = {
85102 info : { } ,
86103} ;
87104
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+
88124ProfileHeader . propTypes = {
89125 info : PT . shape ( ) ,
126+ lookerInfo : PT . shape ( ) . isRequired ,
127+ getLookerDone : PT . func . isRequired ,
90128} ;
91129
92- export default ProfileHeader ;
130+ const Container = connect (
131+ mapStateToProps ,
132+ mapDispatchToProps ,
133+ ) ( ProfileHeader ) ;
134+
135+ export default Container ;
0 commit comments