diff --git a/admin/src/pages/ContactMessages.tsx b/admin/src/pages/ContactMessages.tsx index 9c74662..d9d63a8 100644 --- a/admin/src/pages/ContactMessages.tsx +++ b/admin/src/pages/ContactMessages.tsx @@ -9,6 +9,7 @@ import '../styles/Model.css' import { ColorRing } from 'react-loader-spinner'; import { MdMessage } from "react-icons/md"; import { TbReportAnalytics } from "react-icons/tb"; +import toast from "react-hot-toast"; const ContactMessages = () => { const [contactMessages, setContactMessages] = useState([]); @@ -59,6 +60,21 @@ const ContactMessages = () => { } }; + const handleDeleteMessage = async (id: string) => { + try { + await axios.delete(`/api/v1/admin/deletecontactmessage/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + setContactMessages(contactMessages.filter((msg) => msg.id !== id)); + toast.success("Contact Message deleted successfully !") + } catch (error) { + console.error("Error deleting message:", error); + toast.error("Error in deleting message") + } + }; + const handleOpenModal = (message: IContactMessage) => { setSelectedMessage(message); setOpen(true); @@ -114,7 +130,7 @@ const ContactMessages = () => { {new Date(contactMessage.createdAt).toLocaleDateString()} {contactMessage.subject.slice(0, 10)} {contactMessage.message.slice(0, 10)} - + ))} diff --git a/backend/src/routes/admin/controller.ts b/backend/src/routes/admin/controller.ts index d4bfdbc..78f0365 100644 --- a/backend/src/routes/admin/controller.ts +++ b/backend/src/routes/admin/controller.ts @@ -1088,4 +1088,23 @@ export const downloadFavoritesReportController = async (req: Request, res: Respo error: "An unexpected exception occurred!", }); } +}; + +export const deleteContactMessage = async (req: Request, res: Response) => { + const { id } = req.params; + + try { + const deletedMessage = await prisma.contactMessage.delete({ + where: { id }, + }); + + res.status(200).json({ + message: "Contact message deleted successfully!", + deletedMessage, + }); + } catch (error) { + res.status(500).json({ + error: "An error occurred while deleting the contact message!", + }); + } }; \ No newline at end of file diff --git a/backend/src/routes/admin/route.ts b/backend/src/routes/admin/route.ts index 2483c73..6388864 100644 --- a/backend/src/routes/admin/route.ts +++ b/backend/src/routes/admin/route.ts @@ -1,5 +1,5 @@ import {Router} from 'express'; -import { getPostReactionsController,getFavoritesController,adminLoginController, adminProfileController, allUserForAdmin, blockUserController, unblockUserController, getAdminPostsController, getAdminTrendingPostsController, getAdminStatsController, getGraphsStatsController, updatePostController, deletePostController, getPostByIdController, getAllContactMessages, deleteCommentController, downloadReportController, getFeedbacks, toggleFeedbackVisibility, downloadCommentsReportController, downloadFavoritesReportController, downloadReactionsReportController, downloadUsersReportController, downloadContactMessagesReportController, downloadPostsReportController } from './controller'; +import { getPostReactionsController,getFavoritesController,adminLoginController, adminProfileController, allUserForAdmin, blockUserController, unblockUserController, getAdminPostsController, getAdminTrendingPostsController, getAdminStatsController, getGraphsStatsController, updatePostController, deletePostController, getPostByIdController, getAllContactMessages, deleteCommentController, downloadReportController, getFeedbacks, toggleFeedbackVisibility, downloadCommentsReportController, downloadFavoritesReportController, downloadReactionsReportController, downloadUsersReportController, downloadContactMessagesReportController, downloadPostsReportController, deleteContactMessage } from './controller'; import { isAdmin } from '../../middleware/adminAuth'; const adminRouter = Router(); @@ -54,4 +54,6 @@ adminRouter.get("/downloadusersfavoritesreport", downloadFavoritesReportControll adminRouter.get("/downloadusersreactionreport", downloadReactionsReportController); +adminRouter.delete("/deletecontactmessage/:id", isAdmin, deleteContactMessage); + export default adminRouter; \ No newline at end of file