Skip to content

Commit 562cafe

Browse files
committed
delete contact us
1 parent b9790b3 commit 562cafe

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

frontend/src/pages/Admin/Components/Contact/Card/Card.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import style from "./card.module.scss";
22

3-
export function Card({ content: { email, message, name, subject } }) {
3+
export function Card({ content: { email, message, name, subject }, id , handleDelete }) {
44
return (
55
<div className={style["card-item"]}>
66
<div className={style["card-info"]}>
@@ -12,7 +12,7 @@ export function Card({ content: { email, message, name, subject } }) {
1212
<a href={`mailto:${email}`}>
1313
<button className={style["button-edit"]}>Reply</button>
1414
</a>
15-
<button className={style["button-delete"]}>Delete</button>
15+
<button name={`${id}`} onClick={(e)=>handleDelete(e.currentTarget.name)} className={style["button-delete"]}>Delete</button>
1616
</div>
1717
</div>
1818
</div>

frontend/src/pages/Admin/Components/Contact/Contact.jsx

+54-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ import Grid from "@material-ui/core/Grid";
55
import { Card } from "./Card/index.js";
66
import style from "./contactus.module.scss";
77
import Loader from "../../../../components/util/Loader";
8+
import { SimpleToast } from "../../../../components/util/Toast/Toast.jsx";
89

910
export function Contact() {
1011
const [contactUsData, setContactUsData] = useState([]);
1112
const [isLoaded, setIsLoaded] = useState(false);
13+
const [toast, setToast] = useState({
14+
toastStatus: false,
15+
toastType: "",
16+
toastMessage: "",
17+
});
1218
const fetchJoinUs = async () => {
13-
const response = await fetch(`${END_POINT}/getContactUs`, {
19+
const response = await fetch(`${END_POINT}/contactus/getcontactus`, {
1420
method: "GET",
1521
headers: {
1622
"Content-Type": "application/json",
@@ -21,24 +27,68 @@ export function Contact() {
2127
setContactUsData(data.ContactUs);
2228
setIsLoaded(false);
2329
};
30+
const handleCloseToast = (event, reason) => {
31+
if (reason === "clickaway") {
32+
return;
33+
}
34+
setToast({ ...toast, toastStatus: false });
35+
};
36+
const handleDelete = async (id) => {
37+
try {
38+
const url = `${END_POINT}/contactus/deleteContactUs`;
39+
const response = await fetch(url, {
40+
method: "DELETE",
41+
headers: {
42+
"Content-Type": "application/json",
43+
Authorization: `Bearer ${localStorage.getItem("token")}`,
44+
},
45+
body: JSON.stringify({ contactUsId: id }),
46+
});
47+
48+
const data = await response.json();
49+
setToast({
50+
...toast,
51+
toastMessage: "Successfully deleted!",
52+
toastStatus: true,
53+
toastType: "success",
54+
});
55+
fetchJoinUs()
56+
} catch (error) {
57+
console.log(error);
58+
setToast({
59+
...toast,
60+
toastMessage: "Unable to delete!",
61+
toastStatus: true,
62+
toastType: "error",
63+
});
64+
}
65+
};
2466
useEffect(() => {
2567
setIsLoaded(true);
2668
fetchJoinUs();
2769
}, []);
2870
return (
2971
<div>
3072
<h1 style={{ textAlign: "center" }}> Contact Us </h1>
31-
<div className={style["data-loader"]}>{isLoaded ? <Loader /> : null}</div>
73+
{isLoaded ? <div className={style["data-loader"]}><Loader /></div>:
3274
<div className={style["card-container"]}>
3375
<Grid container spacing={2}>
3476
<Grid item>
3577
{contactUsData &&
3678
contactUsData.map((data) => {
37-
return <Card key={data._id} content={data} />;
79+
return <Card key={data._id} id={data._id} handleDelete={handleDelete} content={data} />;
3880
})}
3981
</Grid>
4082
</Grid>
41-
</div>
83+
</div>}
84+
{toast.toastStatus && (
85+
<SimpleToast
86+
open={toast.toastStatus}
87+
message={toast.toastMessage}
88+
handleCloseToast={handleCloseToast}
89+
severity={toast.toastType}
90+
/>
91+
)}
4292
</div>
4393
);
4494
}

0 commit comments

Comments
 (0)