diff --git a/components/dialog/galery-detail-dialog.tsx b/components/dialog/galery-detail-dialog.tsx index 37e47cf..30b97df 100644 --- a/components/dialog/galery-detail-dialog.tsx +++ b/components/dialog/galery-detail-dialog.tsx @@ -8,14 +8,39 @@ import { DialogFooter, } from "@/components/ui/dialog"; import Image from "next/image"; -import { CheckCircle } from "lucide-react"; +import { Check, CheckCheck, CheckCircle, Clock, X } from "lucide-react"; import { useEffect, useState } from "react"; -import { getGaleryFileData } from "@/service/galery"; +import { approveGalery, getGaleryFileData } from "@/service/galery"; +import { convertDateFormat } from "@/utils/global"; +import { Button } from "../ui/button"; +import { useRouter } from "next/navigation"; +import Cookies from "js-cookie"; +import { error, loading, success } from "@/config/swal"; export function DialogDetailGaleri({ open, onClose, data }: any) { const [images, setImages] = useState([]); const [openApproverHistory, setOpenApproverHistory] = useState(false); + const [userLevelId, setUserLevelId] = useState(null); + const [openViewDialog, setOpenViewDialog] = useState(false); + const router = useRouter(); + // 🔹 Ambil userlevelId dari cookies + useEffect(() => { + const ulne = Cookies.get("ulne"); // contoh: "3" + setUserLevelId(ulne ?? null); + }, []); + + 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 fetchImages = async () => { try { const res = await getGaleryFileData(data.id); @@ -44,6 +69,21 @@ export function DialogDetailGaleri({ open, onClose, data }: any) { setOpenApproverHistory(true); }; + const handleApproveGalery = async (id: number) => { + loading(); + const res = await approveGalery(id); + + if (res?.error) { + error(res.message || "Gagal menyetujui galeri"); + close(); + return; + } + + close(); + success("Galeri berhasil disetujui"); + fetchImages(); // refresh table + }; + return ( <> @@ -107,55 +147,128 @@ export function DialogDetailGaleri({ open, onClose, data }: any) { {/* Timeline */}
-

+

Status Timeline -

+

-
-
- -
-

Diupload Oleh :

-

- {new Date(data.created_at).toLocaleString("id-ID")} -

+
+
+
+
-
-
-
-

Disetujui Oleh :

-

- {new Date(data.created_at).toLocaleString("id-ID")} +

+ Diupload oleh Operator +

+

+ {convertDateFormat(data?.created_at)} WIB

- {data.approved_at && ( -
- -
-

Disetujui oleh Approver

-

- {new Date(data.approved_at).toLocaleString("id-ID")} -

-
+
+
+ {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

+
+
+
+
+ {openViewDialog && userLevelId !== "2" && ( +
+ {data.status_id === 1 ? ( + <> + + + + + {userLevelId === "1" && ( + + )} + + ) : ( + )}
-
-
-

Comment :

-
- -

Jaecoo - Approver | 10/11/2026

-
-
+ )}
{/* diff --git a/components/dialog/promo-dialog.tsx b/components/dialog/promo-dialog.tsx index d6ebb9b..979d33b 100644 --- a/components/dialog/promo-dialog.tsx +++ b/components/dialog/promo-dialog.tsx @@ -7,8 +7,20 @@ import { DialogHeader, DialogTitle, } from "@/components/ui/dialog"; -import { CheckCircle2, FileText } from "lucide-react"; -import { getPromotionById } from "@/service/promotion"; +import { + Check, + CheckCheck, + CheckCircle2, + Clock, + FileText, + X, +} from "lucide-react"; +import { approvePromotion, getPromotionById } from "@/service/promotion"; +import { convertDateFormat } from "@/utils/global"; +import { Button } from "../ui/button"; +import { useRouter } from "next/navigation"; +import Cookies from "js-cookie"; +import { error, loading, success } from "@/config/swal"; type PromoDetailDialogProps = { promoId: number | null; @@ -21,10 +33,20 @@ export default function PromoDetailDialog({ open, onOpenChange, }: PromoDetailDialogProps) { - const [loading, setLoading] = useState(false); + const [loadingData, setLoadingData] = useState(false); const [promo, setPromo] = useState(null); const [openApproverHistory, setOpenApproverHistory] = useState(false); + const [userLevelId, setUserLevelId] = useState(null); + + const router = useRouter(); + + // 🔹 Ambil userlevelId dari cookies + useEffect(() => { + const ulne = Cookies.get("ulne"); // contoh: "3" + setUserLevelId(ulne ?? null); + }, []); + // FORMAT TANGGAL → DD-MM-YYYY const formatDate = (dateStr: string) => { const d = new Date(dateStr); @@ -37,17 +59,37 @@ export default function PromoDetailDialog({ const handleOpenApproverHistory = () => { setOpenApproverHistory(true); }; + + const handleApprovePromotion = async (promoId: number) => { + loading(); + const res = await approvePromotion(promoId); + + if (res?.error) { + error(res.message || "Gagal menyetujui promotion"); + close(); + return; + } + + close(); + success("Promotion berhasil disetujui"); + // fetchData(); // refresh table + }; + useEffect(() => { if (!promoId || !open) return; async function fetchData() { try { - setLoading(true); + setLoadingData(true); const res = await getPromotionById(promoId); // Mapping ke format dialog const mapped = { + id: res?.data?.data?.id, title: res?.data?.data?.title, + status_id: res?.data?.data?.status_id, + created_at: res?.data?.data?.created_at, + updated_at: res?.data?.data?.updated_at, fileSize: "Tidak diketahui", uploadDate: formatDate(res?.data?.data?.created_at), status: res?.data?.data?.is_active ? "Aktif" : "Nonaktif", @@ -75,19 +117,32 @@ export default function PromoDetailDialog({ } catch (err) { console.error("ERROR FETCH PROMO:", err); } finally { - setLoading(false); + setLoadingData(false); } } fetchData(); }, [promoId, open]); + const [openCommentModal, setOpenCommentModal] = useState(false); + const [commentValue, setCommentValue] = useState(""); + const [openViewDialog, setOpenViewDialog] = useState(false); + if (!open) return null; + const handleSubmitComment = async () => { + // await api.post("/banner/comment", { + // bannerId: promo.id, + // comment: commentValue, + // }); + + setOpenCommentModal(false); + }; + return ( <> - + {/* HEADER */}
@@ -107,7 +162,7 @@ export default function PromoDetailDialog({ {/* BODY */}
- {loading ? ( + {loadingData ? (

Memuat data...

) : promo ? ( <> @@ -133,37 +188,71 @@ export default function PromoDetailDialog({
{/* TIMELINE */} -
-

+

+

Status Timeline -

+

- {promo.timeline.map((item: any, idx: number) => ( -
- -
-

{item.label}

-

- {item.date} • {item.time} WIB -

-
+
+
+
- ))} -
-
-

Comment :

-
-
+
+ +
+
- View Approver History - -

Jaecoo - Approver | 10/11/2026

+ {promo?.status_id === 1 ? ( + + ) : promo?.status_id === 2 ? ( + + ) : ( + + )} +
+ +
+

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

+ +

+ {convertDateFormat(promo?.updated_at)} WIB +

+
+
+ +
+

Comment :

+
+ +

Jaecoo - Approver | 10/11/2026

+
@@ -173,6 +262,61 @@ export default function PromoDetailDialog({

Data tidak ditemukan

)}
+ {userLevelId !== "2" && promo && ( +
+ {promo.status_id === 1 ? ( + <> + + + + + {userLevelId === "1" && ( + + )} + + ) : ( + + )} +
+ )} {openApproverHistory && (
)} - {/* FOOTER */} + {/* FOOTER
-
+
*/}
{openApproverHistory && ( @@ -380,6 +524,76 @@ export default function PromoDetailDialog({
)} + {openCommentModal && promo && ( +
setOpenCommentModal(false)} + > +
e.stopPropagation()} + > + {/* HEADER */} +
+ + +

Beri Tanggapan

+ + {/* Badge */} +
+ + Menunggu + + + + Banner + + + + {promo.position} + +
+
+ + {/* BODY */} +
+
+ +