Skip to content

Commit

Permalink
Adding search tool in user administration table
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizFNJ committed Nov 20, 2024
1 parent 01ee225 commit 17d5e6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 54 deletions.
1 change: 0 additions & 1 deletion src/api/userApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const updatePassword = () => {
const getUsers = (
params: {
searchName: string;
searchEmail: string;
filterOutRoles?: Roles[];
nameSpaceSlug: string;
canAssignUsers: boolean;
Expand Down
14 changes: 13 additions & 1 deletion src/components/PaginetedDataGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataGrid } from "@mui/x-data-grid";
import { DataGrid, GridToolbar } from "@mui/x-data-grid";
import React from "react";

const PaginatedDataGrid = ({ rows, columns, sx }) => {
Expand All @@ -11,6 +11,18 @@ const PaginatedDataGrid = ({ rows, columns, sx }) => {
<DataGrid
rows={rows}
columns={columns}
slots={{ toolbar: GridToolbar }}
slotProps={{
toolbar: {
showQuickFilter: true,
quickFilterProps: { debounceMs: 500 },
printOptions: { disableToolbarButton: true },
csvOptions: { disableToolbarButton: true },
},
}}
disableColumnFilter
disableColumnSelector
disableDensitySelector
paginationModel={paginationModel}
pageSizeOptions={[5, 10, 50]}
onPaginationModelChange={setPaginationModel}
Expand Down
54 changes: 2 additions & 52 deletions src/components/adminArea/AdminTabNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import React, { useCallback, useEffect, useState } from "react";
import React from "react";
import Tab from "@mui/material/Tab";
import { Grid } from "@mui/material";
import DashboardOutlinedIcon from "@mui/icons-material/DashboardOutlined";
import ManageAccountsOutlinedIcon from "@mui/icons-material/ManageAccountsOutlined";
import { useTranslation } from "next-i18next";
import TabsNavigatorStyle from "./TabsNavigator.style";
import SearchOverlay from "../Search/SearchOverlay";
import userApi from "../../api/userApi";

const AdminTabNavigator = ({ value, handleChange }) => {
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const [totalUsers, setTotalUsers] = useState(0);
const [filteredUsers, setFilteredUsers] = useState([]);
const [paginationModel, setPaginationModel] = useState({
page: 0,
pageSize: 10,
});
const [searchName, setSearchName] = useState("");
const [searchEmail, setSearchEmail] = useState("");
const [applyFilters, setApplyFilters] = useState(false);
const [isInitialLoad, setIsInitialLoad] = useState(true);

function tabProps(index: number) {
return {
Expand All @@ -29,42 +16,6 @@ const AdminTabNavigator = ({ value, handleChange }) => {
};
}

const fetchData = useCallback(async () => {
setLoading(true);
try {
const response = await userApi.getUsers(
{
searchName,
searchEmail,
nameSpaceSlug: "",
canAssignUsers: false,
},
t
);
if (response) {
setTotalUsers(response.total);
setFilteredUsers(response.data);
}
} catch (error) {
console.error("Error fetching users:", error);
} finally {
setLoading(false);
}
}, [
paginationModel.page,
paginationModel.pageSize,
searchName,
searchEmail,
]);

useEffect(() => {
if (isInitialLoad || applyFilters) {
fetchData();
if (isInitialLoad) setIsInitialLoad(false);
setApplyFilters(false);
}
}, [applyFilters, fetchData, isInitialLoad]);

return (
<Grid item xs={10} sx={{ borderBottom: 1, borderColor: "divider" }}>
<TabsNavigatorStyle
Expand All @@ -91,9 +42,8 @@ const AdminTabNavigator = ({ value, handleChange }) => {
{...tabProps(1)}
/>
</TabsNavigatorStyle>
<SearchOverlay />
</Grid>
);
};

export default AdminTabNavigator;
export default AdminTabNavigator;

0 comments on commit 17d5e6a

Please sign in to comment.