update
This commit is contained in:
parent
63e0890e08
commit
13f76dc8b5
|
|
@ -0,0 +1,12 @@
|
|||
import DetailAgentForm from "@/components/form/agent/detail-agent-form";
|
||||
import DetailProductForm from "@/components/form/product/detail-product-form";
|
||||
|
||||
export default function DetailAgentPage() {
|
||||
return (
|
||||
<div className="">
|
||||
<div className="h-[96vh] p-3 lg:p-8 bg-slate-100 dark:!bg-black overflow-y-auto">
|
||||
<DetailAgentForm isDetail={true} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -3,17 +3,6 @@ import EditArticleForm from "@/components/form/article/edit-article-form";
|
|||
export default function DetailArticlePage() {
|
||||
return (
|
||||
<div className="">
|
||||
{/* <div className="flex flex-row justify-between border-b-2 px-4 bg-white shadow-md">
|
||||
<div className="flex flex-col gap-1 py-2">
|
||||
<h1 className="font-bold text-[25px]">Article</h1>
|
||||
<p className="text-[14px]">Article</p>
|
||||
</div>
|
||||
<span className="flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="44" height="44" viewBox="0 0 20 20">
|
||||
<path fill="currentColor" d="M5 1a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm0 3h5v1H5zm0 2h5v1H5zm0 2h5v1H5zm10 7H5v-1h10zm0-2H5v-1h10zm0-2H5v-1h10zm0-2h-4V4h4z" />
|
||||
</svg>
|
||||
</span>
|
||||
</div> */}
|
||||
<div className="h-[96vh] p-3 lg:p-8 bg-slate-100 dark:!bg-black overflow-y-auto">
|
||||
<EditArticleForm isDetail={true} />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
import EditArticleForm from "@/components/form/article/edit-article-form";
|
||||
import DetailProductForm from "@/components/form/product/detail-product-form";
|
||||
|
||||
export default function DetailProductPage() {
|
||||
return (
|
||||
<div className="">
|
||||
<div className="h-[96vh] p-3 lg:p-8 bg-slate-100 dark:!bg-black overflow-y-auto">
|
||||
<DetailProductForm isDetail={true} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ import { getGaleryFileData } from "@/service/galery";
|
|||
|
||||
export function DialogDetailGaleri({ open, onClose, data }: any) {
|
||||
const [images, setImages] = useState<any[]>([]);
|
||||
const [openApproverHistory, setOpenApproverHistory] = useState(false);
|
||||
|
||||
const fetchImages = async () => {
|
||||
try {
|
||||
|
|
@ -21,7 +22,7 @@ export function DialogDetailGaleri({ open, onClose, data }: any) {
|
|||
const allImages = res?.data?.data ?? [];
|
||||
|
||||
const filteredImages = allImages.filter(
|
||||
(img: any) => img.gallery_id === data.id
|
||||
(img: any) => img.gallery_id === data.id,
|
||||
);
|
||||
|
||||
setImages(filteredImages);
|
||||
|
|
@ -39,108 +40,232 @@ export function DialogDetailGaleri({ open, onClose, data }: any) {
|
|||
const openFile = (url: string) => {
|
||||
window.open(url, "_blank");
|
||||
};
|
||||
const handleOpenApproverHistory = () => {
|
||||
setOpenApproverHistory(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onClose}>
|
||||
<DialogContent className="max-w-3xl rounded-2xl p-0 overflow-hidden">
|
||||
{/* Header */}
|
||||
<div className="bg-[#1F6779] text-white px-6 py-4">
|
||||
<DialogTitle className="text-white">Detail Galeri</DialogTitle>
|
||||
</div>
|
||||
|
||||
<div className="px-6 py-6 space-y-6">
|
||||
{/* Images List */}
|
||||
<div>
|
||||
<p className="font-medium mb-2">Daftar Gambar</p>
|
||||
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
{images.length === 0 && (
|
||||
<p className="text-gray-500 col-span-3 text-center">
|
||||
Tidak ada gambar.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{images.map((img) => (
|
||||
<div
|
||||
key={img.id}
|
||||
className="relative h-32 w-full cursor-pointer group"
|
||||
onClick={() => openFile(img.image_url)}
|
||||
>
|
||||
<Image
|
||||
src={img.image_url}
|
||||
alt={img.title}
|
||||
fill
|
||||
className="object-cover rounded-lg"
|
||||
/>
|
||||
|
||||
<div className="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 text-white flex items-center justify-center text-sm transition">
|
||||
Lihat File
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<>
|
||||
<Dialog open={open} onOpenChange={onClose}>
|
||||
<DialogContent className="max-w-3xl rounded-2xl p-0 overflow-hidden">
|
||||
{/* Header */}
|
||||
<div className="bg-[#1F6779] text-white px-6 py-4">
|
||||
<DialogTitle className="text-white">Detail Galeri</DialogTitle>
|
||||
</div>
|
||||
|
||||
{/* Title */}
|
||||
<h2 className="text-2xl font-semibold text-[#1F6779]">
|
||||
{data.title}
|
||||
</h2>
|
||||
|
||||
{/* Deskripsi */}
|
||||
<div>
|
||||
<p className="font-medium text-sm text-gray-700">Deskripsi</p>
|
||||
<p className="text-gray-600">{data.description}</p>
|
||||
</div>
|
||||
|
||||
{/* Tanggal Upload */}
|
||||
<div>
|
||||
<p className="font-medium text-sm text-gray-700">Tanggal Upload</p>
|
||||
<p className="text-gray-600">
|
||||
{new Date(data.created_at).toLocaleDateString("id-ID")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Timeline */}
|
||||
<div>
|
||||
<p className="font-medium text-sm text-gray-700 mb-2">
|
||||
Status Timeline
|
||||
</p>
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-start gap-3">
|
||||
<CheckCircle className="text-green-600" />
|
||||
<div>
|
||||
<p className="font-semibold">Upload Berhasil</p>
|
||||
<p className="text-gray-500 text-sm">
|
||||
{new Date(data.created_at).toLocaleString("id-ID")}
|
||||
</p>
|
||||
</div>
|
||||
<div className="px-6 py-3">
|
||||
{/* Images List */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-semibold text-black">
|
||||
{data.title}
|
||||
</h2>
|
||||
<div className="my-3">
|
||||
<p className="font-medium text-sm text-black">Deskripsi</p>
|
||||
<p className="text-gray-800">{data.description}</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
{images.length === 0 && (
|
||||
<p className="text-gray-500 col-span-3 text-center">
|
||||
Tidak ada gambar.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{data.approved_at && (
|
||||
{images.map((img) => (
|
||||
<div
|
||||
key={img.id}
|
||||
className="relative h-32 w-full cursor-pointer group"
|
||||
onClick={() => openFile(img.image_url)}
|
||||
>
|
||||
<Image
|
||||
src={img.image_url}
|
||||
alt={img.title}
|
||||
fill
|
||||
className="object-cover rounded-lg"
|
||||
/>
|
||||
|
||||
<div className="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 text-white flex items-center justify-center text-sm transition">
|
||||
Lihat File
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Title */}
|
||||
|
||||
{/* Deskripsi */}
|
||||
|
||||
{/* Tanggal Upload */}
|
||||
<div>
|
||||
<p className="font-medium text-sm text-gray-700">
|
||||
Tanggal Upload
|
||||
</p>
|
||||
<p className="text-gray-600">
|
||||
{new Date(data.created_at).toLocaleDateString("id-ID")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Timeline */}
|
||||
<div>
|
||||
<p className="font-medium text-sm text-gray-700 mb-2">
|
||||
Status Timeline
|
||||
</p>
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-start gap-3">
|
||||
<CheckCircle className="text-green-600" />
|
||||
<div>
|
||||
<p className="font-semibold">Disetujui oleh Approver</p>
|
||||
<p className="font-semibold">Diupload Oleh :</p>
|
||||
<p className="text-gray-500 text-sm">
|
||||
{new Date(data.approved_at).toLocaleString("id-ID")}
|
||||
{new Date(data.created_at).toLocaleString("id-ID")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-start gap-3">
|
||||
<CheckCircle className="text-green-600" />
|
||||
<div>
|
||||
<p className="font-semibold">Disetujui Oleh :</p>
|
||||
<p className="text-gray-500 text-sm">
|
||||
{new Date(data.created_at).toLocaleString("id-ID")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{data.approved_at && (
|
||||
<div className="flex items-start gap-3">
|
||||
<CheckCircle className="text-green-600" />
|
||||
<div>
|
||||
<p className="font-semibold">Disetujui oleh Approver</p>
|
||||
<p className="text-gray-500 text-sm">
|
||||
{new Date(data.approved_at).toLocaleString("id-ID")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="border rounded-lg px-3 py-3">
|
||||
<p>Comment : </p>
|
||||
<div className="flex flex-row justify-between">
|
||||
<button
|
||||
onClick={handleOpenApproverHistory}
|
||||
className="text-sm text-blue-600 hover:underline mt-2"
|
||||
>
|
||||
View Approver History
|
||||
</button>
|
||||
<p>Jaecoo - Approver | 10/11/2026</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* <DialogFooter className="px-6 pb-6">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="bg-gray-300 text-gray-700 px-6 py-2 rounded-lg"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
</DialogFooter> */}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
{openApproverHistory && (
|
||||
<div
|
||||
className="fixed inset-0 z-[60] flex items-center justify-center bg-black/50 p-4"
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
>
|
||||
<div
|
||||
className="bg-white rounded-2xl shadow-2xl max-w-3xl w-full overflow-hidden"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* HEADER */}
|
||||
<div className="bg-gradient-to-br from-[#1F6779] to-[#0F6C75] text-white px-6 py-5 relative">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="absolute top-4 right-4 text-white/80 hover:text-white text-xl"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
|
||||
<h2 className="text-lg font-semibold">Approver History</h2>
|
||||
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
<span className="bg-white text-[#0F6C75] text-xs font-medium px-3 py-1 rounded-full">
|
||||
Banner
|
||||
</span>
|
||||
<span className="bg-white/20 text-white text-xs px-2 py-[2px] rounded-full">
|
||||
1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BODY */}
|
||||
<div className="p-6 grid grid-cols-[1fr_auto_1fr] gap-6 items-start">
|
||||
{/* LEFT TIMELINE */}
|
||||
<div className="relative space-y-6">
|
||||
{/* Upload */}
|
||||
<div className="flex flex-col items-center">
|
||||
<span className="bg-[#C7DDE4] text-[#0F6C75] text-xs px-4 py-1 rounded-full">
|
||||
Upload
|
||||
</span>
|
||||
<div className="w-px h-6 bg-gray-300" />
|
||||
</div>
|
||||
|
||||
{/* Diterima */}
|
||||
<div className="relative bg-[#1F6779] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Diterima</h4>
|
||||
<span className="inline-block bg-[#E3EFF4] text-[#0F6C75] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-px h-6 bg-gray-300 mx-auto" />
|
||||
|
||||
{/* Pending */}
|
||||
<div className="relative bg-[#B36A00] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Pending</h4>
|
||||
<span className="inline-block bg-[#FFF6CC] text-[#7A4A00] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ARROW */}
|
||||
<div className="flex flex-col gap-20 text-gray-500 font-bold">
|
||||
<span>></span>
|
||||
<span>></span>
|
||||
</div>
|
||||
|
||||
{/* RIGHT NOTES */}
|
||||
<div className="space-y-14">
|
||||
<div>
|
||||
<div className="bg-[#C7DDE4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="bg-[#FFF9C4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* FOOTER */}
|
||||
<div className="border-t bg-[#F2F7FA] text-center py-3">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="text-[#0F6C75] font-medium hover:underline"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="px-6 pb-6">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="bg-gray-300 text-gray-700 px-6 py-2 rounded-lg"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ export default function PromoDetailDialog({
|
|||
}: PromoDetailDialogProps) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [promo, setPromo] = useState<any>(null);
|
||||
const [openApproverHistory, setOpenApproverHistory] = useState(false);
|
||||
|
||||
// FORMAT TANGGAL → DD-MM-YYYY
|
||||
const formatDate = (dateStr: string) => {
|
||||
|
|
@ -33,7 +34,9 @@ export default function PromoDetailDialog({
|
|||
return `${day}-${month}-${year}`;
|
||||
};
|
||||
|
||||
// FETCH API PROMO BY ID
|
||||
const handleOpenApproverHistory = () => {
|
||||
setOpenApproverHistory(true);
|
||||
};
|
||||
useEffect(() => {
|
||||
if (!promoId || !open) return;
|
||||
|
||||
|
|
@ -54,7 +57,7 @@ export default function PromoDetailDialog({
|
|||
date: formatDate(res?.data?.data?.created_at),
|
||||
time: new Date(res?.data?.data?.created_at).toLocaleTimeString(
|
||||
"id-ID",
|
||||
{ hour: "2-digit", minute: "2-digit" }
|
||||
{ hour: "2-digit", minute: "2-digit" },
|
||||
),
|
||||
},
|
||||
{
|
||||
|
|
@ -62,7 +65,7 @@ export default function PromoDetailDialog({
|
|||
date: formatDate(res?.data?.data?.updated_at),
|
||||
time: new Date(res?.data?.data?.updated_at).toLocaleTimeString(
|
||||
"id-ID",
|
||||
{ hour: "2-digit", minute: "2-digit" }
|
||||
{ hour: "2-digit", minute: "2-digit" },
|
||||
),
|
||||
},
|
||||
],
|
||||
|
|
@ -82,92 +85,301 @@ export default function PromoDetailDialog({
|
|||
if (!open) return null;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="p-0 max-w-xl overflow-hidden rounded-2xl">
|
||||
{/* HEADER */}
|
||||
<div className="bg-gradient-to-r from-[#0f6c75] to-[#145f66] text-white px-6 py-5 relative">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-white text-xl font-semibold">
|
||||
Detail Promo
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<>
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="p-0 max-w-xl overflow-hidden rounded-2xl">
|
||||
{/* HEADER */}
|
||||
<div className="bg-gradient-to-r from-[#0f6c75] to-[#145f66] text-white px-6 py-5 relative">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-white text-xl font-semibold">
|
||||
Detail Promo
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{/* STATUS BADGE */}
|
||||
{promo && (
|
||||
<div className="mt-2 bg-white/20 text-white px-4 py-[3px] rounded-full text-xs inline-flex items-center gap-2">
|
||||
<span className="w-2 h-2 rounded-full bg-lime-300"></span>
|
||||
{promo.status}
|
||||
{/* STATUS BADGE */}
|
||||
{promo && (
|
||||
<div className="mt-2 bg-white/20 text-white px-4 py-[3px] rounded-full text-xs inline-flex items-center gap-2">
|
||||
<span className="w-2 h-2 rounded-full bg-lime-300"></span>
|
||||
{promo.status}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* BODY */}
|
||||
<div className="p-6">
|
||||
{loading ? (
|
||||
<p className="text-Start text-gray-600">Memuat data...</p>
|
||||
) : promo ? (
|
||||
<>
|
||||
{/* <div className="flex justify-center mb-4">
|
||||
<div className="bg-[#E8F1F6] p-4 rounded-xl">
|
||||
<FileText size={60} className="text-[#0f6c75]" />
|
||||
</div>
|
||||
</div> */}
|
||||
|
||||
<h2 className="text-xl font-semibold text-Start mb-6">
|
||||
{promo.title}
|
||||
</h2>
|
||||
|
||||
<div className="space-y-4 text-sm">
|
||||
<div>
|
||||
<p className="text-gray-600">Ukuran File</p>
|
||||
<p className="font-medium">{promo.fileSize}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-gray-600">Tanggal Upload</p>
|
||||
<p className="font-medium">{promo.uploadDate}</p>
|
||||
</div>
|
||||
|
||||
{/* TIMELINE */}
|
||||
<div className="mt-4">
|
||||
<p className="text-gray-600 mb-3 font-medium">
|
||||
Status Timeline
|
||||
</p>
|
||||
|
||||
<div className="space-y-4">
|
||||
{promo.timeline.map((item: any, idx: number) => (
|
||||
<div key={idx} className="flex gap-3 items-start">
|
||||
<CheckCircle2
|
||||
size={20}
|
||||
className="text-green-600 shrink-0"
|
||||
/>
|
||||
<div>
|
||||
<p className="font-medium">{item.label}</p>
|
||||
<p className="text-gray-600 text-sm">
|
||||
{item.date} • {item.time} WIB
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="border rounded-lg px-3 py-3 mt-3">
|
||||
<p>Comment : </p>
|
||||
<div className="flex flex-row justify-between">
|
||||
<button
|
||||
onClick={handleOpenApproverHistory}
|
||||
className="text-sm text-blue-600 hover:underline mt-2"
|
||||
>
|
||||
View Approver History
|
||||
</button>
|
||||
<p>Jaecoo - Approver | 10/11/2026</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-center text-gray-600">Data tidak ditemukan</p>
|
||||
)}
|
||||
</div>
|
||||
{openApproverHistory && (
|
||||
<div
|
||||
className="fixed inset-0 z-[60] flex items-center justify-center bg-black/50 p-4"
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
>
|
||||
<div
|
||||
className="bg-white rounded-2xl shadow-2xl max-w-3xl w-full overflow-hidden"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* HEADER */}
|
||||
<div className="bg-gradient-to-br from-[#1F6779] to-[#0F6C75] text-white px-6 py-5 relative">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="absolute top-4 right-4 text-white/80 hover:text-white text-xl"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
|
||||
<h2 className="text-lg font-semibold">Approver History</h2>
|
||||
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
<span className="bg-white text-[#0F6C75] text-xs font-medium px-3 py-1 rounded-full">
|
||||
Banner
|
||||
</span>
|
||||
<span className="bg-white/20 text-white text-xs px-2 py-[2px] rounded-full">
|
||||
1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BODY */}
|
||||
<div className="p-6 grid grid-cols-[1fr_auto_1fr] gap-6 items-start">
|
||||
{/* LEFT TIMELINE */}
|
||||
<div className="relative space-y-6">
|
||||
{/* Upload */}
|
||||
<div className="flex flex-col items-center">
|
||||
<span className="bg-[#C7DDE4] text-[#0F6C75] text-xs px-4 py-1 rounded-full">
|
||||
Upload
|
||||
</span>
|
||||
<div className="w-px h-6 bg-gray-300" />
|
||||
</div>
|
||||
|
||||
{/* Diterima */}
|
||||
<div className="relative bg-[#1F6779] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Diterima</h4>
|
||||
<span className="inline-block bg-[#E3EFF4] text-[#0F6C75] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-px h-6 bg-gray-300 mx-auto" />
|
||||
|
||||
{/* Pending */}
|
||||
<div className="relative bg-[#B36A00] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Pending</h4>
|
||||
<span className="inline-block bg-[#FFF6CC] text-[#7A4A00] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ARROW */}
|
||||
<div className="flex flex-col gap-20 text-gray-500 font-bold">
|
||||
<span>></span>
|
||||
<span>></span>
|
||||
</div>
|
||||
|
||||
{/* RIGHT NOTES */}
|
||||
<div className="space-y-14">
|
||||
<div>
|
||||
<div className="bg-[#C7DDE4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="bg-[#FFF9C4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* FOOTER */}
|
||||
<div className="border-t bg-[#F2F7FA] text-center py-3">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="text-[#0F6C75] font-medium hover:underline"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{/* FOOTER */}
|
||||
<div className="bg-[#E3EFF4] text-center py-3">
|
||||
<button
|
||||
onClick={() => onOpenChange(false)}
|
||||
className="text-[#0F6C75] font-medium hover:underline w-full"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
{openApproverHistory && (
|
||||
<div
|
||||
className="fixed inset-0 z-[60] flex items-center justify-center bg-black/50 p-4"
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
>
|
||||
<div
|
||||
className="bg-white rounded-2xl shadow-2xl max-w-3xl w-full overflow-hidden"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* HEADER */}
|
||||
<div className="bg-gradient-to-br from-[#1F6779] to-[#0F6C75] text-white px-6 py-5 relative">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="absolute top-4 right-4 text-white/80 hover:text-white text-xl"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
|
||||
{/* BODY */}
|
||||
<div className="p-6">
|
||||
{loading ? (
|
||||
<p className="text-center text-gray-600">Memuat data...</p>
|
||||
) : promo ? (
|
||||
<>
|
||||
<div className="flex justify-center mb-4">
|
||||
<div className="bg-[#E8F1F6] p-4 rounded-xl">
|
||||
<FileText size={60} className="text-[#0f6c75]" />
|
||||
<h2 className="text-lg font-semibold">Approver History</h2>
|
||||
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
<span className="bg-white text-[#0F6C75] text-xs font-medium px-3 py-1 rounded-full">
|
||||
Banner
|
||||
</span>
|
||||
<span className="bg-white/20 text-white text-xs px-2 py-[2px] rounded-full">
|
||||
1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BODY */}
|
||||
<div className="p-6 grid grid-cols-[1fr_auto_1fr] gap-6 items-start">
|
||||
{/* LEFT TIMELINE */}
|
||||
<div className="relative space-y-6">
|
||||
{/* Upload */}
|
||||
<div className="flex flex-col items-center">
|
||||
<span className="bg-[#C7DDE4] text-[#0F6C75] text-xs px-4 py-1 rounded-full">
|
||||
Upload
|
||||
</span>
|
||||
<div className="w-px h-6 bg-gray-300" />
|
||||
</div>
|
||||
|
||||
{/* Diterima */}
|
||||
<div className="relative bg-[#1F6779] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Diterima</h4>
|
||||
<span className="inline-block bg-[#E3EFF4] text-[#0F6C75] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-px h-6 bg-gray-300 mx-auto" />
|
||||
|
||||
{/* Pending */}
|
||||
<div className="relative bg-[#B36A00] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Pending</h4>
|
||||
<span className="inline-block bg-[#FFF6CC] text-[#7A4A00] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 className="text-xl font-semibold text-center mb-6">
|
||||
{promo.title}
|
||||
</h2>
|
||||
{/* ARROW */}
|
||||
<div className="flex flex-col gap-20 text-gray-500 font-bold">
|
||||
<span>></span>
|
||||
<span>></span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4 text-sm">
|
||||
{/* RIGHT NOTES */}
|
||||
<div className="space-y-14">
|
||||
<div>
|
||||
<p className="text-gray-600">Ukuran File</p>
|
||||
<p className="font-medium">{promo.fileSize}</p>
|
||||
<div className="bg-[#C7DDE4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-gray-600">Tanggal Upload</p>
|
||||
<p className="font-medium">{promo.uploadDate}</p>
|
||||
</div>
|
||||
|
||||
{/* TIMELINE */}
|
||||
<div className="mt-4">
|
||||
<p className="text-gray-600 mb-3 font-medium">
|
||||
Status Timeline
|
||||
</p>
|
||||
|
||||
<div className="space-y-4">
|
||||
{promo.timeline.map((item: any, idx: number) => (
|
||||
<div key={idx} className="flex gap-3 items-start">
|
||||
<CheckCircle2
|
||||
size={20}
|
||||
className="text-green-600 shrink-0"
|
||||
/>
|
||||
<div>
|
||||
<p className="font-medium">{item.label}</p>
|
||||
<p className="text-gray-600 text-sm">
|
||||
{item.date} • {item.time} WIB
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div className="bg-[#FFF9C4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-center text-gray-600">Data tidak ditemukan</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* FOOTER */}
|
||||
<div className="bg-[#E3EFF4] text-center py-3">
|
||||
<button
|
||||
onClick={() => onOpenChange(false)}
|
||||
className="text-[#0F6C75] font-medium hover:underline w-full"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
{/* FOOTER */}
|
||||
<div className="border-t bg-[#F2F7FA] text-center py-3">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="text-[#0F6C75] font-medium hover:underline"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,275 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Upload, Plus, Settings, CheckCheck } 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 { loading } 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 } from "next/navigation";
|
||||
import Cookies from "js-cookie";
|
||||
import { getProductDataById } from "@/service/product";
|
||||
import { getAgentById } from "@/service/agent";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
|
||||
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<any>(null);
|
||||
const [openApproverHistory, setOpenApproverHistory] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
async function fetchData() {
|
||||
const res = await getAgentById(id);
|
||||
setData(res?.data?.data);
|
||||
}
|
||||
|
||||
if (!data) return null;
|
||||
|
||||
const handleOpenApproverHistory = () => {
|
||||
setOpenApproverHistory(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card className="w-full border-none shadow-md">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-xl font-bold text-teal-900">
|
||||
Detail Agen
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="space-y-6">
|
||||
{/* FORM */}
|
||||
<div className="grid md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<Label className="mb-2">Nama Lengkap</Label>
|
||||
<Input value={data.name} readOnly />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label className="mb-2">Jabatan</Label>
|
||||
<Input value={data.job_title} readOnly />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label className="mb-2">No Telp</Label>
|
||||
<Input value={data.phone} readOnly />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* JENIS AGEN */}
|
||||
<div>
|
||||
<Label className="mb-2 block">Jenis Agen</Label>
|
||||
<div className="flex gap-6">
|
||||
{AGENT_TYPES.map((item) => (
|
||||
<div key={item.key} className="flex items-center gap-2">
|
||||
<Checkbox checked={data.job_title === item.key} disabled />
|
||||
<span>{item.label}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* FOTO PROFILE */}
|
||||
<div>
|
||||
<Label className="mb-2 block">Foto Profile</Label>
|
||||
<div className="w-24 h-24 rounded-lg overflow-hidden border">
|
||||
<Image
|
||||
src={data.profile_picture_url}
|
||||
alt="Profile"
|
||||
width={96}
|
||||
height={96}
|
||||
className="object-cover"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border rounded-lg px-3 py-3">
|
||||
<p>Comment : </p>
|
||||
<div className="flex flex-row justify-between">
|
||||
<button
|
||||
onClick={handleOpenApproverHistory}
|
||||
className="text-sm text-blue-600 hover:underline mt-2"
|
||||
>
|
||||
View Approver History
|
||||
</button>
|
||||
<p>Jaecoo - Approver | 10/11/2026</p>
|
||||
</div>
|
||||
</div>
|
||||
{/* <Button className=" bg-teal-800 hover:bg-teal-900 text-white py-3">
|
||||
Submit
|
||||
</Button> */}
|
||||
</CardContent>
|
||||
</Card>
|
||||
{openApproverHistory && (
|
||||
<div
|
||||
className="fixed inset-0 z-[60] flex items-center justify-center bg-black/50 p-4"
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
>
|
||||
<div
|
||||
className="bg-white rounded-2xl shadow-2xl max-w-3xl w-full overflow-hidden"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* HEADER */}
|
||||
<div className="bg-gradient-to-br from-[#1F6779] to-[#0F6C75] text-white px-6 py-5 relative">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="absolute top-4 right-4 text-white/80 hover:text-white text-xl"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
|
||||
<h2 className="text-lg font-semibold">Approver History</h2>
|
||||
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
<span className="bg-white text-[#0F6C75] text-xs font-medium px-3 py-1 rounded-full">
|
||||
Banner
|
||||
</span>
|
||||
<span className="bg-white/20 text-white text-xs px-2 py-[2px] rounded-full">
|
||||
1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BODY */}
|
||||
<div className="p-6 grid grid-cols-[1fr_auto_1fr] gap-6 items-start">
|
||||
{/* LEFT TIMELINE */}
|
||||
<div className="relative space-y-6">
|
||||
{/* Upload */}
|
||||
<div className="flex flex-col items-center">
|
||||
<span className="bg-[#C7DDE4] text-[#0F6C75] text-xs px-4 py-1 rounded-full">
|
||||
Upload
|
||||
</span>
|
||||
<div className="w-px h-6 bg-gray-300" />
|
||||
</div>
|
||||
|
||||
{/* Diterima */}
|
||||
<div className="relative bg-[#1F6779] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Diterima</h4>
|
||||
<span className="inline-block bg-[#E3EFF4] text-[#0F6C75] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-px h-6 bg-gray-300 mx-auto" />
|
||||
|
||||
{/* Pending */}
|
||||
<div className="relative bg-[#B36A00] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Pending</h4>
|
||||
<span className="inline-block bg-[#FFF6CC] text-[#7A4A00] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ARROW */}
|
||||
<div className="flex flex-col gap-20 text-gray-500 font-bold">
|
||||
<span>></span>
|
||||
<span>></span>
|
||||
</div>
|
||||
|
||||
{/* RIGHT NOTES */}
|
||||
<div className="space-y-14">
|
||||
<div>
|
||||
<div className="bg-[#C7DDE4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="bg-[#FFF9C4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* FOOTER */}
|
||||
<div className="border-t bg-[#F2F7FA] text-center py-3">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="text-[#0F6C75] font-medium hover:underline"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ import {
|
|||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
|
|
@ -24,55 +23,49 @@ type AgentFormValues = {
|
|||
position: string;
|
||||
phone: string;
|
||||
roles: string[];
|
||||
profileImage: File | null;
|
||||
};
|
||||
|
||||
const agentTypes = ["After Sales", "Sales", "Spv", "Branch Manager"];
|
||||
const AGENT_TYPES = ["after-Sales", "sales", "spv", "branch_manager"];
|
||||
|
||||
export default function UpdateAgentForm({ id }: { id: number }) {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [previewImg, setPreviewImg] = useState<string | null>(null);
|
||||
const [agentData, setAgentData] = useState<any>(null);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [preview, setPreview] = useState<string | null>(null);
|
||||
|
||||
const router = useRouter();
|
||||
const MySwal = withReactContent(Swal);
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [preview, setPreview] = useState<string | null>(null);
|
||||
const [agentData, setAgentData] = useState<any>(null);
|
||||
|
||||
const form = useForm<AgentFormValues>({
|
||||
defaultValues: {
|
||||
fullName: "",
|
||||
position: "",
|
||||
phone: "",
|
||||
roles: [],
|
||||
profileImage: null,
|
||||
},
|
||||
});
|
||||
|
||||
/* ================= FETCH DATA ================= */
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
try {
|
||||
const res = await getAgentById(id);
|
||||
const agent = res?.data?.data;
|
||||
if (!agent) return;
|
||||
|
||||
if (!res || !res.data) {
|
||||
console.error("DATA AGENT TIDAK DITEMUKAN");
|
||||
return;
|
||||
}
|
||||
|
||||
setAgentData(res.data);
|
||||
setAgentData(agent);
|
||||
|
||||
form.reset({
|
||||
fullName: res?.data?.data?.name,
|
||||
position: res?.data?.data?.job_title,
|
||||
phone: res?.data?.data?.phone,
|
||||
roles: res?.data?.data?.agent_type || [],
|
||||
profileImage: null,
|
||||
fullName: agent.name,
|
||||
position: agent.job_title,
|
||||
phone: agent.phone,
|
||||
roles: agent.job_title ? [agent.job_title] : [],
|
||||
});
|
||||
|
||||
console.log("name", res?.data?.data?.name);
|
||||
setPreviewImg(res.data.data.profile_picture_path || null);
|
||||
} catch (err) {
|
||||
console.error("ERROR FETCH DATA AGENT:", err);
|
||||
// ✅ FOTO DARI API
|
||||
setPreview(agent.profile_picture_url ?? null);
|
||||
} catch (error) {
|
||||
console.error("FETCH AGENT ERROR:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
|
@ -81,154 +74,133 @@ export default function UpdateAgentForm({ id }: { id: number }) {
|
|||
fetchData();
|
||||
}, [id, form]);
|
||||
|
||||
const handleFileChange = (e: any) => {
|
||||
const selected = e.target.files[0];
|
||||
if (selected) {
|
||||
setFile(selected);
|
||||
setPreview(URL.createObjectURL(selected));
|
||||
}
|
||||
/* ================= FILE HANDLER ================= */
|
||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const selected = e.target.files?.[0];
|
||||
if (!selected) return;
|
||||
|
||||
setFile(selected);
|
||||
setPreview(URL.createObjectURL(selected));
|
||||
};
|
||||
|
||||
const handleRemoveFile = () => {
|
||||
setFile(null);
|
||||
setPreview(null);
|
||||
setPreview(agentData?.profile_picture_url ?? null);
|
||||
};
|
||||
|
||||
/* ================= SUBMIT ================= */
|
||||
const onSubmit = async (data: AgentFormValues) => {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append("name", data.fullName);
|
||||
formData.append("job_title", data.position);
|
||||
formData.append("job_title", data.roles[0]); // single role
|
||||
formData.append("phone", data.phone);
|
||||
|
||||
data.roles.forEach((role) => {
|
||||
formData.append("agent_type", role);
|
||||
});
|
||||
|
||||
if (file) {
|
||||
formData.append("file", file);
|
||||
}
|
||||
|
||||
await updateAgent(id, formData);
|
||||
|
||||
successSubmit("/admin/agent");
|
||||
} catch (err) {
|
||||
console.error("ERROR UPDATE AGENT:", err);
|
||||
MySwal.fire({
|
||||
title: "Berhasil",
|
||||
text: "Data agen berhasil diperbarui",
|
||||
icon: "success",
|
||||
}).then(() => router.push("/admin/agent"));
|
||||
} catch (error) {
|
||||
console.error("UPDATE AGENT ERROR:", error);
|
||||
}
|
||||
};
|
||||
|
||||
function successSubmit(redirect: string) {
|
||||
MySwal.fire({
|
||||
title: "Data Berhasil Diupdate",
|
||||
icon: "success",
|
||||
confirmButtonColor: "#3085d6",
|
||||
confirmButtonText: "OK",
|
||||
}).then((res) => {
|
||||
if (res.isConfirmed) router.push(redirect);
|
||||
});
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <div className="p-6 text-gray-600">Loading data...</div>;
|
||||
}
|
||||
if (loading) return <p className="p-6">Loading...</p>;
|
||||
|
||||
return (
|
||||
<div className="bg-white dark:bg-neutral-900 p-6 rounded-lg shadow-sm">
|
||||
<div className="bg-white p-6 rounded-lg shadow-sm">
|
||||
<h2 className="text-2xl font-bold text-teal-800 mb-6">Edit Agen</h2>
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-5">
|
||||
{/* BASIC INFO */}
|
||||
<div className="grid md:grid-cols-3 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="fullName"
|
||||
rules={{ required: true }}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Nama Lengkap *</FormLabel>
|
||||
<FormLabel>Nama Lengkap</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Masukkan Nama" {...field} />
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Jabatan */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="position"
|
||||
rules={{ required: true }}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Jabatan *</FormLabel>
|
||||
<FormLabel>Jabatan</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Contoh: Branch Manager" {...field} />
|
||||
<Input {...field} readOnly />
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Telepon */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="phone"
|
||||
rules={{ required: true }}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>No Telp *</FormLabel>
|
||||
<FormLabel>No Telp</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Contoh: 0812xxxx" {...field} />
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* ROLES */}
|
||||
{/* JENIS AGEN */}
|
||||
<div>
|
||||
<FormLabel>Pilih Jenis Agen *</FormLabel>
|
||||
|
||||
<div className="flex flex-wrap gap-6 mt-3">
|
||||
{agentTypes.map((role) => (
|
||||
<FormLabel>Jenis Agen</FormLabel>
|
||||
<div className="flex gap-6 mt-3">
|
||||
{AGENT_TYPES.map((role) => (
|
||||
<FormField
|
||||
key={role}
|
||||
control={form.control}
|
||||
name="roles"
|
||||
render={({ field }) => {
|
||||
const selected = field.value || [];
|
||||
return (
|
||||
<FormItem className="flex flex-row items-center space-x-2">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={selected.includes(role)}
|
||||
onCheckedChange={(checked) => {
|
||||
const updated = checked
|
||||
? [...selected, role]
|
||||
: selected.filter((i) => i !== role);
|
||||
field.onChange(updated);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormLabel className="font-normal">{role}</FormLabel>
|
||||
</FormItem>
|
||||
);
|
||||
}}
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex items-center gap-2">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={field.value?.includes(role)}
|
||||
onCheckedChange={(checked) =>
|
||||
field.onChange(checked ? [role] : [])
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<span className="capitalize">
|
||||
{role.replace("_", " ")}
|
||||
</span>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* FOTO */}
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<FormLabel>Foto Agen</FormLabel>
|
||||
|
||||
<div className="flex items-center gap-5">
|
||||
<div className="flex items-center gap-5 mt-3">
|
||||
{preview && (
|
||||
<div className="mt-3 relative w-28 h-28 rounded-md overflow-hidden border">
|
||||
<div className="relative w-28 h-28 rounded-md overflow-hidden border">
|
||||
<img
|
||||
src={preview}
|
||||
alt="Preview"
|
||||
alt="Foto Agen"
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
<button
|
||||
|
|
@ -243,8 +215,8 @@ export default function UpdateAgentForm({ id }: { id: number }) {
|
|||
|
||||
<Button
|
||||
type="button"
|
||||
className="bg-teal-700 hover:bg-teal-800 text-white"
|
||||
onClick={() => document.getElementById("upload-photo")?.click()}
|
||||
className="bg-teal-700 text-white"
|
||||
>
|
||||
Upload Baru
|
||||
</Button>
|
||||
|
|
@ -252,31 +224,29 @@ export default function UpdateAgentForm({ id }: { id: number }) {
|
|||
<input
|
||||
id="upload-photo"
|
||||
type="file"
|
||||
className="hidden"
|
||||
accept="image/*"
|
||||
className="hidden"
|
||||
onChange={handleFileChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BUTTON */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 pt-5">
|
||||
<div className="grid md:grid-cols-3 gap-4 pt-6">
|
||||
<Button
|
||||
type="button"
|
||||
className="bg-gray-300 text-gray-700 hover:bg-gray-400"
|
||||
variant="secondary"
|
||||
onClick={() => router.back()}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
|
||||
<div className="md:col-span-2">
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full bg-teal-700 hover:bg-teal-800 text-white py-3"
|
||||
>
|
||||
Simpan Perubahan
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
type="submit"
|
||||
className="md:col-span-2 bg-teal-700 text-white"
|
||||
>
|
||||
Simpan Perubahan
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export default function AddProductForm() {
|
|||
const [file, setFile] = useState<File | null>(null);
|
||||
const router = useRouter();
|
||||
const MySwal = withReactContent(Swal);
|
||||
const [priceDisplay, setPriceDisplay] = useState("");
|
||||
|
||||
const handleFileChange = (e: any) => {
|
||||
const selected = e.target.files[0];
|
||||
|
|
@ -42,6 +43,7 @@ export default function AddProductForm() {
|
|||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
|
|
@ -86,10 +88,21 @@ export default function AddProductForm() {
|
|||
});
|
||||
}
|
||||
|
||||
const handlePriceChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const rawValue = e.target.value.replace(/\D/g, "");
|
||||
setPriceDisplay(formatRupiah(rawValue));
|
||||
setValue("price", rawValue ? Number(rawValue) : 0);
|
||||
};
|
||||
|
||||
const handleAddColor = () => {
|
||||
setColors((prev) => [...prev, { id: prev.length + 1 }]);
|
||||
};
|
||||
|
||||
const formatRupiah = (value: string) => {
|
||||
const number = value.replace(/\D/g, "");
|
||||
return number ? `Rp ${Number(number).toLocaleString("id-ID")}` : "";
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="w-full max-w-full mx-auto shadow-md border-none">
|
||||
<CardHeader>
|
||||
|
|
@ -127,8 +140,10 @@ export default function AddProductForm() {
|
|||
<Label>Harga Produk *</Label>
|
||||
<Input
|
||||
placeholder="Masukkan Harga Produk"
|
||||
{...register("price")}
|
||||
value={priceDisplay}
|
||||
onChange={handlePriceChange}
|
||||
/>
|
||||
|
||||
{errors.price && (
|
||||
<p className="text-sm text-red-500 mt-1">
|
||||
{errors.price.message}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,700 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Upload, Plus, Settings, CheckCheck } 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 { loading } 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 } from "next/navigation";
|
||||
import Cookies from "js-cookie";
|
||||
import { getProductDataById } from "@/service/product";
|
||||
|
||||
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 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 DetailProductForm(props: { isDetail: boolean }) {
|
||||
const { isDetail } = props;
|
||||
const params = useParams();
|
||||
const id = params?.id;
|
||||
const username = Cookies.get("username");
|
||||
const userId = Cookies.get("uie");
|
||||
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
||||
const [useAi, setUseAI] = useState(false);
|
||||
const [listCategory, setListCategory] = useState<CategoryType[]>([]);
|
||||
const [tag, setTag] = useState("");
|
||||
const [detailfiles, setDetailFiles] = useState<any>([]);
|
||||
const [mainImage, setMainImage] = useState(0);
|
||||
const [thumbnail, setThumbnail] = useState("");
|
||||
const [diseId, setDiseId] = useState(0);
|
||||
const [thumbnailImg, setThumbnailImg] = useState<File[]>([]);
|
||||
const [selectedMainImage, setSelectedMainImage] = useState<number | null>(
|
||||
null,
|
||||
);
|
||||
const [thumbnailValidation, setThumbnailValidation] = useState("");
|
||||
// const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const onOpen = () => setIsOpen(true);
|
||||
const onOpenChange = () => setIsOpen((prev) => !prev);
|
||||
const [approvalStatus, setApprovalStatus] = useState<number>(2);
|
||||
const [approvalMessage, setApprovalMessage] = useState("");
|
||||
const [detailData, setDetailData] = useState<any>();
|
||||
const [startDateValue, setStartDateValue] = useState<any>(null);
|
||||
const [timeValue, setTimeValue] = useState("00:00");
|
||||
const [openApproverHistory, setOpenApproverHistory] = useState(false);
|
||||
|
||||
const { getRootProps, getInputProps } = useDropzone({
|
||||
onDrop: (acceptedFiles) => {
|
||||
setFiles((prevFiles) => [
|
||||
...prevFiles,
|
||||
...acceptedFiles.map((file) => Object.assign(file)),
|
||||
]);
|
||||
},
|
||||
multiple: true,
|
||||
accept: {
|
||||
"image/*": [],
|
||||
},
|
||||
});
|
||||
|
||||
const formOptions = {
|
||||
resolver: zodResolver(createArticleSchema),
|
||||
defaultValues: { title: "", description: "", category: [], tags: [] },
|
||||
};
|
||||
type UserSettingSchema = z.infer<typeof createArticleSchema>;
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
setValue,
|
||||
getValues,
|
||||
watch,
|
||||
setError,
|
||||
clearErrors,
|
||||
} = useForm<UserSettingSchema>(formOptions);
|
||||
const [specs, setSpecs] = useState([
|
||||
{
|
||||
id: 1,
|
||||
title: "Jaecoo 7 SHS Teknologi dan Exterior",
|
||||
images: ["/spec1.jpg", "/spec2.jpg", "/spec3.jpg", "/spec4.jpg"],
|
||||
},
|
||||
]);
|
||||
|
||||
type ColorType = {
|
||||
id: number;
|
||||
name: string;
|
||||
preview: string;
|
||||
colorSelected: string | null;
|
||||
};
|
||||
|
||||
const [colors, setColors] = useState<ColorType[]>([
|
||||
{
|
||||
id: 1,
|
||||
name: "",
|
||||
preview: "/car-1.png",
|
||||
colorSelected: null,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "",
|
||||
preview: "/car-2.png",
|
||||
colorSelected: null,
|
||||
},
|
||||
]);
|
||||
|
||||
const palette = [
|
||||
"#1E4E52",
|
||||
"#597E8D",
|
||||
"#6B6B6B",
|
||||
"#BEBEBE",
|
||||
"#E2E2E2",
|
||||
"#F4F4F4",
|
||||
"#FFFFFF",
|
||||
"#F9360A",
|
||||
"#9A2A00",
|
||||
"#7A1400",
|
||||
"#4B0200",
|
||||
"#B48B84",
|
||||
"#FFA598",
|
||||
];
|
||||
|
||||
const handleAddSpec = () => {
|
||||
setSpecs((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: prev.length + 1,
|
||||
title: "",
|
||||
images: [],
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const handleAddColor = () => {
|
||||
setColors((p) => [
|
||||
...p,
|
||||
{
|
||||
id: p.length + 1,
|
||||
name: "",
|
||||
preview: "/car-default.png",
|
||||
colorSelected: null,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const [isUploadDialogOpen, setIsUploadDialogOpen] = useState(false);
|
||||
const [uploadTarget, setUploadTarget] = useState<{
|
||||
type: "spec" | "color";
|
||||
index: number;
|
||||
} | null>(null);
|
||||
|
||||
const fileInputId = "file-upload-input";
|
||||
|
||||
const handleFileSelected = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (!file || !uploadTarget) return;
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const fileUrl = reader.result as string;
|
||||
|
||||
if (uploadTarget.type === "spec") {
|
||||
setSpecs((prev) => {
|
||||
const updated = [...prev];
|
||||
updated[uploadTarget.index].images.push(fileUrl);
|
||||
return updated;
|
||||
});
|
||||
}
|
||||
|
||||
if (uploadTarget.type === "color") {
|
||||
setColors((prev) => {
|
||||
const updated = [...prev];
|
||||
updated[uploadTarget.index].preview = fileUrl;
|
||||
return updated;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file);
|
||||
setIsUploadDialogOpen(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
initState();
|
||||
}, [listCategory]);
|
||||
|
||||
async function initState() {
|
||||
const res = await getProductDataById(id);
|
||||
const data = res?.data?.data;
|
||||
|
||||
if (!data) return;
|
||||
|
||||
setDetailData(data);
|
||||
|
||||
// form
|
||||
setValue("title", data.title);
|
||||
setValue("variant", data.variant);
|
||||
setValue("price", formatRupiah(data.price));
|
||||
|
||||
// thumbnail
|
||||
setThumbnail(data.thumbnail_url);
|
||||
|
||||
// colors
|
||||
if (data.colors?.length) {
|
||||
setColors(
|
||||
data.colors.map((color: string, index: number) => ({
|
||||
id: index + 1,
|
||||
name: color,
|
||||
preview: data.thumbnail_url,
|
||||
colorSelected: color,
|
||||
})),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const handleOpenApproverHistory = () => {
|
||||
setOpenApproverHistory(true);
|
||||
};
|
||||
|
||||
const formatRupiah = (value: string) =>
|
||||
"Rp " + Number(value).toLocaleString("id-ID");
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card className="w-full border-none shadow-md">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-xl font-bold text-teal-900">
|
||||
Edit Produk
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="space-y-8">
|
||||
<div className="grid md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<Controller
|
||||
control={control}
|
||||
name="title"
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<div className="w-full">
|
||||
<label
|
||||
htmlFor="title"
|
||||
className="block text-sm font-medium mb-1"
|
||||
>
|
||||
Nama Produk <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
type="text"
|
||||
id="title"
|
||||
placeholder="Masukkan judul"
|
||||
value={value ?? ""}
|
||||
readOnly={isDetail}
|
||||
onChange={onChange}
|
||||
className="w-full border rounded-lg"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Controller
|
||||
control={control}
|
||||
name="variant"
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<div className="w-full">
|
||||
<label
|
||||
htmlFor="variant"
|
||||
className="block text-sm font-medium mb-1"
|
||||
>
|
||||
Variant <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
type="text"
|
||||
id="title"
|
||||
placeholder="Masukkan judul"
|
||||
value={value ?? ""}
|
||||
readOnly={isDetail}
|
||||
onChange={onChange}
|
||||
className="w-full border rounded-lg"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Controller
|
||||
control={control}
|
||||
name="price"
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<div className="w-full">
|
||||
<label
|
||||
htmlFor="price"
|
||||
className="block text-sm font-medium mb-1"
|
||||
>
|
||||
Variant <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
type="text"
|
||||
id="price"
|
||||
placeholder="Masukkan judul"
|
||||
value={value ?? ""}
|
||||
readOnly={isDetail}
|
||||
onChange={onChange}
|
||||
className="w-full border rounded-lg"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="font-semibold">Banner</Label>
|
||||
<div className="mt-2 w-[120px] h-[80px] rounded-lg overflow-hidden border bg-gray-100">
|
||||
{thumbnail ? (
|
||||
<Image
|
||||
src={thumbnail}
|
||||
alt="Banner"
|
||||
width={120}
|
||||
height={80}
|
||||
className="object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex items-center justify-center text-xs text-gray-400 h-full">
|
||||
No Image
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label className="font-semibold">Warna Produk *</Label>
|
||||
|
||||
{colors.map((item, index) => (
|
||||
<div key={item.id} className="mt-6 border-b pb-6">
|
||||
<Label>Pilih Warna {index + 1}</Label>
|
||||
<Input
|
||||
placeholder="Contoh: Silver / #E2E2E2"
|
||||
className="mt-1"
|
||||
value={item.name}
|
||||
readOnly
|
||||
/>
|
||||
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<div className="w-10 h-10 rounded-full flex items-center justify-center bg-teal-900">
|
||||
<Settings className="w-5 h-5 text-white" />
|
||||
</div>
|
||||
|
||||
{palette.map((colorCode) => (
|
||||
<button
|
||||
key={colorCode}
|
||||
type="button"
|
||||
disabled={isDetail}
|
||||
style={{ backgroundColor: colorCode }}
|
||||
className={`w-10 h-10 rounded-full border-2
|
||||
${
|
||||
item.colorSelected === colorCode
|
||||
? "border-teal-700 scale-110"
|
||||
: "border-gray-300"
|
||||
}
|
||||
${isDetail ? "cursor-not-allowed opacity-70" : ""}
|
||||
`}
|
||||
onClick={() => {
|
||||
setColors((prev) => {
|
||||
const updated = [...prev];
|
||||
updated[index].colorSelected = colorCode;
|
||||
return updated;
|
||||
});
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
<Label className="font-semibold">
|
||||
Foto Produk Warna {index + 1}
|
||||
</Label>
|
||||
|
||||
<div className="flex items-center gap-4 mt-2">
|
||||
<Image
|
||||
src={item.preview}
|
||||
alt="car color"
|
||||
width={120}
|
||||
height={80}
|
||||
className="object-cover rounded-md border"
|
||||
/>
|
||||
|
||||
<Button
|
||||
className="bg-teal-800 hover:bg-teal-900 text-white"
|
||||
onClick={() => {
|
||||
setUploadTarget({ type: "color", index });
|
||||
setIsUploadDialogOpen(true);
|
||||
}}
|
||||
>
|
||||
Upload File Baru
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* <Button
|
||||
type="button"
|
||||
onClick={handleAddColor}
|
||||
className="w-full bg-teal-800 hover:bg-teal-900 text-white mt-4"
|
||||
>
|
||||
<Plus className="w-4 h-4 mr-2" /> Tambah Warna Baru
|
||||
</Button> */}
|
||||
</div>
|
||||
|
||||
<div className="mt-10">
|
||||
<Label className="text-lg font-semibold text-teal-900">
|
||||
Spesifikasi Produk <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
|
||||
{specs.map((spec, index) => (
|
||||
<div key={spec.id} className="mt-6">
|
||||
<Label className="font-semibold text-sm">
|
||||
Judul Spesifikasi {index + 1}
|
||||
</Label>
|
||||
<Input
|
||||
defaultValue={spec.title}
|
||||
placeholder="Masukkan Judul Spesifikasi"
|
||||
className="mt-1"
|
||||
/>
|
||||
|
||||
<Label className="font-semibold text-sm mt-4 block">
|
||||
Foto Spesifikasi {index + 1}
|
||||
</Label>
|
||||
|
||||
<div className="flex flex-wrap gap-4 mt-2">
|
||||
{spec.images.map((img, i) => (
|
||||
<Image
|
||||
key={i}
|
||||
src={img}
|
||||
width={120}
|
||||
height={120}
|
||||
alt="spec"
|
||||
className="rounded-lg border object-cover"
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* <Button
|
||||
className="bg-teal-800 hover:bg-teal-900 text-white"
|
||||
onClick={() => {
|
||||
setUploadTarget({ type: "spec", index });
|
||||
setIsUploadDialogOpen(true);
|
||||
}}
|
||||
>
|
||||
Upload File Baru
|
||||
</Button> */}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* <Button
|
||||
onClick={handleAddSpec}
|
||||
className="w-full bg-teal-800 hover:bg-teal-900 text-white flex items-center justify-center gap-2 py-4 rounded-xl"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
Tambahkan Spesifikasi Baru
|
||||
</Button> */}
|
||||
</div>
|
||||
<div>
|
||||
<p>Status Timeline</p>
|
||||
<div className="flex gap-3">
|
||||
<div className="w-6 h-6 rounded-full bg-green-100 flex items-center justify-center">
|
||||
<CheckCheck className="w-4 h-4 text-green-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium text-gray-800">Diupload oleh</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-3 mt-3">
|
||||
<div className="w-6 h-6 rounded-full bg-green-100 flex items-center justify-center">
|
||||
<CheckCheck className="w-4 h-4 text-green-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium text-gray-800">Disetujui oleh</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border rounded-lg px-3 py-3">
|
||||
<p>Comment : </p>
|
||||
<div className="flex flex-row justify-between">
|
||||
<button
|
||||
onClick={handleOpenApproverHistory}
|
||||
className="text-sm text-blue-600 hover:underline mt-2"
|
||||
>
|
||||
View Approver History
|
||||
</button>
|
||||
<p>Jaecoo - Approver | 10/11/2026</p>
|
||||
</div>
|
||||
</div>
|
||||
{/* <Button className=" bg-teal-800 hover:bg-teal-900 text-white py-3">
|
||||
Submit
|
||||
</Button> */}
|
||||
</CardContent>
|
||||
</Card>
|
||||
{openApproverHistory && (
|
||||
<div
|
||||
className="fixed inset-0 z-[60] flex items-center justify-center bg-black/50 p-4"
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
>
|
||||
<div
|
||||
className="bg-white rounded-2xl shadow-2xl max-w-3xl w-full overflow-hidden"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* HEADER */}
|
||||
<div className="bg-gradient-to-br from-[#1F6779] to-[#0F6C75] text-white px-6 py-5 relative">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="absolute top-4 right-4 text-white/80 hover:text-white text-xl"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
|
||||
<h2 className="text-lg font-semibold">Approver History</h2>
|
||||
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
<span className="bg-white text-[#0F6C75] text-xs font-medium px-3 py-1 rounded-full">
|
||||
Banner
|
||||
</span>
|
||||
<span className="bg-white/20 text-white text-xs px-2 py-[2px] rounded-full">
|
||||
1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BODY */}
|
||||
<div className="p-6 grid grid-cols-[1fr_auto_1fr] gap-6 items-start">
|
||||
{/* LEFT TIMELINE */}
|
||||
<div className="relative space-y-6">
|
||||
{/* Upload */}
|
||||
<div className="flex flex-col items-center">
|
||||
<span className="bg-[#C7DDE4] text-[#0F6C75] text-xs px-4 py-1 rounded-full">
|
||||
Upload
|
||||
</span>
|
||||
<div className="w-px h-6 bg-gray-300" />
|
||||
</div>
|
||||
|
||||
{/* Diterima */}
|
||||
<div className="relative bg-[#1F6779] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Diterima</h4>
|
||||
<span className="inline-block bg-[#E3EFF4] text-[#0F6C75] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-px h-6 bg-gray-300 mx-auto" />
|
||||
|
||||
{/* Pending */}
|
||||
<div className="relative bg-[#B36A00] text-white rounded-xl p-4">
|
||||
<h4 className="font-semibold text-sm mb-2">Pending</h4>
|
||||
<span className="inline-block bg-[#FFF6CC] text-[#7A4A00] text-xs px-3 py-1 rounded-full">
|
||||
Direview oleh: approver-jaecoo1
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ARROW */}
|
||||
<div className="flex flex-col gap-20 text-gray-500 font-bold">
|
||||
<span>></span>
|
||||
<span>></span>
|
||||
</div>
|
||||
|
||||
{/* RIGHT NOTES */}
|
||||
<div className="space-y-14">
|
||||
<div>
|
||||
<div className="bg-[#C7DDE4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="bg-[#FFF9C4] text-sm px-4 py-2 rounded-lg">
|
||||
Catatan:
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* FOOTER */}
|
||||
<div className="border-t bg-[#F2F7FA] text-center py-3">
|
||||
<button
|
||||
onClick={() => setOpenApproverHistory(false)}
|
||||
className="text-[#0F6C75] font-medium hover:underline"
|
||||
>
|
||||
Tutup
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Dialog open={isUploadDialogOpen} onOpenChange={setIsUploadDialogOpen}>
|
||||
<DialogContent className="max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-teal-900 font-semibold">
|
||||
Upload File
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div
|
||||
className="border-2 border-dashed rounded-xl p-8 text-center cursor-pointer"
|
||||
onClick={() => document.getElementById(fileInputId)?.click()}
|
||||
>
|
||||
<Upload className="w-10 h-10 text-gray-400 mx-auto mb-3" />
|
||||
<p className="text-sm text-gray-500">
|
||||
Klik untuk upload atau drag & drop
|
||||
</p>
|
||||
<p className="text-xs text-gray-400">PNG, JPG (max 2 MB)</p>
|
||||
|
||||
<input
|
||||
id={fileInputId}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
className="hidden"
|
||||
onChange={handleFileSelected}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="flex gap-3 pt-4">
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="bg-slate-200"
|
||||
onClick={() => setIsUploadDialogOpen(false)}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={() => document.getElementById(fileInputId)?.click()}
|
||||
className="bg-teal-800 hover:bg-teal-900 text-white"
|
||||
>
|
||||
Pilih File
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import { usePathname } from "next/navigation";
|
|||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import { useTheme } from "../layout/theme-context";
|
||||
import Option from "./option";
|
||||
import { LogOut } from "lucide-react";
|
||||
|
||||
interface RetractingSidebarProps {
|
||||
sidebarData: boolean;
|
||||
|
|
@ -56,7 +57,7 @@ const sidebarSections = [
|
|||
// link: "/admin/magazine",
|
||||
// },
|
||||
{
|
||||
title: "Agen",
|
||||
title: "Agent",
|
||||
icon: () => <Icon icon="ic:people-outline" className="text-lg" />,
|
||||
link: "/admin/agent",
|
||||
},
|
||||
|
|
@ -365,10 +366,10 @@ const SidebarContent = ({
|
|||
} p-3 rounded-xl bg-gradient-to-r from-slate-50 to-slate-100/50 hover:from-slate-100 hover:to-slate-200/50 transition-all duration-200 cursor-pointer group`}
|
||||
>
|
||||
<div className="relative">
|
||||
<div className="w-10 h-10 rounded-full bg-gradient-to-r from-blue-500 to-purple-500 flex items-center justify-center text-white font-semibold text-sm shadow-lg">
|
||||
{/* <div className="w-10 h-10 rounded-full bg-gradient-to-r from-blue-500 to-purple-500 flex items-center justify-center text-white font-semibold text-sm shadow-lg">
|
||||
A
|
||||
</div>
|
||||
<div className="absolute -bottom-1 -right-1 w-4 h-4 bg-[#1F6779] rounded-full border-2 border-white"></div>
|
||||
<div className="absolute -bottom-1 -right-1 w-4 h-4 bg-[#1F6779] rounded-full border-2 border-white"></div> */}
|
||||
</div>
|
||||
{open && (
|
||||
<motion.div
|
||||
|
|
@ -377,14 +378,17 @@ const SidebarContent = ({
|
|||
transition={{ delay: 0.5 }}
|
||||
className="flex-1 min-w-0"
|
||||
>
|
||||
<p className="text-sm font-medium text-slate-800 truncate">
|
||||
admin-mabes
|
||||
</p>
|
||||
<Link href="/auth">
|
||||
<p className="text-xs text-slate-500 hover:text-blue-600 transition-colors duration-200">
|
||||
Sign out
|
||||
</p>
|
||||
</Link>
|
||||
{/* <p className="text-sm font-medium text-slate-800 truncate">
|
||||
Jaecoo
|
||||
</p> */}
|
||||
<div className="flex flex-row items-center gap-3 text-red-500">
|
||||
<LogOut />
|
||||
<Link href="/auth">
|
||||
<p className="text-xs text-red-500 hover:text-blue-600 transition-colors duration-200">
|
||||
Log Out
|
||||
</p>
|
||||
</Link>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ export default function AgentTable() {
|
|||
return cellValue;
|
||||
}
|
||||
},
|
||||
[article, page]
|
||||
[article, page],
|
||||
);
|
||||
|
||||
let typingTimer: NodeJS.Timeout;
|
||||
|
|
@ -386,19 +386,9 @@ export default function AgentTable() {
|
|||
|
||||
{/* STATUS */}
|
||||
<TableCell className="text-center">
|
||||
{item.is_active === "true" ? (
|
||||
<span className="bg-green-100 text-green-700 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Published
|
||||
</span>
|
||||
) : item.publishedStatus === "On Schedule" ? (
|
||||
<span className="bg-gray-100 text-gray-600 text-xs font-medium px-3 py-1 rounded-full">
|
||||
On Schedule
|
||||
</span>
|
||||
) : (
|
||||
<span className="bg-red-100 text-red-600 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Cancel
|
||||
</span>
|
||||
)}
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
</TableCell>
|
||||
|
||||
{/* AKSI */}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ import CustomPagination from "../layout/custom-pagination";
|
|||
import { EditBannerDialog } from "../form/banner-edit-dialog";
|
||||
import { deleteBanner, getBannerData, updateBanner } from "@/service/banner";
|
||||
import { CheckCheck, Eye } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
const columns = [
|
||||
{ name: "No", uid: "no" },
|
||||
|
|
@ -90,6 +91,15 @@ export default function ArticleTable() {
|
|||
startDate: null,
|
||||
endDate: null,
|
||||
});
|
||||
const [userLevelId, setUserLevelId] = useState<string | null>(null);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// 🔹 Ambil userlevelId dari cookies
|
||||
useEffect(() => {
|
||||
const ulne = Cookies.get("ulne"); // contoh: "3"
|
||||
setUserLevelId(ulne ?? null);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
initState();
|
||||
|
|
@ -173,6 +183,17 @@ export default function ArticleTable() {
|
|||
const [openViewDialog, setOpenViewDialog] = useState(false);
|
||||
const [viewBanner, setViewBanner] = useState<any>(null);
|
||||
const [openApproverHistory, setOpenApproverHistory] = useState(false);
|
||||
const [openCommentModal, setOpenCommentModal] = useState(false);
|
||||
const [commentValue, setCommentValue] = useState("");
|
||||
|
||||
const handleSubmitComment = async () => {
|
||||
// await api.post("/banner/comment", {
|
||||
// bannerId: viewBanner.id,
|
||||
// comment: commentValue,
|
||||
// });
|
||||
|
||||
setOpenCommentModal(false);
|
||||
};
|
||||
|
||||
const handleView = (item: any) => {
|
||||
setViewBanner(item);
|
||||
|
|
@ -305,7 +326,7 @@ export default function ArticleTable() {
|
|||
return cellValue;
|
||||
}
|
||||
},
|
||||
[article, page]
|
||||
[article, page],
|
||||
);
|
||||
|
||||
let typingTimer: NodeJS.Timeout;
|
||||
|
|
@ -402,19 +423,19 @@ export default function ArticleTable() {
|
|||
|
||||
{/* STATUS */}
|
||||
<TableCell className="text-center">
|
||||
{item.status === "Disetujui" ? (
|
||||
{/* {item.status === "Disetujui" ? (
|
||||
<span className="bg-green-100 text-green-700 text-xs px-3 py-1 rounded-full font-medium">
|
||||
Disetujui
|
||||
</span>
|
||||
) : item.status === "Menunggu" ? (
|
||||
<span className="bg-yellow-100 text-yellow-700 text-xs px-3 py-1 rounded-full font-medium">
|
||||
Menunggu
|
||||
</span>
|
||||
) : (
|
||||
) : item.status === "Menunggu" ? ( */}
|
||||
<span className="bg-yellow-100 text-yellow-700 text-xs px-3 py-1 rounded-full font-medium">
|
||||
Menunggu
|
||||
</span>
|
||||
{/* ) : (
|
||||
<span className="bg-red-100 text-red-700 text-xs px-3 py-1 rounded-full font-medium">
|
||||
Ditolak
|
||||
</span>
|
||||
)}
|
||||
)} */}
|
||||
</TableCell>
|
||||
|
||||
{/* AKSI */}
|
||||
|
|
@ -429,15 +450,17 @@ export default function ArticleTable() {
|
|||
<Eye className="w-4 h-4 mr-1" />
|
||||
Lihat
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-[#0F6C75] hover:bg-transparent hover:underline p-0"
|
||||
onClick={() => handleEdit(item)}
|
||||
>
|
||||
<CreateIconIon className="w-4 h-4 mr-1" />
|
||||
Edit
|
||||
</Button>
|
||||
{userLevelId !== "3" && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-[#0F6C75] hover:bg-transparent hover:underline p-0"
|
||||
onClick={() => handleEdit(item)}
|
||||
>
|
||||
<CreateIconIon className="w-4 h-4 mr-1" />
|
||||
Edit
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
|
|
@ -584,8 +607,8 @@ export default function ArticleTable() {
|
|||
viewBanner.status === "Menunggu"
|
||||
? "bg-yellow-100 text-yellow-800"
|
||||
: viewBanner.status === "Disetujui"
|
||||
? "bg-green-100 text-green-800"
|
||||
: "bg-red-100 text-red-800"
|
||||
? "bg-green-100 text-green-800"
|
||||
: "bg-red-100 text-red-800"
|
||||
}`}
|
||||
>
|
||||
{viewBanner.status}
|
||||
|
|
@ -679,16 +702,27 @@ export default function ArticleTable() {
|
|||
</div>
|
||||
|
||||
{/* FOOTER */}
|
||||
<div className="flex justify-between items-center gap-3 px-6 py-4 border-t bg-[#F2F7FA]">
|
||||
<Button variant="secondary">Beri Tanggapan</Button>
|
||||
{userLevelId !== "2" && (
|
||||
<div className="flex justify-between items-center gap-3 px-6 py-4 border-t bg-[#F2F7FA]">
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="bg-blue-200 hover:bg-blue-400"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setOpenCommentModal(true);
|
||||
}}
|
||||
>
|
||||
Beri Tanggapan
|
||||
</Button>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<Button variant="destructive">Reject</Button>
|
||||
<Button className="bg-green-600 hover:bg-green-700 text-white">
|
||||
<Button variant="destructive" className="w-[180]">
|
||||
Reject
|
||||
</Button>
|
||||
<Button className="bg-green-600 hover:bg-green-700 text-white w-[180]">
|
||||
Approved
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
|
@ -790,6 +824,76 @@ export default function ArticleTable() {
|
|||
</div>
|
||||
</div>
|
||||
)}
|
||||
{openCommentModal && viewBanner && (
|
||||
<div
|
||||
className="fixed inset-0 z-[60] flex items-center justify-center bg-black/50 p-4"
|
||||
onClick={() => setOpenCommentModal(false)}
|
||||
>
|
||||
<div
|
||||
className="bg-white rounded-2xl shadow-2xl max-w-lg w-full overflow-hidden"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* HEADER */}
|
||||
<div className="bg-gradient-to-br from-[#1F6779] to-[#0F6C75] text-white px-6 py-5 relative">
|
||||
<button
|
||||
onClick={() => setOpenCommentModal(false)}
|
||||
className="absolute top-4 right-4 text-white/80 hover:text-white text-xl"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
|
||||
<h2 className="text-lg font-semibold">Beri Tanggapan</h2>
|
||||
|
||||
{/* Badge */}
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
|
||||
<span className="bg-white text-[#0F6C75] text-xs font-medium px-3 py-1 rounded-full">
|
||||
Banner
|
||||
</span>
|
||||
|
||||
<span className="bg-white/20 text-white text-xs px-2 py-[2px] rounded-full">
|
||||
{viewBanner.position}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BODY */}
|
||||
<div className="p-6 space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-500 mb-2">
|
||||
Comment
|
||||
</label>
|
||||
<textarea
|
||||
value={commentValue}
|
||||
onChange={(e) => setCommentValue(e.target.value)}
|
||||
placeholder="Masukkan komentar"
|
||||
className="w-full min-h-[100px] border rounded-lg p-3 focus:outline-none focus:ring-2 focus:ring-[#0F6C75]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* FOOTER */}
|
||||
<div className="flex justify-between gap-3 px-6 py-4 border-t bg-[#F2F7FA]">
|
||||
<button
|
||||
onClick={() => setOpenCommentModal(false)}
|
||||
className="flex-1 py-2 rounded-xl bg-blue-100 hover:bg-blue-200 text-gray-700 font-medium"
|
||||
>
|
||||
Batal
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={handleSubmitComment}
|
||||
className="flex-1 py-2 rounded-xl bg-[#1F6779] hover:bg-[#0F6C75] text-white font-medium"
|
||||
>
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ import {
|
|||
import CustomPagination from "../layout/custom-pagination";
|
||||
import { EditBannerDialog } from "../form/banner-edit-dialog";
|
||||
import { deleteProduct, getProductPagination } from "@/service/product";
|
||||
import { CheckCheck } from "lucide-react";
|
||||
import { CheckCheck, Eye } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
const columns = [
|
||||
{ name: "No", uid: "no" },
|
||||
|
|
@ -91,6 +92,15 @@ export default function ProductTable() {
|
|||
startDate: null,
|
||||
endDate: null,
|
||||
});
|
||||
const [userLevelId, setUserLevelId] = useState<string | null>(null);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// 🔹 Ambil userlevelId dari cookies
|
||||
useEffect(() => {
|
||||
const ulne = Cookies.get("ulne"); // contoh: "3"
|
||||
setUserLevelId(ulne ?? null);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
initState();
|
||||
|
|
@ -298,7 +308,7 @@ export default function ProductTable() {
|
|||
return cellValue;
|
||||
}
|
||||
},
|
||||
[article, page]
|
||||
[article, page],
|
||||
);
|
||||
|
||||
let typingTimer: NodeJS.Timeout;
|
||||
|
|
@ -318,6 +328,15 @@ export default function ProductTable() {
|
|||
initState();
|
||||
}
|
||||
|
||||
const formatRupiah = (value?: number | string) => {
|
||||
if (!value) return "Rp 0";
|
||||
|
||||
const number =
|
||||
typeof value === "string" ? Number(value.replace(/[^\d]/g, "")) : value;
|
||||
|
||||
return `Rp ${number.toLocaleString("id-ID")}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="py-3">
|
||||
|
|
@ -371,7 +390,7 @@ export default function ProductTable() {
|
|||
<TableCell className="font-semibold text-[#0F6C75]">
|
||||
{item.title ?? "—"}
|
||||
<div className="mt-1">
|
||||
{item.isPublish ? (
|
||||
{/* {item.isPublish ? (
|
||||
<span className="text-xs bg-blue-100 text-blue-700 px-2 py-[2px] rounded-md">
|
||||
Tampil di Landing
|
||||
</span>
|
||||
|
|
@ -379,15 +398,13 @@ export default function ProductTable() {
|
|||
<span className="text-xs bg-gray-100 text-gray-600 px-2 py-[2px] rounded-md">
|
||||
Draft
|
||||
</span>
|
||||
)}
|
||||
)} */}
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
{/* HARGA PRODUK */}
|
||||
<TableCell className="font-medium">
|
||||
{item.price
|
||||
? `Rp ${item.price.toLocaleString("id-ID")}`
|
||||
: "Rp 0"}
|
||||
{formatRupiah(item.price)}
|
||||
</TableCell>
|
||||
|
||||
{/* VARIAN */}
|
||||
|
|
@ -413,8 +430,8 @@ export default function ProductTable() {
|
|||
Disetujui
|
||||
</span>
|
||||
) : (
|
||||
<span className="bg-gray-100 text-gray-600 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Draft
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
)}
|
||||
</TableCell>
|
||||
|
|
@ -422,24 +439,27 @@ export default function ProductTable() {
|
|||
{/* AKSI */}
|
||||
<TableCell className="text-center">
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-[#0F6C75] hover:bg-transparent hover:underline p-0"
|
||||
// onClick={() => handleEdit(item)}
|
||||
>
|
||||
<CheckCheck className="w-4 h-4 mr-1" />
|
||||
Approve
|
||||
</Button>
|
||||
<Link href={"/admin/product/update"}>
|
||||
<Link href={`/admin/product/detail/${item.id}`}>
|
||||
<Button
|
||||
className="text-[#0F6C75] hover:bg-transparent hover:underline p-0"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-[#0F6C75] hover:bg-transparent hover:underline p-0"
|
||||
>
|
||||
<CreateIconIon className="w-4 h-4 mr-1" /> Edit
|
||||
<Eye className="w-4 h-4 mr-1" />
|
||||
Lihat
|
||||
</Button>
|
||||
</Link>
|
||||
{userLevelId !== "3" && (
|
||||
<Link href={"/admin/product/update"}>
|
||||
<Button
|
||||
className="text-[#0F6C75] hover:bg-transparent hover:underline p-0"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
>
|
||||
<CreateIconIon className="w-4 h-4 mr-1" /> Edit
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ export default function PromotionTable() {
|
|||
return cellValue;
|
||||
}
|
||||
},
|
||||
[article, page]
|
||||
[article, page],
|
||||
);
|
||||
|
||||
let typingTimer: NodeJS.Timeout;
|
||||
|
|
@ -378,19 +378,9 @@ export default function PromotionTable() {
|
|||
|
||||
{/* STATUS */}
|
||||
<TableCell className="text-center">
|
||||
{item.publishedStatus === "Published" ? (
|
||||
<span className="bg-green-100 text-green-700 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Published
|
||||
</span>
|
||||
) : item.publishedStatus === "On Schedule" ? (
|
||||
<span className="bg-gray-100 text-gray-600 text-xs font-medium px-3 py-1 rounded-full">
|
||||
On Schedule
|
||||
</span>
|
||||
) : (
|
||||
<span className="bg-red-100 text-red-600 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Cancel
|
||||
</span>
|
||||
)}
|
||||
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium px-3 py-1 rounded-full">
|
||||
Menunggu
|
||||
</span>
|
||||
</TableCell>
|
||||
|
||||
{/* AKSI */}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
httpPostInterceptor,
|
||||
httpPutInterceptor,
|
||||
} from "./http-config/http-interceptor-services";
|
||||
import { httpGet } from "./http-config/http-base-services";
|
||||
|
||||
export async function getProductPagination(props: PaginationRequest) {
|
||||
const { page, limit, search } = props;
|
||||
|
|
@ -28,6 +29,13 @@ export async function updateProduct(data: any, id: any) {
|
|||
return await httpPutInterceptor(pathUrl, data);
|
||||
}
|
||||
|
||||
export async function getProductDataById(id: any) {
|
||||
const headers = {
|
||||
"content-type": "application/json",
|
||||
};
|
||||
return await httpGet(`/products/${id}`, headers);
|
||||
}
|
||||
|
||||
export async function deleteProduct(id: string) {
|
||||
const headers = {
|
||||
"content-type": "application/json",
|
||||
|
|
|
|||
Loading…
Reference in New Issue