@@ -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 ( ) {
@@ -221,12 +236,39 @@ class ChallengeCard extends React.Component {
221236 }
222237 }
223238
239+ async onDeleteChallenge ( ) {
240+ const { deleteChallenge, challenge } = this . props
241+ try {
242+ this . setState ( { isSaving : true } )
243+ // Call action to delete the challenge
244+ await deleteChallenge ( challenge . id )
245+ this . setState ( { isSaving : false } )
246+ this . resetModal ( )
247+ } catch ( e ) {
248+ const error = _ . get ( e , 'response.data.message' , 'Unable to Delete the challenge' )
249+ this . setState ( { isSaving : false , error } )
250+ }
251+ }
252+
224253 render ( ) {
225- const { isLaunch, isConfirm, isSaving } = this . state
254+ const { isLaunch, isConfirm, isSaving, isDeleteLaunch } = this . state
226255 const { challenge, shouldShowCurrentPhase, reloadChallengeList } = this . props
227256 const { phaseMessage, endTime } = getPhaseInfo ( challenge )
228257 return (
229258 < div className = { styles . item } >
259+ {
260+ isDeleteLaunch && ! isConfirm && (
261+ < ConfirmationModal
262+ title = 'Confirm Delete'
263+ message = { `Do you want to delete "${ challenge . name } "?` }
264+ theme = { theme }
265+ isProcessing = { isSaving }
266+ errorMessage = { this . state . error }
267+ onCancel = { this . resetModal }
268+ onConfirm = { this . onDeleteChallenge }
269+ />
270+ )
271+ }
230272 { isLaunch && ! isConfirm && (
231273 < ConfirmationModal
232274 title = 'Confirm Launch'
@@ -268,7 +310,7 @@ class ChallengeCard extends React.Component {
268310 < span className = 'block light-text' > { endTime } </ span >
269311 </ Link > ) }
270312 < div className = { cn ( styles . col4 , styles . editingContainer ) } >
271- { hoverComponents ( challenge , this . onUpdateLaunch , this . props . showError ) }
313+ { hoverComponents ( challenge , this . onUpdateLaunch , this . deleteModalLaunch ) }
272314 </ div >
273315 < div className = { cn ( styles . col4 , styles . iconsContainer ) } >
274316 < div className = { styles . faIconContainer } >
@@ -287,16 +329,15 @@ class ChallengeCard extends React.Component {
287329
288330ChallengeCard . defaultPrps = {
289331 shouldShowCurrentPhase : true ,
290- showError : ( ) => { } ,
291332 reloadChallengeList : ( ) => { }
292333}
293334
294335ChallengeCard . propTypes = {
295336 challenge : PropTypes . object ,
296337 shouldShowCurrentPhase : PropTypes . bool ,
297- showError : PropTypes . func ,
298338 reloadChallengeList : PropTypes . func ,
299- partiallyUpdateChallengeDetails : PropTypes . func . isRequired
339+ partiallyUpdateChallengeDetails : PropTypes . func . isRequired ,
340+ deleteChallenge : PropTypes . func . isRequired
300341}
301342
302343export default withRouter ( ChallengeCard )
0 commit comments