Newer
Older

Lucendio
committed
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
import React, { Component } from 'react';
import { MDBContainer, MDBRow, MDBCol, MDBInput } from "mdbreact";
import { addTodo } from '../../utils/APICalls'
import WelcomeHeader from '../WelcomeHeader/WelcomeHeader'
import './AddTodo.css'
class AddTodo extends Component {
state = {
title: '',
description: '',
done: false,
important: false,
titleError: false,
errMessage: ''
}
validateInput = () => {
return (!this.state.title) ? false : true
}
handleTitleChange = (e) => {
this.setState({
title: e.target.value,
titleError: false
})
}
handleDescriptionChange = (e) => {
this.setState({ description: e.target.value })
}
resetInput = () => {
this.setState({
title: '',
description: '',
})
}
handleAddTodo = () => {
this.setState({ errMessage: '' })
if (this.validateInput()) {
addTodo(this.state.title, this.state.description)
.then(todo => {
this.props.addTodo({
title: this.state.title,
description: this.state.description,
important: false,
done: false,
_id: todo.todo._id
})
this.resetInput()
})
.catch(error => {
this.setState({ errMessage: error.data.message })
})
}
else {
this.setState({
titleError: true
})
}
}
render() {
const { userName, signout } = this.props
return (
<MDBContainer className="add-todo-main">
<WelcomeHeader userName={userName} signout={signout} />
<MDBRow>
<MDBCol>
<MDBInput
value={this.state.title}
onChange={this.handleTitleChange}
label="ToDo Title"
id="todoTitle" /* required for the label to be associated (for="") with the input */

Lucendio
committed
background
size={(this.state.titleError) ? "lg inputErrorDiv" : "lg"}
className={(this.state.titleError) ? "inputError" : ""}
maxLength={100}
/>
{
(this.state.titleError) && <span className="error-text"> ToDo Title cannot be blank.</span>
}
</MDBCol>
</MDBRow>
<MDBRow>
<MDBCol>
<MDBInput
value={this.state.description}
onChange={this.handleDescriptionChange}
type="textarea"
label="ToDo Description"
id="todoDescription" /* required for the label to be associated (for="") with the input */

Lucendio
committed
background
maxLength={250}
/>
</MDBCol>
</MDBRow>
<MDBRow>
<MDBCol className="align-right">
<button type="button" onClick={this.resetInput} className="btn btn-outline-info-modified waves-effect">Reset</button>
<button type="button" onClick={this.handleAddTodo} className="btn btn-outline-info-modified waves-effect">Add</button>
</MDBCol>
</MDBRow>
</MDBContainer>
);
}
}
export default AddTodo;