Skip to content

Commit 46d0ccf

Browse files
author
Vikas Agarwal
committed
fix: git#823-Popup message or toaster is missing to notify user if there is any server side error
1 parent 83aaed3 commit 46d0ccf

File tree

1 file changed

+24
-32
lines changed
  • src/components/ChallengesComponent/ChallengeCard

1 file changed

+24
-32
lines changed

src/components/ChallengesComponent/ChallengeCard/index.js

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Component to render a row for ChallengeList component
33
*/
4-
// import _ from 'lodash'
4+
import _ from 'lodash'
55
import React from 'react'
66
import PropTypes from 'prop-types'
77
import cn from 'classnames'
@@ -11,13 +11,13 @@ import 'moment-duration-format'
1111
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
1212
import { faFile, faUser } from '@fortawesome/free-solid-svg-icons'
1313
import ChallengeStatus from '../ChallengeStatus'
14-
import Modal from '../../Modal'
1514
import ChallengeTag from '../ChallengeTag'
1615
import styles from './ChallengeCard.module.scss'
1716
import { getFormattedDuration } from '../../../util/date'
1817
import { CHALLENGE_STATUS, COMMUNITY_APP_URL, DIRECT_PROJECT_URL, ONLINE_REVIEW_URL } from '../../../config/constants'
19-
import { OutlineButton, PrimaryButton } from '../../Buttons'
2018
import { patchChallenge } from '../../../services/challenges'
19+
import ConfirmationModal from '../../Modal/ConfirmationModal'
20+
import AlertModal from '../../Modal/AlertModal'
2121

2222
const theme = {
2323
container: styles.modalContainer
@@ -208,7 +208,8 @@ class ChallengeCard extends React.Component {
208208
const response = await patchChallenge(challenge.id, { status: 'Active' })
209209
this.setState({ isLaunch: true, isConfirm: response.data.id, isSaving: false })
210210
} 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 })
212213
}
213214
}
214215

@@ -219,37 +220,28 @@ class ChallengeCard extends React.Component {
219220
return (
220221
<div className={styles.item}>
221222
{ 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+
/>
236232
)
237233
}
238234
{ 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+
/>
253245
) }
254246

255247
<Link className={styles.col1} to={`/projects/${challenge.projectId}/challenges/${challenge.id}/view`}>

0 commit comments

Comments
 (0)