From addd7d49e6fbd8f3623946fba237f658a508877a Mon Sep 17 00:00:00 2001 From: Rahul-538 Date: Fri, 26 Apr 2024 10:46:58 +0530 Subject: [PATCH 1/6] Added search feature based on active status in user details tab in admin --- src/ui/pages/container/Admin/UserDetail.jsx | 49 ++++++--------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/src/ui/pages/container/Admin/UserDetail.jsx b/src/ui/pages/container/Admin/UserDetail.jsx index 10554cdd2..bc19f77ee 100644 --- a/src/ui/pages/container/Admin/UserDetail.jsx +++ b/src/ui/pages/container/Admin/UserDetail.jsx @@ -125,41 +125,18 @@ const UserDetail = (props) => { const pageSearch = () => { return UserDetail.filter((el) => { - if (SearchUserDetail == "") { - return el; - } else if ( - el.email?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) - ) { - return el; - }else if( - el.username?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) - ){ - return el; - } else if ( - el.first_name?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) - ) { - return el; - }else if( - el.is_active?.toString() - ?.toLowerCase() - .includes(SearchUserDetail?.toLowerCase()) - ){ - return el; - } else if ( - el.last_name?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) - ) { - return el; - } else if ( - el.participation_type - .toString() - ?.toLowerCase() - .includes(SearchUserDetail?.toLowerCase()) - ) { - return el; - } else if ( - el.languages?.some((val) => - val?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) - ) + const searchValue = SearchUserDetail.toLowerCase(); + if ( + searchValue === "" || + el.email?.toLowerCase().includes(searchValue) || + el.username?.toLowerCase().includes(searchValue) || + el.first_name?.toLowerCase().includes(searchValue) || + el.last_name?.toLowerCase().includes(searchValue) || + el.participation_type.toString().toLowerCase().includes(searchValue) || + el.languages?.some((val) => val?.toLowerCase().includes(searchValue)) || + ((el.is_active === true && searchValue === "active") || + (el.is_active === false && searchValue === "not active")) || + (searchValue === "not" && !el.is_active) // Recommend "not active" when searching for "not" ) { return el; } @@ -395,4 +372,4 @@ const UserDetail = (props) => { ); }; -export default UserDetail; +export default UserDetail; \ No newline at end of file From f9f2fde798b9ee90ec9e3aa0d70c0dd06fc668e7 Mon Sep 17 00:00:00 2001 From: Rahul-538 Date: Thu, 16 May 2024 13:06:06 +0530 Subject: [PATCH 2/6] added filtering based on active/inactive status in admin/userdetails tab --- src/ui/pages/container/Admin/UserDetail.jsx | 94 +++++++++++++++++---- 1 file changed, 78 insertions(+), 16 deletions(-) diff --git a/src/ui/pages/container/Admin/UserDetail.jsx b/src/ui/pages/container/Admin/UserDetail.jsx index bc19f77ee..5dbd58cb3 100644 --- a/src/ui/pages/container/Admin/UserDetail.jsx +++ b/src/ui/pages/container/Admin/UserDetail.jsx @@ -3,7 +3,7 @@ import MUIDataTable from "mui-datatables"; import { useNavigate } from "react-router-dom"; import APITransport from "../../../../redux/actions/apitransport/apitransport"; import { useDispatch, useSelector } from "react-redux"; -import { ThemeProvider, Grid, IconButton } from "@mui/material"; +import { ThemeProvider, Grid, IconButton, Switch } from "@mui/material"; import tableTheme from "../../../theme/tableTheme"; import CustomizedSnackbars from "../../component/common/Snackbar"; import Search from "../../component/common/Search"; @@ -68,8 +68,9 @@ const UserDetail = (props) => { participation_type, role, is_active, + openDialog = true, ) => { - setOpenDialog(true); + setOpenDialog(openDialog); setId(id); setEmail(email); setUserName(username); @@ -123,25 +124,72 @@ const UserDetail = (props) => { handleCloseDialog(); }; + const handleToggleIsActive = async (id, data) => { + setLoading(true); + const UserObj = new GetUserDetailUpdateAPI(id, data); + const res = await fetch(UserObj.apiEndPoint(), { + method: "PATCH", + body: JSON.stringify(UserObj.getBody()), + headers: UserObj.getHeaders().headers, + }); + const resp = await res.json(); + setLoading(false); + if (res.ok) { + setSnackbarInfo({ + open: true, + message: resp?.message, + variant: "success", + }); + } else { + setSnackbarInfo({ + open: true, + message: resp?.message, + variant: "error", + }); + } + }; const pageSearch = () => { return UserDetail.filter((el) => { - const searchValue = SearchUserDetail.toLowerCase(); - if ( - searchValue === "" || - el.email?.toLowerCase().includes(searchValue) || - el.username?.toLowerCase().includes(searchValue) || - el.first_name?.toLowerCase().includes(searchValue) || - el.last_name?.toLowerCase().includes(searchValue) || - el.participation_type.toString().toLowerCase().includes(searchValue) || - el.languages?.some((val) => val?.toLowerCase().includes(searchValue)) || - ((el.is_active === true && searchValue === "active") || - (el.is_active === false && searchValue === "not active")) || - (searchValue === "not" && !el.is_active) // Recommend "not active" when searching for "not" + const isActive = el.is_active ? "active" : "inactive"; + if (SearchUserDetail == "") { + return el; + } else if ( + el.email?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) + ) { + return el; + }else if( + el.username?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) + ){ + return el; + } else if ( + el.first_name?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) + ) { + return el; + }else if ( + SearchUserDetail.toLowerCase() === "active" && el.is_active || + SearchUserDetail.toLowerCase() === "inactive" && !el.is_active + ) { + return el; + } else if ( + el.last_name?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) + ) { + return el; + } else if ( + el.participation_type + .toString() + ?.toLowerCase() + .includes(SearchUserDetail?.toLowerCase()) + ) { + return el; + } else if ( + el.languages?.some((val) => + val?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) + ) ) { return el; } }); - }; + }; const columns = [ { @@ -257,7 +305,21 @@ const UserDetail = (props) => { el.languages.join(", "), el.participation_type, userRoleFromList ? userRoleFromList : el.role, - el.is_active==true?"Active":"Not Active", + { + handleToggleIsActive(el.id, { + email: el.email, + username: el.username, + first_name: el.first_name, + last_name: el.last_name, + languages: el.languages, + participation_type: el.participation_type, + role: el.role, + is_active: !el.is_active, + }) + }} + />, <>
From a87760e86b03fb97dc787a49d29165ab1e4bfc7a Mon Sep 17 00:00:00 2001 From: Rahul-538 Date: Thu, 16 May 2024 13:07:36 +0530 Subject: [PATCH 3/6] Removed active status dropdown from edituser page --- src/ui/pages/container/Admin/EditProfile.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/pages/container/Admin/EditProfile.jsx b/src/ui/pages/container/Admin/EditProfile.jsx index 1f426adfa..f9b96c780 100644 --- a/src/ui/pages/container/Admin/EditProfile.jsx +++ b/src/ui/pages/container/Admin/EditProfile.jsx @@ -230,7 +230,7 @@ const EditProfile = (props) => { - + {/* Active_status - + */} From dbba7fa58183e3067a0461dfafd5f0a99c864a0b Mon Sep 17 00:00:00 2001 From: Rahul Kumar <142306874+Rahul-538@users.noreply.github.com> Date: Fri, 17 May 2024 10:04:43 +0530 Subject: [PATCH 4/6] Added active/inactive filter in admin --- src/ui/pages/container/Admin/UserDetail.jsx | 442 +------------------- 1 file changed, 1 insertion(+), 441 deletions(-) diff --git a/src/ui/pages/container/Admin/UserDetail.jsx b/src/ui/pages/container/Admin/UserDetail.jsx index b15e5fc4f..af3f37174 100644 --- a/src/ui/pages/container/Admin/UserDetail.jsx +++ b/src/ui/pages/container/Admin/UserDetail.jsx @@ -1,443 +1,3 @@ -// import React, { useState, useEffect } from "react"; -// import MUIDataTable from "mui-datatables"; -// import { useNavigate } from "react-router-dom"; -// import APITransport from "../../../../redux/actions/apitransport/apitransport"; -// import { useDispatch, useSelector } from "react-redux"; -// import { ThemeProvider, Grid, IconButton, Switch } from "@mui/material"; -// import tableTheme from "../../../theme/tableTheme"; -// import CustomizedSnackbars from "../../component/common/Snackbar"; -// import Search from "../../component/common/Search"; -// import GetUserDetailAPI from "../../../../redux/actions/api/Admin/UserDetail"; -// import UserMappedByRole from "../../../../utils/UserMappedByRole/UserMappedByRole"; -// import EditOutlinedIcon from "@mui/icons-material/EditOutlined"; -// import VisibilityIcon from '@mui/icons-material/Visibility'; -// import UserInfo from "./UserInfo"; -// import Spinner from "../../component/common/Spinner"; -// import GetUserDetailUpdateAPI from "../../../../redux/actions/api/Admin/EditProfile"; -// import { el } from "date-fns/locale"; - -// const UserDetail = (props) => { -// const dispatch = useDispatch(); -// const navigate = useNavigate(); -// const [loading, setLoading] = useState(false); -// const [snackbar, setSnackbarInfo] = useState({ -// open: false, -// message: "", -// variant: "success", -// }); -// const [openDialog, setOpenDialog] = useState(false); -// const [id, setId] = useState(""); -// const [userName,setUserName] = useState(""); -// const [email, setEmail] = useState(""); -// const [active, setActive] = useState(); -// const [firstName, setFirstName] = useState(""); -// const [lastName, setLastName] = useState(""); -// const [language, setLanguage] = useState([]); -// const [participationType, setParticipationType] = useState(""); -// const [Role, setRole] = useState(""); - -// const UserDetail = useSelector((state) => state.getUserDetails.data); -// console.log(UserDetail); -// const apiLoading = useSelector((state) => state.apiStatus.loading); -// const SearchUserDetail = useSelector( -// (state) => state.SearchProjectCards.data -// ); -// const getUserDetail = () => { -// setLoading(true); -// const UserObj = new GetUserDetailAPI(); -// dispatch(APITransport(UserObj)); -// }; - -// useEffect(() => { -// getUserDetail(); -// }, []); - -// useEffect(() => { -// if (UserDetail.length > 0) { -// setLoading(false); -// } -// }, [UserDetail]); - -// const handleEditChange = ( -// id, -// email, -// username, -// first_name, -// last_name, -// languages, -// participation_type, -// role, -// is_active, -// openDialog = true, -// ) => { -// setOpenDialog(openDialog); -// setId(id); -// setEmail(email); -// setUserName(username); -// setFirstName(first_name); -// setLastName(last_name); -// setLanguage(languages); -// setParticipationType(participation_type); -// setRole(role); -// setActive(is_active); -// }; - -// const handleCloseDialog = () => { -// setOpenDialog(false); -// }; - -// const handleUpdateEditProfile = async () => { -// const data = { -// email:email, -// username: userName, -// first_name: firstName, -// last_name: lastName, -// languages: language, -// participation_type: participationType, -// role: Role, -// is_active: active, -// }; - -// const UserObj = new GetUserDetailUpdateAPI(id, data); -// // dispatch(APITransport(UserObj)); -// const res = await fetch(UserObj.apiEndPoint(), { -// method: "PATCH", -// body: JSON.stringify(UserObj.getBody()), -// headers: UserObj.getHeaders().headers, -// }); -// const resp = await res.json(); -// setLoading(false); -// if (res.ok) { -// setSnackbarInfo({ -// open: true, -// message: resp?.message, -// variant: "success", -// }); -// getUserDetail(); -// } else { -// setSnackbarInfo({ -// open: true, -// message: resp?.message, -// variant: "error", -// }); -// } -// handleCloseDialog(); -// }; - -// const handleToggleIsActive = async (id, data) => { -// setLoading(true); -// const UserObj = new GetUserDetailUpdateAPI(id, data); -// const res = await fetch(UserObj.apiEndPoint(), { -// method: "PATCH", -// body: JSON.stringify(UserObj.getBody()), -// headers: UserObj.getHeaders().headers, -// }); -// const resp = await res.json(); -// setLoading(false); -// if (res.ok) { -// setSnackbarInfo({ -// open: true, -// message: resp?.message, -// variant: "success", -// }); -// } else { -// setSnackbarInfo({ -// open: true, -// message: resp?.message, -// variant: "error", -// }); -// } -// }; - -// const pageSearch = () => { -// return UserDetail.filter((el) => { -// // const isActive = el.is_active ? "active" : "inactive"; -// if (SearchUserDetail == "") { -// return el; -// } else if ( -// el.email?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) -// ) { -// return el; -// }else if( -// el.username?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) -// ){ -// return el; -// } else if ( -// el.first_name?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) -// ) { -// return el; -// }else if ( -// SearchUserDetail.toLowerCase() === "active" && el.is_active || -// SearchUserDetail.toLowerCase() === "inactive" && !el.is_active -// ) { -// return el; -// } else if ( -// el.last_name?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) -// ) { -// return el; -// } else if ( -// el.participation_type -// .toString() -// ?.toLowerCase() -// .includes(SearchUserDetail?.toLowerCase()) -// ) { -// return el; -// } else if ( -// el.languages?.some((val) => -// val?.toLowerCase().includes(SearchUserDetail?.toLowerCase()) -// ) -// ) { -// return el; -// } -// }); -// }; - -// const columns = [ -// { -// name: "id", -// label: "Id", -// options: { -// display: false, -// filter: false, -// sort: false, -// align: "center", -// }, -// }, -// { -// name: "email", -// label: "Email", -// options: { -// filter: false, -// sort: false, -// align: "center", -// }, -// }, -// { -// name: "username", -// label: "UserName", -// options: { -// filter: false, -// sort: false, -// align: "center", -// }, -// }, -// { -// name: "first_name", -// label: "First Name", -// options: { -// filter: false, -// sort: false, -// align: "center", -// }, -// }, -// { -// name: "last_name", -// label: "Last Name", -// options: { -// filter: false, -// sort: false, -// align: "center", -// setCellProps: () => ({ style: { paddingLeft: "30px" } }), -// }, -// }, -// { -// name: "languages", -// label: "Languages", -// options: { -// filter: false, -// sort: false, -// align: "center", -// setCellProps: () => ({ style: { paddingLeft: "30px" } }), -// }, -// }, -// { -// name: "participation_type", -// label: "Participation Type", -// options: { -// filter: false, -// sort: false, -// align: "center", -// setCellProps: () => ({ style: { paddingLeft: "40px" , paddingRight: "30px" } }), -// }, -// }, -// { -// name: "role", -// label: "Role", -// options: { -// filter: false, -// sort: false, -// align: "center", -// }, -// }, -// { -// name: "is_active", -// label: "Active Status", -// options: { -// filter: false, -// sort: false, -// align: "center", -// setCellProps: () => ({ style: { paddingLeft: "30px" , paddingRight: "30px"} }), -// }, -// }, -// { -// name: "Actions", -// label: "Actions", -// options: { -// filter: false, -// sort: false, -// align: "center", -// setCellProps: () => ({ style: {paddingLeft: "10px" , paddingRight: "20px"}} ), -// }, -// }, -// ]; - -// const data = -// UserDetail && UserDetail.length > 0 -// ? pageSearch().map((el, i) => { -// const userRoleFromList = -// el.role && UserMappedByRole(el.role)?.element; - -// return [ -// el.id, -// el.email, -// el.username, -// el.first_name, -// el.last_name, -// el.languages.join(", "), -// el.participation_type, -// userRoleFromList ? userRoleFromList : el.role, -// { -// handleToggleIsActive(el.id, { -// email: el.email, -// username: el.username, -// first_name: el.first_name, -// last_name: el.last_name, -// languages: el.languages, -// participation_type: el.participation_type, -// role: el.role, -// is_active: !el.is_active, -// }) -// }} -// />, -// <> -//
-// -// navigate(`/profile/${el.id}`)} /> -// -// -// -// handleEditChange( -// el.id, -// el.email, -// el.username, -// el.first_name, -// el.last_name, -// el.languages, -// el.participation_type, -// el.role, -// el.is_active, -// ) -// } -// /> -// -//
-// , -// ]; -// }) -// : []; - - - - -// const options = { -// textLabels: { -// body: { -// noMatch: "No records", -// }, -// toolbar: { -// search: "Search", -// viewColumns: "View Column", -// }, -// pagination: { rowsPerPage: "Rows per page" }, -// options: { sortDirection: "desc" }, -// }, -// // customToolbar: fetchHeaderButton, -// displaySelectToolbar: false, -// fixedHeader: false, -// filterType: "checkbox", -// download: false, -// print: false, -// rowsPerPageOptions: [10, 25, 50, 100], -// // rowsPerPage: PageInfo.count, -// filter: false, -// // page: PageInfo.page, -// viewColumns: false, -// selectableRows: "none", -// search: false, -// jumpToPage: true, -// }; -// const renderSnackBar = () => { -// return ( -// -// setSnackbarInfo({ open: false, message: "", variant: "" }) -// } -// anchorOrigin={{ vertical: "top", horizontal: "right" }} -// variant={snackbar.variant} -// message={snackbar.message} -// /> -// ); -// }; - -// return ( -//
-// {renderSnackBar()} -// {loading && } -// -// -// -// -// -// - -// {openDialog && ( -// handleCloseDialog()} -// submit={() => handleUpdateEditProfile()} -// Email={email} -// FirstName={firstName} -// userName = {userName} -// setUserName={setUserName} -// active={active} -// setActive={setActive} -// setFirstName={setFirstName} -// LastName={lastName} -// setLastName={setLastName} -// Language={language} -// setLanguage={setLanguage} -// ParticipationType={participationType} -// setParticipationType={setParticipationType} -// Role={Role} -// setRole={setRole} -// /> -// )} -//
-// ); -// }; - -// export default UserDetail; -import React, { useState, useEffect } from "react"; -import MUIDataTable from "mui-datatables"; import { useNavigate } from "react-router-dom"; import APITransport from "../../../../redux/actions/apitransport/apitransport"; import { useDispatch, useSelector } from "react-redux"; @@ -878,4 +438,4 @@ const UserDetail = (props) => { ); }; -export default UserDetail; \ No newline at end of file +export default UserDetail; From 738831a70aba7ea7191fc628edbe75a9c2d0ed4b Mon Sep 17 00:00:00 2001 From: Rahul Kumar <142306874+Rahul-538@users.noreply.github.com> Date: Fri, 17 May 2024 10:14:58 +0530 Subject: [PATCH 5/6] . --- src/ui/pages/container/Admin/UserDetail.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/pages/container/Admin/UserDetail.jsx b/src/ui/pages/container/Admin/UserDetail.jsx index af3f37174..ff593ff27 100644 --- a/src/ui/pages/container/Admin/UserDetail.jsx +++ b/src/ui/pages/container/Admin/UserDetail.jsx @@ -1,3 +1,5 @@ +import React, { useState, useEffect } from "react"; +import MUIDataTable from "mui-datatables"; import { useNavigate } from "react-router-dom"; import APITransport from "../../../../redux/actions/apitransport/apitransport"; import { useDispatch, useSelector } from "react-redux"; From b50cfb97d1f3a1226c21ad57aa7ebec25312b1b1 Mon Sep 17 00:00:00 2001 From: Rahul Kumar <142306874+Rahul-538@users.noreply.github.com> Date: Fri, 17 May 2024 10:17:05 +0530 Subject: [PATCH 6/6] . --- src/ui/pages/container/Admin/UserDetail.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ui/pages/container/Admin/UserDetail.jsx b/src/ui/pages/container/Admin/UserDetail.jsx index ff593ff27..25a9cb15f 100644 --- a/src/ui/pages/container/Admin/UserDetail.jsx +++ b/src/ui/pages/container/Admin/UserDetail.jsx @@ -439,5 +439,4 @@ const UserDetail = (props) => {
); }; - export default UserDetail;