forked from lfrprazeres/alura-studies
-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.tsx
75 lines (71 loc) · 1.84 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import { ITarefa } from '../../types/tarefa';
import Botao from '../Botao';
import style from './Formulario.module.scss';
import { v4 as uuidv4 } from 'uuid';
class Formulario extends React.Component<{
setTarefas: React.Dispatch<React.SetStateAction<ITarefa[]>>
}> {
state = {
tarefa: "",
tempo: "00:00"
}
adicionarTarefa(evento: React.FormEvent<HTMLFormElement>) {
evento.preventDefault();
this.props.setTarefas(tarefasAntigas =>
[
...tarefasAntigas,
{
...this.state,
selecionado: false,
completado: false,
id: uuidv4()
}
]
)
this.setState({
tarefa: "",
tempo: "00:00"
})
}
render() {
return (
<form className={style.novaTarefa} onSubmit={this.adicionarTarefa.bind(this)}>
<div className={style.inputContainer}>
<label htmlFor="tarefa">
Adicione um novo estudo
</label>
<input
type="text"
name="tarefa"
id="tarefa"
value={this.state.tarefa}
onChange={evento => this.setState({ ...this.state, tarefa: evento.target.value })}
placeholder="O que você quer estudar"
required
/>
</div>
<div className={style.inputContainer}>
<label htmlFor="tempo">
Tempo
</label>
<input
type="time"
step="1"
name="tempo"
value={this.state.tempo}
onChange={evento => this.setState({ ...this.state, tempo: evento.target.value })}
id="tempo"
min="00:00:00"
max="01:30:00"
required
/>
</div>
<Botao type="submit">
Adicionar
</Botao>
</form>
)
}
}
export default Formulario;