import React from 'react';
import { useFormik } from 'formik'
import store from './Store'
const { uuid } = require('uuidv4')
const AddTodoForm = () => {
const handleSubmit = () => {
store.dispatch({
type: "ADD_TODO", payload: {
todo: {
...formik.values,
started: false,
status: 'Todo',
id: uuid(),
minutes: formik.values.minutes ? formik.values.minutes : 0,
seconds: formik.values.seconds ? formik.values.seconds : 0
}
}
})
formik.resetForm()
}
const formik = useFormik({
initialValues: {
minutes: '',
seconds: '',
description: '',
},
onSubmit: handleSubmit
})
return (
<form className="addTodoForm" onSubmit={formik.handleSubmit}>
<h2>Add a Task</h2>
<div className='inputContainer'>
<label htmlFor="minutes">minutes:</label>
<input type="number" max='59' min='0'
value={formik.values.minutes}
name='minutes'
id='minutes'
onChange={formik.handleChange} />
</div>
<div className='inputContainer'>
<label htmlFor="seconds">seconds:</label>
<input type="number" max='59' min='0'
onChange={formik.handleChange}
value={formik.values.seconds}
name='seconds'
id='seconds' />
</div>
<div className='inputContainer'>
<label htmlFor="description">description:</label>
<input type="text"
onChange={formik.handleChange}
value={formik.values.description}
name='description'
id='description' />
</div>
<button type="submit" className='btn submitForm'> submit</button>
</form>
);
}
export default AddTodoForm;
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}