admin roadmap done, reupload request, submission history, manual override
This commit is contained in:
@@ -4,7 +4,11 @@ import { getServerSession } from "next-auth";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
import { isAdminEmail } from "@/lib/admin";
|
||||
import { organizerService } from "@/server/services/organizer.service";
|
||||
import {
|
||||
isReuploadField,
|
||||
organizerService,
|
||||
type ReuploadField,
|
||||
} from "@/server/services/organizer.service";
|
||||
import { auditLog } from "@/server/services/audit-log.service";
|
||||
import { submitVerificationSchema, reviewVerificationSchema } from "./schemas";
|
||||
|
||||
@@ -125,3 +129,81 @@ export async function reopenVerificationAction(
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 2: admin minta organizer upload ulang field tertentu — daripada
|
||||
* reject penuh, set flag `reuploadRequested` + daftar field + note.
|
||||
*/
|
||||
export async function requestReuploadAction(
|
||||
verificationId: string,
|
||||
fields: string[],
|
||||
note: string
|
||||
) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user || !isAdminEmail(session.user.email)) {
|
||||
return { error: "Tidak memiliki akses admin" };
|
||||
}
|
||||
const valid = fields.filter(isReuploadField) as ReuploadField[];
|
||||
|
||||
try {
|
||||
await organizerService.requestReupload({
|
||||
verificationId,
|
||||
adminId: session.user.id,
|
||||
fields: valid,
|
||||
note,
|
||||
});
|
||||
await auditLog.record({
|
||||
admin: { id: session.user.id, email: session.user.email },
|
||||
action: "VERIFICATION_REQUEST_REUPLOAD",
|
||||
entityType: "OrganizerVerification",
|
||||
entityId: verificationId,
|
||||
payload: { fields: valid, note: note.trim() },
|
||||
});
|
||||
revalidatePath("/admin/verifications");
|
||||
revalidatePath("/verify");
|
||||
return { success: true as const };
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 4: admin verify user tanpa upload KYC (partner trusted referral).
|
||||
* Bikin row APPROVED dengan flag `isManualOverride = true`.
|
||||
*/
|
||||
export async function manualOverrideVerificationAction(input: {
|
||||
userId: string;
|
||||
note: string;
|
||||
bankName: string;
|
||||
bankAccountNumber: string;
|
||||
bankAccountName: string;
|
||||
}) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user || !isAdminEmail(session.user.email)) {
|
||||
return { error: "Tidak memiliki akses admin" };
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await organizerService.manualOverrideVerification({
|
||||
userId: input.userId,
|
||||
adminId: session.user.id,
|
||||
note: input.note,
|
||||
bankName: input.bankName,
|
||||
bankAccountNumber: input.bankAccountNumber,
|
||||
bankAccountName: input.bankAccountName,
|
||||
});
|
||||
await auditLog.record({
|
||||
admin: { id: session.user.id, email: session.user.email },
|
||||
action: "VERIFICATION_MANUAL_OVERRIDE",
|
||||
entityType: "OrganizerVerification",
|
||||
entityId: result.id,
|
||||
payload: { userId: input.userId, note: input.note.trim() },
|
||||
});
|
||||
revalidatePath("/admin/verifications");
|
||||
revalidatePath(`/admin/users/${input.userId}`);
|
||||
revalidatePath("/verify");
|
||||
return { success: true as const, verificationId: result.id };
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,18 @@ import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
reopenVerificationAction,
|
||||
requestReuploadAction,
|
||||
reviewVerificationAction,
|
||||
} from "@/features/organizer/actions";
|
||||
|
||||
const REUPLOAD_FIELD_LABELS: { value: string; label: string }[] = [
|
||||
{ value: "ktpImage", label: "Foto KTP" },
|
||||
{ value: "liveness", label: "Foto liveness (pegang kertas SETRIP)" },
|
||||
{ value: "nik", label: "NIK" },
|
||||
{ value: "bankInfo", label: "Info rekening" },
|
||||
{ value: "address", label: "Alamat" },
|
||||
];
|
||||
|
||||
type Verification = {
|
||||
id: string;
|
||||
fullName: string;
|
||||
@@ -37,11 +46,41 @@ export function ReviewCard({ verification }: { verification: Verification }) {
|
||||
const router = useRouter();
|
||||
const [showReject, setShowReject] = useState(false);
|
||||
const [showReopen, setShowReopen] = useState(false);
|
||||
const [showReupload, setShowReupload] = useState(false);
|
||||
const [rejectionReason, setRejectionReason] = useState("");
|
||||
const [reopenNote, setReopenNote] = useState("");
|
||||
const [reuploadNote, setReuploadNote] = useState("");
|
||||
const [reuploadFields, setReuploadFields] = useState<string[]>([]);
|
||||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
function toggleReuploadField(value: string) {
|
||||
setReuploadFields((prev) =>
|
||||
prev.includes(value)
|
||||
? prev.filter((v) => v !== value)
|
||||
: [...prev, value]
|
||||
);
|
||||
}
|
||||
|
||||
async function requestReupload() {
|
||||
setError("");
|
||||
setLoading(true);
|
||||
const result = await requestReuploadAction(
|
||||
verification.id,
|
||||
reuploadFields,
|
||||
reuploadNote
|
||||
);
|
||||
setLoading(false);
|
||||
if ("error" in result && result.error) {
|
||||
setError(result.error);
|
||||
return;
|
||||
}
|
||||
setShowReupload(false);
|
||||
setReuploadFields([]);
|
||||
setReuploadNote("");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
async function decide(decision: "APPROVED" | "REJECTED") {
|
||||
setError("");
|
||||
setLoading(true);
|
||||
@@ -192,26 +231,7 @@ export function ReviewCard({ verification }: { verification: Verification }) {
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{!showReject ? (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decide("APPROVED")}
|
||||
disabled={loading}
|
||||
className="rounded-xl bg-primary-600 px-4 py-2 text-sm font-bold text-white hover:bg-primary-700 disabled:opacity-50"
|
||||
>
|
||||
✅ Setujui
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowReject(true)}
|
||||
disabled={loading}
|
||||
className="rounded-xl border border-red-200 bg-white px-4 py-2 text-sm font-bold text-red-600 hover:bg-red-50 disabled:opacity-50"
|
||||
>
|
||||
❌ Tolak
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
{showReject ? (
|
||||
<div className="space-y-2">
|
||||
<textarea
|
||||
value={rejectionReason}
|
||||
@@ -241,6 +261,102 @@ export function ReviewCard({ verification }: { verification: Verification }) {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : showReupload ? (
|
||||
<div className="space-y-3 rounded-xl border border-amber-200 bg-amber-50/60 p-3">
|
||||
<div>
|
||||
<label className="mb-1 block text-xs font-semibold text-amber-900">
|
||||
Field yang perlu di-upload ulang (min 1)
|
||||
</label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{REUPLOAD_FIELD_LABELS.map((f) => {
|
||||
const checked = reuploadFields.includes(f.value);
|
||||
return (
|
||||
<label
|
||||
key={f.value}
|
||||
className={`cursor-pointer rounded-full border px-3 py-1 text-xs font-medium ${
|
||||
checked
|
||||
? "border-amber-600 bg-amber-600 text-white"
|
||||
: "border-amber-200 bg-white text-amber-800 hover:bg-amber-100"
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={() => toggleReuploadField(f.value)}
|
||||
className="sr-only"
|
||||
/>
|
||||
{f.label}
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-xs font-semibold text-amber-900">
|
||||
Catatan untuk organizer (min 10 char — akan dilihat user)
|
||||
</label>
|
||||
<textarea
|
||||
value={reuploadNote}
|
||||
onChange={(e) => setReuploadNote(e.target.value)}
|
||||
rows={2}
|
||||
maxLength={500}
|
||||
placeholder="contoh: Foto KTP terlalu buram, tolong foto ulang dengan pencahayaan lebih baik."
|
||||
className="w-full rounded-xl border border-amber-200 bg-white px-3 py-2 text-sm focus:border-amber-400"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={requestReupload}
|
||||
disabled={
|
||||
loading ||
|
||||
reuploadFields.length === 0 ||
|
||||
reuploadNote.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..." : "Kirim Permintaan"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setShowReupload(false);
|
||||
setReuploadFields([]);
|
||||
setReuploadNote("");
|
||||
}}
|
||||
className="rounded-xl border border-neutral-200 bg-white px-4 py-2 text-sm font-medium text-neutral-600 hover:bg-neutral-50"
|
||||
>
|
||||
Batal
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decide("APPROVED")}
|
||||
disabled={loading}
|
||||
className="rounded-xl bg-primary-600 px-4 py-2 text-sm font-bold text-white hover:bg-primary-700 disabled:opacity-50"
|
||||
>
|
||||
✅ Setujui
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowReupload(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"
|
||||
>
|
||||
🔄 Minta re-upload
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowReject(true)}
|
||||
disabled={loading}
|
||||
className="rounded-xl border border-red-200 bg-white px-4 py-2 text-sm font-bold text-red-600 hover:bg-red-50 disabled:opacity-50"
|
||||
>
|
||||
❌ Tolak
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user