Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Admin client community management (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
amarnath-dev authored Mar 10, 2024
2 parents d8eb28f + a9b0ea5 commit 23a75d4
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 1 deletion.
26 changes: 25 additions & 1 deletion client/src/Services/communityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const getComments = async (id) => {
}
}


export const newCommunity = createAsyncThunk(
"community/newCommunity",
async (payload, thunkAPI) => {
Expand Down Expand Up @@ -75,6 +74,31 @@ export const getMyCommunity = createAsyncThunk(
return thunkAPI.rejectWithValue(payload)
}
})
//New Services
export const getCommunitys = async () => {
try {
const response = await thaliaAPI.get('/admin/community', { withCredentials: true })
return response.data;
} catch (error) {
console.log(error)
}
}
export const blockCommunitys = async (communityId) => {
try {
const response = await thaliaAPI.put(`/admin/community/block/${communityId}`, { withCredentials: true })
return response.data;
} catch (error) {
console.log(error)
}
}
export const UnblockCommunitys = async (communityId) => {
try {
const response = await thaliaAPI.put(`/admin/community/unblock/${communityId}`, { withCredentials: true })
return response.data;
} catch (error) {
console.log(error)
}
}

export const getAllCommunity = createAsyncThunk(
"community/getAllCommunity",
Expand Down
7 changes: 7 additions & 0 deletions client/src/components/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FaUsers } from "react-icons/fa";
import { TbFileReport } from "react-icons/tb";
import { IoBody } from "react-icons/io5";
import { FaBrain } from "react-icons/fa";
import { MdGroups3 } from "react-icons/md";
function Sidebar() {
return (
<>
Expand Down Expand Up @@ -42,6 +43,12 @@ function Sidebar() {
My Mind
</button>
</Link>
<Link className="ml-4 font-bold text-gray-500" to={"/admin/community"}>
<button className="flex items-center px-4 py-2 rounded-md w-full mt-8 hover:bg-gray-800">
<MdGroups3 className="text-primary" />
Community
</button>
</Link>
</div>
</div>
</>
Expand Down
138 changes: 138 additions & 0 deletions client/src/pages/AdminPages/Community/CommunityAdmin.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// import CheckReport from "../../../components/CheckReport/CheckReport";
import { useState, useEffect } from "react";
import { toast } from "react-toastify";
import { getCommunitys } from "../../../Services/communityService";
import { UnblockCommunitys } from "../../../Services/communityService";
import { blockCommunitys } from "../../../Services/communityService";

function Community() {
const [community, setCommunity] = useState([]);
// const [openModal, setOpenModal] = useState(false);
// const [communityReport, setCommunityReport] = useState([]);

// const handleModal = (communityId) => {
// const community = community.find((community) => {
// return community._id === communityId;
// });
// setCommunityReport(community.reports);
// setOpenModal(true);
// };
useEffect(() => {
const fetchCommunities = async () => {
const response = await getCommunitys();
if (response.success === true) {
setCommunity(response?.community);
}
};
fetchCommunities();
}, [setCommunity]);

const handleBlock = async (communityId) => {
const response = await blockCommunitys(communityId);
if (response?.success === true) {
const updatedCommunity = community.map((community) => {
if (community?._id === communityId) {
return { ...community, is_blocked: true };
}
return community;
});
setCommunity(updatedCommunity);
toast(response?.message);
}
};
const handleUnBlock = async (communityId) => {
const response = await UnblockCommunitys(communityId);
if (response?.success === true) {
const updatedCommunity = community.map((community) => {
if (community._id === communityId) {
return { ...community, is_blocked: false };
}
return community;
});
setCommunity(updatedCommunity);
toast(response?.message);
}
};
return (
<>
{/* <CheckReport
openModal={openModal}
setOpenModal={setOpenModal}
community={community}
/> */}
<div className=" h-screen bg-background">
<div className="col-span-9">
<div className="text-text">
<h1 className="text-2xl py-12">Community Managment</h1>
<div>
<table className="w-full text-sm text-left rtl:text-right rounded">
<thead className="text-xs bg-secondary rounded">
<tr>
<th scope="col" className="px-6 py-3 text-primary">
No
</th>
<th scope="col" className="px-6 py-3 text-primary">
Name
</th>
<th scope="col" className="px-6 py-3 text-primary">
Reports
</th>
<th scope="col" className="px-6 py-3 text-primary">
View Reports
</th>
<th scope="col" className="px-6 py-3 text-primary">
Block/Unblock
</th>
</tr>
</thead>
{community?.map((community, index) => {
return (
<>
<tbody key={index}>
<tr className="border-b border-gray-600">
<th scope="row" className="px-6 py-4 font-medium">
{index + 1}
</th>
<td className="px-6 py-4">{community?.email}</td>
<td className="px-6 py-4">
{community?.community_name}
</td>
<td className="px-6 py-4">
<button
className="border border-gray-600 bg-gray-700 py-1 px-6 rounded"
// onClick={() => handleModal(user?._id)}
>
View
</button>
</td>
<td className="px-6 py-4">
{community?.is_blocked ? (
<button
className="border py-1 px-4 rounded hover:bg-green-700"
onClick={() => handleUnBlock(community?._id)}
>
UnBlock
</button>
) : (
<button
className="border py-1 px-6 rounded hover:bg-red-700"
onClick={() => handleBlock(community?._id)}
>
Block
</button>
)}
</td>
</tr>
</tbody>
</>
);
})}
</table>
</div>
</div>
</div>
</div>
</>
);
}
export default Community;
4 changes: 4 additions & 0 deletions client/src/routes/AdminRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const Rights = lazy(() => import("../pages/AdminPages/Rights/Rights"));
const Sidebar = lazy(() => import("../components/Sidebar/Sidebar"));
const MyBody = lazy(() => import("../pages/AdminPages/MyBody/MyBody"));
const MyMind = lazy(() => import("../pages/AdminPages/MyMind/MyMind"));
const CommunityAdmin = lazy(() =>
import("../pages/AdminPages/Community/CommunityAdmin")
);

export default function AdminRoute() {
return (
Expand All @@ -24,6 +27,7 @@ export default function AdminRoute() {
<Route path={"/rights"} element={<Rights />} />
<Route path={"/body"} element={<MyBody />} />
<Route path={"/mind"} element={<MyMind />} />
<Route path={"/community"} element={<CommunityAdmin />} />
</Routes>
</Suspense>
</div>
Expand Down

0 comments on commit 23a75d4

Please sign in to comment.