@@ -4,6 +4,7 @@ import { Moment } from 'moment/moment';
44import moment from 'moment' ;
55import { DeleteFilled } from '@ant-design/icons' ;
66import { observer } from 'mobx-react' ;
7+ import isBefore from 'date-fns/isBefore' ;
78
89import './TimeRangeModal.less' ;
910
@@ -31,10 +32,22 @@ export default observer(function TimeRangeModal({
3132 visible,
3233 onClose,
3334} : TimeRangeModalProps ) {
35+ const [ valid , setValid ] = useState < boolean > ( false ) ;
3436 const [ description , setDescription ] = useState < string > ( '' ) ;
3537 const [ timeRange , setTimeRange ] = useState < Undefined < ITimeRangeModel > > ( ) ;
3638 const timeInProgress = ! taskTime ?. time . end ;
3739
40+ useEffect ( ( ) => {
41+ setValid (
42+ ! ! timeRange ?. start ||
43+ ! ! (
44+ timeRange ?. start &&
45+ timeRange ?. end &&
46+ isBefore ( timeRange ?. start , timeRange ?. end )
47+ )
48+ ) ;
49+ } , [ timeRange ] ) ;
50+
3851 useEffect ( ( ) => {
3952 if ( taskTime ) {
4053 setTimeRange ( { ...taskTime . time } ) ;
@@ -43,7 +56,7 @@ export default observer(function TimeRangeModal({
4356 } , [ taskTime ] ) ;
4457
4558 function handleOk ( ) {
46- if ( taskTime ?. task && timeRange ) {
59+ if ( taskTime ?. task && timeRange ?. start ) {
4760 const { task, index } = taskTime ;
4861 if ( description ) {
4962 timeRange . description = description ;
@@ -78,6 +91,7 @@ export default observer(function TimeRangeModal({
7891 < Modal
7992 title = "Edit time range"
8093 visible = { visible }
94+ okButtonProps = { { disabled : ! valid } }
8195 onOk = { handleOk }
8296 onCancel = { handleCancel }
8397 okText = "Save"
@@ -98,7 +112,7 @@ export default observer(function TimeRangeModal({
98112 < Form . Item label = "Start" labelCol = { { span : 24 } } >
99113 < TimePicker
100114 format = "HH:mm"
101- value = { moment ( timeRange ?. start ) }
115+ value = { timeRange ?. start && moment ( timeRange ?. start ) }
102116 onChange = { onChange ( RangeField . start ) }
103117 />
104118 </ Form . Item >
0 commit comments