Skip to content

Commit 7cc0e57

Browse files
authored
Merge pull request #1327 from nursoltan-s/issue-1319-feedback
fix issue 1319 feedback
2 parents 17176ca + 2f36d43 commit 7cc0e57

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

src/components/ChallengeEditor/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,7 @@ class ChallengeEditor extends Component {
813813

814814
onUpdatePhaseDate (phase, index) {
815815
let newChallenge = _.cloneDeep(this.state.challenge)
816-
const hourToSecond = 60 * 60
817-
newChallenge.phases[index]['duration'] = phase.duration / hourToSecond
816+
newChallenge.phases[index]['duration'] = phase.duration
818817
newChallenge.phases[index]['scheduledStartDate'] = phase.scheduledStartDate
819818
newChallenge.phases[index]['scheduledEndDate'] = phase.scheduledEndDate
820819
this.setState({ challenge: newChallenge })

src/components/DurationInput/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { useRef } from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
const DurationInput = ({ duration, onDurationChange, index }) => {
5+
const inputRef = useRef(null)
6+
7+
return (
8+
<div key={`duration-${index}-edit`}>
9+
<input
10+
id={`duration-${index}`}
11+
key={`duration-${index}`}
12+
ref={inputRef}
13+
min={0}
14+
type='number'
15+
value={Number(duration).toString()}
16+
onChange={e => onDurationChange(e.target.value)}
17+
autoFocus={inputRef.current === document.activeElement}
18+
/>
19+
</div>
20+
)
21+
}
22+
23+
DurationInput.propTypes = {
24+
duration: PropTypes.string,
25+
onDurationChange: PropTypes.func.isRequired,
26+
index: PropTypes.string.isRequired
27+
}
28+
29+
export default DurationInput

src/components/PhaseInput/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import DateTime from '@nateradebaugh/react-datetime'
99
import isAfter from 'date-fns/isAfter'
1010
import subDays from 'date-fns/subDays'
1111
import '@nateradebaugh/react-datetime/scss/styles.scss'
12+
import DurationInput from '../DurationInput'
1213

1314
const dateFormat = 'MM/DD/YYYY HH:mm'
1415
const MAX_LENGTH = 5
@@ -22,7 +23,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
2223
if (phase) {
2324
setStartDate(phase.scheduledStartDate)
2425
setEndDate(phase.scheduledEndDate)
25-
setDuration(moment(phase.scheduledEndDate).diff(phase.scheduledStartDate, 'seconds'))
26+
setDuration(moment(phase.scheduledEndDate).diff(phase.scheduledStartDate, 'hours'))
2627
}
2728
}, [])
2829

@@ -46,7 +47,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
4647
}
4748

4849
setStartDate(moment(e).format(dateFormat))
49-
setDuration(moment(end).diff(start, 'seconds'))
50+
setDuration(moment(end).diff(start, 'hours'))
5051
}
5152

5253
const onEndDateChange = (e) => {
@@ -58,20 +59,20 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
5859
}
5960

6061
setEndDate(moment(e).format(dateFormat))
61-
setDuration(moment(end).diff(start, 'seconds'))
62+
setDuration(moment(end).diff(start, 'hours'))
6263
}
6364

6465
const onDurationChange = (e) => {
65-
if (e.target.value.length > MAX_LENGTH) return null
66+
if (e.length > MAX_LENGTH) return null
6667

67-
const dur = parseInt(e.target.value || 0)
68+
const dur = parseInt(e || 0)
6869
setDuration(dur)
69-
const end = moment(startDate).add(duration, 'seconds')
70+
const end = moment(startDate).add(dur, 'hours')
7071
setEndDate(moment(end).format(dateFormat))
7172
}
7273

7374
return (
74-
<div className={styles.container} key={phaseIndex}>
75+
<div className={styles.container}>
7576
<div className={styles.row}>
7677
<div className={cn(styles.field, styles.col1, styles.phaseName)}>
7778
<label htmlFor={`${phase.name}`}>{phase.name} :</label>
@@ -118,13 +119,12 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
118119
readOnly ? (
119120
<span className={styles.readOnlyValue}>{duration}</span>
120121
)
121-
: (
122-
<input
123-
min={0}
124-
type='number'
125-
value={Number(duration).toString()}
126-
onChange={onDurationChange}
127-
/>)}
122+
: <DurationInput
123+
duration={duration}
124+
name={phase.name}
125+
onDurationChange={onDurationChange}
126+
index={phaseIndex}
127+
/>}
128128
</div>
129129
</div>
130130
</div>

0 commit comments

Comments
 (0)