mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-09-11 11:50:17 +08:00
Adding a very rudimentary admin page that displays a table of users and their basic information
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useEffect } from "react";
|
||||
import { getTransparentHeaderLayout } from "src/components/Layout";
|
||||
import UsersCell from "src/components/UsersCell";
|
||||
|
||||
/**
|
||||
* Provides the admin index page that will display a list of users and give
|
||||
* admins the ability to manage their access rights.
|
||||
*/
|
||||
const AdminIndex = () => {
|
||||
const router = useRouter();
|
||||
const { data: session, status } = useSession();
|
||||
|
||||
// Check when the user session is loaded and re-route if the user is not an
|
||||
// admin. This follows the suggestion by NextJS for handling private pages:
|
||||
// https://nextjs.org/docs/api-reference/next/router#usage
|
||||
//
|
||||
// All admin pages should use the same check and routing steps.
|
||||
useEffect(() => {
|
||||
if (status === "loading") {
|
||||
return;
|
||||
}
|
||||
if (session?.user?.role === "admin") {
|
||||
return;
|
||||
}
|
||||
router.push("/");
|
||||
}, [session, status]);
|
||||
|
||||
// While loading, just show something.
|
||||
if (status === "loading") {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Open Assistant</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="Conversational AI for everyone. An open source project to create a chat enabled GPT LLM run by LAION and contributors around the world."
|
||||
/>
|
||||
</Head>
|
||||
<main className="oa-basic-theme">loading...</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// Show the final page.
|
||||
// TODO(#237): Display a component that fetches actual user data.
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Open Assistant</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="Conversational AI for everyone. An open source project to create a chat enabled GPT LLM run by LAION and contributors around the world."
|
||||
/>
|
||||
</Head>
|
||||
<main className="oa-basic-theme">
|
||||
<UsersCell />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
AdminIndex.getLayout = getTransparentHeaderLayout;
|
||||
|
||||
export default AdminIndex;
|
||||
Reference in New Issue
Block a user