admin roadmap filter & search, user management, reopen rejected, system health
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"use server";
|
||||
|
||||
import { getServerSession } from "next-auth";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
import { isAdminEmail } from "@/lib/admin";
|
||||
import { userService } from "@/server/services/user.service";
|
||||
|
||||
export async function suspendUserAction(userId: string, reason: string) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return { error: "Kamu harus login terlebih dahulu" };
|
||||
}
|
||||
if (!isAdminEmail(session.user.email)) {
|
||||
return { error: "Hanya admin yang bisa melakukan aksi ini" };
|
||||
}
|
||||
|
||||
try {
|
||||
await userService.suspendUser({
|
||||
userId,
|
||||
adminId: session.user.id,
|
||||
reason,
|
||||
});
|
||||
revalidatePath("/admin/users");
|
||||
revalidatePath(`/admin/users/${userId}`);
|
||||
return { success: true as const };
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
export async function unsuspendUserAction(userId: string) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return { error: "Kamu harus login terlebih dahulu" };
|
||||
}
|
||||
if (!isAdminEmail(session.user.email)) {
|
||||
return { error: "Hanya admin yang bisa melakukan aksi ini" };
|
||||
}
|
||||
|
||||
try {
|
||||
await userService.unsuspendUser({ userId, adminId: session.user.id });
|
||||
revalidatePath("/admin/users");
|
||||
revalidatePath(`/admin/users/${userId}`);
|
||||
return { success: true as const };
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
interface AdminFilterBarProps {
|
||||
/** URL base (mis. `/admin/refunds`) yang menerima query params. */
|
||||
action: string;
|
||||
/** Nilai current dari searchParams. */
|
||||
values: {
|
||||
tab?: string;
|
||||
dateFrom?: string;
|
||||
dateTo?: string;
|
||||
reviewer?: string;
|
||||
reason?: string;
|
||||
};
|
||||
/** Daftar admin email untuk dropdown reviewer/processor. */
|
||||
reviewerOptions: string[];
|
||||
/** Label dropdown reviewer (mis. "Reviewer", "Processor"). */
|
||||
reviewerLabel?: string;
|
||||
/** Kalau diisi, tampilkan dropdown reason dengan opsi-opsi tersebut. */
|
||||
reasonOptions?: { value: string; label: string }[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter bar reusable untuk admin list pages. Pakai GET form supaya URL
|
||||
* shareable dan tidak perlu state client.
|
||||
*/
|
||||
export function AdminFilterBar({
|
||||
action,
|
||||
values,
|
||||
reviewerOptions,
|
||||
reviewerLabel = "Reviewer",
|
||||
reasonOptions,
|
||||
}: AdminFilterBarProps) {
|
||||
return (
|
||||
<form
|
||||
method="get"
|
||||
action={action}
|
||||
className="mb-4 rounded-2xl border border-neutral-200 bg-white p-3 shadow-sm sm:p-4"
|
||||
>
|
||||
{/* Preserve tab via hidden input */}
|
||||
{values.tab && <input type="hidden" name="tab" value={values.tab} />}
|
||||
|
||||
<div className="grid gap-3 sm:grid-cols-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor="filter-dateFrom"
|
||||
className="mb-1 block text-[10px] font-semibold uppercase tracking-wide text-neutral-500"
|
||||
>
|
||||
Dari tanggal
|
||||
</label>
|
||||
<input
|
||||
id="filter-dateFrom"
|
||||
name="dateFrom"
|
||||
type="date"
|
||||
defaultValue={values.dateFrom ?? ""}
|
||||
className="w-full rounded-lg border border-neutral-200 bg-neutral-50 px-2 py-1.5 text-sm text-neutral-800 focus:border-primary-400 focus:bg-white"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label
|
||||
htmlFor="filter-dateTo"
|
||||
className="mb-1 block text-[10px] font-semibold uppercase tracking-wide text-neutral-500"
|
||||
>
|
||||
Sampai tanggal
|
||||
</label>
|
||||
<input
|
||||
id="filter-dateTo"
|
||||
name="dateTo"
|
||||
type="date"
|
||||
defaultValue={values.dateTo ?? ""}
|
||||
className="w-full rounded-lg border border-neutral-200 bg-neutral-50 px-2 py-1.5 text-sm text-neutral-800 focus:border-primary-400 focus:bg-white"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label
|
||||
htmlFor="filter-reviewer"
|
||||
className="mb-1 block text-[10px] font-semibold uppercase tracking-wide text-neutral-500"
|
||||
>
|
||||
{reviewerLabel}
|
||||
</label>
|
||||
<select
|
||||
id="filter-reviewer"
|
||||
name="reviewer"
|
||||
defaultValue={values.reviewer ?? ""}
|
||||
className="w-full rounded-lg border border-neutral-200 bg-neutral-50 px-2 py-1.5 text-sm text-neutral-800 focus:border-primary-400 focus:bg-white"
|
||||
>
|
||||
<option value="">Semua</option>
|
||||
{reviewerOptions.map((email) => (
|
||||
<option key={email} value={email}>
|
||||
{email}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{reasonOptions ? (
|
||||
<div>
|
||||
<label
|
||||
htmlFor="filter-reason"
|
||||
className="mb-1 block text-[10px] font-semibold uppercase tracking-wide text-neutral-500"
|
||||
>
|
||||
Reason
|
||||
</label>
|
||||
<select
|
||||
id="filter-reason"
|
||||
name="reason"
|
||||
defaultValue={values.reason ?? ""}
|
||||
className="w-full rounded-lg border border-neutral-200 bg-neutral-50 px-2 py-1.5 text-sm text-neutral-800 focus:border-primary-400 focus:bg-white"
|
||||
>
|
||||
<option value="">Semua</option>
|
||||
{reasonOptions.map((opt) => (
|
||||
<option key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-end">
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full rounded-lg bg-primary-600 px-3 py-1.5 text-sm font-semibold text-white hover:bg-primary-700"
|
||||
>
|
||||
Terapkan
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{reasonOptions && (
|
||||
<div className="mt-3 flex gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-lg bg-primary-600 px-4 py-1.5 text-sm font-semibold text-white hover:bg-primary-700"
|
||||
>
|
||||
Terapkan
|
||||
</button>
|
||||
<a
|
||||
href={`${action}${values.tab ? `?tab=${values.tab}` : ""}`}
|
||||
className="rounded-lg border border-neutral-200 bg-white px-4 py-1.5 text-sm font-semibold text-neutral-600 hover:bg-neutral-50"
|
||||
>
|
||||
Reset
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
suspendUserAction,
|
||||
unsuspendUserAction,
|
||||
} from "@/features/admin/actions";
|
||||
|
||||
interface SuspendUserButtonProps {
|
||||
userId: string;
|
||||
isSuspended: boolean;
|
||||
}
|
||||
|
||||
export function SuspendUserButton({
|
||||
userId,
|
||||
isSuspended,
|
||||
}: SuspendUserButtonProps) {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [reason, setReason] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function handleSuspend() {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
const res = await suspendUserAction(userId, reason);
|
||||
setLoading(false);
|
||||
if ("error" in res && res.error) {
|
||||
setError(res.error);
|
||||
return;
|
||||
}
|
||||
setOpen(false);
|
||||
setReason("");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
async function handleUnsuspend() {
|
||||
if (!confirm("Buka kembali akun ini? User akan langsung bisa login.")) {
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
setError("");
|
||||
const res = await unsuspendUserAction(userId);
|
||||
setLoading(false);
|
||||
if ("error" in res && res.error) {
|
||||
setError(res.error);
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
if (isSuspended) {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleUnsuspend}
|
||||
disabled={loading}
|
||||
className="rounded-xl border border-emerald-300 bg-white px-4 py-2 text-sm font-bold text-emerald-700 hover:bg-emerald-50 disabled:opacity-50"
|
||||
>
|
||||
{loading ? "Memproses..." : "Buka Suspend"}
|
||||
</button>
|
||||
{error && (
|
||||
<div className="rounded-lg bg-red-50 px-3 py-2 text-xs font-medium text-red-700">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!open) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(true)}
|
||||
className="rounded-xl bg-red-600 px-4 py-2 text-sm font-bold text-white shadow-sm hover:bg-red-700"
|
||||
>
|
||||
Suspend User
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3 rounded-xl border border-red-200 bg-red-50/60 p-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor="suspend-reason"
|
||||
className="mb-1 block text-xs font-semibold text-red-900"
|
||||
>
|
||||
Alasan suspend (wajib min 10 karakter — untuk audit)
|
||||
</label>
|
||||
<textarea
|
||||
id="suspend-reason"
|
||||
rows={3}
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
maxLength={500}
|
||||
placeholder="contoh: User membuat 5 trip palsu dengan alias, lapor masuk dari peserta korban (ticket #123)."
|
||||
className="w-full rounded-xl border border-red-200 bg-white px-3 py-2 text-sm text-neutral-800 placeholder:text-neutral-400 focus:border-red-400"
|
||||
/>
|
||||
<p className="mt-1 text-[11px] text-red-900/70">
|
||||
{reason.trim().length}/500 karakter
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="rounded-lg bg-red-100 px-3 py-2 text-xs font-medium text-red-700">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSuspend}
|
||||
disabled={loading || reason.trim().length < 10}
|
||||
className="rounded-xl bg-red-600 px-4 py-2 text-sm font-bold text-white shadow-sm hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{loading ? "Memproses..." : "Konfirmasi Suspend"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setOpen(false);
|
||||
setReason("");
|
||||
setError("");
|
||||
}}
|
||||
disabled={loading}
|
||||
className="rounded-xl border border-neutral-200 bg-white px-4 py-2 text-sm font-semibold text-neutral-700 hover:bg-neutral-50 disabled:opacity-50"
|
||||
>
|
||||
Batal
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -76,3 +76,31 @@ export async function reviewVerificationAction(formData: FormData) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin reopen pengajuan REJECTED ke PENDING — supaya organizer bisa
|
||||
* di-review ulang tanpa drop & recreate row. Note wajib min 10 char untuk audit.
|
||||
*/
|
||||
export async function reopenVerificationAction(
|
||||
verificationId: string,
|
||||
note: string
|
||||
) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user || !isAdminEmail(session.user.email)) {
|
||||
return { error: "Tidak memiliki akses admin" };
|
||||
}
|
||||
|
||||
try {
|
||||
await organizerService.reopenVerification({
|
||||
verificationId,
|
||||
adminId: session.user.id,
|
||||
note,
|
||||
});
|
||||
revalidatePath("/admin/verifications");
|
||||
revalidatePath("/verify");
|
||||
revalidatePath("/profile");
|
||||
return { success: true as const };
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { reviewVerificationAction } from "@/features/organizer/actions";
|
||||
import {
|
||||
reopenVerificationAction,
|
||||
reviewVerificationAction,
|
||||
} from "@/features/organizer/actions";
|
||||
|
||||
type Verification = {
|
||||
id: string;
|
||||
@@ -33,7 +36,9 @@ function formatDate(d: Date): string {
|
||||
export function ReviewCard({ verification }: { verification: Verification }) {
|
||||
const router = useRouter();
|
||||
const [showReject, setShowReject] = useState(false);
|
||||
const [showReopen, setShowReopen] = useState(false);
|
||||
const [rejectionReason, setRejectionReason] = useState("");
|
||||
const [reopenNote, setReopenNote] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
@@ -55,6 +60,20 @@ export function ReviewCard({ verification }: { verification: Verification }) {
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
async function reopen() {
|
||||
setError("");
|
||||
setLoading(true);
|
||||
const result = await reopenVerificationAction(verification.id, reopenNote);
|
||||
setLoading(false);
|
||||
if ("error" in result && result.error) {
|
||||
setError(result.error);
|
||||
return;
|
||||
}
|
||||
setShowReopen(false);
|
||||
setReopenNote("");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
return (
|
||||
<article className="rounded-2xl border border-neutral-200 bg-white p-5 shadow-sm sm:p-6">
|
||||
<header className="mb-4 flex flex-wrap items-start justify-between gap-3 border-b border-neutral-100 pb-4">
|
||||
@@ -110,6 +129,62 @@ export function ReviewCard({ verification }: { verification: Verification }) {
|
||||
</p>
|
||||
)}
|
||||
|
||||
{verification.status === "REJECTED" && (
|
||||
<div className="mt-5 border-t border-neutral-100 pt-4">
|
||||
{error && (
|
||||
<div className="mb-3 rounded-lg bg-red-50 px-3 py-2 text-xs text-red-600">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{!showReopen ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowReopen(true)}
|
||||
disabled={loading}
|
||||
className="rounded-xl border border-amber-300 bg-white px-4 py-2 text-sm font-bold text-amber-700 hover:bg-amber-50 disabled:opacity-50"
|
||||
>
|
||||
🔄 Buka kembali ke PENDING
|
||||
</button>
|
||||
) : (
|
||||
<div className="space-y-2 rounded-xl border border-amber-200 bg-amber-50/60 p-3">
|
||||
<label className="block text-xs font-semibold text-amber-900">
|
||||
Catatan reopen (min 10 karakter — akan disimpan di rejection
|
||||
reason sebagai history)
|
||||
</label>
|
||||
<textarea
|
||||
value={reopenNote}
|
||||
onChange={(e) => setReopenNote(e.target.value)}
|
||||
rows={2}
|
||||
maxLength={500}
|
||||
placeholder="contoh: Organizer kirim ulang foto KTP jelas via email, siap di-review ulang."
|
||||
className="w-full rounded-xl border border-amber-200 bg-white px-3 py-2 text-sm focus:bg-white focus:border-amber-400"
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={reopen}
|
||||
disabled={loading || reopenNote.trim().length < 10}
|
||||
className="rounded-xl bg-amber-600 px-4 py-2 text-sm font-bold text-white hover:bg-amber-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{loading ? "Memproses..." : "Konfirmasi Reopen"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setShowReopen(false);
|
||||
setReopenNote("");
|
||||
}}
|
||||
disabled={loading}
|
||||
className="rounded-xl border border-neutral-200 bg-white px-4 py-2 text-sm font-medium text-neutral-600 hover:bg-neutral-50 disabled:opacity-50"
|
||||
>
|
||||
Batal
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{verification.status === "PENDING" && (
|
||||
<div className="mt-5 border-t border-neutral-100 pt-4">
|
||||
{error && (
|
||||
|
||||
@@ -11,12 +11,18 @@ import { tripService } from "@/server/services/trip.service";
|
||||
import { organizerService } from "@/server/services/organizer.service";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { tripStoredInstantFromYmd } from "@/lib/trip-dates";
|
||||
import { requireActiveUser } from "@/lib/auth-guards";
|
||||
|
||||
export async function createTripAction(formData: FormData) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return { error: "Kamu harus login terlebih dahulu" };
|
||||
}
|
||||
try {
|
||||
await requireActiveUser(session.user.id);
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
|
||||
const raw = {
|
||||
category: formData.get("category") as string,
|
||||
@@ -120,6 +126,7 @@ export async function joinTripAction(tripId: string) {
|
||||
}
|
||||
|
||||
try {
|
||||
await requireActiveUser(session.user.id);
|
||||
await tripService.joinTrip(tripId, session.user.id);
|
||||
revalidatePath(`/trips/${tripId}`);
|
||||
revalidatePath("/trips");
|
||||
|
||||
Reference in New Issue
Block a user