37 lines
2.6 KiB
TypeScript
37 lines
2.6 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { connection } from "next/server";
|
|
|
|
import { AdminHeader } from "@/components/admin/admin-header";
|
|
import { StygianEditor } from "@/components/admin/stygian-editor";
|
|
import { StygianSyncButton } from "@/components/admin/stygian-sync-button";
|
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
import { getAdminSession } from "@/lib/auth/server";
|
|
import { getActiveCatalog } from "@/lib/guides/queries";
|
|
import { getStygianSchedule, listStygianSchedules } from "@/lib/stygian/repository";
|
|
|
|
export default async function AdminStygianPage({ searchParams }: { searchParams: Promise<Record<string, string | string[] | undefined>> }) {
|
|
await connection();
|
|
if (!(await getAdminSession())) redirect("/auth/login?next=%2Fadmin");
|
|
const query = await searchParams;
|
|
const schedules = await listStygianSchedules();
|
|
const raw = Array.isArray(query.schedule) ? query.schedule[0] : query.schedule;
|
|
const selectedId = Number(raw) || schedules[0]?.scheduleId;
|
|
const [schedule, catalog] = await Promise.all([selectedId ? getStygianSchedule(selectedId) : null, getActiveCatalog()]);
|
|
return (
|
|
<div className="min-h-svh"><AdminHeader /><main className="mx-auto flex w-full max-w-7xl flex-col gap-8 p-4 sm:p-6 lg:p-8">
|
|
<header><p className="text-sm font-medium text-primary">Stygian Onslaught</p><h1 className="font-heading text-4xl font-semibold">Stygian Guide</h1></header>
|
|
{!schedule || !catalog ? <Alert><AlertTitle>No Stygian schedules yet</AlertTitle><AlertDescription>Use the sync action below after the catalog has been synchronized.</AlertDescription></Alert> : null}
|
|
{schedule && catalog ? <StygianEditor
|
|
key={schedule.scheduleId}
|
|
schedules={schedules.map(({ scheduleId, challengeName }) => ({ scheduleId, challengeName }))}
|
|
schedule={{ scheduleId: schedule.scheduleId, challengeName: schedule.challengeName, version: schedule.version }}
|
|
bosses={schedule.bosses}
|
|
recommendations={schedule.recommendations}
|
|
characters={catalog.characters.map(({ key, name, aliases, imageUrl, rarity, weaponType, element, elementIconUrl }) => ({ key, name, aliases, imageUrl, rarity, weaponType, element, elementIconUrl }))}
|
|
weapons={catalog.weapons.map(({ key, name, aliases, imageUrl, rarity, weaponType }) => ({ key, name, aliases, imageUrl, rarity, weaponType }))}
|
|
artifacts={catalog.artifacts.map(({ key, name, aliases, imageUrl, rarity }) => ({ key, name, aliases, imageUrl, rarity }))}
|
|
/> : schedules.length === 0 && catalog ? <StygianSyncButton /> : null}
|
|
</main></div>
|
|
);
|
|
}
|