@@ -120,7 +120,9 @@ class ChallengeCard extends React.Component {
120120 isSaving : false ,
121121 isCheckChalengePermission : false ,
122122 hasEditChallengePermission : false ,
123- loginUserRoleInProject : ''
123+ loginUserRoleInProject : '' ,
124+ currentPhase : this . getCurrentPhase ( props . challenge ) ,
125+ forumLink : this . getForumLink ( props . challenge )
124126 }
125127 this . onUpdateConfirm = this . onUpdateConfirm . bind ( this )
126128 this . onUpdateLaunch = this . onUpdateLaunch . bind ( this )
@@ -130,6 +132,31 @@ class ChallengeCard extends React.Component {
130132 this . onLaunchChallenge = this . onLaunchChallenge . bind ( this )
131133 }
132134
135+ getCurrentPhase ( challenge ) {
136+ return challenge . phases . filter ( ( p ) => p . isOpen ) . map ( ( p ) => p . name ) . join ( ' / ' ) || '-'
137+ }
138+
139+ getForumLink ( challenge ) {
140+ const discussionsHaveUrls = ( challenge . discussions || [ ] ) . filter ( ( p ) => ! ! p . url )
141+ return discussionsHaveUrls . length ? discussionsHaveUrls [ 0 ] . url : ''
142+ }
143+
144+ componentDidUpdate ( prevProps ) {
145+ const { challenge } = this . props
146+ if ( ! _ . isEqual ( challenge . phases , prevProps . challenge . phases ) ) {
147+ // eslint-disable-next-line react/no-did-update-set-state
148+ this . setState ( {
149+ currentPhase : this . getCurrentPhase ( challenge )
150+ } )
151+ }
152+ if ( ! _ . isEqual ( challenge . discussions , prevProps . challenge . discussions ) ) {
153+ // eslint-disable-next-line react/no-did-update-set-state
154+ this . setState ( {
155+ forumLink : this . getForumLink ( challenge )
156+ } )
157+ }
158+ }
159+
133160 onUpdateConfirm ( value ) {
134161 this . setState ( { isConfirm : value } )
135162 }
@@ -202,7 +229,7 @@ class ChallengeCard extends React.Component {
202229 }
203230
204231 render ( ) {
205- const { isLaunch, isConfirm, isSaving, isDeleteLaunch, isCheckChalengePermission, hasEditChallengePermission } = this . state
232+ const { isLaunch, isConfirm, isSaving, isDeleteLaunch, isCheckChalengePermission, hasEditChallengePermission, currentPhase , forumLink } = this . state
206233 const { setActiveProject, challenge, reloadChallengeList, isBillingAccountExpired, disableHover, getStatusText, challengeTypes, loginUserRoleInProject } = this . props
207234 const deleteMessage = isCheckChalengePermission
208235 ? 'Checking permissions...'
@@ -279,6 +306,9 @@ class ChallengeCard extends React.Component {
279306 < div className = { styles . col3 } >
280307 { renderStatus ( challenge . status . toUpperCase ( ) , getStatusText ) }
281308 </ div >
309+ < div className = { styles . col3 } >
310+ { currentPhase }
311+ </ div >
282312 {
283313 ! isReadOnly && (
284314 < div className = { styles . col6 } >
@@ -292,6 +322,10 @@ class ChallengeCard extends React.Component {
292322 < div className = { styles . col6 } >
293323 < a className = { styles . link } href = { communityAppUrl } target = '_blank' > CA</ a >
294324 </ div >
325+ < div className = { styles . col6 } >
326+ { forumLink ? ( < a className = { styles . link } href = { forumLink } target = '_blank' > CA</ a > )
327+ : ( < a className = { styles . link } href = 'javascript:void(0)' > Forum</ a > ) }
328+ </ div >
295329 </ div >
296330 )
297331 }
0 commit comments