generated from lucien/api-template
add: added message sending
This commit is contained in:
parent
4ea8c9f2b3
commit
42eb432b58
5 changed files with 110 additions and 7 deletions
50
front/src/pages/CreateChannel.tsx
Normal file
50
front/src/pages/CreateChannel.tsx
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import axios from "axios";
|
||||
|
||||
|
||||
export default function CreateChannel() {
|
||||
const navigate = useNavigate();
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [token, setToken] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
const localToken = localStorage.getItem("token");
|
||||
if (localToken) setToken(localToken);
|
||||
}, []);
|
||||
|
||||
function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
axios
|
||||
.post("/api/channels/add", { name, description, token })
|
||||
.then(() => {
|
||||
navigate("/");
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err.response.data.message);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Link to="/">Home</Link>
|
||||
<h1>Create Channel</h1>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Description"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
/>
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue