@@ -96,14 +96,20 @@ const getPhaseInfo = (c) => {
9696 * @param onUpdateLaunch
9797 * @returns {* }
9898 */
99- const hoverComponents = ( challenge , onUpdateLaunch ) => {
99+ const hoverComponents = ( challenge , onUpdateLaunch , deleteModalLaunch ) => {
100100 const communityAppUrl = `${ COMMUNITY_APP_URL } /challenges/${ challenge . id } `
101101 const directUrl = `${ DIRECT_PROJECT_URL } /contest/detail?projectId=${ challenge . legacyId } `
102102 const orUrl = `${ ONLINE_REVIEW_URL } /review/actions/ViewProjectDetails?pid=${ challenge . legacyId } `
103103
104104 // NEW projects never have Legacy challenge created, so don't show links and "Activate" button for them at all
105105 if ( challenge . status . toUpperCase ( ) === CHALLENGE_STATUS . NEW ) {
106- return null
106+ if ( challenge . status . toUpperCase ( ) === CHALLENGE_STATUS . NEW ) {
107+ return (
108+ < button className = { styles . deleteButton } onClick = { deleteModalLaunch } >
109+ < span > Delete</ span >
110+ </ button >
111+ )
112+ }
107113 }
108114
109115 return challenge . legacyId ? (
@@ -177,10 +183,13 @@ class ChallengeCard extends React.Component {
177183 this . state = {
178184 isConfirm : false ,
179185 isLaunch : false ,
186+ isDeleteLaunch : false ,
180187 isSaving : false
181188 }
182189 this . onUpdateConfirm = this . onUpdateConfirm . bind ( this )
183190 this . onUpdateLaunch = this . onUpdateLaunch . bind ( this )
191+ this . onDeleteChallenge = this . onDeleteChallenge . bind ( this )
192+ this . deleteModalLaunch = this . deleteModalLaunch . bind ( this )
184193 this . resetModal = this . resetModal . bind ( this )
185194 this . onLaunchChallenge = this . onLaunchChallenge . bind ( this )
186195 }
@@ -195,8 +204,14 @@ class ChallengeCard extends React.Component {
195204 }
196205 }
197206
207+ deleteModalLaunch ( ) {
208+ if ( ! this . state . isDeleteLaunch ) {
209+ this . setState ( { isDeleteLaunch : true } )
210+ }
211+ }
212+
198213 resetModal ( ) {
199- this . setState ( { isConfirm : false , isLaunch : false } )
214+ this . setState ( { isConfirm : false , isLaunch : false , isDeleteLaunch : false } )
200215 }
201216
202217 async onLaunchChallenge ( ) {
@@ -216,12 +231,39 @@ class ChallengeCard extends React.Component {
216231 }
217232 }
218233
234+ async onDeleteChallenge ( ) {
235+ const { deleteChallenge, challenge } = this . props
236+ try {
237+ this . setState ( { isSaving : true } )
238+ // Call action to delete the challenge
239+ await deleteChallenge ( challenge . id )
240+ this . setState ( { isSaving : false } )
241+ this . resetModal ( )
242+ } catch ( e ) {
243+ const error = _ . get ( e , 'response.data.message' , 'Unable to Delete the challenge' )
244+ this . setState ( { isSaving : false , error } )
245+ }
246+ }
247+
219248 render ( ) {
220- const { isLaunch, isConfirm, isSaving } = this . state
249+ const { isLaunch, isConfirm, isSaving, isDeleteLaunch } = this . state
221250 const { challenge, shouldShowCurrentPhase, reloadChallengeList } = this . props
222251 const { phaseMessage, endTime } = getPhaseInfo ( challenge )
223252 return (
224253 < div className = { styles . item } >
254+ {
255+ isDeleteLaunch && ! isConfirm && (
256+ < ConfirmationModal
257+ title = 'Confirm Delete'
258+ message = { `Do you want to delete "${ challenge . name } "?` }
259+ theme = { theme }
260+ isProcessing = { isSaving }
261+ errorMessage = { this . state . error }
262+ onCancel = { this . resetModal }
263+ onConfirm = { this . onDeleteChallenge }
264+ />
265+ )
266+ }
225267 { isLaunch && ! isConfirm && (
226268 < ConfirmationModal
227269 title = 'Confirm Launch'
@@ -263,7 +305,7 @@ class ChallengeCard extends React.Component {
263305 < span className = 'block light-text' > { endTime } </ span >
264306 </ Link > ) }
265307 < div className = { cn ( styles . col4 , styles . editingContainer ) } >
266- { hoverComponents ( challenge , this . onUpdateLaunch , this . props . showError ) }
308+ { hoverComponents ( challenge , this . onUpdateLaunch , this . deleteModalLaunch ) }
267309 </ div >
268310 < div className = { cn ( styles . col4 , styles . iconsContainer ) } >
269311 < div className = { styles . faIconContainer } >
@@ -282,16 +324,15 @@ class ChallengeCard extends React.Component {
282324
283325ChallengeCard . defaultPrps = {
284326 shouldShowCurrentPhase : true ,
285- showError : ( ) => { } ,
286327 reloadChallengeList : ( ) => { }
287328}
288329
289330ChallengeCard . propTypes = {
290331 challenge : PropTypes . object ,
291332 shouldShowCurrentPhase : PropTypes . bool ,
292- showError : PropTypes . func ,
293333 reloadChallengeList : PropTypes . func ,
294- partiallyUpdateChallengeDetails : PropTypes . func . isRequired
334+ partiallyUpdateChallengeDetails : PropTypes . func . isRequired ,
335+ deleteChallenge : PropTypes . func . isRequired
295336}
296337
297338export default withRouter ( ChallengeCard )
0 commit comments