mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 09:59:00 +02:00
♻️ Move admin setup out of space (#1795)
This commit is contained in:
parent
cc4b23067c
commit
56e0ca0151
4 changed files with 54 additions and 71 deletions
|
@ -1,71 +0,0 @@
|
||||||
import { PageIcon } from "@/app/components/page-icons";
|
|
||||||
import {
|
|
||||||
PageContainer,
|
|
||||||
PageContent,
|
|
||||||
PageHeader,
|
|
||||||
PageTitle,
|
|
||||||
} from "@/app/components/page-layout";
|
|
||||||
import { isInitialAdmin, requireUser } from "@/auth/queries";
|
|
||||||
import {
|
|
||||||
EmptyState,
|
|
||||||
EmptyStateDescription,
|
|
||||||
EmptyStateFooter,
|
|
||||||
EmptyStateIcon,
|
|
||||||
EmptyStateTitle,
|
|
||||||
} from "@/components/empty-state";
|
|
||||||
import { Trans } from "@/components/trans";
|
|
||||||
import { Button } from "@rallly/ui/button";
|
|
||||||
import { CrownIcon } from "lucide-react";
|
|
||||||
import Link from "next/link";
|
|
||||||
import { notFound, redirect } from "next/navigation";
|
|
||||||
import { MakeMeAdminButton } from "./make-me-admin-button";
|
|
||||||
|
|
||||||
export default async function AdminSetupPage() {
|
|
||||||
const user = await requireUser();
|
|
||||||
|
|
||||||
if (user.role === "admin") {
|
|
||||||
// User is already an admin
|
|
||||||
redirect("/control-panel");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isInitialAdmin(user.email)) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PageContainer>
|
|
||||||
<PageHeader>
|
|
||||||
<PageTitle>
|
|
||||||
<PageIcon color="indigo">
|
|
||||||
<CrownIcon />
|
|
||||||
</PageIcon>
|
|
||||||
<Trans i18nKey="adminSetup" defaults="Admin Setup" />
|
|
||||||
</PageTitle>
|
|
||||||
</PageHeader>
|
|
||||||
<PageContent>
|
|
||||||
<EmptyState className="h-full">
|
|
||||||
<EmptyStateIcon>
|
|
||||||
<CrownIcon />
|
|
||||||
</EmptyStateIcon>
|
|
||||||
<EmptyStateTitle>
|
|
||||||
<Trans i18nKey="adminSetupTitle" defaults="Are you the admin?" />
|
|
||||||
</EmptyStateTitle>
|
|
||||||
<EmptyStateDescription>
|
|
||||||
<Trans
|
|
||||||
i18nKey="adminSetupDescription"
|
|
||||||
defaults="Click the button below to make yourself an admin user."
|
|
||||||
/>
|
|
||||||
</EmptyStateDescription>
|
|
||||||
<EmptyStateFooter className="flex gap-2">
|
|
||||||
<Button asChild>
|
|
||||||
<Link href="/">
|
|
||||||
<Trans i18nKey="cancel" defaults="Cancel" />
|
|
||||||
</Link>
|
|
||||||
</Button>
|
|
||||||
<MakeMeAdminButton />
|
|
||||||
</EmptyStateFooter>
|
|
||||||
</EmptyState>
|
|
||||||
</PageContent>
|
|
||||||
</PageContainer>
|
|
||||||
);
|
|
||||||
}
|
|
54
apps/web/src/app/[locale]/admin-setup/page.tsx
Normal file
54
apps/web/src/app/[locale]/admin-setup/page.tsx
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import { isInitialAdmin, requireUser } from "@/auth/queries";
|
||||||
|
import {
|
||||||
|
EmptyState,
|
||||||
|
EmptyStateDescription,
|
||||||
|
EmptyStateFooter,
|
||||||
|
EmptyStateIcon,
|
||||||
|
EmptyStateTitle,
|
||||||
|
} from "@/components/empty-state";
|
||||||
|
import { Trans } from "@/components/trans";
|
||||||
|
import { Button } from "@rallly/ui/button";
|
||||||
|
import { CrownIcon } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { notFound, redirect } from "next/navigation";
|
||||||
|
import { MakeMeAdminButton } from "./make-me-admin-button";
|
||||||
|
|
||||||
|
export default async function AdminSetupPage() {
|
||||||
|
const user = await requireUser();
|
||||||
|
|
||||||
|
if (user.role === "admin") {
|
||||||
|
// User is already an admin
|
||||||
|
redirect("/control-panel");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isInitialAdmin(user.email)) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-dvh items-center justify-center">
|
||||||
|
<EmptyState className="h-full">
|
||||||
|
<EmptyStateIcon>
|
||||||
|
<CrownIcon />
|
||||||
|
</EmptyStateIcon>
|
||||||
|
<EmptyStateTitle>
|
||||||
|
<Trans i18nKey="adminSetupTitle" defaults="Are you the admin?" />
|
||||||
|
</EmptyStateTitle>
|
||||||
|
<EmptyStateDescription>
|
||||||
|
<Trans
|
||||||
|
i18nKey="adminSetupDescription"
|
||||||
|
defaults="Click the button below to make yourself an admin user."
|
||||||
|
/>
|
||||||
|
</EmptyStateDescription>
|
||||||
|
<EmptyStateFooter className="flex gap-2">
|
||||||
|
<Button asChild>
|
||||||
|
<Link href="/">
|
||||||
|
<Trans i18nKey="cancel" defaults="Cancel" />
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
<MakeMeAdminButton />
|
||||||
|
</EmptyStateFooter>
|
||||||
|
</EmptyState>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue