mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-28 16:20:34 +08:00
Fixing some lint errors with the new admin features
This commit is contained in:
@@ -27,7 +27,7 @@ const UsersCell = () => {
|
||||
// Fetch and save the users.
|
||||
// This follows useSWR's recommendation for simple pagination:
|
||||
// https://swr.vercel.app/docs/pagination#when-to-use-useswr
|
||||
const { isLoading } = useSWR(`/api/admin/users?pageIndex=${pageIndex}`, fetcher, {
|
||||
useSWR(`/api/admin/users?pageIndex=${pageIndex}`, fetcher, {
|
||||
onSuccess: setUsers,
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getToken } from "next-auth/jwt";
|
||||
* Wraps any API Route handler and verifies that the user has the appropriate
|
||||
* role before running the handler. Returns a 403 otherwise.
|
||||
*/
|
||||
const withRole = (role: string, handler: (arg0: NextApiRequest, arg1: NextApiResponse<any>) => any) => {
|
||||
const withRole = (role: string, handler: (arg0: NextApiRequest, arg1: NextApiResponse) => void) => {
|
||||
return async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const token = await getToken({ req });
|
||||
if (!token || token.role !== role) {
|
||||
|
||||
@@ -26,7 +26,7 @@ const AdminIndex = () => {
|
||||
return;
|
||||
}
|
||||
router.push("/");
|
||||
}, [session, status]);
|
||||
}, [router, session, status]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Box, Button, Container, Flex, FormControl, FormLabel, Input, Select, useToast } from "@chakra-ui/react";
|
||||
import { Button, Container, FormControl, FormLabel, Input, Select, useToast } from "@chakra-ui/react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
@@ -27,7 +27,7 @@ const ManageUser = ({ user }) => {
|
||||
return;
|
||||
}
|
||||
router.push("/");
|
||||
}, [session, status]);
|
||||
}, [router, session, status]);
|
||||
|
||||
// Trigger to let us update the user's role. Triggers a toast when complete.
|
||||
const { trigger } = useSWRMutation("/api/admin/update_user", poster, {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import withRole from "src/lib/auth";
|
||||
import prisma from "src/lib/prismadb";
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import withRole from "src/lib/auth";
|
||||
import prisma from "src/lib/prismadb";
|
||||
|
||||
@@ -15,7 +14,7 @@ const handler = withRole("admin", async (req, res) => {
|
||||
// Note: with Prisma this isn't the most efficient but it's the only possible
|
||||
// option with cuid based User IDs.
|
||||
const { pageIndex } = req.query;
|
||||
const skip = pageIndex * PAGE_SIZE;
|
||||
const skip = parseInt(pageIndex as string) * PAGE_SIZE || 0;
|
||||
|
||||
// Fetch 20 users.
|
||||
const users = await prisma.user.findMany({
|
||||
|
||||
Reference in New Issue
Block a user