Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { createFileRoute, redirect } from "@tanstack/react-router";
|
|
import { type } from "arktype";
|
|
import { fetchUser } from "../route";
|
|
import type { AppContext } from "~/context";
|
|
import { AdminPage } from "~/client/modules/admin/routes/admin-page";
|
|
import { getAdminUsersOptions, getRegistrationStatusOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
|
|
|
export const Route = createFileRoute("/(dashboard)/admin/")({
|
|
validateSearch: type({ tab: "string?" }),
|
|
component: RouteComponent,
|
|
loader: async ({ context }) => {
|
|
const authContext = await fetchUser();
|
|
|
|
if (authContext.user?.role !== "admin") {
|
|
throw redirect({ to: "/settings" });
|
|
}
|
|
|
|
await Promise.all([
|
|
context.queryClient.ensureQueryData({ ...getAdminUsersOptions() }),
|
|
context.queryClient.ensureQueryData({ ...getRegistrationStatusOptions() }),
|
|
]);
|
|
|
|
return authContext as AppContext;
|
|
},
|
|
staticData: {
|
|
breadcrumb: () => [{ label: "Administration" }],
|
|
},
|
|
});
|
|
|
|
function RouteComponent() {
|
|
const appContext = Route.useLoaderData();
|
|
return <AdminPage appContext={appContext} />;
|
|
}
|