@@ -9,7 +9,7 @@ import moment from 'moment';
99
1010import { API } from '../../services' ;
1111import { FormActionButtons } from '../FormActionButtons' ;
12- import { TODO_LABEL } from '../../helpers/' ;
12+ import { TODO_LABEL } from '../../helpers/constants ' ;
1313
1414const { Option } = Select ;
1515
@@ -20,28 +20,22 @@ const TodoSchema = Yup.object({
2020 label : Yup . number ( ) . required ( 'Label code required' ) ,
2121} ) ;
2222
23+ const TOMORROW = moment ( ) . add ( 1 , 'days' ) ;
24+
2325function TodoForm ( { onClose, editMode, editableTodo } ) {
2426 const dispatch = useDispatch ( ) ;
2527 const [ dueDate , setDueDate ] = useState ( ) ;
28+ const [ todoLabel , setTodoLabel ] = useState ( ) ;
2629
2730 const initialValues = {
2831 title : editMode ? editableTodo . title : undefined ,
2932 description : editMode ? editableTodo . description : undefined ,
30- dueDate : editMode ? editableTodo . phone : moment ( ) ,
33+ dueDate : editMode ? editableTodo . phone : TOMORROW ,
3134 label : editMode ? editableTodo . label : 3 ,
3235 } ;
3336
3437 function handleSubmit ( values , { setErrors, resetForm, setSubmitting } ) {
35- /**
36- * below two keys no needed for post call
37- */
38-
39- // let data = {
40- // ...values,
41- // phone: values.phone.toString(),
42- // };
4338 console . log ( 'values visit' , values ) ;
44-
4539 let url = `todos` ;
4640
4741 if ( editMode ) {
@@ -64,6 +58,8 @@ function TodoForm({ onClose, editMode, editableTodo }) {
6458 . then ( ( ) => {
6559 showSuccessMessage ( values ) ;
6660 resetForm ( ) ;
61+ setTodoLabel ( 1 ) ;
62+ setDueDate ( TOMORROW ) ;
6763 } )
6864 . finally ( ( ) => {
6965 setSubmitting ( false ) ;
@@ -153,26 +149,16 @@ function TodoForm({ onClose, editMode, editableTodo }) {
153149 allowClear = { true }
154150 optionFilterProp = "children"
155151 onChange = { ( data ) => {
152+ console . log ( 'setTodoLabel' , data ) ;
153+ setTodoLabel ( data ) ;
156154 setFieldValue ( 'label' , data ) ;
157155 } }
158- filterOption = { ( input , option ) =>
159- option . props . children
160- . toLowerCase ( )
161- . indexOf ( input . toLowerCase ( ) ) >= 0
162- }
163156 >
164- < Option key = { 1 } value = { 1 } >
165- PERSONAL
166- </ Option >
167- < Option key = { 2 } value = { 2 } >
168- WORK
169- </ Option >
170- < Option key = { 3 } value = { 3 } >
171- SHOPPING
172- </ Option >
173- < Option key = { 4 } value = { 4 } >
174- OTHER
175- </ Option >
157+ { TODO_LABEL . map ( ( { id, key } ) => (
158+ < Option key = { id } value = { id } >
159+ { key }
160+ </ Option >
161+ ) ) }
176162 </ Select >
177163 </ Form . Item >
178164 </ Col >
0 commit comments