Skip to content

Commit c150060

Browse files
author
vikasrohit
authored
Merge pull request #824 from topcoder-platform/develop
Moving latest and greatest to prod before beta release
2 parents 128cbb3 + 46d0ccf commit c150060

File tree

2 files changed

+50
-45
lines changed
  • src/components

2 files changed

+50
-45
lines changed

src/components/ChallengeEditor/Track-Field/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const TrackField = ({ challenge, tracks, onUpdateOthers, disabled }) => {
2424
}
2525
</div>
2626
</div>
27-
{ challenge.submitTriggered && !challenge.track && <div className={styles.row}>
27+
{ challenge.submitTriggered && !challenge.trackId && <div className={styles.row}>
2828
<div className={cn(styles.field, styles.col1)} />
2929
<div className={cn(styles.field, styles.col2, styles.error)}>
3030
Work Type is required field

src/components/ChallengesComponent/ChallengeCard/index.js

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -39,17 +39,16 @@ const getTimeLeft = (phase, status) => {
3939
if (phase.phaseType === 'Final Fix') {
4040
return FF_TIME_LEFT_MSG
4141
}
42-
43-
let time = moment(phase.scheduledEndTime).diff()
42+
let time = moment(phase.scheduledEndDate).diff()
4443
const late = time < 0
4544
if (late) time = -time
4645

47-
if (status !== CHALLENGE_STATUS.COMPLETED) {
46+
if (status !== CHALLENGE_STATUS.COMPLETED.toLowerCase()) {
4847
const duration = getFormattedDuration(time)
4948
return late ? `Late by ${duration}` : `${duration} to go`
5049
}
5150

52-
return moment(phase.scheduledEndTime).format('DD/MM/YYYY')
51+
return moment(phase.scheduledEndDate).format('DD/MM/YYYY')
5352
}
5453

5554
/**
@@ -58,8 +57,8 @@ const getTimeLeft = (phase, status) => {
5857
* @returns {{phaseMessage: string, endTime: {late, text}}}
5958
*/
6059
const getPhaseInfo = (c) => {
61-
const { allPhases, currentPhases, subTrack, status } = c
62-
let checkPhases = (currentPhases && currentPhases.length > 0 ? currentPhases : allPhases)
60+
const { currentPhaseNames, status, startDate, phases } = c
61+
/* let checkPhases = (currentPhases && currentPhases.length > 0 ? currentPhases : allPhases)
6362
if (_.isEmpty(checkPhases)) checkPhases = []
6463
let statusPhase = checkPhases
6564
.filter(p => p.phaseType !== 'Registration')
@@ -68,12 +67,26 @@ const getPhaseInfo = (c) => {
6867
if (!statusPhase && subTrack === 'FIRST_2_FINISH' && checkPhases.length) {
6968
statusPhase = Object.clone(checkPhases[0])
7069
statusPhase.phaseType = 'Submission'
71-
}
70+
} */
7271
let phaseMessage = STALLED_MSG
73-
if (statusPhase) phaseMessage = statusPhase.phaseType
74-
else if (status === 'DRAFT') phaseMessage = DRAFT_MSG
75-
76-
const endTime = getTimeLeft(statusPhase)
72+
// if (statusPhase) phaseMessage = statusPhase.phaseType
73+
// else if (status === 'DRAFT') phaseMessage = DRAFT_MSG
74+
var lowerStatus = status.toLowerCase()
75+
if (lowerStatus === 'draft') {
76+
phaseMessage = DRAFT_MSG
77+
} else if (lowerStatus === 'active') {
78+
if (!currentPhaseNames || currentPhaseNames.length === 0) {
79+
var timeToStart = moment(startDate).diff()
80+
if (timeToStart > 0) {
81+
phaseMessage = `Scheduled in ${getFormattedDuration(timeToStart)}`
82+
}
83+
} else {
84+
phaseMessage = currentPhaseNames.join('/')
85+
}
86+
}
87+
const activePhases = phases.filter(p => !!p.isOpen)
88+
const activePhase = activePhases.length > 0 ? activePhases[0] : null
89+
const endTime = getTimeLeft(activePhase, lowerStatus)
7790
return { phaseMessage, endTime }
7891
}
7992

@@ -195,7 +208,8 @@ class ChallengeCard extends React.Component {
195208
const response = await patchChallenge(challenge.id, { status: 'Active' })
196209
this.setState({ isLaunch: true, isConfirm: response.data.id, isSaving: false })
197210
} catch (e) {
198-
this.setState({ isSaving: false })
211+
const error = _.get(e, 'response.data.message', 'Unable to activate the challenge')
212+
this.setState({ isSaving: false, error })
199213
}
200214
}
201215

@@ -206,37 +220,28 @@ class ChallengeCard extends React.Component {
206220
return (
207221
<div className={styles.item}>
208222
{ isLaunch && !isConfirm && (
209-
<Modal theme={theme} onCancel={() => this.resetModal()}>
210-
<div className={styles.contentContainer}>
211-
<div className={styles.title}>Launch Challenge Confirmation</div>
212-
<span>{`Do you want to launch ${challenge.type} challenge "${challenge.name}"?`}</span>
213-
<div className={styles.buttonGroup}>
214-
<div className={styles.button}>
215-
<OutlineButton className={cn({ disabled: isSaving })} text={'Cancel'} type={'danger'} onClick={() => this.resetModal()} />
216-
</div>
217-
<div className={styles.button}>
218-
<PrimaryButton text={isSaving ? 'Launching...' : 'Confirm'} type={'info'} onClick={() => this.onLaunchChallenge()} />
219-
</div>
220-
</div>
221-
</div>
222-
</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+
/>
223232
)
224233
}
225234
{ isLaunch && isConfirm && (
226-
<Modal theme={theme} onCancel={reloadChallengeList}>
227-
<div className={cn(styles.contentContainer, styles.confirm)}>
228-
<div className={styles.title}>Success</div>
229-
<span>Your challenge is saved as active</span>
230-
<div className={styles.buttonGroup}>
231-
<div className={styles.buttonSizeA} onClick={reloadChallengeList}>
232-
<PrimaryButton text={'Close'} type={'info'} />
233-
</div>
234-
<div className={styles.buttonSizeA} onClick={() => this.resetModal()}>
235-
<OutlineButton text={'View Challenge'} type={'success'} link={`/projects/${challenge.projectId}/challenges/${isConfirm}/view`} />
236-
</div>
237-
</div>
238-
</div>
239-
</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+
/>
240245
) }
241246

242247
<Link className={styles.col1} to={`/projects/${challenge.projectId}/challenges/${challenge.id}/view`}>
@@ -258,11 +263,11 @@ class ChallengeCard extends React.Component {
258263
<div className={cn(styles.col4, styles.iconsContainer)}>
259264
<div className={styles.faIconContainer}>
260265
<FontAwesomeIcon icon={faUser} className={styles.faIcon} />
261-
<span>{challenge.numRegistrants || 0}</span>
266+
<span>{challenge.numOfRegistrants || 0}</span>
262267
</div>
263268
<div className={styles.faIconContainer}>
264269
<FontAwesomeIcon icon={faFile} className={styles.faIcon} />
265-
<span>{challenge.numSubmissions || 0}</span>
270+
<span>{challenge.numOfSubmissions || 0}</span>
266271
</div>
267272
</div>
268273
</div>

0 commit comments

Comments
 (0)