@@ -9,6 +9,7 @@ import DateTime from '@nateradebaugh/react-datetime'
9
9
import isAfter from 'date-fns/isAfter'
10
10
import subDays from 'date-fns/subDays'
11
11
import '@nateradebaugh/react-datetime/scss/styles.scss'
12
+ import DurationInput from '../DurationInput'
12
13
13
14
const dateFormat = 'MM/DD/YYYY HH:mm'
14
15
const MAX_LENGTH = 5
@@ -22,7 +23,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
22
23
if ( phase ) {
23
24
setStartDate ( phase . scheduledStartDate )
24
25
setEndDate ( phase . scheduledEndDate )
25
- setDuration ( moment ( phase . scheduledEndDate ) . diff ( phase . scheduledStartDate , 'seconds ' ) )
26
+ setDuration ( moment ( phase . scheduledEndDate ) . diff ( phase . scheduledStartDate , 'hours ' ) )
26
27
}
27
28
} , [ ] )
28
29
@@ -46,7 +47,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
46
47
}
47
48
48
49
setStartDate ( moment ( e ) . format ( dateFormat ) )
49
- setDuration ( moment ( end ) . diff ( start , 'seconds ' ) )
50
+ setDuration ( moment ( end ) . diff ( start , 'hours ' ) )
50
51
}
51
52
52
53
const onEndDateChange = ( e ) => {
@@ -58,20 +59,20 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
58
59
}
59
60
60
61
setEndDate ( moment ( e ) . format ( dateFormat ) )
61
- setDuration ( moment ( end ) . diff ( start , 'seconds ' ) )
62
+ setDuration ( moment ( end ) . diff ( start , 'hours ' ) )
62
63
}
63
64
64
65
const onDurationChange = ( e ) => {
65
- if ( e . target . value . length > MAX_LENGTH ) return null
66
+ if ( e . length > MAX_LENGTH ) return null
66
67
67
- const dur = parseInt ( e . target . value || 0 )
68
+ const dur = parseInt ( e || 0 )
68
69
setDuration ( dur )
69
- const end = moment ( startDate ) . add ( duration , 'seconds ' )
70
+ const end = moment ( startDate ) . add ( dur , 'hours ' )
70
71
setEndDate ( moment ( end ) . format ( dateFormat ) )
71
72
}
72
73
73
74
return (
74
- < div className = { styles . container } key = { phaseIndex } >
75
+ < div className = { styles . container } >
75
76
< div className = { styles . row } >
76
77
< div className = { cn ( styles . field , styles . col1 , styles . phaseName ) } >
77
78
< label htmlFor = { `${ phase . name } ` } > { phase . name } :</ label >
@@ -118,13 +119,12 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
118
119
readOnly ? (
119
120
< span className = { styles . readOnlyValue } > { duration } </ span >
120
121
)
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
+ /> }
128
128
</ div >
129
129
</ div >
130
130
</ div >
0 commit comments