Skip to content

Fix issue 1378 #1379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,21 @@ class ChallengeEditor extends Component {
this.onDeleteChallenge = this.onDeleteChallenge.bind(this)
this.deleteModalLaunch = this.deleteModalLaunch.bind(this)
this.toggleForumOnCreate = this.toggleForumOnCreate.bind(this)
this.isPhaseEditable = this.isPhaseEditable.bind(this)
this.intervalId = null
}

componentDidMount () {
this.resetChallengeData(this.setState.bind(this))
setTimeout(() => {
this.onTick()
}, 500)
this.intervalId = setInterval(() => {
this.onTick()
}, 60000)
}

componentDidUnMount () {
clearInterval(this.intervalId)
}

componentDidUpdate () {
Expand Down Expand Up @@ -811,6 +821,22 @@ class ChallengeEditor extends Component {
this.setState({ challenge: newChallenge })
}

onTick () {
if (this.state && this.state) {
const { phases } = this.state.challenge
let newChallenge = _.cloneDeep(this.state.challenge)
for (let index = 0; index < phases.length; ++index) {
newChallenge.phases[index].isDurationActive =
moment(newChallenge.phases[index]['scheduledEndDate']).isAfter()
newChallenge.phases[index].isStartTimeActive = index > 0 ? false
: moment(newChallenge.phases[0]['scheduledStartDate']).isAfter()
newChallenge.phases[index].isOpen =
newChallenge.phases[index].isDurationActive
}
this.setState({ challenge: newChallenge })
}
}

onUpdatePhaseDate (phase, index) {
const { phases } = this.state.challenge
let newChallenge = _.cloneDeep(this.state.challenge)
Expand Down Expand Up @@ -848,6 +874,10 @@ class ChallengeEditor extends Component {
}

this.setState({ challenge: newChallenge })

setTimeout(() => {
this.onTick()
}, 500)
}

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

/**
* Check if current phase is active for edit
*/
isPhaseEditable (phaseIndex) {
const { phases } = this.state.challenge
const phase = phases[phaseIndex]
if (phase.name !== 'Registration') {
return false
}
return !phase.isOpen
}

render () {
const {
isLaunch,
Expand Down Expand Up @@ -1623,7 +1641,6 @@ class ChallengeEditor extends Component {
phaseIndex={index}
key={index}
readOnly={false}
isActive={this.isPhaseEditable(index)}
onUpdatePhase={(item) => {
this.onUpdatePhaseDate(item, index)
}}
Expand Down
7 changes: 5 additions & 2 deletions src/components/DurationInput/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React, { useRef } from 'react'
import React, { useEffect, useRef } from 'react'
import PropTypes from 'prop-types'
import styles from './DurationInput.module.scss'

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

useEffect(() => {
document.getElementById(`duration-${index}`).disabled = !isActive
}, [isActive, index])

return (
<div key={`duration-${index}-edit`}>
<input
Expand All @@ -24,7 +28,6 @@ const DurationInput = ({ duration, onDurationChange, index, isActive }) => {
onDurationChange(e.target.value, true)
}}
autoFocus={inputRef.current === document.activeElement}
disabled={!isActive}
/>
</div>
)
Expand Down
16 changes: 7 additions & 9 deletions src/components/PhaseInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const inputDateFormat = 'MM/dd/yyyy'
const inputTimeFormat = 'HH:mm'
const MAX_LENGTH = 5

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

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

const onStartDateChange = (e) => {
let startDate = moment(e).format(dateFormat)
Expand Down Expand Up @@ -54,7 +54,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) =>
<span className={styles.title}>Start Date:</span>
<div className={styles.dayPicker}>
{
readOnly || !isActive ? (
readOnly || !isStartTimeActive ? (
<span className={styles.readOnlyValue}>{moment(startDate).format(dateFormat)}</span>
)
: (
Expand Down Expand Up @@ -88,7 +88,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) =>
name={phase.name}
onDurationChange={onDurationChange}
index={phaseIndex}
isActive
isActive={isDurationActive || false}
/>
)}
</div>
Expand All @@ -100,15 +100,13 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) =>

PhaseInput.defaultProps = {
endDate: null,
readOnly: false,
isActive: false
readOnly: false
}

PhaseInput.propTypes = {
phase: PropTypes.shape().isRequired,
onUpdatePhase: PropTypes.func,
readOnly: PropTypes.bool,
phaseIndex: PropTypes.number.isRequired,
isActive: PropTypes.bool
phaseIndex: PropTypes.number.isRequired
}
export default PhaseInput