11import React , { useState , useEffect } from 'react' ;
22import { useDispatch , useSelector } from 'react-redux' ;
33import { message , Col , Row , Select } from 'antd' ;
4- import { Form , Input } from 'formik-antd' ;
4+ import { Form , Input , DatePicker } from 'formik-antd' ;
55import { Formik } from 'formik' ;
66import * as Yup from 'yup' ;
77import PropTypes from 'prop-types' ;
8+ import moment from 'moment' ;
9+
810import { API } from '../../services' ;
911import { FormActionButtons } from '../FormActionButtons' ;
1012import { TODO_LABEL } from '../../helpers/' ;
@@ -14,18 +16,19 @@ const { Option } = Select;
1416const TodoSchema = Yup . object ( {
1517 title : Yup . string ( ) . required ( 'Title required' ) ,
1618 description : Yup . string ( ) . required ( 'Description required' ) ,
17- // dueDate: Yup.number ().required('Duedate code required'),
19+ dueDate : Yup . string ( ) . required ( 'Duedate required' ) ,
1820 label : Yup . number ( ) . required ( 'Label code required' ) ,
1921} ) ;
2022
2123function TodoForm ( { onClose, editMode, editableTodo } ) {
2224 const dispatch = useDispatch ( ) ;
25+ const [ dueDate , setDueDate ] = useState ( ) ;
2326
2427 const initialValues = {
2528 title : editMode ? editableTodo . title : undefined ,
2629 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 ,
2932 } ;
3033
3134 function handleSubmit ( values , { setErrors, resetForm, setSubmitting } ) {
@@ -48,7 +51,12 @@ function TodoForm({ onClose, editMode, editableTodo }) {
4851 const CREDENTIALS = {
4952 url,
5053 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+ } ,
5260 setErrors,
5361 } ;
5462
@@ -102,6 +110,33 @@ function TodoForm({ onClose, editMode, editableTodo }) {
102110 </ Form . Item >
103111 </ Col >
104112 </ 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 >
105140 < Row gutter = { 8 } >
106141 < Col span = { 24 } >
107142 < Form . Item
0 commit comments