"use client"; import { useEffect, useState } from "react"; import { Upload, Plus, Settings, CheckCheck, Check, Clock, X, } from "lucide-react"; import Image from "next/image"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { Card, CardHeader, CardContent, CardTitle } from "@/components/ui/card"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { error, loading, success } from "@/config/swal"; import { Controller, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { useDropzone } from "react-dropzone"; import z from "zod"; import dynamic from "next/dynamic"; import { useParams, useRouter } from "next/navigation"; import Cookies from "js-cookie"; import { getProductDataById } from "@/service/product"; import { approveAgent, getAgentById, updateAgent } from "@/service/agent"; import { Checkbox } from "@/components/ui/checkbox"; import { convertDateFormat } from "@/utils/global"; const ViewEditor = dynamic( () => { return import("@/components/editor/view-editor"); }, { ssr: false }, ); const CustomEditor = dynamic( () => { return import("@/components/editor/custom-editor"); }, { ssr: false }, ); interface FileWithPreview extends File { preview: string; } interface CategoryType { id: number; label: string; value: number; } const categorySchema = z.object({ id: z.number(), label: z.string(), value: z.number(), }); const AGENT_TYPES = [ { key: "after-sales", label: "After Sales" }, { key: "sales", label: "Sales" }, { key: "spv", label: "SPV" }, { key: "branch_manager", label: "Branch Manager" }, ]; const createArticleSchema = z.object({ title: z.string().min(2, { message: "Judul harus diisi", }), variant: z.string().min(2, { message: "variant diisi", }), price: z.string().min(2, { message: "Price harus diisi", }), category: z.array(categorySchema).nonempty({ message: "Kategori harus memiliki setidaknya satu item", }), tags: z.array(z.string()).nonempty({ message: "Minimal 1 tag", }), // Array berisi string }); export default function DetailAgentForm(props: { isDetail: boolean }) { const { isDetail } = props; const params = useParams(); const id = params?.id; const [data, setData] = useState(null); const [openApproverHistory, setOpenApproverHistory] = useState(false); const [userLevelId, setUserLevelId] = useState(null); const router = useRouter(); const [openCommentModal, setOpenCommentModal] = useState(false); const [commentValue, setCommentValue] = useState(""); const handleSubmitComment = async () => { // await api.post("/banner/comment", { // bannerId: viewBanner.id, // comment: commentValue, // }); setOpenCommentModal(false); }; // 🔹 Ambil userlevelId dari cookies useEffect(() => { const ulne = Cookies.get("ulne"); // contoh: "3" setUserLevelId(ulne ?? null); }, []); useEffect(() => { fetchData(); }, []); async function fetchData() { const res = await getAgentById(id); setData(res?.data?.data); } if (!data) return null; const handleOpenApproverHistory = () => { setOpenApproverHistory(true); }; // const handleRejectProduct = async (id: number) => { // loading(); // const payload = { // status_id: 3, // ✅ number // }; // const res = await updateAgent(payload, id); // if (res?.error) { // error(res.message || "Gagal menolak product"); // close(); // return; // } // close(); // success("Product berhasil ditolak"); // fetchData(); // }; const handleApproveAgent = async (id: number) => { loading(); const res = await approveAgent(id); if (res?.error) { error(res.message || "Gagal menyetujui agent"); close(); return; } close(); success("Agent berhasil disetujui"); fetchData(); // refresh table }; return ( <> Detail Agen {/* FORM */}
{/* JENIS AGEN */}
{AGENT_TYPES.map((item) => (
{item.label}
))}
{/* FOTO PROFILE */}
Profile

Status Timeline

Diupload oleh Operator

{convertDateFormat(data.created_at)} WIB

{data?.status_id === 1 ? ( ) : data?.status_id === 2 ? ( ) : ( )}

{data?.status_id === 1 ? "Menunggu disetujui oleh Approver" : data?.status_id === 2 ? "Disetujui oleh Approver" : "Ditolak oleh Approver"}

{convertDateFormat(data?.updated_at)} WIB

Comment :

Jaecoo - Approver | 10/11/2026

{userLevelId !== "2" && data && (
{data.status_id === 1 ? ( <> {userLevelId === "1" && ( )} ) : ( )}
)} {/* */}
{openApproverHistory && (
setOpenApproverHistory(false)} >
e.stopPropagation()} > {/* HEADER */}

Approver History

Menunggu Banner 1
{/* BODY */}
{/* LEFT TIMELINE */}
{/* Upload */}
Upload
{/* Diterima */}

Diterima

Direview oleh: approver-jaecoo1
{/* Pending */}

Pending

Direview oleh: approver-jaecoo1
{/* ARROW */}
> >
{/* RIGHT NOTES */}
Catatan:
Catatan:
{/* FOOTER */}
)} ); }