"use client"; import { ChevronRightIcon } from "@/components/icons"; import { close, loading } from "@/config/swal"; import { getMagazineById } from "@/services/magazine"; import { convertDateFormat, formatMonthString, formatTextToHtmlTag, } from "@/utils/global"; import { BreadcrumbItem, Breadcrumbs } from "@heroui/breadcrumbs"; import { Button } from "@heroui/button"; import { Accordion, AccordionItem } from "@heroui/react"; import Link from "next/link"; import { useParams } from "next/navigation"; import React, { useEffect, useState } from "react"; export default function EMagazineDetail() { const params = useParams(); const id = params?.id; const [detailData, setDetailData] = useState(); const [detailFiles, setDetailFiles] = useState([]); useEffect(() => { initFetch(); }, [id]); const initFetch = async () => { loading(); const res = await getMagazineById(String(id)); const data = res?.data?.data; setDetailData(data); setDetailFiles(data?.files); close(); }; const doDownload = async (fileName: string, title: string): Promise => { try { const response = await fetch( `https://layananpemerintahri.com/magazine-files/viewer/${fileName}` ); if (!response.ok) { throw new Error("File not found or server error"); } const blob = await response.blob(); const url = window.URL.createObjectURL(blob); const anchor = document.createElement("a"); anchor.href = url; anchor.download = title === "" ? fileName : title; document.body.appendChild(anchor); anchor.click(); window.URL.revokeObjectURL(url); document.body.removeChild(anchor); } catch (error) { console.error("Download failed:", error); } }; return (
Beranda E-Majalah Polri
{detailData?.title}
{/* emagazine */} emagazine
{detailFiles?.map((file: any, index: number) => ( {file?.title === "" ? `File ${index + 1}` : file?.title}

} >
Nama File
{file?.fileName}
Deskripsi
{file?.description == "" ? "-" : file?.description}
Ukuran File
{Math.round(file?.size / 100) / 10 > 1000 ? ( <> {(Math.round(file?.size / 100) / 10000).toFixed(1)} ) : ( <>{(Math.round(file?.size / 100) / 10).toFixed(1)} )} {" kb"}
Tanggal Publish
{formatMonthString(file?.createdAt)}
))}
); }