Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 48f416c

Browse files
with date post call done
1 parent 22b5bf6 commit 48f416c

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"formik-antd": "^2.0.1",
1616
"js-sha512": "^0.8.0",
1717
"lodash": "^4.17.15",
18+
"moment": "^2.26.0",
1819
"node-sass": "^4.14.1",
1920
"prop-types": "^15.7.2",
2021
"qs": "^6.9.4",
@@ -57,4 +58,4 @@
5758
"devDependencies": {
5859
"env-cmd": "^10.1.0"
5960
}
60-
}
61+
}

src/forms/todo/todo.form.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, { useState, useEffect } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33
import { message, Col, Row, Select } from 'antd';
4-
import { Form, Input } from 'formik-antd';
4+
import { Form, Input, DatePicker } from 'formik-antd';
55
import { Formik } from 'formik';
66
import * as Yup from 'yup';
77
import PropTypes from 'prop-types';
8+
import moment from 'moment';
9+
810
import { API } from '../../services';
911
import { FormActionButtons } from '../FormActionButtons';
1012
import { TODO_LABEL } from '../../helpers/';
@@ -14,18 +16,19 @@ const { Option } = Select;
1416
const 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

2123
function 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

Comments
 (0)