-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpensesForm.js
More file actions
71 lines (70 loc) · 1.63 KB
/
ExpensesForm.js
File metadata and controls
71 lines (70 loc) · 1.63 KB
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
import React from "react";
import moment from "moment";
import { SingleDatePicker } from "react-dates";
import "react-dates/lib/css/_datepicker.css";
export default class ExpenseForm extends React.Component {
state = {
description: "",
note: "",
amount: 0,
createdAt: moment(),
calenderFocused: false
};
onDescriptionChange = e => {
const description = e.target.value;
this.setState(() => ({
description
}));
};
onNoteChange = e => {
const note = e.target.value;
this.setState(() => ({
note
}));
};
onDateChange = createdAt => {
this.setState(() => ({
createdAt
}));
};
onFocusChange = ({ focused }) => {
this.setState(() => ({
calenderFocused: focused
}));
};
onAmountChange = e => {
const amount = e.target.value;
if (amount.match(/^\d*(\.\d{0,2})?$/)) {
this.setState(() => ({
amount
}));
}
};
render() {
return (
<div>
<form>
<input
onChange={this.onDescriptionChange}
type="text"
value={this.state.description}
placeholder="Description"
autoFocus
/>
<input
type="number"
value={this.state.amount}
onChange={this.onAmountChange}
placeholder="Amount"
/>
<SingleDatePicker />
<textarea
type="text"
placeholder="Add a notefor your exppense (optional)"
/>
<button>Add Expenses.</button>
</form>
</div>
);
}
}