Updated the MasterCorporate with the improved queries
This commit is contained in:
@@ -80,7 +80,7 @@ export default function UserList({
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (users) {
|
||||
if (users && users.length > 0) {
|
||||
const filteredUsers = filters.reduce((d, f) => d.filter(f), users);
|
||||
const sortedUsers = await asyncSorter<User>(filteredUsers, sortFunction);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {getLinkedUsers} from "@/utils/users.be";
|
||||
import {Type} from "@/interfaces/user";
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -12,6 +13,14 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
const users = await getLinkedUsers(req.session.user?.id, req.session.user?.type);
|
||||
const {page, size, type} = req.query as {page?: string; size?: string; type?: Type};
|
||||
const users = await getLinkedUsers(
|
||||
req.session.user?.id,
|
||||
req.session.user?.type,
|
||||
type,
|
||||
page !== undefined ? parseInt(page) : undefined,
|
||||
size !== undefined ? parseInt(size) : undefined,
|
||||
);
|
||||
|
||||
res.status(200).json(users);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import Head from "next/head";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import {ToastContainer} from "react-toastify";
|
||||
import Layout from "@/components/High/Layout";
|
||||
import CodeGenerator from "./(admin)/CodeGenerator";
|
||||
@@ -28,6 +27,7 @@ import {User} from "@/interfaces/user";
|
||||
import {getUserPermissions} from "@/utils/permissions.be";
|
||||
import {Permission, PermissionType} from "@/interfaces/permissions";
|
||||
import {getUsers} from "@/utils/users.be";
|
||||
import useUsers from "@/hooks/useUsers";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
const user = req.session.user;
|
||||
@@ -50,21 +50,20 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
}
|
||||
|
||||
const permissions = await getUserPermissions(user.id);
|
||||
const users = await getUsers();
|
||||
|
||||
return {
|
||||
props: {user, permissions, users},
|
||||
props: {user, permissions},
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
interface Props {
|
||||
user: User;
|
||||
users: User[];
|
||||
permissions: PermissionType[];
|
||||
}
|
||||
|
||||
export default function Admin({user, users, permissions}: Props) {
|
||||
export default function Admin({user, permissions}: Props) {
|
||||
const {gradingSystem, mutate} = useGradingSystem();
|
||||
const {users} = useUsers();
|
||||
|
||||
const [modalOpen, setModalOpen] = useState<string>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user