From 12017afe525e3d396a84da8cbc2794d3484bcdbe Mon Sep 17 00:00:00 2001 From: Sonika Date: Wed, 27 Dec 2023 12:37:43 +0530 Subject: [PATCH] search feature for intranet screen --- src/App.css | 6 ++ .../intranet_users/IntranetUsers.tsx | 77 ++++++++++++++++--- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/src/App.css b/src/App.css index 5e18b00..ecc8184 100644 --- a/src/App.css +++ b/src/App.css @@ -32,3 +32,9 @@ padding-top: 6.5px !important; padding-bottom: 6.5px !important; } + +.table-header-bottomBorder-style .css-1ygcj2i-MuiTableCell-root{ + /* background-color: #171716 !important; */ + /* color:white ; */ + border-bottom: 1px solid rgb(45 51 59) !important; +} diff --git a/src/components/intranet_users/IntranetUsers.tsx b/src/components/intranet_users/IntranetUsers.tsx index dc17df3..e6aca51 100644 --- a/src/components/intranet_users/IntranetUsers.tsx +++ b/src/components/intranet_users/IntranetUsers.tsx @@ -17,11 +17,14 @@ import { DialogContent, DialogActions, TablePagination, + Grid, + InputAdornment, } from '@mui/material'; -import DeleteIcon from '@mui/icons-material/Delete'; import EditIcon from '@mui/icons-material/Edit'; import AddIcon from '@mui/icons-material/Add'; import { postNewIntranetUsersData } from "../../APIs/IntranetUsersAPIs/postAddUser"; +import { AccountCircle } from "@mui/icons-material"; +import SearchIcon from '@mui/icons-material/Search'; const StyledTextField = (props:any) => ( @@ -52,7 +55,7 @@ const StyledTextField = (props:any) => ( } export default function IntranetUsers(){ - const [manageUsersData,setManageUsersData] = useState() + const [searchByFilterOnBlur,setSearchByFilterOnBlur] = useState() const { data: manageUsersResponse, isLoading, isError } = useGetIntranetUsersData(); const [data, setData] = useState([]); const [open, setOpen] = useState(false); @@ -60,6 +63,20 @@ export default function IntranetUsers(){ const [newRow, setNewRow] = useState(); const [page, setPage] = React.useState(0); const [rowsPerPage, setRowsPerPage] = React.useState(10); + const [filteredData, setFilteredData] = useState([]); + + useEffect(() => { + if (searchByFilterOnBlur) { + // Filter data based on the username + const filtered = manageUsersResponse?.filter((row: any) => + row.username.toLowerCase().includes(searchByFilterOnBlur.toLowerCase()) + ); + setFilteredData(filtered || []); + } else { + // If search input is empty, show all data + setFilteredData(manageUsersResponse || []); + } + }, [searchByFilterOnBlur, manageUsersResponse]); useEffect(()=>{ if (!open){ @@ -125,6 +142,51 @@ export default function IntranetUsers(){ + + + + + + ), + }} + value={searchByFilterOnBlur} + onChange={(e)=>{ + setSearchByFilterOnBlur(e.target.value); + }} + sx={{input: { color: 'white' }, + "& label": { + color: "white" + }, + "& label.Mui-focused": { + color: "white" + }, + "& .MuiInput-underline:after": { + borderBottomColor: "white" + }, + "& .MuiOutlinedInput-root": { + "& fieldset": { + borderColor: "white" + }}, + "&:hover fieldset": { + borderColor: "white", + borderWidth: 2 + }, + "&.Mui-focused fieldset": { + borderColor: "white" + }, + margin:1, + // marginTop:3 + + }} + placeholder="Search..." + /> + + @@ -133,28 +195,25 @@ export default function IntranetUsers(){ New - Name + Name Role Active - {manageUsersResponse && manageUsersResponse.map((row:any) => ( + {filteredData && filteredData.map((row:any) => ( handleEdit(row)} aria-label="edit"> - {/* handleDelete(row.id)} aria-label="delete"> - - */} {row.username} {row.role} {row.active==1? - Active + Active : - Inactive} + Inactive} ))}