1
1
import React , { useState , useEffect } from 'react' ;
2
2
import { useDispatch , useSelector } from 'react-redux' ;
3
3
import { message , Col , Row , Select } from 'antd' ;
4
- import { Form , Input } from 'formik-antd' ;
4
+ import { Form , Input , DatePicker } from 'formik-antd' ;
5
5
import { Formik } from 'formik' ;
6
6
import * as Yup from 'yup' ;
7
7
import PropTypes from 'prop-types' ;
8
+ import moment from 'moment' ;
9
+
8
10
import { API } from '../../services' ;
9
11
import { FormActionButtons } from '../FormActionButtons' ;
10
12
import { TODO_LABEL } from '../../helpers/' ;
@@ -14,18 +16,19 @@ const { Option } = Select;
14
16
const TodoSchema = Yup . object ( {
15
17
title : Yup . string ( ) . required ( 'Title required' ) ,
16
18
description : Yup . string ( ) . required ( 'Description required' ) ,
17
- // dueDate: Yup.number ().required('Duedate code required'),
19
+ dueDate : Yup . string ( ) . required ( 'Duedate required' ) ,
18
20
label : Yup . number ( ) . required ( 'Label code required' ) ,
19
21
} ) ;
20
22
21
23
function TodoForm ( { onClose, editMode, editableTodo } ) {
22
24
const dispatch = useDispatch ( ) ;
25
+ const [ dueDate , setDueDate ] = useState ( ) ;
23
26
24
27
const initialValues = {
25
28
title : editMode ? editableTodo . title : undefined ,
26
29
description : editMode ? editableTodo . description : undefined ,
27
- dueDate : editMode ? editableTodo . phone : undefined ,
28
- label : editMode ? editableTodo . label : undefined ,
30
+ dueDate : editMode ? editableTodo . phone : moment ( ) ,
31
+ label : editMode ? editableTodo . label : 3 ,
29
32
} ;
30
33
31
34
function handleSubmit ( values , { setErrors, resetForm, setSubmitting } ) {
@@ -48,7 +51,12 @@ function TodoForm({ onClose, editMode, editableTodo }) {
48
51
const CREDENTIALS = {
49
52
url,
50
53
method : editMode ? 'put' : 'post' ,
51
- data : values ,
54
+ data : {
55
+ ...values ,
56
+ dueDate : moment ( values . dueDate , 'DD-MM-YYYY' ) . format (
57
+ 'YYYY-MM-DD'
58
+ ) ,
59
+ } ,
52
60
setErrors,
53
61
} ;
54
62
@@ -102,6 +110,33 @@ function TodoForm({ onClose, editMode, editableTodo }) {
102
110
</ Form . Item >
103
111
</ Col >
104
112
</ Row >
113
+ < Row >
114
+ < Col span = { 24 } >
115
+ { /* <label className="ant-form-item-label">
116
+ Duedate
117
+ </label> */ }
118
+ < Form . Item
119
+ name = "dueDate"
120
+ label = "Duedate"
121
+ hasFeedback = { true }
122
+ showValidateSuccess = { true }
123
+ >
124
+ < DatePicker
125
+ value = { dueDate }
126
+ name = "dueDate"
127
+ onChange = { ( date , dateString ) => {
128
+ setDueDate ( date ) ;
129
+ setFieldValue ( 'dueDate' , dateString ) ;
130
+ } }
131
+ format = "DD-MM-YYYY"
132
+ disabledDate = { ( current ) => {
133
+ return current && current < moment ( ) ;
134
+ } }
135
+ style = { { width : '100%' } }
136
+ />
137
+ </ Form . Item >
138
+ </ Col >
139
+ </ Row >
105
140
< Row gutter = { 8 } >
106
141
< Col span = { 24 } >
107
142
< Form . Item
0 commit comments