Skip to content

Commit 4190a56

Browse files
authored
Merge pull request #1379 from 52cs/fix-1378
Fix issue 1378
2 parents 6aba0cc + 95548cd commit 4190a56

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

src/components/ChallengeEditor/index.js

+31-14
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,21 @@ class ChallengeEditor extends Component {
138138
this.onDeleteChallenge = this.onDeleteChallenge.bind(this)
139139
this.deleteModalLaunch = this.deleteModalLaunch.bind(this)
140140
this.toggleForumOnCreate = this.toggleForumOnCreate.bind(this)
141-
this.isPhaseEditable = this.isPhaseEditable.bind(this)
141+
this.intervalId = null
142142
}
143143

144144
componentDidMount () {
145145
this.resetChallengeData(this.setState.bind(this))
146+
setTimeout(() => {
147+
this.onTick()
148+
}, 500)
149+
this.intervalId = setInterval(() => {
150+
this.onTick()
151+
}, 60000)
152+
}
153+
154+
componentDidUnMount () {
155+
clearInterval(this.intervalId)
146156
}
147157

148158
componentDidUpdate () {
@@ -811,6 +821,22 @@ class ChallengeEditor extends Component {
811821
this.setState({ challenge: newChallenge })
812822
}
813823

824+
onTick () {
825+
if (this.state && this.state) {
826+
const { phases } = this.state.challenge
827+
let newChallenge = _.cloneDeep(this.state.challenge)
828+
for (let index = 0; index < phases.length; ++index) {
829+
newChallenge.phases[index].isDurationActive =
830+
moment(newChallenge.phases[index]['scheduledEndDate']).isAfter()
831+
newChallenge.phases[index].isStartTimeActive = index > 0 ? false
832+
: moment(newChallenge.phases[0]['scheduledStartDate']).isAfter()
833+
newChallenge.phases[index].isOpen =
834+
newChallenge.phases[index].isDurationActive
835+
}
836+
this.setState({ challenge: newChallenge })
837+
}
838+
}
839+
814840
onUpdatePhaseDate (phase, index) {
815841
const { phases } = this.state.challenge
816842
let newChallenge = _.cloneDeep(this.state.challenge)
@@ -848,6 +874,10 @@ class ChallengeEditor extends Component {
848874
}
849875

850876
this.setState({ challenge: newChallenge })
877+
878+
setTimeout(() => {
879+
this.onTick()
880+
}, 500)
851881
}
852882

853883
collectChallengeData (status) {
@@ -1249,18 +1279,6 @@ class ChallengeEditor extends Component {
12491279
return _.filter(timelineTemplates, tt => availableTemplateIds.indexOf(tt.id) !== -1)
12501280
}
12511281

1252-
/**
1253-
* Check if current phase is active for edit
1254-
*/
1255-
isPhaseEditable (phaseIndex) {
1256-
const { phases } = this.state.challenge
1257-
const phase = phases[phaseIndex]
1258-
if (phase.name !== 'Registration') {
1259-
return false
1260-
}
1261-
return !phase.isOpen
1262-
}
1263-
12641282
render () {
12651283
const {
12661284
isLaunch,
@@ -1623,7 +1641,6 @@ class ChallengeEditor extends Component {
16231641
phaseIndex={index}
16241642
key={index}
16251643
readOnly={false}
1626-
isActive={this.isPhaseEditable(index)}
16271644
onUpdatePhase={(item) => {
16281645
this.onUpdatePhaseDate(item, index)
16291646
}}

src/components/DurationInput/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import React, { useRef } from 'react'
1+
import React, { useEffect, useRef } from 'react'
22
import PropTypes from 'prop-types'
33
import styles from './DurationInput.module.scss'
44

55
const DurationInput = ({ duration, onDurationChange, index, isActive }) => {
66
const inputRef = useRef(null)
77

8+
useEffect(() => {
9+
document.getElementById(`duration-${index}`).disabled = !isActive
10+
}, [isActive, index])
11+
812
return (
913
<div key={`duration-${index}-edit`}>
1014
<input
@@ -24,7 +28,6 @@ const DurationInput = ({ duration, onDurationChange, index, isActive }) => {
2428
onDurationChange(e.target.value, true)
2529
}}
2630
autoFocus={inputRef.current === document.activeElement}
27-
disabled={!isActive}
2831
/>
2932
</div>
3033
)

src/components/PhaseInput/index.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const inputDateFormat = 'MM/dd/yyyy'
1616
const inputTimeFormat = 'HH:mm'
1717
const MAX_LENGTH = 5
1818

19-
const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) => {
20-
const { scheduledStartDate: startDate, scheduledEndDate: endDate, duration } = phase
19+
const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
20+
const { scheduledStartDate: startDate, scheduledEndDate: endDate, duration, isStartTimeActive, isDurationActive } = phase
2121

22-
const getEndDate = (startDate, duration) => moment(startDate).add(duration, 'hours')
22+
const getEndDate = (startDate, duration) => moment(startDate).add(duration, 'hours').format(dateFormat)
2323

2424
const onStartDateChange = (e) => {
2525
let startDate = moment(e).format(dateFormat)
@@ -54,7 +54,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) =>
5454
<span className={styles.title}>Start Date:</span>
5555
<div className={styles.dayPicker}>
5656
{
57-
readOnly || !isActive ? (
57+
readOnly || !isStartTimeActive ? (
5858
<span className={styles.readOnlyValue}>{moment(startDate).format(dateFormat)}</span>
5959
)
6060
: (
@@ -88,7 +88,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) =>
8888
name={phase.name}
8989
onDurationChange={onDurationChange}
9090
index={phaseIndex}
91-
isActive
91+
isActive={isDurationActive || false}
9292
/>
9393
)}
9494
</div>
@@ -100,15 +100,13 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) =>
100100

101101
PhaseInput.defaultProps = {
102102
endDate: null,
103-
readOnly: false,
104-
isActive: false
103+
readOnly: false
105104
}
106105

107106
PhaseInput.propTypes = {
108107
phase: PropTypes.shape().isRequired,
109108
onUpdatePhase: PropTypes.func,
110109
readOnly: PropTypes.bool,
111-
phaseIndex: PropTypes.number.isRequired,
112-
isActive: PropTypes.bool
110+
phaseIndex: PropTypes.number.isRequired
113111
}
114112
export default PhaseInput

0 commit comments

Comments
 (0)