diff --git a/src/components/ChallengeEditor/index.js b/src/components/ChallengeEditor/index.js
index 0b718f50..735c7267 100644
--- a/src/components/ChallengeEditor/index.js
+++ b/src/components/ChallengeEditor/index.js
@@ -813,8 +813,7 @@ class ChallengeEditor extends Component {
onUpdatePhaseDate (phase, index) {
let newChallenge = _.cloneDeep(this.state.challenge)
- const hourToSecond = 60 * 60
- newChallenge.phases[index]['duration'] = phase.duration / hourToSecond
+ newChallenge.phases[index]['duration'] = phase.duration
newChallenge.phases[index]['scheduledStartDate'] = phase.scheduledStartDate
newChallenge.phases[index]['scheduledEndDate'] = phase.scheduledEndDate
this.setState({ challenge: newChallenge })
diff --git a/src/components/DurationInput/index.js b/src/components/DurationInput/index.js
new file mode 100644
index 00000000..2a637fd2
--- /dev/null
+++ b/src/components/DurationInput/index.js
@@ -0,0 +1,29 @@
+import React, { useRef } from 'react'
+import PropTypes from 'prop-types'
+
+const DurationInput = ({ duration, onDurationChange, index }) => {
+ const inputRef = useRef(null)
+
+ return (
+
+ onDurationChange(e.target.value)}
+ autoFocus={inputRef.current === document.activeElement}
+ />
+
+ )
+}
+
+DurationInput.propTypes = {
+ duration: PropTypes.string,
+ onDurationChange: PropTypes.func.isRequired,
+ index: PropTypes.string.isRequired
+}
+
+export default DurationInput
diff --git a/src/components/PhaseInput/index.js b/src/components/PhaseInput/index.js
index 2338d5d3..8e0220d6 100644
--- a/src/components/PhaseInput/index.js
+++ b/src/components/PhaseInput/index.js
@@ -9,6 +9,7 @@ import DateTime from '@nateradebaugh/react-datetime'
import isAfter from 'date-fns/isAfter'
import subDays from 'date-fns/subDays'
import '@nateradebaugh/react-datetime/scss/styles.scss'
+import DurationInput from '../DurationInput'
const dateFormat = 'MM/DD/YYYY HH:mm'
const MAX_LENGTH = 5
@@ -22,7 +23,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
if (phase) {
setStartDate(phase.scheduledStartDate)
setEndDate(phase.scheduledEndDate)
- setDuration(moment(phase.scheduledEndDate).diff(phase.scheduledStartDate, 'seconds'))
+ setDuration(moment(phase.scheduledEndDate).diff(phase.scheduledStartDate, 'hours'))
}
}, [])
@@ -46,7 +47,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
}
setStartDate(moment(e).format(dateFormat))
- setDuration(moment(end).diff(start, 'seconds'))
+ setDuration(moment(end).diff(start, 'hours'))
}
const onEndDateChange = (e) => {
@@ -58,20 +59,20 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
}
setEndDate(moment(e).format(dateFormat))
- setDuration(moment(end).diff(start, 'seconds'))
+ setDuration(moment(end).diff(start, 'hours'))
}
const onDurationChange = (e) => {
- if (e.target.value.length > MAX_LENGTH) return null
+ if (e.length > MAX_LENGTH) return null
- const dur = parseInt(e.target.value || 0)
+ const dur = parseInt(e || 0)
setDuration(dur)
- const end = moment(startDate).add(duration, 'seconds')
+ const end = moment(startDate).add(dur, 'hours')
setEndDate(moment(end).format(dateFormat))
}
return (
-