1
1
/**
2
2
* Component to render a row for ChallengeList component
3
3
*/
4
- // import _ from 'lodash'
4
+ import _ from 'lodash'
5
5
import React from 'react'
6
6
import PropTypes from 'prop-types'
7
7
import cn from 'classnames'
@@ -11,13 +11,13 @@ import 'moment-duration-format'
11
11
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
12
12
import { faFile , faUser } from '@fortawesome/free-solid-svg-icons'
13
13
import ChallengeStatus from '../ChallengeStatus'
14
- import Modal from '../../Modal'
15
14
import ChallengeTag from '../ChallengeTag'
16
15
import styles from './ChallengeCard.module.scss'
17
16
import { getFormattedDuration } from '../../../util/date'
18
17
import { CHALLENGE_STATUS , COMMUNITY_APP_URL , DIRECT_PROJECT_URL , ONLINE_REVIEW_URL } from '../../../config/constants'
19
- import { OutlineButton , PrimaryButton } from '../../Buttons'
20
18
import { patchChallenge } from '../../../services/challenges'
19
+ import ConfirmationModal from '../../Modal/ConfirmationModal'
20
+ import AlertModal from '../../Modal/AlertModal'
21
21
22
22
const theme = {
23
23
container : styles . modalContainer
@@ -208,7 +208,8 @@ class ChallengeCard extends React.Component {
208
208
const response = await patchChallenge ( challenge . id , { status : 'Active' } )
209
209
this . setState ( { isLaunch : true , isConfirm : response . data . id , isSaving : false } )
210
210
} catch ( e ) {
211
- this . setState ( { isSaving : false } )
211
+ const error = _ . get ( e , 'response.data.message' , 'Unable to activate the challenge' )
212
+ this . setState ( { isSaving : false , error } )
212
213
}
213
214
}
214
215
@@ -219,37 +220,28 @@ class ChallengeCard extends React.Component {
219
220
return (
220
221
< div className = { styles . item } >
221
222
{ isLaunch && ! isConfirm && (
222
- < Modal theme = { theme } onCancel = { ( ) => this . resetModal ( ) } >
223
- < div className = { styles . contentContainer } >
224
- < div className = { styles . title } > Launch Challenge Confirmation</ div >
225
- < span > { `Do you want to launch ${ challenge . type } challenge "${ challenge . name } "?` } </ span >
226
- < div className = { styles . buttonGroup } >
227
- < div className = { styles . button } >
228
- < OutlineButton className = { cn ( { disabled : isSaving } ) } text = { 'Cancel' } type = { 'danger' } onClick = { ( ) => this . resetModal ( ) } />
229
- </ div >
230
- < div className = { styles . button } >
231
- < PrimaryButton text = { isSaving ? 'Launching...' : 'Confirm' } type = { 'info' } onClick = { ( ) => this . onLaunchChallenge ( ) } />
232
- </ div >
233
- </ div >
234
- </ div >
235
- </ Modal >
223
+ < ConfirmationModal
224
+ title = 'Confirm Launch'
225
+ message = { `Do you want to launch "${ challenge . name } "?` }
226
+ theme = { theme }
227
+ isProcessing = { isSaving }
228
+ errorMessage = { this . state . error }
229
+ onCancel = { this . resetModal }
230
+ onConfirm = { this . onLaunchChallenge }
231
+ />
236
232
)
237
233
}
238
234
{ isLaunch && isConfirm && (
239
- < Modal theme = { theme } onCancel = { reloadChallengeList } >
240
- < div className = { cn ( styles . contentContainer , styles . confirm ) } >
241
- < div className = { styles . title } > Success</ div >
242
- < span > Your challenge is saved as active</ span >
243
- < div className = { styles . buttonGroup } >
244
- < div className = { styles . buttonSizeA } onClick = { reloadChallengeList } >
245
- < PrimaryButton text = { 'Close' } type = { 'info' } />
246
- </ div >
247
- < div className = { styles . buttonSizeA } onClick = { ( ) => this . resetModal ( ) } >
248
- < OutlineButton text = { 'View Challenge' } type = { 'success' } link = { `/projects/${ challenge . projectId } /challenges/${ isConfirm } /view` } />
249
- </ div >
250
- </ div >
251
- </ div >
252
- </ Modal >
235
+ < AlertModal
236
+ title = 'Success'
237
+ message = { `Challenge "${ challenge . name } " is activated successfuly` }
238
+ theme = { theme }
239
+ onCancel = { reloadChallengeList }
240
+ closeText = 'Close'
241
+ okText = 'View Challenge'
242
+ okLink = './view'
243
+ onClose = { this . resetModal }
244
+ />
253
245
) }
254
246
255
247
< Link className = { styles . col1 } to = { `/projects/${ challenge . projectId } /challenges/${ challenge . id } /view` } >
0 commit comments