admin roadmap filter & search, user management, reopen rejected, system health
This commit is contained in:
@@ -0,0 +1,349 @@
|
||||
import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
import { isAdminEmail } from "@/lib/admin";
|
||||
import { userRepo } from "@/server/repositories/user.repo";
|
||||
import { formatRupiah } from "@/lib/utils";
|
||||
import { SuspendUserButton } from "@/features/admin/components/suspend-user-button";
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{ id: string }>;
|
||||
}
|
||||
|
||||
export default async function AdminUserDetailPage({ params }: PageProps) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login?callbackUrl=/admin/users");
|
||||
if (!isAdminEmail(session.user.email)) {
|
||||
return (
|
||||
<div className="mx-auto max-w-2xl px-4 py-12 text-center">
|
||||
<p className="text-sm text-neutral-600">
|
||||
Halaman ini hanya untuk admin SeTrip.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const user = await userRepo.findByIdForAdmin(id);
|
||||
if (!user) notFound();
|
||||
|
||||
const isSelf = user.id === session.user.id;
|
||||
const totalSpent = user.bookings
|
||||
.filter((b) => b.status === "PAID" || b.status === "PARTIALLY_REFUNDED")
|
||||
.reduce((sum, b) => sum + b.amount, 0);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-4 py-8 sm:py-12">
|
||||
<div className="mb-4 text-xs text-neutral-500">
|
||||
<Link href="/admin/users" className="hover:text-primary-600">
|
||||
← Kembali ke list users
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<header
|
||||
className={`mb-6 rounded-2xl border p-5 shadow-sm sm:p-6 ${
|
||||
user.suspended
|
||||
? "border-red-300 bg-red-50/60"
|
||||
: "border-neutral-200 bg-white"
|
||||
}`}
|
||||
>
|
||||
<div className="flex flex-wrap items-start gap-4">
|
||||
{user.image ? (
|
||||
<Image
|
||||
src={user.image}
|
||||
alt=""
|
||||
width={64}
|
||||
height={64}
|
||||
className="h-16 w-16 shrink-0 rounded-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-16 w-16 shrink-0 items-center justify-center rounded-full bg-primary-600 text-xl font-bold text-white">
|
||||
{user.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<h1 className="text-xl font-bold text-neutral-900 sm:text-2xl">
|
||||
{user.name}
|
||||
</h1>
|
||||
{user.suspended && (
|
||||
<span className="rounded-full bg-red-100 px-2 py-0.5 text-[11px] font-bold uppercase tracking-wide text-red-800">
|
||||
Suspended
|
||||
</span>
|
||||
)}
|
||||
{user.organizerVerification?.status === "APPROVED" && (
|
||||
<span className="rounded-full bg-emerald-100 px-2 py-0.5 text-[11px] font-bold uppercase tracking-wide text-emerald-800">
|
||||
✓ Verified Organizer
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-0.5 text-sm text-neutral-600">{user.email}</p>
|
||||
<p className="mt-0.5 text-[11px] text-neutral-500">
|
||||
User ID:{" "}
|
||||
<code className="rounded bg-neutral-100 px-1.5 py-0.5 font-mono text-neutral-700">
|
||||
{user.id}
|
||||
</code>
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-neutral-500">
|
||||
Bergabung{" "}
|
||||
{user.createdAt.toLocaleDateString("id-ID", {
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
})}
|
||||
{user.acceptedAt && (
|
||||
<>
|
||||
{" "}
|
||||
· Setuju T&C{" "}
|
||||
{user.acceptedAt.toLocaleDateString("id-ID", {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section className="mb-6 grid gap-3 sm:grid-cols-3">
|
||||
<StatCard label="Trip dibuat" value={String(user.trips.length)} />
|
||||
<StatCard label="Booking aktif" value={String(user.bookings.length)} />
|
||||
<StatCard
|
||||
label="Total spent (PAID)"
|
||||
value={formatRupiah(totalSpent)}
|
||||
accent="emerald"
|
||||
/>
|
||||
</section>
|
||||
|
||||
{user.suspended && (
|
||||
<section className="mb-6 rounded-2xl border border-red-300 bg-red-50 p-4 sm:p-5">
|
||||
<h2 className="text-sm font-bold text-red-900">
|
||||
⛔ Akun ditangguhkan
|
||||
</h2>
|
||||
<p className="mt-1 text-xs text-red-900/80">
|
||||
{user.suspendedReason ?? "Tidak ada alasan tercatat."}
|
||||
</p>
|
||||
{user.suspendedBy && (
|
||||
<p className="mt-2 text-[11px] text-red-900/70">
|
||||
Disuspend oleh {user.suspendedBy.email}
|
||||
{user.suspendedAt && (
|
||||
<>
|
||||
{" "}
|
||||
pada{" "}
|
||||
{user.suspendedAt.toLocaleString("id-ID", {
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="mb-6 rounded-2xl border border-neutral-200 bg-white p-4 shadow-sm sm:p-5">
|
||||
<h2 className="mb-3 text-sm font-bold text-neutral-900">
|
||||
Aksi Admin
|
||||
</h2>
|
||||
{isSelf ? (
|
||||
<p className="text-xs text-neutral-500">
|
||||
Tidak bisa suspend akun sendiri.
|
||||
</p>
|
||||
) : (
|
||||
<SuspendUserButton userId={user.id} isSuspended={user.suspended} />
|
||||
)}
|
||||
</section>
|
||||
|
||||
{user.profile && (
|
||||
<section className="mb-6 rounded-2xl border border-neutral-200 bg-white p-4 shadow-sm sm:p-5">
|
||||
<h2 className="mb-3 text-xs font-bold uppercase tracking-wide text-neutral-500">
|
||||
Profil Sosial
|
||||
</h2>
|
||||
<dl className="grid gap-3 text-sm sm:grid-cols-2">
|
||||
{user.profile.bio && (
|
||||
<div className="sm:col-span-2">
|
||||
<dt className="text-[10px] font-semibold uppercase tracking-wide text-neutral-500">
|
||||
Bio
|
||||
</dt>
|
||||
<dd className="whitespace-pre-wrap text-neutral-700">
|
||||
{user.profile.bio}
|
||||
</dd>
|
||||
</div>
|
||||
)}
|
||||
{user.profile.city && (
|
||||
<div>
|
||||
<dt className="text-[10px] font-semibold uppercase tracking-wide text-neutral-500">
|
||||
Kota
|
||||
</dt>
|
||||
<dd className="text-neutral-700">{user.profile.city}</dd>
|
||||
</div>
|
||||
)}
|
||||
{user.profile.vibe && (
|
||||
<div>
|
||||
<dt className="text-[10px] font-semibold uppercase tracking-wide text-neutral-500">
|
||||
Vibe
|
||||
</dt>
|
||||
<dd className="text-neutral-700">{user.profile.vibe}</dd>
|
||||
</div>
|
||||
)}
|
||||
{user.profile.interests.length > 0 && (
|
||||
<div className="sm:col-span-2">
|
||||
<dt className="text-[10px] font-semibold uppercase tracking-wide text-neutral-500">
|
||||
Minat
|
||||
</dt>
|
||||
<dd className="mt-0.5 flex flex-wrap gap-1.5">
|
||||
{user.profile.interests.map((tag) => (
|
||||
<span
|
||||
key={tag}
|
||||
className="rounded-full bg-secondary-50 px-2 py-0.5 text-[11px] font-medium text-secondary-700"
|
||||
>
|
||||
#{tag}
|
||||
</span>
|
||||
))}
|
||||
</dd>
|
||||
</div>
|
||||
)}
|
||||
{user.profile.instagram && (
|
||||
<div>
|
||||
<dt className="text-[10px] font-semibold uppercase tracking-wide text-neutral-500">
|
||||
Instagram
|
||||
</dt>
|
||||
<dd className="text-neutral-700">@{user.profile.instagram}</dd>
|
||||
</div>
|
||||
)}
|
||||
</dl>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{user.organizerVerification && (
|
||||
<section className="mb-6 rounded-2xl border border-neutral-200 bg-white p-4 shadow-sm sm:p-5">
|
||||
<h2 className="mb-3 text-xs font-bold uppercase tracking-wide text-neutral-500">
|
||||
Verifikasi Organizer
|
||||
</h2>
|
||||
<p className="text-sm text-neutral-700">
|
||||
Status:{" "}
|
||||
<span className="font-semibold">
|
||||
{user.organizerVerification.status}
|
||||
</span>
|
||||
{" · "}
|
||||
<Link
|
||||
href={`/admin/verifications?tab=${user.organizerVerification.status}`}
|
||||
className="text-secondary-700 hover:text-secondary-900"
|
||||
>
|
||||
Buka di /admin/verifications →
|
||||
</Link>
|
||||
</p>
|
||||
{user.organizerVerification.rejectionReason && (
|
||||
<p className="mt-1 text-xs text-red-700">
|
||||
Reason: {user.organizerVerification.rejectionReason}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="mb-6 rounded-2xl border border-neutral-200 bg-white p-4 shadow-sm sm:p-5">
|
||||
<h2 className="mb-3 text-xs font-bold uppercase tracking-wide text-neutral-500">
|
||||
Trip yang dibuat ({user.trips.length})
|
||||
</h2>
|
||||
{user.trips.length === 0 ? (
|
||||
<p className="text-xs text-neutral-500">
|
||||
User ini belum pernah membuat trip.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="divide-y divide-neutral-100">
|
||||
{user.trips.map((t) => (
|
||||
<li key={t.id} className="py-2.5">
|
||||
<Link
|
||||
href={`/admin/trips/${t.id}`}
|
||||
className="flex items-center justify-between gap-3 text-sm hover:text-primary-700"
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate font-semibold text-neutral-800">
|
||||
{t.title}
|
||||
</p>
|
||||
<p className="text-[11px] text-neutral-500">
|
||||
{t.destination} ·{" "}
|
||||
{t.date.toLocaleDateString("id-ID", {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
})}{" "}
|
||||
· {t.status}
|
||||
</p>
|
||||
</div>
|
||||
<p className="shrink-0 text-xs font-semibold text-primary-700">
|
||||
{formatRupiah(t.price)}
|
||||
</p>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="mb-6 rounded-2xl border border-neutral-200 bg-white p-4 shadow-sm sm:p-5">
|
||||
<h2 className="mb-3 text-xs font-bold uppercase tracking-wide text-neutral-500">
|
||||
Booking sebagai peserta ({user.bookings.length})
|
||||
</h2>
|
||||
{user.bookings.length === 0 ? (
|
||||
<p className="text-xs text-neutral-500">Belum ada booking.</p>
|
||||
) : (
|
||||
<ul className="divide-y divide-neutral-100">
|
||||
{user.bookings.map((b) => (
|
||||
<li key={b.id} className="py-2.5">
|
||||
<Link
|
||||
href={`/admin/bookings/${b.id}`}
|
||||
className="flex items-center justify-between gap-3 text-sm hover:text-primary-700"
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate font-semibold text-neutral-800">
|
||||
{b.trip.title}
|
||||
</p>
|
||||
<p className="text-[11px] text-neutral-500">
|
||||
{b.trip.date.toLocaleDateString("id-ID", {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
})}{" "}
|
||||
· status: <span className="font-semibold">{b.status}</span>
|
||||
</p>
|
||||
</div>
|
||||
<p className="shrink-0 text-xs font-semibold text-primary-700">
|
||||
{formatRupiah(b.amount)}
|
||||
</p>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StatCard({
|
||||
label,
|
||||
value,
|
||||
accent = "primary",
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
accent?: "primary" | "emerald";
|
||||
}) {
|
||||
const cls = accent === "emerald" ? "text-emerald-700" : "text-primary-700";
|
||||
return (
|
||||
<div className="rounded-xl border border-neutral-200 bg-white p-3 sm:p-4">
|
||||
<p className="text-[10px] font-semibold uppercase tracking-wide text-neutral-500">
|
||||
{label}
|
||||
</p>
|
||||
<p className={`mt-0.5 text-lg font-bold sm:text-xl ${cls}`}>{value}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
import { redirect } from "next/navigation";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
import { isAdminEmail } from "@/lib/admin";
|
||||
import { userRepo } from "@/server/repositories/user.repo";
|
||||
|
||||
type Tab = "ALL" | "ACTIVE" | "SUSPENDED";
|
||||
|
||||
const TABS: { key: Tab; label: string }[] = [
|
||||
{ key: "ALL", label: "Semua" },
|
||||
{ key: "ACTIVE", label: "Aktif" },
|
||||
{ key: "SUSPENDED", label: "Suspended" },
|
||||
];
|
||||
|
||||
interface PageProps {
|
||||
searchParams: Promise<{ tab?: string; q?: string }>;
|
||||
}
|
||||
|
||||
export default async function AdminUsersPage({ searchParams }: PageProps) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login?callbackUrl=/admin/users");
|
||||
if (!isAdminEmail(session.user.email)) {
|
||||
return (
|
||||
<div className="mx-auto max-w-2xl px-4 py-12 text-center">
|
||||
<p className="text-sm text-neutral-600">
|
||||
Halaman ini hanya untuk admin SeTrip.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const params = await searchParams;
|
||||
const tab: Tab = TABS.some((t) => t.key === params.tab)
|
||||
? (params.tab as Tab)
|
||||
: "ALL";
|
||||
const q = (params.q ?? "").trim();
|
||||
|
||||
const users = await userRepo.searchForAdmin({
|
||||
q: q || undefined,
|
||||
suspended: tab === "SUSPENDED" ? true : tab === "ACTIVE" ? false : undefined,
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-5xl px-4 py-8 sm:py-12">
|
||||
<header className="mb-6">
|
||||
<h1 className="text-2xl font-bold text-neutral-900 sm:text-3xl">
|
||||
User Management
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-neutral-500">
|
||||
Cari user, lihat history booking & trip, dan suspend akun yang
|
||||
melakukan abuse (scam, harassment, TOS violation).
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<form method="get" className="mb-4 flex gap-2">
|
||||
<input type="hidden" name="tab" value={tab} />
|
||||
<input
|
||||
name="q"
|
||||
defaultValue={q}
|
||||
placeholder="Cari email atau nama..."
|
||||
className="flex-1 rounded-xl border border-neutral-200 bg-white px-4 py-2 text-sm text-neutral-800 placeholder:text-neutral-400 focus:border-primary-400"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-xl bg-primary-600 px-4 py-2 text-sm font-semibold text-white hover:bg-primary-700"
|
||||
>
|
||||
Cari
|
||||
</button>
|
||||
{q && (
|
||||
<Link
|
||||
href={`/admin/users?tab=${tab}`}
|
||||
className="rounded-xl border border-neutral-200 bg-white px-4 py-2 text-sm font-semibold text-neutral-600 hover:bg-neutral-50"
|
||||
>
|
||||
Reset
|
||||
</Link>
|
||||
)}
|
||||
</form>
|
||||
|
||||
<div className="mb-6 flex flex-wrap gap-2">
|
||||
{TABS.map((t) => (
|
||||
<Link
|
||||
key={t.key}
|
||||
href={`/admin/users?tab=${t.key}${q ? `&q=${encodeURIComponent(q)}` : ""}`}
|
||||
className={`rounded-full px-4 py-1.5 text-sm font-semibold transition-colors ${
|
||||
tab === t.key
|
||||
? "bg-primary-600 text-white"
|
||||
: "bg-neutral-100 text-neutral-600 hover:bg-neutral-200"
|
||||
}`}
|
||||
>
|
||||
{t.label}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{users.length === 0 ? (
|
||||
<div className="rounded-2xl border border-dashed border-neutral-300 bg-white p-10 text-center">
|
||||
<p className="text-sm text-neutral-500">
|
||||
{q
|
||||
? `Tidak ada user yang cocok dengan "${q}".`
|
||||
: "Tidak ada user pada tab ini."}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="space-y-2">
|
||||
{users.map((u) => (
|
||||
<li
|
||||
key={u.id}
|
||||
className={`rounded-2xl border bg-white p-3 shadow-sm transition-shadow hover:shadow-md sm:p-4 ${
|
||||
u.suspended ? "border-red-200" : "border-neutral-200"
|
||||
}`}
|
||||
>
|
||||
<Link
|
||||
href={`/admin/users/${u.id}`}
|
||||
className="flex items-center gap-3"
|
||||
>
|
||||
{u.image ? (
|
||||
<Image
|
||||
src={u.image}
|
||||
alt=""
|
||||
width={40}
|
||||
height={40}
|
||||
className="h-10 w-10 shrink-0 rounded-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary-600 text-sm font-bold text-white">
|
||||
{u.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<p className="truncate text-sm font-semibold text-neutral-800">
|
||||
{u.name}
|
||||
</p>
|
||||
{u.suspended && (
|
||||
<span className="rounded-full bg-red-100 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide text-red-800">
|
||||
Suspended
|
||||
</span>
|
||||
)}
|
||||
{u.organizerVerification?.status === "APPROVED" && (
|
||||
<span className="rounded-full bg-emerald-100 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide text-emerald-800">
|
||||
✓ Organizer
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="truncate text-xs text-neutral-500">{u.email}</p>
|
||||
<p className="mt-0.5 text-[11px] text-neutral-400">
|
||||
Bergabung{" "}
|
||||
{u.createdAt.toLocaleDateString("id-ID", {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
})}
|
||||
{" · "}
|
||||
{u._count.trips} trip dibuat, {u._count.participations}{" "}
|
||||
booking
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user