Reapply "Add missing admin action files and navigation links"
This reverts commit 4d515bc400.
This commit is contained in:
@@ -1,137 +1,11 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import {
|
||||
alertUser,
|
||||
disconnectUser,
|
||||
giveCurrency,
|
||||
setMotto,
|
||||
setRank,
|
||||
} from "@/actions/admin-users";
|
||||
import { InfoItem, StatusCard } from "@/components/admin/dashboard";
|
||||
import { User } from "lucide-react";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminUserDetail({
|
||||
/** Legacy route — redirects to /admin/users/show/[id] */
|
||||
export default async function UserLegacyPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
params: Promise<{ locale: string; id: string }>
|
||||
}) {
|
||||
const { id } = await params;
|
||||
const t = await getTranslations("pages.admin.users");
|
||||
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();
|
||||
|
||||
const isOnline = user.online === "1";
|
||||
|
||||
return (
|
||||
<main>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400 mb-2">
|
||||
<Link href="/admin/users">← {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">
|
||||
<User size={20} className="text-[var(--color-primary)]" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="m-0 text-xl font-extrabold text-[var(--color-text)]">{user.username}</h1>
|
||||
<p className="m-0 text-xs text-[var(--color-text-muted)] mt-0.5">{user.motto ? user.motto : t("detail.noMotto")}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
|
||||
<StatusCard label={t("detail.userId")} value={user.id} icon="🆔" />
|
||||
<StatusCard label={t("detail.rank")} value={user.rank} icon="🎖️" />
|
||||
<StatusCard label={t("detail.credits")} value={user.credits} icon="💰" />
|
||||
<StatusCard
|
||||
label={t("detail.online")}
|
||||
value={isOnline ? t("detail.online") : t("offline")}
|
||||
state={isOnline ? "ok" : "neutral"}
|
||||
icon={isOnline ? "🟢" : "⚪"}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<section className="mt-6">
|
||||
<h2 className="admin-section-title">{t("detail.overview")}</h2>
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(150px,1fr))] gap-2.5">
|
||||
<InfoItem label={t("detail.username")} value={user.username} />
|
||||
<InfoItem
|
||||
label={t("detail.online")}
|
||||
value={
|
||||
<span className={`inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full ${isOnline ? "bg-green-600/20 text-[var(--color-text)]" : "bg-[var(--color-primary)]/18 text-[var(--color-text)]"}`}>
|
||||
{isOnline ? t("detail.online") : t("offline")}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<InfoItem label={t("detail.rank")} value={user.rank} />
|
||||
<InfoItem label={t("detail.credits")} value={user.credits} />
|
||||
<InfoItem label={t("detail.look")} value={<code>{user.look || "—"}</code>} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="mt-6">
|
||||
<h2 className="admin-section-title">{t("detail.actions")}</h2>
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<form action={giveCurrency} className="admin-card">
|
||||
<input type="hidden" name="userId" value={user.id} />
|
||||
<h3 className="text-sm font-bold text-[var(--color-text)] m-0 mb-3">{t("detail.giveCurrency")}</h3>
|
||||
<select name="type">
|
||||
<option value="credits">{t("detail.credits")}</option>
|
||||
<option value="duckets">{t("detail.duckets")}</option>
|
||||
<option value="diamonds">{t("detail.diamonds")}</option>
|
||||
<option value="points">{t("detail.points")}</option>
|
||||
</select>{" "}
|
||||
<input name="amount" type="number" min={1} placeholder={t("detail.amountPlaceholder")} />{" "}
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("detail.give")}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form action={setMotto} className="admin-card">
|
||||
<input type="hidden" name="userId" value={user.id} />
|
||||
<h3 className="text-sm font-bold text-[var(--color-text)] m-0 mb-3">{t("detail.setMotto")}</h3>
|
||||
<input name="motto" defaultValue={user.motto} maxLength={127} />{" "}
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("detail.save")}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form action={setRank} className="admin-card">
|
||||
<input type="hidden" name="userId" value={user.id} />
|
||||
<h3 className="text-sm font-bold text-[var(--color-text)] m-0 mb-3">{t("detail.setRank")}</h3>
|
||||
<input name="rank" type="number" min={1} defaultValue={user.rank} />{" "}
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("detail.set")}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form action={alertUser} className="admin-card">
|
||||
<input type="hidden" name="userId" value={user.id} />
|
||||
<h3 className="text-sm font-bold text-[var(--color-text)] m-0 mb-3">{t("detail.sendAlert")}</h3>
|
||||
<input name="message" placeholder={t("detail.messagePlaceholder")} />{" "}
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("detail.send")}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form action={disconnectUser} className="admin-card">
|
||||
<input type="hidden" name="userId" value={user.id} />
|
||||
<input type="hidden" name="username" value={user.username} />
|
||||
<h3 className="text-sm font-bold text-[var(--color-text)] m-0 mb-3">{t("detail.disconnectUser")}</h3>
|
||||
<button type="submit" className="btn btn-danger">
|
||||
{t("detail.disconnectFromHotel")}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
const { id } = await params
|
||||
redirect(`/admin/users/show/${id}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user