-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCreate.js
More file actions
98 lines (89 loc) · 3.02 KB
/
Create.js
File metadata and controls
98 lines (89 loc) · 3.02 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
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
import "./Create.css";
import { useState } from "react";
import { useHistory } from "react-router-dom";
import 'bootstrap/dist/css/bootstrap.min.css';
const Create = () => {
const [title, setTitle] = useState("");
const [thumbnail, setThumbnail] = useState("");
const [description, setDescription] = useState("");
const [body, setBody] = useState("");
const history = useHistory();
function handleSubmit(e) {
e.preventDefault();
const blog = { title, description, body };
fetch(process.env.REACT_APP_BASE_API + "api/blogs", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(blog),
}).then(() => {
alert("Blog added successfully!");
history.push("/api/blogs");
});
}
return (
<div className="create">
<center>
<h1 className="title">Go on write your Blog!</h1>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Category
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">Food</a></li>
<li><a class="dropdown-item" href="#">Music</a></li>
<li><a class="dropdown-item" href="#">Travel</a></li>
</ul>
</div>
<form>
<input
type="text"
className="form-control blog-title-detail blog-form"
id="formGroupExampleInput"
placeholder="Give a title to your blog"
name="title"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
{/* TODO - handle image upload */}
{/* <input type="file"
name="thumbnail"
value={ thumbnail }
onChange = {(e) => setThumbnail(e.target.value)}
className="form-control file-input blog-form"
id="inputGroupFile02"
placeholder="Select image for thumbnail"/> */}
<textarea
className="form-control desc-input blog-form"
id="exampleFormControlTextarea1"
rows="3"
placeholder="Describe your blog in short"
name="description"
value={description}
onChange={(e) => setDescription(e.target.value)}
required
></textarea>
<textarea
className="form-control blog-input blog-form"
id="exampleFormControlTextarea1"
rows="3"
placeholder="Write your blog post here"
name="body"
value={body}
onChange={(e) => setBody(e.target.value)}
required
></textarea>
<br />
<button
onClick={handleSubmit}
type="button"
className="btn btn-primary"
>
Post Blog
</button>
</form>
</center>
</div>
);
};
export default Create;