@@ -9,6 +9,7 @@ import DateTime from '@nateradebaugh/react-datetime'
99import isAfter from 'date-fns/isAfter'
1010import subDays from 'date-fns/subDays'
1111import '@nateradebaugh/react-datetime/scss/styles.scss'
12+ import DurationInput from '../DurationInput'
1213
1314const dateFormat = 'MM/DD/YYYY HH:mm'
1415const 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