diff --git a/client/src/Services/bodyServices.js b/client/src/Services/bodyServices.js new file mode 100644 index 0000000..950d103 --- /dev/null +++ b/client/src/Services/bodyServices.js @@ -0,0 +1,38 @@ +import thaliaAPI from "../API/thaliaAPI"; + +export const getTopics = async () => { + try { + const response = await thaliaAPI.get("/admin/my-body", { withCredentials: true }); + return response.data; + } catch (error) { + return error; + } +} + +export const addTopic = async (formData) => { + try { + const response = await thaliaAPI.post("/admin/my-body", formData, { withCredentials: true }); + return response.data; + } catch (error) { + return error; + } +} + +export const deleteBody = async (bodyId) => { + try { + const response = await thaliaAPI.delete(`/admin/my-body/${bodyId}`, { withCredentials: true }); + return response.data; + } catch (error) { + return error; + } +} + +export const editBody = async (formData, bodyId) => { + try { + const response = await thaliaAPI.put(`/admin/my-body/${bodyId}`, formData); + return response.data; + } catch (error) { + console.log("error=>", error) + return error; + } +} \ No newline at end of file diff --git a/client/src/Services/rightServices.js b/client/src/Services/rightServices.js index ef248e2..4056d45 100644 --- a/client/src/Services/rightServices.js +++ b/client/src/Services/rightServices.js @@ -10,8 +10,6 @@ export const createRight = async (rightDetails) => { } export const editRight = async (rightDetails, rightId) => { try { - console.log("details", rightDetails) - console.log("right id", rightId) const response = await thaliaAPI.put(`/admin/rights/${rightId}`, rightDetails, { withCredentials: true }); return response.data; } catch (error) { diff --git a/client/src/Services/userService.js b/client/src/Services/userService.js new file mode 100644 index 0000000..e69de29 diff --git a/client/src/components/AddBody/AddBody.jsx b/client/src/components/AddBody/AddBody.jsx index 2a382e9..bd9c9f6 100644 --- a/client/src/components/AddBody/AddBody.jsx +++ b/client/src/components/AddBody/AddBody.jsx @@ -1,10 +1,13 @@ import { useState } from "react"; import { Modal } from "flowbite-react"; +import { addTopic } from "../../Services/bodyServices"; +import { toast } from "react-toastify"; +// eslint-disable-next-line react/prop-types function AddBody({ openModal, setOpenModal }) { const [formData, setFormData] = useState({ - body_name: "", - body_desc: "", + name: "", + content: "", }); const handleChange = (e) => { const { name, value } = e.target; @@ -13,6 +16,18 @@ function AddBody({ openModal, setOpenModal }) { [name]: value, }); }; + const handleAdd = () => { + const addNew = async () => { + const response = await addTopic(formData); + if (response.success === true) { + formData.name = ""; + formData.content = ""; + setOpenModal(false); + toast.success(response.message); + } + }; + addNew(); + }; return ( <> setOpenModal(false)}> @@ -26,9 +41,9 @@ function AddBody({ openModal, setOpenModal }) { @@ -36,8 +51,8 @@ function AddBody({ openModal, setOpenModal }) { - diff --git a/client/src/components/EditBody/EditBody.jsx b/client/src/components/EditBody/EditBody.jsx index 37a2115..f21d876 100644 --- a/client/src/components/EditBody/EditBody.jsx +++ b/client/src/components/EditBody/EditBody.jsx @@ -1,19 +1,22 @@ -import { useState, useEffect } from "react"; import { Modal } from "flowbite-react"; +import { useState, useEffect } from "react"; +import { toast } from "react-toastify"; +import { editBody } from "../../Services/bodyServices"; -function EditBody({ bodyDetails, openModal, setOpenModal }) { +// eslint-disable-next-line react/prop-types +function EditBody({ setOpenModal, openModal, bodyDetails }) { const [formData, setFormData] = useState({ - body_name: "", - body_desc: "", + name: "", + content: "", }); useEffect(() => { if (bodyDetails) { - // eslint-disable-next-line react/prop-types - formData.body_name = bodyDetails?.name; - // eslint-disable-next-line react/prop-types - formData.body_desc = bodyDetails?.description; + setFormData({ + name: bodyDetails?.name || "", + content: bodyDetails?.content || "", + }); } - }, [formData, bodyDetails]); + }, [bodyDetails]); const handleChange = (e) => { const { name, value } = e.target; setFormData({ @@ -21,6 +24,17 @@ function EditBody({ bodyDetails, openModal, setOpenModal }) { [name]: value, }); }; + + const handleEdit = async () => { + const response = await editBody(formData, bodyDetails?._id); + if (response.success === true) { + toast.success(response.message); + formData.name = ""; + formData.content = ""; + setOpenModal(false); + } + }; + return ( <> setOpenModal(false)}> @@ -34,9 +48,9 @@ function EditBody({ bodyDetails, openModal, setOpenModal }) { @@ -44,15 +58,18 @@ function EditBody({ bodyDetails, openModal, setOpenModal }) { - diff --git a/client/src/pages/AdminPages/Managment/Managment.jsx b/client/src/pages/AdminPages/Managment/Managment.jsx index 132c02b..c43ecd8 100644 --- a/client/src/pages/AdminPages/Managment/Managment.jsx +++ b/client/src/pages/AdminPages/Managment/Managment.jsx @@ -5,7 +5,6 @@ function Managment() { const [openModal, setOpenModal] = useState(false); const [reportObject, setReportObject] = useState(); const handleModal = () => { - console.log("Handle Modal Called"); setOpenModal(true); }; return ( @@ -19,7 +18,6 @@ function Managment() {

User Managment

-
@@ -41,28 +39,7 @@ function Managment() { - - - - - - - - - + - - - - - - - - + {bodyDeatails.map((data, index) => { + return ( + <> + + + + + + + + + + ); + })}
- Amarnath as - SilverLaptop - - - -
diff --git a/client/src/pages/AdminPages/MyBody/MyBody.jsx b/client/src/pages/AdminPages/MyBody/MyBody.jsx index 02a0d85..f870ed8 100644 --- a/client/src/pages/AdminPages/MyBody/MyBody.jsx +++ b/client/src/pages/AdminPages/MyBody/MyBody.jsx @@ -1,20 +1,59 @@ -import { useState } from "react"; -import EditRight from "../../../components/EditRight/EditRight"; +import { useEffect, useState } from "react"; +import EditBody from "../../../components/EditBody/EditBody"; import AddBody from "../../../components/AddBody/AddBody"; +import { getTopics } from "../../../Services/bodyServices"; +import { deleteBody } from "../../../Services/bodyServices"; +import timeFormat from "../../../utils/timeFormat"; +import { toast } from "react-toastify"; function MyBody() { const [openModal, setOpenModal] = useState(false); - // eslint-disable-next-line no-unused-vars - const [rightDetails, setRightDetails] = useState(); + const [bodyDeatails, setBodyDetails] = useState([]); + + const [editBody, setEditBody] = useState(); + const [editModal, setEditModal] = useState(false); + const handleModal = () => { setOpenModal(true); }; + const handleEditModal = (bodyId) => { + setEditModal(true); + const bodyToEdit = bodyDeatails.find((body) => { + return body?._id === bodyId; + }); + setEditBody(bodyToEdit); + }; + useEffect(() => { + const getData = async () => { + const response = await getTopics(); + if (response.success === true) { + setBodyDetails(response.contents); + } + }; + getData(); + }, [ + openModal, + setOpenModal, + setBodyDetails, + setEditModal, + editModal, + setEditBody, + ]); + const handleDelete = async (bodyId) => { + const response = await deleteBody(bodyId); + if (response.success === true) { + setBodyDetails((prevDetails) => + prevDetails.filter((body) => body?._id !== bodyId) + ); + toast.success(response.message); + } + }; return ( <> -
@@ -55,26 +94,37 @@ function MyBody() {
- 1 - Dealing with Period Cramps18-03-2003 - - -
+ {index + 1} + {data?.name} + {timeFormat(data.createdAt)} + + + +
diff --git a/client/src/pages/AdminPages/Rights/Rights.jsx b/client/src/pages/AdminPages/Rights/Rights.jsx index 64130f4..8519aca 100644 --- a/client/src/pages/AdminPages/Rights/Rights.jsx +++ b/client/src/pages/AdminPages/Rights/Rights.jsx @@ -24,7 +24,6 @@ function Rights() { setEditRight(rightToEdit); }; useEffect(() => { - console.log("Runnning.."); const getRights = async () => { const response = await getRight(); setRightDetails(response.rights);