From 646e0f94fc4dec5e2173a1e7f6ae1bca2759ab02 Mon Sep 17 00:00:00 2001 From: Amarnath AS Date: Sun, 10 Mar 2024 16:19:25 +0530 Subject: [PATCH 1/7] admin: sidebar new option added --- client/src/components/Sidebar/Sidebar.jsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/src/components/Sidebar/Sidebar.jsx b/client/src/components/Sidebar/Sidebar.jsx index f718339..2a93101 100644 --- a/client/src/components/Sidebar/Sidebar.jsx +++ b/client/src/components/Sidebar/Sidebar.jsx @@ -3,6 +3,7 @@ import { MdDashboard } from "react-icons/md"; import { FaUsers } from "react-icons/fa"; import { TbFileReport } from "react-icons/tb"; import { IoBody } from "react-icons/io5"; +import { FaBrain } from "react-icons/fa"; function Sidebar() { return ( <> @@ -35,6 +36,12 @@ function Sidebar() { My Body + From 14079768bcd8526719a093a722481290f0e82d50 Mon Sep 17 00:00:00 2001 From: Amarnath AS Date: Sun, 10 Mar 2024 16:21:31 +0530 Subject: [PATCH 2/7] fix:admin rights page upation --- client/src/pages/AdminPages/Rights/Rights.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/pages/AdminPages/Rights/Rights.jsx b/client/src/pages/AdminPages/Rights/Rights.jsx index 0c68e88..fd4699d 100644 --- a/client/src/pages/AdminPages/Rights/Rights.jsx +++ b/client/src/pages/AdminPages/Rights/Rights.jsx @@ -63,7 +63,7 @@ function Rights() {
From 5c3616ed763cbf3547d5b67193e0b7e34d5a598f Mon Sep 17 00:00:00 2001 From: Amarnath AS Date: Sun, 10 Mar 2024 16:26:47 +0530 Subject: [PATCH 4/7] feat: admin mind services implementation --- client/src/Services/mindServices.js | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 client/src/Services/mindServices.js diff --git a/client/src/Services/mindServices.js b/client/src/Services/mindServices.js new file mode 100644 index 0000000..c87f127 --- /dev/null +++ b/client/src/Services/mindServices.js @@ -0,0 +1,37 @@ +import thaliaAPI from "../API/thaliaAPI"; + +export const getMind = async () => { + try { + const response = await thaliaAPI.get('/admin/my-mind', {}, { withCredentials: true }); + return response.data; + } catch (error) { + return error; + } +} + +export const editMind = async (mindDetails, rightId) => { + try { + const response = await thaliaAPI.put(`/admin/my-mind/${rightId}`, mindDetails, { withCredentials: true }); + return response.data; + } catch (error) { + return error; + } +} + +export const createMind = async (mindDetails) => { + try { + const response = await thaliaAPI.post("/admin/my-mind", mindDetails, { withCredentials: true }); + return response.data; + } catch (error) { + return error; + } +} + +export const getDelete = async (mindId) => { + try { + const response = await thaliaAPI.delete(`/admin/my-mind/${mindId}`, {}, { withCredentials: true }); + return response.data; + } catch (error) { + return error; + } +} \ No newline at end of file From ea46bab1eefbf8e0eaa6b3744225439a4f3b5cc9 Mon Sep 17 00:00:00 2001 From: Amarnath AS Date: Sun, 10 Mar 2024 16:30:50 +0530 Subject: [PATCH 5/7] feat: admin new mind topic creation --- client/src/components/AddMind/AddMind.jsx | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 client/src/components/AddMind/AddMind.jsx diff --git a/client/src/components/AddMind/AddMind.jsx b/client/src/components/AddMind/AddMind.jsx new file mode 100644 index 0000000..cc03a40 --- /dev/null +++ b/client/src/components/AddMind/AddMind.jsx @@ -0,0 +1,78 @@ +import { useState } from "react"; +import { Modal } from "flowbite-react"; +import { toast } from "react-toastify"; +import { createMind } from "../../Services/mindServices"; + +function AddMind({ setOpenModal, openModal }) { + const [formData, setFormData] = useState({ + name: "", + content: "", + }); + const handleChange = (e) => { + const { name, value } = e.target; + setFormData({ + ...formData, + [name]: value, + }); + }; + + const handleCreate = async () => { + if (!formData.name || !formData.content) { + return; + } + try { + const response = await createMind(formData); + if (response.success === true) { + formData.name = ""; + formData.content = ""; + toast.success(response.message); + setOpenModal(false); + } + } catch (error) { + console.log("Error occurred", error); + } + }; + return ( + <> + setOpenModal(false)}> + +

Add New Mind

+
+ +
+ +
+
+ +
+ +
+
+ + ); +} +export default AddMind; From 931514712e6f6e88323f11ee4c79b60fad1fe083 Mon Sep 17 00:00:00 2001 From: Amarnath AS Date: Sun, 10 Mar 2024 16:32:05 +0530 Subject: [PATCH 6/7] feat: admin mind edit --- client/src/components/EditMind/EditMind.jsx | 79 +++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 client/src/components/EditMind/EditMind.jsx diff --git a/client/src/components/EditMind/EditMind.jsx b/client/src/components/EditMind/EditMind.jsx new file mode 100644 index 0000000..e59b826 --- /dev/null +++ b/client/src/components/EditMind/EditMind.jsx @@ -0,0 +1,79 @@ +import { Modal } from "flowbite-react"; +import { useEffect, useState } from "react"; +import { toast } from "react-toastify"; +import { editMind } from "../../Services/mindServices"; + +function EditMind({ setOpenModal, openModal, mindDetails }) { + const [formData, setFormData] = useState({ + name: "", + content: "", + }); + useEffect(() => { + console.log(mindDetails); + if (mindDetails) { + setFormData({ + name: mindDetails?.name || "", + content: mindDetails?.content || "", + }); + } + }, [mindDetails]); + const handleChange = (e) => { + const { name, value } = e.target; + setFormData((prevData) => ({ + ...prevData, + [name]: value, + })); + }; + const handleEdit = async () => { + const response = await editMind(formData, mindDetails?._id); + if (response.success === true) { + toast.success(response.message); + formData.name = ""; + formData.content = ""; + setOpenModal(false); + } + }; + return ( + <> + setOpenModal(false)}> + +

Add New Mind

+
+ +
+ +
+
+ +
+ +
+
+ + ); +} +export default EditMind; From 7095e11a06d17673698ab871d31c99066c5ccb32 Mon Sep 17 00:00:00 2001 From: Amarnath AS Date: Sun, 10 Mar 2024 16:32:57 +0530 Subject: [PATCH 7/7] feat: admin my mind controller --- client/src/pages/AdminPages/MyMind/MyMind.jsx | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 client/src/pages/AdminPages/MyMind/MyMind.jsx diff --git a/client/src/pages/AdminPages/MyMind/MyMind.jsx b/client/src/pages/AdminPages/MyMind/MyMind.jsx new file mode 100644 index 0000000..d891bad --- /dev/null +++ b/client/src/pages/AdminPages/MyMind/MyMind.jsx @@ -0,0 +1,141 @@ +import { useEffect } from "react"; +import { useState } from "react"; +import { toast } from "react-toastify"; +import EditMind from "../../../components/EditMind/EditMind"; +import AddMind from "../../../components/AddMind/AddMind"; +import { getDelete } from "../../../Services/mindServices"; +import { getMind } from "../../../Services/mindServices"; +import timeFormat from "../../../utils/timeFormat"; + +function MyMind() { + const [openModal, setOpenModal] = useState(false); + const [mindDetails, setmindDetails] = useState([]); + + const [editMind, setEditMind] = useState(); + const [mindModal, setMindModal] = useState(false); + + const handleModal = () => { + setOpenModal(true); + }; + const handleEditModal = (mindId) => { + setMindModal(true); + const mindToEdit = mindDetails.find((mind) => { + return mind?._id === mindId; + }); + console.log(mindToEdit); + setEditMind(mindToEdit); + }; + useEffect(() => { + const getMindData = async () => { + const response = await getMind(); + if (response.success === true) { + console.log(response.contents); + setmindDetails(response.contents); + } + }; + getMindData(); + }, [ + setOpenModal, + setMindModal, + openModal, + mindModal, + setmindDetails, + setEditMind, + ]); + const handleDelete = async (mindId) => { + const response = await getDelete(mindId); + if (response.success === true) { + setmindDetails((prevDetails) => + prevDetails.filter((mind) => mind._id !== mindId) + ); + toast.success(response.message); + } + }; + return ( + <> + + +
+
+ {/* Text Components */} +
+
+

Mind Management

+
+
+ +
+
+ {/* Table Component */} +
+ <> + + + + + + + + + + {mindDetails.map((mind, index) => { + return ( + <> + + + + + + + + + + ); + })} +
+ No + + Name + + Date + + Edit or Delete +
+ {index + 1} + {mind?.name} + {timeFormat(mind?.createdAt)} + + + +
+ +
+
+
+ + ); +} + +export default MyMind;