-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
124 lines (109 loc) · 3.03 KB
/
index.jsx
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Libraries
import React, { useState } from "react";
import CurrencyFormat from "react-currency-format";
// Styles
import { Wrapper, FormWrap, Submit } from "./addCharity.style";
const AddCharity = ({ addChar }) => {
const [formData, setFormData] = useState({
organization: "",
hashtag: "",
amount: "",
limit: "",
});
const [charities] = useState([
{
name: "Reclaim the Block",
website: "https://secure.everyaction.com/zae4prEeKESHBy0MKXTIcQ2",
},
{
name: "Black Visions Collective",
website: "https://secure.everyaction.com/4omQDAR0oUiUagTu0EG-Ig2",
},
{
name: "Philly Bail Fund",
website: "https://www.phillybailfund.org/donate",
},
]);
const [formMode, setMode] = useState(false);
function submit() {
let org = formData.organization.split(",")
let newEntry = {
organization: org[0],
website: org[1],
amount: parseFloat(formData.amount),
limit: parseInt(formData.limit),
hashtag: formData.hashtag,
};
addChar(newEntry);
setMode(false);
}
const handleInputChange = (e) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value,
});
};
return (
<Wrapper>
{formMode && (
<FormWrap>
<select
name="organization"
value={formData && formData.organization}
onChange={(e) => handleInputChange(e)}
>
<option name="Choose a Charity" value="">
Choose a Charity
</option>
{charities.map((item) => (
<option name={item.name} value={[item.name, item.website]}>
{item.name}
</option>
))}
</select>
<input
name="hashtag"
type="text"
value={formData && formData.hashtag}
placeholder="eg. #blm"
onChange={(e) => handleInputChange(e)}
/>
<CurrencyFormat
thousandSeparator={true}
prefix={"$"}
name="amount"
type="text"
value={formData && formData.amount}
placeholder="$0.01 / hashtag mention"
onValueChange={(values) => {
// Destructuring the value without the '$' prefix and as a float
const { value } = values;
setFormData({
...formData,
amount: value,
});
}}
/>
<input
name="limit"
type="text"
value={formData && formData.limit}
placeholder="limit"
onChange={(e) => handleInputChange(e)}
/>
<Submit onClick={() => submit()}>✓</Submit>
<Submit onClick={() => setMode(false)}>X</Submit>
</FormWrap>
)}
{!formMode && (
<div>
<button onClick={() => setMode(true)}>
✚ Add a new donation
</button>
</div>
)}
</Wrapper>
);
};
export default AddCharity;