/news and six admin pages issued raw prisma reads with no try/catch, so a DB outage rendered a 500 instead of an empty state. Wrap each read (try/catch or .catch(() => fallback), preserving select() row types and notFound() on the user-detail page). Matches the fail-soft pattern used across the rest of the app. Verified: tsc 0, next build 0, all public pages 200 against a dead DB.
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import Link from "next/link";
|
|
import { notFound } from "next/navigation";
|
|
import {
|
|
alertUser,
|
|
disconnectUser,
|
|
giveCurrency,
|
|
setMotto,
|
|
setRank,
|
|
} from "@/actions/admin-users";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function AdminUserDetail({
|
|
params,
|
|
}: {
|
|
params: Promise<{ id: string }>;
|
|
}) {
|
|
const { id } = await params;
|
|
const userId = Number(id);
|
|
const user = await prisma.user
|
|
.findUnique({
|
|
where: { id: userId },
|
|
select: { id: true, username: true, motto: true, rank: true, credits: true, look: true, online: true },
|
|
})
|
|
.catch(() => null);
|
|
if (!user) notFound();
|
|
|
|
return (
|
|
<main>
|
|
<p className="muted">
|
|
<Link href="/admin/users">← Users</Link>
|
|
</p>
|
|
<h1>{user.username}</h1>
|
|
<p className="muted">
|
|
ID {user.id} · rank {user.rank} · {user.credits} credits ·{" "}
|
|
{user.online === "1" ? "Online" : "Offline"}
|
|
</p>
|
|
|
|
<div className="grid cols-2">
|
|
<form action={giveCurrency} className="card">
|
|
<input type="hidden" name="userId" value={user.id} />
|
|
<h3 style={{ marginTop: 0 }}>Give currency</h3>
|
|
<select name="type">
|
|
<option value="credits">Credits</option>
|
|
<option value="duckets">Duckets</option>
|
|
<option value="diamonds">Diamonds</option>
|
|
<option value="points">Points</option>
|
|
</select>{" "}
|
|
<input name="amount" type="number" min={1} placeholder="Amount" />{" "}
|
|
<button type="submit">Give</button>
|
|
</form>
|
|
|
|
<form action={setMotto} className="card">
|
|
<input type="hidden" name="userId" value={user.id} />
|
|
<h3 style={{ marginTop: 0 }}>Set motto</h3>
|
|
<input name="motto" defaultValue={user.motto} maxLength={127} />{" "}
|
|
<button type="submit">Save</button>
|
|
</form>
|
|
|
|
<form action={setRank} className="card">
|
|
<input type="hidden" name="userId" value={user.id} />
|
|
<h3 style={{ marginTop: 0 }}>Set rank</h3>
|
|
<input name="rank" type="number" min={1} defaultValue={user.rank} />{" "}
|
|
<button type="submit">Set</button>
|
|
</form>
|
|
|
|
<form action={alertUser} className="card">
|
|
<input type="hidden" name="userId" value={user.id} />
|
|
<h3 style={{ marginTop: 0 }}>Alert</h3>
|
|
<input name="message" placeholder="Message" />{" "}
|
|
<button type="submit">Send</button>
|
|
</form>
|
|
|
|
<form action={disconnectUser} className="card">
|
|
<input type="hidden" name="userId" value={user.id} />
|
|
<input type="hidden" name="username" value={user.username} />
|
|
<h3 style={{ marginTop: 0 }}>Disconnect</h3>
|
|
<button type="submit">Disconnect from hotel</button>
|
|
</form>
|
|
</div>
|
|
</main>
|
|
);
|
|
}
|