-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from Ansh101112/announcement
Announcement Feat Added
- Loading branch information
Showing
7 changed files
with
170 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,10 @@ const AdminD = () => { | |
navigate("/user/settings"); | ||
}; | ||
|
||
const handleAnnounce = () => { | ||
navigate("/admin/announcement"); | ||
}; | ||
|
||
const handleManageDatabase = () => { | ||
window.open( | ||
"mongodb+srv://usha15322:SmartSaver%[email protected]/", | ||
|
@@ -186,6 +190,7 @@ const AdminD = () => { | |
<ul> | ||
{announcements.map((announcement) => ( | ||
<li key={announcement.id} className="py-2 border-b"> | ||
{announcement.title} | ||
{announcement.message} | ||
</li> | ||
))} | ||
|
@@ -245,8 +250,16 @@ const AdminD = () => { | |
</tbody> | ||
</table> | ||
</div> | ||
|
||
<div className="px-3 py-4 m-3 shadow-md rounded-lg"> | ||
<div className="px-3 py-2 border-b shadow-md rounded-lg"> | ||
<h3>Create Announcements</h3> | ||
<button | ||
className="rounded-lg bg-blue-500 px-4 m-2 justify-center align-item-center py-2 text-white hover:bg-green-600" | ||
onClick={handleAnnounce} | ||
> | ||
Announncements | ||
</button> | ||
</div> | ||
<div className=" py-4 m-3 shadow-md rounded-lg"> | ||
<h3>Manage Database</h3> | ||
<button | ||
className="rounded-lg bg-blue-500 px-4 m-2 justify-center align-item-center py-2 text-white hover:bg-blue-600" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import React, { useState } from "react"; | ||
import Navbar from "./Navbar"; | ||
import { toast, ToastContainer } from "react-toastify"; | ||
import "react-toastify/dist/ReactToastify.css"; | ||
import Footer from "./Footer"; | ||
import axios from "axios"; | ||
|
||
const Announcement = () => { | ||
const [announcement, setAnnouncement] = useState({ | ||
title: "", | ||
message: "", | ||
}); | ||
|
||
const handleChange = (e) => { | ||
const { name, value } = e.target; | ||
setAnnouncement({ | ||
...announcement, | ||
[name]: value, | ||
}); | ||
}; | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
|
||
try { | ||
const response = await axios.post( | ||
"http://localhost:6352/announcements", | ||
announcement | ||
); | ||
|
||
if (response.status === 200) { | ||
toast.success("Alert Raised successfully."); | ||
setAnnouncement({ title: "", message: "" }); | ||
} else { | ||
toast.error("Error posting announcement"); | ||
} | ||
} catch (error) { | ||
console.error("Error:", error); | ||
alert("Error posting announcement"); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Navbar></Navbar> | ||
|
||
<div className="max-w-md mx-auto mt-10"> | ||
|
||
<form | ||
onSubmit={handleSubmit} | ||
className="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4" | ||
> | ||
<h2>Create Announcements</h2> | ||
<div className="mb-4"> | ||
<label | ||
className="block text-gray-700 text-sm font-bold mb-2" | ||
htmlFor="title" | ||
> | ||
Title | ||
</label> | ||
<input | ||
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" | ||
id="title" | ||
type="text" | ||
name="title" | ||
value={announcement.title} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="mb-6"> | ||
<label | ||
className="block text-gray-700 text-sm font-bold mb-2" | ||
htmlFor="message" | ||
> | ||
Message | ||
</label> | ||
<textarea | ||
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" | ||
id="message" | ||
name="message" | ||
value={announcement.message} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="flex items-center justify-between"> | ||
<button | ||
className="bg-green-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" | ||
type="submit" | ||
> | ||
Post Announcement | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
<Footer></Footer> | ||
</> | ||
); | ||
}; | ||
|
||
export default Announcement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters