1
+ import React from 'react' ;
2
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
3
+ import { faCalendar , faExclamationTriangle } from '@fortawesome/free-solid-svg-icons' ;
4
+
5
+ export default class TaskForm extends React . Component {
6
+ constructor ( props ) {
7
+ super ( props ) ;
8
+ this . state = {
9
+ taskname : '' ,
10
+ taskdesciption : '' ,
11
+ date : null ,
12
+ urgent : false ,
13
+ status : 'todo'
14
+ }
15
+ this . initialState = this . state ;
16
+ }
17
+
18
+ handleChange = ( e ) => {
19
+ const { name, value, type, checked } = e . target ;
20
+ const result = type === 'checkbox' ? checked : value ;
21
+ this . setState ( { [ name ] : result } )
22
+ }
23
+
24
+ handleClearForm = ( ) => {
25
+ this . setState ( { ...this . initialState } )
26
+ }
27
+
28
+ handleAddTask = ( ) => {
29
+ const { taskName, taskdesciption, date, urgent, status } = this . state ;
30
+ if ( taskName && date !== null ) {
31
+ console . log ( this . state )
32
+ }
33
+
34
+ }
35
+
36
+ render ( ) {
37
+ return (
38
+ < div className = "card" style = { { marginTop : '20px' } } >
39
+ < div className = "card-body" >
40
+ < div className = "form-group" >
41
+ < h4 > Add Task</ h4 >
42
+ < label > Task name< span className = "text-muted" > *</ span > </ label >
43
+ < input
44
+ name = "taskname"
45
+ onChange = { this . handleChange }
46
+ value = { this . state . taskname }
47
+ className = "form-control"
48
+ placeholder = "Enter task name" />
49
+ < small className = "form-text text-muted" >
50
+ Это поле обязательное для заполнения
51
+ </ small >
52
+ </ div >
53
+
54
+ < div className = "form-group" >
55
+ < label > Task description</ label >
56
+ < textarea
57
+ name = "taskdesciption"
58
+ onChange = { this . handleChange }
59
+ value = { this . state . taskdesciption }
60
+ className = "form-control"
61
+ rows = "3"
62
+ style = { { resize : "none" } }
63
+ />
64
+ < small className = "form-text text-muted" > </ small >
65
+ </ div >
66
+
67
+ < div className = "form-group" >
68
+ < label > Task date< span className = "text-muted" > *</ span > </ label >
69
+ < div className = "input-group" >
70
+ < div className = "input-group-prepend" >
71
+ < span className = "input-group-text" >
72
+ < FontAwesomeIcon icon = { faCalendar } />
73
+ </ span >
74
+ </ div >
75
+ < input
76
+ readOnly
77
+ type = "text"
78
+ className = "form-control"
79
+ placeholder = "Date"
80
+ />
81
+ </ div >
82
+ < small className = "form-text text-muted"
83
+ > Это поле обязательное для заполнения</ small >
84
+ </ div >
85
+
86
+ < div className = "form-group form-check" >
87
+ < input
88
+ name = "urgent"
89
+ checked = { this . state . urgent }
90
+ onChange = { this . handleChange }
91
+ type = "checkbox"
92
+ className = "form-check-input"
93
+ />
94
+ < label className = "form-check-label" >
95
+ < FontAwesomeIcon icon = { faExclamationTriangle } /> Urgent
96
+ </ label >
97
+ </ div >
98
+
99
+ < div className = "form-group" >
100
+ < label > Select status</ label >
101
+ < select
102
+ className = "form-control"
103
+ name = 'status'
104
+ value = { this . state . status }
105
+ onChange = { this . handleChange } >
106
+ < option value = "todo" > To do</ option >
107
+ < option value = "inprogress" > In progress</ option >
108
+ < option value = "done" > Done</ option >
109
+ </ select >
110
+ </ div >
111
+
112
+ < div className = "row" >
113
+ < div className = "col-sm-6" >
114
+ < button
115
+ type = "submit"
116
+ className = "btn btn-primary"
117
+ onClick = { this . handleAddTask }
118
+ >
119
+ Add new task
120
+ </ button >
121
+ </ div >
122
+ < div className = "col-sm-6" >
123
+ < button
124
+ type = "submit"
125
+ className = "btn btn-secondary"
126
+ onClick = { this . handleClearForm }
127
+ >
128
+ Clear form
129
+ </ button >
130
+ </ div >
131
+ </ div >
132
+ </ div >
133
+ </ div >
134
+ )
135
+ }
136
+ }
0 commit comments