openly/frontend/src/components/CreatePost.js
2021-03-27 18:41:22 -04:00

61 lines
1.6 KiB
JavaScript

import React, { useState, useEffect } from "react";
const CreatePost = (props) => {
const onSubmit = (e) => {
e.preventDefault();
const requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
body: JSON.stringify({ postid: props.id }),
};
fetch(`${process.env.REACT_APP_API_ENDPOINT}/createpost`, requestOptions)
.then((response) => response.json())
.then((data) => {
console.log(data);
});
};
return (
<div className="container card card-body text-left">
<form onSubmit={onSubmit}>
<div className="form-group">
<h1>Create Post</h1>
<label className="" for="title">
Post Title:{" "}
</label>
<input
type="text"
id="title"
name="title"
className="form-control d-flex"
placeholder="Enter title here..."
></input>
</div>
<div class="form-group">
<label className="" for="title">
Post:
</label>
<textarea
type="text"
id="post-text"
name="post-text"
style={{ height: "400px" }}
className="form-control"
placeholder="Enter text here..."
></textarea>
</div>
<input
className="btn btn-success text-left"
type="submit"
value="Submit"
/>
<br />
</form>
</div>
);
};
export default CreatePost;