From 562cafe4014debac76fb6bb3ac22db435c1f3166 Mon Sep 17 00:00:00 2001 From: Hemu21 Date: Mon, 20 May 2024 08:23:54 +0530 Subject: [PATCH 1/2] delete contact us --- .../Admin/Components/Contact/Card/Card.jsx | 4 +- .../Admin/Components/Contact/Contact.jsx | 58 +++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/Admin/Components/Contact/Card/Card.jsx b/frontend/src/pages/Admin/Components/Contact/Card/Card.jsx index 0d1c236b..83532169 100644 --- a/frontend/src/pages/Admin/Components/Contact/Card/Card.jsx +++ b/frontend/src/pages/Admin/Components/Contact/Card/Card.jsx @@ -1,6 +1,6 @@ import style from "./card.module.scss"; -export function Card({ content: { email, message, name, subject } }) { +export function Card({ content: { email, message, name, subject }, id , handleDelete }) { return (
@@ -12,7 +12,7 @@ export function Card({ content: { email, message, name, subject } }) { - +
diff --git a/frontend/src/pages/Admin/Components/Contact/Contact.jsx b/frontend/src/pages/Admin/Components/Contact/Contact.jsx index 95b71feb..2ff330e2 100644 --- a/frontend/src/pages/Admin/Components/Contact/Contact.jsx +++ b/frontend/src/pages/Admin/Components/Contact/Contact.jsx @@ -5,12 +5,18 @@ import Grid from "@material-ui/core/Grid"; import { Card } from "./Card/index.js"; import style from "./contactus.module.scss"; import Loader from "../../../../components/util/Loader"; +import { SimpleToast } from "../../../../components/util/Toast/Toast.jsx"; export function Contact() { const [contactUsData, setContactUsData] = useState([]); const [isLoaded, setIsLoaded] = useState(false); + const [toast, setToast] = useState({ + toastStatus: false, + toastType: "", + toastMessage: "", + }); const fetchJoinUs = async () => { - const response = await fetch(`${END_POINT}/getContactUs`, { + const response = await fetch(`${END_POINT}/contactus/getcontactus`, { method: "GET", headers: { "Content-Type": "application/json", @@ -21,6 +27,42 @@ export function Contact() { setContactUsData(data.ContactUs); setIsLoaded(false); }; + const handleCloseToast = (event, reason) => { + if (reason === "clickaway") { + return; + } + setToast({ ...toast, toastStatus: false }); + }; + const handleDelete = async (id) => { + try { + const url = `${END_POINT}/contactus/deleteContactUs`; + const response = await fetch(url, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${localStorage.getItem("token")}`, + }, + body: JSON.stringify({ contactUsId: id }), + }); + + const data = await response.json(); + setToast({ + ...toast, + toastMessage: "Successfully deleted!", + toastStatus: true, + toastType: "success", + }); + fetchJoinUs() + } catch (error) { + console.log(error); + setToast({ + ...toast, + toastMessage: "Unable to delete!", + toastStatus: true, + toastType: "error", + }); + } + }; useEffect(() => { setIsLoaded(true); fetchJoinUs(); @@ -28,17 +70,25 @@ export function Contact() { return (

Contact Us

-
{isLoaded ? : null}
+ {isLoaded ?
:
{contactUsData && contactUsData.map((data) => { - return ; + return ; })} -
+
} + {toast.toastStatus && ( + + )} ); } From d7d567783ce993154f420db0d3e1759449eed7e8 Mon Sep 17 00:00:00 2001 From: Hemanth kumar Date: Mon, 20 May 2024 21:09:41 +0530 Subject: [PATCH 2/2] Update Contact.jsx --- .../pages/Admin/Components/Contact/Contact.jsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frontend/src/pages/Admin/Components/Contact/Contact.jsx b/frontend/src/pages/Admin/Components/Contact/Contact.jsx index 2ff330e2..43781700 100644 --- a/frontend/src/pages/Admin/Components/Contact/Contact.jsx +++ b/frontend/src/pages/Admin/Components/Contact/Contact.jsx @@ -16,6 +16,8 @@ export function Contact() { toastMessage: "", }); const fetchJoinUs = async () => { + setIsLoaded(true); + try{ const response = await fetch(`${END_POINT}/contactus/getcontactus`, { method: "GET", headers: { @@ -25,6 +27,20 @@ export function Contact() { }); const data = await response.json(); setContactUsData(data.ContactUs); + setToast({ + ...toast, + toastMessage: "Successfully get data!", + toastStatus: true, + toastType: "success", + }); + }catch(error){ + setToast({ + ...toast, + toastMessage: "Unable to get data!", + toastStatus: true, + toastType: "error", + }); + } setIsLoaded(false); }; const handleCloseToast = (event, reason) => {