Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filtering and search in user admin table
Browse files Browse the repository at this point in the history
Toxin4 committed Nov 6, 2024
1 parent aaab729 commit 5016173
Showing 6 changed files with 52 additions and 1 deletion.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions src/api/userApi.ts
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ const updatePassword = () => {
const getUsers = (
params: {
searchName: string;
searchEmail: string;
filterOutRoles?: Roles[];
nameSpaceSlug: string;
canAssignUsers: boolean;
52 changes: 51 additions & 1 deletion src/components/adminArea/AdminTabNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import React from "react";
import React, { useCallback, useEffect, useState } 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 {
@@ -16,6 +29,42 @@ 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
@@ -42,6 +91,7 @@ const AdminTabNavigator = ({ value, handleChange }) => {
{...tabProps(1)}
/>
</TabsNavigatorStyle>
<SearchOverlay />
</Grid>
);
};

0 comments on commit 5016173

Please sign in to comment.