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 (
diff --git a/frontend/src/pages/Admin/Components/Contact/Contact.jsx b/frontend/src/pages/Admin/Components/Contact/Contact.jsx index 95b71feb..43781700 100644 --- a/frontend/src/pages/Admin/Components/Contact/Contact.jsx +++ b/frontend/src/pages/Admin/Components/Contact/Contact.jsx @@ -5,12 +5,20 @@ 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`, { + setIsLoaded(true); + try{ + const response = await fetch(`${END_POINT}/contactus/getcontactus`, { method: "GET", headers: { "Content-Type": "application/json", @@ -19,8 +27,58 @@ 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) => { + 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 +86,25 @@ export function Contact() { return (