@@ -16,6 +16,7 @@ import styles from './ChallengeCard.module.scss'
1616import { getFormattedDuration , formatDate } from '../../../util/date'
1717import { CHALLENGE_STATUS , COMMUNITY_APP_URL , DIRECT_PROJECT_URL , MESSAGE , ONLINE_REVIEW_URL } from '../../../config/constants'
1818import ConfirmationModal from '../../Modal/ConfirmationModal'
19+ import { checkChallengeEditPermission } from '../../../util/tc'
1920import AlertModal from '../../Modal/AlertModal'
2021import Tooltip from '../../Tooltip'
2122
@@ -28,6 +29,9 @@ const DRAFT_MSG = 'In Draft'
2829const STALLED_TIME_LEFT_MSG = 'Challenge is currently on hold'
2930const FF_TIME_LEFT_MSG = 'Winner is working on fixes'
3031
32+ const PERMISSION_DELETE_MESSAGE_ERROR =
33+ "You don't have permission to delete this challenge"
34+
3135/**
3236 * Format the remaining time of a challenge phase
3337 * @param phase Challenge phase
@@ -187,7 +191,9 @@ class ChallengeCard extends React.Component {
187191 isConfirm : false ,
188192 isLaunch : false ,
189193 isDeleteLaunch : false ,
190- isSaving : false
194+ isSaving : false ,
195+ isCheckChalengePermission : false ,
196+ hasEditChallengePermission : false
191197 }
192198 this . onUpdateConfirm = this . onUpdateConfirm . bind ( this )
193199 this . onUpdateLaunch = this . onUpdateLaunch . bind ( this )
@@ -208,8 +214,19 @@ class ChallengeCard extends React.Component {
208214 }
209215
210216 deleteModalLaunch ( ) {
217+ const { challenge } = this . props
211218 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+ } )
213230 }
214231 }
215232
@@ -254,25 +271,32 @@ class ChallengeCard extends React.Component {
254271 }
255272
256273 render ( ) {
257- const { isLaunch, isConfirm, isSaving, isDeleteLaunch } = this . state
274+ const { isLaunch, isConfirm, isSaving, isDeleteLaunch, isCheckChalengePermission , hasEditChallengePermission } = this . state
258275 const { challenge, shouldShowCurrentPhase, reloadChallengeList } = this . props
259276 const { phaseMessage, endTime } = getPhaseInfo ( challenge )
277+ const deleteMessage = isCheckChalengePermission
278+ ? 'Checking permissions...'
279+ : `Do you want to delete "${ challenge . name } "?`
280+
260281 return (
261282 < 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 && (
276300 < ConfirmationModal
277301 title = 'Confirm Launch'
278302 message = { `Do you want to launch "${ challenge . name } "?` }
0 commit comments