84 lines
3.0 KiB
TypeScript
84 lines
3.0 KiB
TypeScript
import Link from "next/link";
|
|
import { getTranslations } from "next-intl/server";
|
|
import { notFound } from "next/navigation";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { DoorOpen } from "lucide-react";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function AdminRoomDetail({
|
|
params,
|
|
}: {
|
|
params: Promise<{ id: string }>;
|
|
}) {
|
|
const t = await getTranslations("pages.admin.rooms");
|
|
|
|
const { id } = await params;
|
|
const roomId = Number(id);
|
|
|
|
if (!Number.isInteger(roomId) || roomId <= 0) notFound();
|
|
|
|
let room: Awaited<ReturnType<typeof prisma.rooms.findUnique>> = null;
|
|
try {
|
|
room = await prisma.rooms.findUnique({ where: { id: roomId } });
|
|
} catch {
|
|
room = null;
|
|
}
|
|
if (!room) notFound();
|
|
|
|
const fields: Array<[string, string]> = [
|
|
[t("colId"), String(room.id)],
|
|
[t("colName"), room.name || t("unnamed")],
|
|
[t("detail.description"), room.description || "—"],
|
|
[t("detail.owner"), `${room.ownerName || "—"} (#${room.ownerId})`],
|
|
[t("detail.state"), room.state],
|
|
[t("colUsers"), `${room.users} / ${room.usersMax}`],
|
|
[t("colCategory"), String(room.category)],
|
|
[t("detail.score"), String(room.score)],
|
|
[t("detail.model"), room.model],
|
|
[t("detail.guildId"), room.guildId ? String(room.guildId) : "—"],
|
|
[t("detail.tags"), room.tags || "—"],
|
|
[t("detail.password"), room.password ? t("detail.yes") : "—"],
|
|
[t("detail.public"), room.isPublic === "1" ? t("detail.yes") : t("detail.no")],
|
|
[t("detail.staffPicked"), room.isStaffPicked === "1" ? t("detail.yes") : t("detail.no")],
|
|
[t("detail.forSale"), room.isForSale === "1" ? t("detail.yes") : t("detail.no")],
|
|
[t("detail.tradeMode"), String(room.tradeMode)],
|
|
];
|
|
|
|
return (
|
|
<main>
|
|
<p className="text-sm text-gray-500 dark:text-gray-400 mb-1">
|
|
<Link href="/admin/rooms">← {t("title")}</Link>
|
|
</p>
|
|
<div className="flex items-center gap-3 mb-6">
|
|
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-[var(--color-primary)]/20 to-[var(--color-primary)]/5 grid place-items-center">
|
|
<DoorOpen size={20} className="text-[var(--color-primary)]" />
|
|
</div>
|
|
<div>
|
|
<h1 className="m-0 text-xl font-extrabold text-[var(--color-text)]">{room.name || t("unnamed")}</h1>
|
|
<p className="m-0 text-xs text-[var(--color-text-muted)] mt-0.5">{t("detail.subtitle", { id: room.id, owner: room.ownerName || "—", users: room.users, maxUsers: room.usersMax, state: room.state })}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="admin-card">
|
|
<table>
|
|
<tbody>
|
|
{fields.map(([label, value]) => (
|
|
<tr key={label}>
|
|
<th className="w-[35%] whitespace-nowrap">{label}</th>
|
|
<td>{value}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
{room.ownerId ? (
|
|
<p className="muted" style={{ marginTop: "1rem" }}>
|
|
<Link href={`/admin/users/${room.ownerId}`}>{t("detail.viewOwner")} →</Link>
|
|
</p>
|
|
) : null}
|
|
</main>
|
|
);
|
|
}
|