@@ -16,6 +16,7 @@ import styles from './ChallengeCard.module.scss'
16
16
import { getFormattedDuration , formatDate } from '../../../util/date'
17
17
import { CHALLENGE_STATUS , COMMUNITY_APP_URL , DIRECT_PROJECT_URL , MESSAGE , ONLINE_REVIEW_URL } from '../../../config/constants'
18
18
import ConfirmationModal from '../../Modal/ConfirmationModal'
19
+ import { checkChallengeEditPermission } from '../../../util/tc'
19
20
import AlertModal from '../../Modal/AlertModal'
20
21
import Tooltip from '../../Tooltip'
21
22
@@ -28,6 +29,9 @@ const DRAFT_MSG = 'In Draft'
28
29
const STALLED_TIME_LEFT_MSG = 'Challenge is currently on hold'
29
30
const FF_TIME_LEFT_MSG = 'Winner is working on fixes'
30
31
32
+ const PERMISSION_DELETE_MESSAGE_ERROR =
33
+ "You don't have permission to delete this challenge"
34
+
31
35
/**
32
36
* Format the remaining time of a challenge phase
33
37
* @param phase Challenge phase
@@ -187,7 +191,9 @@ class ChallengeCard extends React.Component {
187
191
isConfirm : false ,
188
192
isLaunch : false ,
189
193
isDeleteLaunch : false ,
190
- isSaving : false
194
+ isSaving : false ,
195
+ isCheckChalengePermission : false ,
196
+ hasEditChallengePermission : false
191
197
}
192
198
this . onUpdateConfirm = this . onUpdateConfirm . bind ( this )
193
199
this . onUpdateLaunch = this . onUpdateLaunch . bind ( this )
@@ -208,8 +214,19 @@ class ChallengeCard extends React.Component {
208
214
}
209
215
210
216
deleteModalLaunch ( ) {
217
+ const { challenge } = this . props
211
218
if ( ! this . state . isDeleteLaunch ) {
212
- this . setState ( { isDeleteLaunch : true } )
219
+ checkChallengeEditPermission ( challenge . id ) . then ( hasPermission => {
220
+ this . setState ( {
221
+ isCheckChalengePermission : false ,
222
+ hasEditChallengePermission : hasPermission
223
+ } )
224
+ } )
225
+ this . setState ( {
226
+ isDeleteLaunch : true ,
227
+ isCheckChalengePermission : true ,
228
+ hasEditChallengePermission : false
229
+ } )
213
230
}
214
231
}
215
232
@@ -254,25 +271,32 @@ class ChallengeCard extends React.Component {
254
271
}
255
272
256
273
render ( ) {
257
- const { isLaunch, isConfirm, isSaving, isDeleteLaunch } = this . state
274
+ const { isLaunch, isConfirm, isSaving, isDeleteLaunch, isCheckChalengePermission , hasEditChallengePermission } = this . state
258
275
const { challenge, shouldShowCurrentPhase, reloadChallengeList } = this . props
259
276
const { phaseMessage, endTime } = getPhaseInfo ( challenge )
277
+ const deleteMessage = isCheckChalengePermission
278
+ ? 'Checking permissions...'
279
+ : `Do you want to delete "${ challenge . name } "?`
280
+
260
281
return (
261
282
< div className = { styles . item } >
262
- {
263
- isDeleteLaunch && ! isConfirm && (
264
- < ConfirmationModal
265
- title = 'Confirm Delete'
266
- message = { `Do you want to delete "${ challenge . name } "?` }
267
- theme = { theme }
268
- isProcessing = { isSaving }
269
- errorMessage = { this . state . error }
270
- onCancel = { this . resetModal }
271
- onConfirm = { this . onDeleteChallenge }
272
- />
273
- )
274
- }
275
- { isLaunch && ! isConfirm && (
283
+ { isDeleteLaunch && ! isConfirm && (
284
+ < ConfirmationModal
285
+ title = 'Confirm Delete'
286
+ message = { deleteMessage }
287
+ theme = { theme }
288
+ isProcessing = { isSaving }
289
+ disableConfirmButton = { ! hasEditChallengePermission }
290
+ errorMessage = {
291
+ ! isCheckChalengePermission && ! hasEditChallengePermission
292
+ ? PERMISSION_DELETE_MESSAGE_ERROR
293
+ : this . state . error
294
+ }
295
+ onCancel = { this . resetModal }
296
+ onConfirm = { this . onDeleteChallenge }
297
+ />
298
+ ) }
299
+ { isLaunch && ! isConfirm && (
276
300
< ConfirmationModal
277
301
title = 'Confirm Launch'
278
302
message = { `Do you want to launch "${ challenge . name } "?` }
0 commit comments