diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/audio/regional/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/audio/regional/page.tsx new file mode 100644 index 00000000..71c90bf5 --- /dev/null +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/audio/regional/page.tsx @@ -0,0 +1,942 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { + formatDateToIndonesian, + getOnlyDate, + getOnlyMonthAndYear, +} from "@/utils/globals"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; +import { + getPublicCategoryData, + getUserLevelListByParent, + listData, + listDataRegional, +} from "@/service/landing/landing"; +import { + ColumnDef, + ColumnFiltersState, + PaginationState, + SortingState, + VisibilityState, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from "@tanstack/react-table"; +import LandingPagination from "@/components/landing-page/pagination"; +import { Reveal } from "@/components/landing-page/Reveal"; +import { Link, useRouter } from "@/i18n/routing"; +import { Input } from "@/components/ui/input"; +import ReactDatePicker from "react-datepicker"; +import "react-datepicker/dist/react-datepicker.css"; +import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import ImageBlurry from "@/components/ui/image-blurry"; +import { Skeleton } from "@/components/ui/skeleton"; +import Image from "next/image"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => {row.getValue("no")}, + }, +]; + +export default function FilterPage() { + const router = useRouter(); + const asPath = usePathname(); + const params = useParams(); + const searchParams = useSearchParams(); + const locale = params?.locale; + const t = useTranslations("FilterPage"); + const [isLoading, setIsLoading] = useState(true); + const [audioData, setAudioData] = useState([]); + const [totalData, setTotalData] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const [sorting, setSorting] = useState([]); + const [columnFilters, setColumnFilters] = useState([]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [page, setPage] = useState(1); + const [totalContent, setTotalContent] = useState(0); + const [change, setChange] = useState(false); + const sortBy = searchParams?.get("sortBy"); + const title = searchParams?.get("title"); + const categorie = searchParams?.get("category"); + const group = searchParams?.get("group"); + const [categoryFilter, setCategoryFilter] = useState([]); + const [monthYearFilter, setMonthYearFilter] = useState(); + const [searchTitle, setSearchTitle] = useState(""); + const [sortByOpt, setSortByOpt] = useState( + sortBy === "popular" ? "clickCount" : "createdAt" + ); + const [formatFilter, setFormatFilter] = useState([]); + const pages = page ? page - 1 : 0; + const [startDateString, setStartDateString] = useState(); + const [endDateString, setEndDateString] = useState(); + const [dateRange, setDateRange] = useState([null, null]); + const [handleClose, setHandleClose] = useState(false); + const [categories, setCategories] = useState([]); + const [isFilterOpen, setIsFilterOpen] = useState(true); + + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + + // === INIT === + useEffect(() => { + const timer = setTimeout(() => setIsLoading(false), 1200); + return () => clearTimeout(timer); + }, []); + + useEffect(() => { + const pageFromUrl = searchParams?.get("page"); + if (pageFromUrl) setPage(Number(pageFromUrl)); + }, [searchParams]); + + useEffect(() => { + if (categorie) { + setCategoryFilter( + categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie] + ); + } + }, [categorie]); + + useEffect(() => { + fetchCategories(categoryPage); + }, []); + + const fetchCategories = async (pageNumber: number) => { + const groupParam = + poldaName && poldaName.length > 1 + ? poldaName + : satkerName && satkerName.length > 1 + ? "satker-" + satkerName + : ""; + + const isInt = locale === "en"; + + const response = await getPublicCategoryData( + groupParam, + "", + isInt, + pageNumber + ); // halaman 1-based + + const content = response?.data?.data?.content || []; + const total = response?.data?.data?.totalPages || 1; + + setCategories(content); + setCategoryTotalPages(total); + }; + useEffect(() => { + if (asPath?.includes("/regional")) getDataRegional(); + else getDataAll(); + }, [ + asPath, + monthYearFilter, + page, + sortBy, + sortByOpt, + title, + startDateString, + endDateString, + categorie, + formatFilter, + ]); + + async function getDataAll() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listData( + "4", + name, + filter, + 12, + pages, + sortByOpt, + format, + "", + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + locale == "en" ? true : false + ); + close(); + + const data = response?.data?.data; + setAudioData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + async function getDataRegional() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listDataRegional( + "4", + name, + filter, + format, + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + 12, + pages, + sortByOpt + ); + close(); + + const data = response?.data?.data; + setAudioData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + const handleCategoryFilter = (e: boolean, id: string) => { + let filter = [...categoryFilter]; + if (e) filter.push(String(id)); + else filter = filter.filter((item) => item !== String(id)); + router.push(`?category=${filter.join("&")}`); + }; + + const handleFormatFilter = (e: boolean, id: string) => { + let filter = [...formatFilter]; + if (e) filter.push(id); + else filter = filter.filter((item) => item !== id); + setFormatFilter(filter); + }; + + const handleSorting = (e: any) => { + const value = e.target.value; + setSortByOpt(value === "latest" ? "createdAt" : "clickCount"); + }; + + const handleDeleteDate = () => { + setDateRange([null, null]); + setStartDateString(""); + setEndDateString(""); + setHandleClose(false); + }; + + const handleKeyUp = () => { + if (!searchTitle) router.push("?title="); + else router.push(`?title=${searchTitle.toLowerCase()}`); + }; + + // === REACT TABLE === + const table = useReactTable({ + data: audioData, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + onRowSelectionChange: setRowSelection, + onPaginationChange: setPagination, + state: { + sorting, + columnFilters, + columnVisibility, + rowSelection, + pagination, + }, + }); + + const [calenderState, setCalenderState] = useState(false); + const [categoryPage, setCategoryPage] = useState(1); + const [categoryTotalPages, setCategoryTotalPages] = useState(1); + let typingTimer: any; + + const cleanCheckbox = () => { + setCategoryFilter([]); + setFormatFilter([]); + router.push(`?category=&title=`); + setDateRange([null, null]); + setMonthYearFilter(null); + setChange(!change); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + return ( +
+ {/* Header */} +
+

+ {" "} + Audio {">"}{" "} + + {t("allAudio", { defaultValue: "All Audio" })} + +

+

|

+ {!title ? ( +

+ {`${t("thereIs", { defaultValue: "Terdapat" })} ${totalContent} ${t( + "downloadableImage", + { defaultValue: "artikel berisi Foto yang dapat diunduh" } + )}`} +

+ ) : ( +

+ {t("search-results", { defaultValue: "Hasil pencarian untuk" })}{" "} + "{title}" +

+ )} +
+ +
+ {/* Left */} +
+

+ + Filter +

+
+
+
+ + setSearchTitle(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + id="search" + placeholder={t("searchTitle", { defaultValue: "Search Title" })} + className="mt-1 w-full text-sm border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" + /> +
+ +
+ + setMonthYearFilter(date)} + dateFormat="MM | yyyy" + placeholderText={t("selectYear", { + defaultValue: "Select Year", + })} + showMonthYearPicker + /> +
+ +
+ +
+ { + setDateRange(update); + }} + placeholderText={t("searchDate", { + defaultValue: "Search Date", + })} + onCalendarClose={() => setCalenderState(!calenderState)} + /> +
+ {handleClose ? ( + + ) : ( + "" + )} +
+
+
+ +
+

+ {t("categories", { defaultValue: "Categories" })} +

+ +
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
+ + {/* ⬇️ Pagination kategori (rata sejajar) */} +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+
+ + {/*
+

+ {t("categories", { defaultValue: "Categories" })} +

+
    + {categories?.map((category: any) => ( +
  • + +
  • + ))} +
    + + + {Array.from({ length: categoryTotalPages }, (_, i) => ( + + ))} + + +
    +
+
*/} + {/* Garis */} +
+ {/* Garis */} +
+

+ Format +

+
    +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+ + {/* CONTENT */} +
+ +
+

Sort By

+ +
+ + {isLoading ? ( +
+ + +
+ ) : audioData?.length > 0 ? ( +
+ {audioData?.map((audio: any) => ( + + + + // router.push(prefixPath + `/document/detail/${text?.slug}`) + // } + className="cursor-pointer rounded-lg shadow-md overflow-hidden bg-white dark:bg-black dark:border dark:border-gray-500" + > + {/* Ikon di tengah dengan latar kuning */} +
+ + + {" "} +
+ + {/* Konten bawah */} +
+ {/* Kategori merah */} +
+ {audio?.categoryName?.toUpperCase() ?? "Text"} +
+ + {/* Judul */} +
+ {audio?.title} +
+
+ +
+
+ ))} +
+ ) : ( +
+ empty +
+ )} + + {totalPage > 1 && ( + + )} +
+
+
+
+ ); +} + +// import AllContentPage from "@/components/landing-page/all-content-page"; + +// const regions = [ +// { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, +// { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, +// { +// name: "Polda Bangka Belitung", +// slug: "bangka-belitung", +// logo: "/logo/polda/polda-bangka-belitung.png", +// }, +// { +// name: "Polda Banten", +// slug: "banten", +// logo: "/logo/polda/polda-banten.png", +// }, +// { +// name: "Polda Bengkulu", +// slug: "bengkulu", +// logo: "/logo/polda/polda-bengkulu.png", +// }, +// { +// name: "Polda DIY", +// slug: "jogja", +// logo: "/logo/polda/polda-jogja.png", +// }, +// { +// name: "Polda Gorontalo", +// slug: "gorontalo", +// logo: "/logo/polda/polda-gorontalo.png", +// }, +// { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, +// { +// name: "Polda Jawa Barat", +// slug: "jawa-barat", +// logo: "/logo/polda/polda-jawa-barat.png", +// }, +// { +// name: "Polda Jawa Tengah", +// slug: "jawa-tengah", +// logo: "/logo/polda/polda-jawa-tengah.png", +// }, +// { +// name: "Polda Jawa Timur", +// slug: "jawa-timur", +// logo: "/logo/polda/polda-jawa-timur.png", +// }, +// { +// name: "Polda Kalimantan Barat", +// slug: "kalimantan-barat", +// logo: "/logo/polda/polda-kalimantan-barat.png", +// }, +// { +// name: "Polda Kalimantan Selatan", +// slug: "kalimantan-selatan", +// logo: "/logo/polda/polda-kalimantan-selatan.png", +// }, +// { +// name: "Polda Kalimantan Tengah", +// slug: "kalimantan-tengah", +// logo: "/logo/polda/polda-kalimantan-tengah.png", +// }, +// { +// name: "Polda Kalimantan Timur", +// slug: "kalimantan-timur", +// logo: "/logo/polda/polda-kalimantan-timur.png", +// }, +// { +// name: "Polda Kalimantan Utara", +// slug: "kalimantan-utara", +// logo: "/logo/polda/polda-kalimantan-utara.png", +// }, +// { +// name: "Polda Kepulauan Riau", +// slug: "kepulauan-riau", +// logo: "/logo/polda/polda-kepulauan-riau.png", +// }, +// { +// name: "Polda Lampung", +// slug: "lampung", +// logo: "/logo/polda/polda-lampung.png", +// }, +// { +// name: "Polda Maluku", +// slug: "maluku", +// logo: "/logo/polda/polda-maluku.png", +// }, +// { +// name: "Polda Maluku Utara", +// slug: "maluku-utara", +// logo: "/logo/polda/polda-maluku-utara.png", +// }, +// { +// name: "Polda Metro Jaya", +// slug: "metro-jaya", +// logo: "/logo/polda/polda-metro-jaya.png", +// }, +// { +// name: "Polda NTB", +// slug: "ntb", +// logo: "/logo/polda/polda-ntb.png", +// }, +// { +// name: "Polda NTT", +// slug: "ntt", +// logo: "/logo/polda/polda-ntt.png", +// }, +// { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, +// { +// name: "Polda Papua Barat", +// slug: "papua-barat", +// logo: "/logo/polda/polda-papua-barat.png", +// }, +// { +// name: "Polda Papua Barat Daya", +// slug: "papua-barat-daya", +// logo: "/logo/polda/polda-papua-barat-daya.png", +// }, +// { +// name: "Polda Papua Tengah", +// slug: "papua-tengah", +// logo: "/logo/polda/polda-papua-tengah.png", +// }, +// { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, +// { +// name: "Polda Sulawesi Barat", +// slug: "sulawesi-barat", +// logo: "/logo/polda/polda-sulawesi-barat.png", +// }, +// { +// name: "Polda Sulawesi Selatan", +// slug: "sulawesi-selatan", +// logo: "/logo/polda/polda-sulawesi-selatan.png", +// }, +// { +// name: "Polda Sulawesi Tengah", +// slug: "sulawesi-tengah", +// logo: "/logo/polda/polda-sulawesi-tengah.png", +// }, +// { +// name: "Polda Sulawesi Tenggara", +// slug: "sulawesi-tenggara", +// logo: "/logo/polda/polda-sulawesi-tenggara.png", +// }, +// { +// name: "Polda Sulawesi Utara", +// slug: "sulawesi-utara", +// logo: "/logo/polda/polda-sulawesi-utara.png", +// }, +// { +// name: "Polda Sumatera Barat", +// slug: "sumatera-barat", +// logo: "/logo/polda/polda-sumatera-barat.png", +// }, +// { +// name: "Polda Sumatera Selatan", +// slug: "sumatera-selatan", +// logo: "/logo/polda/polda-sumatera-selatan.png", +// }, +// { +// name: "Polda Sumatera Utara", +// slug: "sumatera-utara", +// logo: "/logo/polda/polda-sumatera-utara.png", +// }, +// // { +// // name: "Satuan Kerja POLRI", +// // slug: "satker-polri", +// // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", +// // }, +// // { +// // name: "Internasional", +// // slug: "internasional", +// // logo: "/assets/polda/internasional.png", +// // }, +// ]; + +// export default function PoldaAllAudioPage() { +// return ( +// +// ); +// } diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/document/regional/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/document/regional/page.tsx new file mode 100644 index 00000000..aa7c7f47 --- /dev/null +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/document/regional/page.tsx @@ -0,0 +1,988 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { + formatDateToIndonesian, + getOnlyDate, + getOnlyMonthAndYear, +} from "@/utils/globals"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; +import { + getPublicCategoryData, + getUserLevelListByParent, + listData, + listDataRegional, +} from "@/service/landing/landing"; +import { + ColumnDef, + ColumnFiltersState, + PaginationState, + SortingState, + VisibilityState, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from "@tanstack/react-table"; +import LandingPagination from "@/components/landing-page/pagination"; +import { Reveal } from "@/components/landing-page/Reveal"; +import { Link, useRouter } from "@/i18n/routing"; +import { Input } from "@/components/ui/input"; +import ReactDatePicker from "react-datepicker"; +import "react-datepicker/dist/react-datepicker.css"; +import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import ImageBlurry from "@/components/ui/image-blurry"; +import { Skeleton } from "@/components/ui/skeleton"; +import Image from "next/image"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => {row.getValue("no")}, + }, +]; + +export default function FilterPage() { + const router = useRouter(); + const asPath = usePathname(); + const params = useParams(); + const searchParams = useSearchParams(); + const locale = params?.locale; + const t = useTranslations("FilterPage"); + const [isLoading, setIsLoading] = useState(true); + const [documentData, setDocumentData] = useState([]); + const [totalData, setTotalData] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const [sorting, setSorting] = useState([]); + const [columnFilters, setColumnFilters] = useState([]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [page, setPage] = useState(1); + const [totalContent, setTotalContent] = useState(0); + const [change, setChange] = useState(false); + const sortBy = searchParams?.get("sortBy"); + const title = searchParams?.get("title"); + const categorie = searchParams?.get("category"); + const group = searchParams?.get("group"); + const [categoryFilter, setCategoryFilter] = useState([]); + const [monthYearFilter, setMonthYearFilter] = useState(); + const [searchTitle, setSearchTitle] = useState(""); + const [sortByOpt, setSortByOpt] = useState( + sortBy === "popular" ? "clickCount" : "createdAt" + ); + const [formatFilter, setFormatFilter] = useState([]); + const pages = page ? page - 1 : 0; + const [startDateString, setStartDateString] = useState(); + const [endDateString, setEndDateString] = useState(); + const [dateRange, setDateRange] = useState([null, null]); + const [handleClose, setHandleClose] = useState(false); + const [categories, setCategories] = useState([]); + const [isFilterOpen, setIsFilterOpen] = useState(true); + + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + + // === INIT === + useEffect(() => { + const timer = setTimeout(() => setIsLoading(false), 1200); + return () => clearTimeout(timer); + }, []); + + useEffect(() => { + const pageFromUrl = searchParams?.get("page"); + if (pageFromUrl) setPage(Number(pageFromUrl)); + }, [searchParams]); + + useEffect(() => { + if (categorie) { + setCategoryFilter( + categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie] + ); + } + }, [categorie]); + + useEffect(() => { + fetchCategories(categoryPage); + }, []); + + const fetchCategories = async (pageNumber: number) => { + const groupParam = + poldaName && poldaName.length > 1 + ? poldaName + : satkerName && satkerName.length > 1 + ? "satker-" + satkerName + : ""; + + const isInt = locale === "en"; + + const response = await getPublicCategoryData( + groupParam, + "", + isInt, + pageNumber + ); // halaman 1-based + + const content = response?.data?.data?.content || []; + const total = response?.data?.data?.totalPages || 1; + + setCategories(content); + setCategoryTotalPages(total); + }; + + useEffect(() => { + if (asPath?.includes("/regional")) getDataRegional(); + else getDataAll(); + }, [ + asPath, + monthYearFilter, + page, + sortBy, + sortByOpt, + title, + startDateString, + endDateString, + categorie, + formatFilter, + ]); + + async function getDataAll() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listData( + "3", + name, + filter, + 12, + pages, + sortByOpt, + format, + "", + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + locale == "en" ? true : false + ); + close(); + + const data = response?.data?.data; + setDocumentData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + async function getDataRegional() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listDataRegional( + "3", + name, + filter, + format, + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + 12, + pages, + sortByOpt + ); + close(); + + const data = response?.data?.data; + setDocumentData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + const handleCategoryFilter = (e: boolean, id: string) => { + let filter = [...categoryFilter]; + if (e) filter.push(String(id)); + else filter = filter.filter((item) => item !== String(id)); + router.push(`?category=${filter.join("&")}`); + }; + + const handleFormatFilter = (e: boolean, id: string) => { + let filter = [...formatFilter]; + if (e) filter.push(id); + else filter = filter.filter((item) => item !== id); + setFormatFilter(filter); + }; + + const handleSorting = (e: any) => { + const value = e.target.value; + setSortByOpt(value === "latest" ? "createdAt" : "clickCount"); + }; + + const handleDeleteDate = () => { + setDateRange([null, null]); + setStartDateString(""); + setEndDateString(""); + setHandleClose(false); + }; + + const handleKeyUp = () => { + if (!searchTitle) router.push("?title="); + else router.push(`?title=${searchTitle.toLowerCase()}`); + }; + + // === REACT TABLE === + const table = useReactTable({ + data: documentData, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + onRowSelectionChange: setRowSelection, + onPaginationChange: setPagination, + state: { + sorting, + columnFilters, + columnVisibility, + rowSelection, + pagination, + }, + }); + + const [calenderState, setCalenderState] = useState(false); + const [categoryPage, setCategoryPage] = useState(1); + const [categoryTotalPages, setCategoryTotalPages] = useState(1); + let typingTimer: any; + + const cleanCheckbox = () => { + setCategoryFilter([]); + setFormatFilter([]); + router.push(`?category=&title=`); + setDateRange([null, null]); + setMonthYearFilter(null); + setChange(!change); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + return ( +
+ {/* Header */} +
+

+ {" "} + {t("text", { defaultValue: "Text" })} {">"}{" "} + + {t("allText", { defaultValue: "All Text" })} + +

+

|

+ {!title ? ( +

+ {`${t("thereIs", { defaultValue: "Terdapat" })} ${totalContent} ${t( + "downloadableImage", + { defaultValue: "artikel berisi Foto yang dapat diunduh" } + )}`} +

+ ) : ( +

+ {t("search-results", { defaultValue: "Hasil pencarian untuk" })}{" "} + "{title}" +

+ )} +
+ +
+ {/* Left */} +
+

+ + Filter +

+
+
+
+ + setSearchTitle(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + id="search" + placeholder={t("searchTitle", { defaultValue: "Search Title" })} + className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" + /> +
+ +
+ + setMonthYearFilter(date)} + dateFormat="MM | yyyy" + placeholderText={t("selectYear", { + defaultValue: "Select Year", + })} + showMonthYearPicker + /> +
+ +
+ +
+ { + setDateRange(update); + }} + placeholderText={t("selectDate", { + defaultValue: "Select Date", + })} + onCalendarClose={() => setCalenderState(!calenderState)} + /> +
+ {handleClose ? ( + + ) : ( + "" + )} +
+
+
+ +
+

+ {t("categories", { defaultValue: "Categories" })} +

+ +
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
+ + {/* ⬇️ Pagination kategori (rata sejajar) */} +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+
+ + {/*
+

+ {t("categories", { defaultValue: "Categories" })} +

+
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
    + + + {Array.from({ length: categoryTotalPages }, (_, i) => ( + + ))} + + +
    +
+
*/} + {/* Garis */} +
+ {/* Garis */} +
+

+ Format +

+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+ + {/* RIGHT */} +
+ +
+

Sort By

+ +
+ + {isLoading ? ( +
+ + +
+ ) : documentData?.length > 0 ? ( +
+ {documentData?.map((document: any) => ( + + + + // router.push(prefixPath + `/document/detail/${text?.slug}`) + // } + className="cursor-pointer rounded-lg shadow-md overflow-hidden bg-white dark:bg-black dark:border dark:border-gray-500" + > + {/* Ikon di tengah dengan latar kuning */} +
+ + + +
+ + {/* Konten bawah */} +
+ {/* Kategori merah */} +
+ {document?.categoryName?.toUpperCase() ?? "Text"} +
+ + {/* Judul */} +
+ {document?.title} +
+
+ +
+
+ ))} +
+ ) : ( +
+ empty +
+ )} + + {totalPage > 1 && ( + + )} +
+
+
+
+ ); +} + +// import AllContentPage from "@/components/landing-page/all-content-page"; + +// const regions = [ +// { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, +// { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, +// { +// name: "Polda Bangka Belitung", +// slug: "bangka-belitung", +// logo: "/logo/polda/polda-bangka-belitung.png", +// }, +// { +// name: "Polda Banten", +// slug: "banten", +// logo: "/logo/polda/polda-banten.png", +// }, +// { +// name: "Polda Bengkulu", +// slug: "bengkulu", +// logo: "/logo/polda/polda-bengkulu.png", +// }, +// { +// name: "Polda DIY", +// slug: "jogja", +// logo: "/logo/polda/polda-jogja.png", +// }, +// { +// name: "Polda Gorontalo", +// slug: "gorontalo", +// logo: "/logo/polda/polda-gorontalo.png", +// }, +// { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, +// { +// name: "Polda Jawa Barat", +// slug: "jawa-barat", +// logo: "/logo/polda/polda-jawa-barat.png", +// }, +// { +// name: "Polda Jawa Tengah", +// slug: "jawa-tengah", +// logo: "/logo/polda/polda-jawa-tengah.png", +// }, +// { +// name: "Polda Jawa Timur", +// slug: "jawa-timur", +// logo: "/logo/polda/polda-jawa-timur.png", +// }, +// { +// name: "Polda Kalimantan Barat", +// slug: "kalimantan-barat", +// logo: "/logo/polda/polda-kalimantan-barat.png", +// }, +// { +// name: "Polda Kalimantan Selatan", +// slug: "kalimantan-selatan", +// logo: "/logo/polda/polda-kalimantan-selatan.png", +// }, +// { +// name: "Polda Kalimantan Tengah", +// slug: "kalimantan-tengah", +// logo: "/logo/polda/polda-kalimantan-tengah.png", +// }, +// { +// name: "Polda Kalimantan Timur", +// slug: "kalimantan-timur", +// logo: "/logo/polda/polda-kalimantan-timur.png", +// }, +// { +// name: "Polda Kalimantan Utara", +// slug: "kalimantan-utara", +// logo: "/logo/polda/polda-kalimantan-utara.png", +// }, +// { +// name: "Polda Kepulauan Riau", +// slug: "kepulauan-riau", +// logo: "/logo/polda/polda-kepulauan-riau.png", +// }, +// { +// name: "Polda Lampung", +// slug: "lampung", +// logo: "/logo/polda/polda-lampung.png", +// }, +// { +// name: "Polda Maluku", +// slug: "maluku", +// logo: "/logo/polda/polda-maluku.png", +// }, +// { +// name: "Polda Maluku Utara", +// slug: "maluku-utara", +// logo: "/logo/polda/polda-maluku-utara.png", +// }, +// { +// name: "Polda Metro Jaya", +// slug: "metro-jaya", +// logo: "/logo/polda/polda-metro-jaya.png", +// }, +// { +// name: "Polda NTB", +// slug: "ntb", +// logo: "/logo/polda/polda-ntb.png", +// }, +// { +// name: "Polda NTT", +// slug: "ntt", +// logo: "/logo/polda/polda-ntt.png", +// }, +// { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, +// { +// name: "Polda Papua Barat", +// slug: "papua-barat", +// logo: "/logo/polda/polda-papua-barat.png", +// }, +// { +// name: "Polda Papua Barat Daya", +// slug: "papua-barat-daya", +// logo: "/logo/polda/polda-papua-barat-daya.png", +// }, +// { +// name: "Polda Papua Tengah", +// slug: "papua-tengah", +// logo: "/logo/polda/polda-papua-tengah.png", +// }, +// { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, +// { +// name: "Polda Sulawesi Barat", +// slug: "sulawesi-barat", +// logo: "/logo/polda/polda-sulawesi-barat.png", +// }, +// { +// name: "Polda Sulawesi Selatan", +// slug: "sulawesi-selatan", +// logo: "/logo/polda/polda-sulawesi-selatan.png", +// }, +// { +// name: "Polda Sulawesi Tengah", +// slug: "sulawesi-tengah", +// logo: "/logo/polda/polda-sulawesi-tengah.png", +// }, +// { +// name: "Polda Sulawesi Tenggara", +// slug: "sulawesi-tenggara", +// logo: "/logo/polda/polda-sulawesi-tenggara.png", +// }, +// { +// name: "Polda Sulawesi Utara", +// slug: "sulawesi-utara", +// logo: "/logo/polda/polda-sulawesi-utara.png", +// }, +// { +// name: "Polda Sumatera Barat", +// slug: "sumatera-barat", +// logo: "/logo/polda/polda-sumatera-barat.png", +// }, +// { +// name: "Polda Sumatera Selatan", +// slug: "sumatera-selatan", +// logo: "/logo/polda/polda-sumatera-selatan.png", +// }, +// { +// name: "Polda Sumatera Utara", +// slug: "sumatera-utara", +// logo: "/logo/polda/polda-sumatera-utara.png", +// }, +// // { +// // name: "Satuan Kerja POLRI", +// // slug: "satker-polri", +// // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", +// // }, +// // { +// // name: "Internasional", +// // slug: "internasional", +// // logo: "/assets/polda/internasional.png", +// // }, +// ]; + +// export default function PoldaAllDocumentPage() { +// return ( +// +// ); +// } diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/image/regional/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/image/regional/page.tsx new file mode 100644 index 00000000..d83a0de5 --- /dev/null +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/image/regional/page.tsx @@ -0,0 +1,895 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { + formatDateToIndonesian, + getOnlyDate, + getOnlyMonthAndYear, +} from "@/utils/globals"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; +import { + getPublicCategoryData, + getUserLevelListByParent, + listData, + listDataRegional, +} from "@/service/landing/landing"; +import { + ColumnDef, + ColumnFiltersState, + PaginationState, + SortingState, + VisibilityState, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from "@tanstack/react-table"; +import LandingPagination from "@/components/landing-page/pagination"; +import { Reveal } from "@/components/landing-page/Reveal"; +import { Link, useRouter } from "@/i18n/routing"; +import { Input } from "@/components/ui/input"; +import ReactDatePicker from "react-datepicker"; +import "react-datepicker/dist/react-datepicker.css"; +import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import ImageBlurry from "@/components/ui/image-blurry"; +import { Skeleton } from "@/components/ui/skeleton"; +import Image from "next/image"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => {row.getValue("no")}, + }, +]; + +export default function FilterPage() { + const router = useRouter(); + const asPath = usePathname(); + const params = useParams(); + const searchParams = useSearchParams(); + const locale = params?.locale; + const t = useTranslations("FilterPage"); + + const [isLoading, setIsLoading] = useState(true); + const [imageData, setImageData] = useState([]); + const [totalData, setTotalData] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const [sorting, setSorting] = useState([]); + const [columnFilters, setColumnFilters] = useState([]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [page, setPage] = useState(1); + const [totalContent, setTotalContent] = useState(0); + const [change, setChange] = useState(false); + const sortBy = searchParams?.get("sortBy"); + const title = searchParams?.get("title"); + const categorie = searchParams?.get("category"); + const group = searchParams?.get("group"); + const [categoryFilter, setCategoryFilter] = useState([]); + const [monthYearFilter, setMonthYearFilter] = useState(); + const [searchTitle, setSearchTitle] = useState(""); + const [sortByOpt, setSortByOpt] = useState( + sortBy === "popular" ? "clickCount" : "createdAt" + ); + const [formatFilter, setFormatFilter] = useState([]); + const pages = page ? page - 1 : 0; + const [startDateString, setStartDateString] = useState(); + const [endDateString, setEndDateString] = useState(); + const [dateRange, setDateRange] = useState([null, null]); + const [handleClose, setHandleClose] = useState(false); + const [categories, setCategories] = useState([]); + const [isFilterOpen, setIsFilterOpen] = useState(true); + + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + + // === INIT === + useEffect(() => { + const timer = setTimeout(() => setIsLoading(false), 1200); + return () => clearTimeout(timer); + }, []); + + useEffect(() => { + const pageFromUrl = searchParams?.get("page"); + if (pageFromUrl) setPage(Number(pageFromUrl)); + }, [searchParams]); + + useEffect(() => { + if (categorie) { + setCategoryFilter( + categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie] + ); + } + }, [categorie]); + + useEffect(() => { + fetchCategories(categoryPage); + }, []); + + const fetchCategories = async (pageNumber: number) => { + const groupParam = + poldaName && poldaName.length > 1 + ? poldaName + : satkerName && satkerName.length > 1 + ? "satker-" + satkerName + : ""; + + const isInt = locale === "en"; + + const response = await getPublicCategoryData( + groupParam, + "", + isInt, + pageNumber + ); // halaman 1-based + + const content = response?.data?.data?.content || []; + const total = response?.data?.data?.totalPages || 1; + + setCategories(content); + setCategoryTotalPages(total); + }; + + // async function fetchCategories() { + // const response = await getPublicCategoryData("", "", locale === "en"); + // setCategories(response?.data?.data?.content || []); + // } + + useEffect(() => { + if (asPath?.includes("/regional")) getDataRegional(); + else getDataAll(); + }, [ + asPath, + monthYearFilter, + page, + sortBy, + sortByOpt, + title, + startDateString, + endDateString, + categorie, + formatFilter, + ]); + + async function getDataAll() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listData( + "1", + name, + filter, + 12, + pages, + sortByOpt, + format, + "", + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + locale == "en" ? true : false + ); + close(); + + const data = response?.data?.data; + setImageData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + async function getDataRegional() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listDataRegional( + "1", + name, + filter, + format, + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + 12, + pages, + sortByOpt + ); + close(); + + const data = response?.data?.data; + setImageData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + const handleCategoryFilter = (e: boolean, id: string) => { + let filter = [...categoryFilter]; + if (e) filter.push(String(id)); + else filter = filter.filter((item) => item !== String(id)); + router.push(`?category=${filter.join("&")}`); + }; + + const handleFormatFilter = (e: boolean, id: string) => { + let filter = [...formatFilter]; + if (e) filter.push(id); + else filter = filter.filter((item) => item !== id); + setFormatFilter(filter); + }; + + const handleSorting = (e: any) => { + const value = e.target.value; + setSortByOpt(value === "latest" ? "createdAt" : "clickCount"); + }; + + const handleDeleteDate = () => { + setDateRange([null, null]); + setStartDateString(""); + setEndDateString(""); + setHandleClose(false); + }; + + const handleKeyUp = () => { + if (!searchTitle) router.push("?title="); + else router.push(`?title=${searchTitle.toLowerCase()}`); + }; + + // === REACT TABLE === + const table = useReactTable({ + data: imageData, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + onRowSelectionChange: setRowSelection, + onPaginationChange: setPagination, + state: { + sorting, + columnFilters, + columnVisibility, + rowSelection, + pagination, + }, + }); + + const [calenderState, setCalenderState] = useState(false); + const [categoryPage, setCategoryPage] = useState(1); + const [categoryTotalPages, setCategoryTotalPages] = useState(1); + let typingTimer: any; + + const cleanCheckbox = () => { + setCategoryFilter([]); + setFormatFilter([]); + router.push(`?category=&title=`); + setDateRange([null, null]); + setMonthYearFilter(null); + setChange(!change); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + return ( +
+ {/* Header */} +
+

{t("image", { defaultValue: "Image" })}

{">"} +

+ + {t("allImage", { defaultValue: "All Image" })} + +

+

|

+ {!title ? ( +

+ {`${t("thereIs", { defaultValue: "Terdapat" })} ${totalContent} ${t( + "downloadableImage", + { defaultValue: "artikel berisi Foto yang dapat diunduh" } + )}`} +

+ ) : ( +

+ {t("search-results", { defaultValue: "Hasil pencarian untuk" })}{" "} + "{title}" +

+ )} +
+ +
+ {/* Left */} +
+ +
+ + {isFilterOpen && ( +
+

+ + Filter +

+
+
+
+ + setSearchTitle(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + id="search" + placeholder={t("searchTitle", { + defaultValue: "Search Title", + })} + className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" + /> +
+ +
+ + setMonthYearFilter(date)} + dateFormat="MM | yyyy" + placeholderText={t("selectYear", { + defaultValue: "Select Year", + })} + showMonthYearPicker + /> +
+ +
+ +
+ { + setDateRange(update); + }} + placeholderText={t("selectDate", { + defaultValue: "Select Date", + })} + onCalendarClose={() => setCalenderState(!calenderState)} + /> +
+ {handleClose ? ( + + ) : ( + "" + )} +
+
+
+ +
+

+ {t("categories", { defaultValue: "Categories" })} +

+ +
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
+ + {/* ⬇️ Pagination kategori (rata sejajar) */} +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+
+ + {/* Garis */} +
+ {/* Garis */} +
+

+ Format +

+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+ )} + + {/* CONTENT */} +
+ +
+

Sort By

+ +
+ + {isLoading ? ( +
+ + +
+ ) : imageData?.length > 0 ? ( +
+ {imageData.map((image: any) => ( + + + +
+ +
+
+
+

+ {image?.categoryName?.toUpperCase() ?? + "Giat Pimpinan"} +

+

+ {formatDateToIndonesian( + new Date(image?.createdAt) + )}{" "} + {image?.timezone ?? "WIB"} | + {" "} + {image.clickCount} +

+
+

+ {image?.title} +

+
+ +
+
+ ))} +
+ ) : ( +
+ empty +
+ )} + + {totalPage > 1 && ( + + )} +
+
+
+
+ ); +} + +// import AllContentPage from "@/components/landing-page/all-content-page"; + +// const regions = [ +// { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, +// { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, +// { +// name: "Polda Bangka Belitung", +// slug: "bangka-belitung", +// logo: "/logo/polda/polda-bangka-belitung.png", +// }, +// { +// name: "Polda Banten", +// slug: "banten", +// logo: "/logo/polda/polda-banten.png", +// }, +// { +// name: "Polda Bengkulu", +// slug: "bengkulu", +// logo: "/logo/polda/polda-bengkulu.png", +// }, +// { +// name: "Polda DIY", +// slug: "jogja", +// logo: "/logo/polda/polda-jogja.png", +// }, +// { +// name: "Polda Gorontalo", +// slug: "gorontalo", +// logo: "/logo/polda/polda-gorontalo.png", +// }, +// { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, +// { +// name: "Polda Jawa Barat", +// slug: "jawa-barat", +// logo: "/logo/polda/polda-jawa-barat.png", +// }, +// { +// name: "Polda Jawa Tengah", +// slug: "jawa-tengah", +// logo: "/logo/polda/polda-jawa-tengah.png", +// }, +// { +// name: "Polda Jawa Timur", +// slug: "jawa-timur", +// logo: "/logo/polda/polda-jawa-timur.png", +// }, +// { +// name: "Polda Kalimantan Barat", +// slug: "kalimantan-barat", +// logo: "/logo/polda/polda-kalimantan-barat.png", +// }, +// { +// name: "Polda Kalimantan Selatan", +// slug: "kalimantan-selatan", +// logo: "/logo/polda/polda-kalimantan-selatan.png", +// }, +// { +// name: "Polda Kalimantan Tengah", +// slug: "kalimantan-tengah", +// logo: "/logo/polda/polda-kalimantan-tengah.png", +// }, +// { +// name: "Polda Kalimantan Timur", +// slug: "kalimantan-timur", +// logo: "/logo/polda/polda-kalimantan-timur.png", +// }, +// { +// name: "Polda Kalimantan Utara", +// slug: "kalimantan-utara", +// logo: "/logo/polda/polda-kalimantan-utara.png", +// }, +// { +// name: "Polda Kepulauan Riau", +// slug: "kepulauan-riau", +// logo: "/logo/polda/polda-kepulauan-riau.png", +// }, +// { +// name: "Polda Lampung", +// slug: "lampung", +// logo: "/logo/polda/polda-lampung.png", +// }, +// { +// name: "Polda Maluku", +// slug: "maluku", +// logo: "/logo/polda/polda-maluku.png", +// }, +// { +// name: "Polda Maluku Utara", +// slug: "maluku-utara", +// logo: "/logo/polda/polda-maluku-utara.png", +// }, +// { +// name: "Polda Metro Jaya", +// slug: "metro-jaya", +// logo: "/logo/polda/polda-metro-jaya.png", +// }, +// { +// name: "Polda NTB", +// slug: "ntb", +// logo: "/logo/polda/polda-ntb.png", +// }, +// { +// name: "Polda NTT", +// slug: "ntt", +// logo: "/logo/polda/polda-ntt.png", +// }, +// { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, +// { +// name: "Polda Papua Barat", +// slug: "papua-barat", +// logo: "/logo/polda/polda-papua-barat.png", +// }, +// { +// name: "Polda Papua Barat Daya", +// slug: "papua-barat-daya", +// logo: "/logo/polda/polda-papua-barat-daya.png", +// }, +// { +// name: "Polda Papua Tengah", +// slug: "papua-tengah", +// logo: "/logo/polda/polda-papua-tengah.png", +// }, +// { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, +// { +// name: "Polda Sulawesi Barat", +// slug: "sulawesi-barat", +// logo: "/logo/polda/polda-sulawesi-barat.png", +// }, +// { +// name: "Polda Sulawesi Selatan", +// slug: "sulawesi-selatan", +// logo: "/logo/polda/polda-sulawesi-selatan.png", +// }, +// { +// name: "Polda Sulawesi Tengah", +// slug: "sulawesi-tengah", +// logo: "/logo/polda/polda-sulawesi-tengah.png", +// }, +// { +// name: "Polda Sulawesi Tenggara", +// slug: "sulawesi-tenggara", +// logo: "/logo/polda/polda-sulawesi-tenggara.png", +// }, +// { +// name: "Polda Sulawesi Utara", +// slug: "sulawesi-utara", +// logo: "/logo/polda/polda-sulawesi-utara.png", +// }, +// { +// name: "Polda Sumatera Barat", +// slug: "sumatera-barat", +// logo: "/logo/polda/polda-sumatera-barat.png", +// }, +// { +// name: "Polda Sumatera Selatan", +// slug: "sumatera-selatan", +// logo: "/logo/polda/polda-sumatera-selatan.png", +// }, +// { +// name: "Polda Sumatera Utara", +// slug: "sumatera-utara", +// logo: "/logo/polda/polda-sumatera-utara.png", +// }, +// // { +// // name: "Satuan Kerja POLRI", +// // slug: "satker-polri", +// // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", +// // }, +// // { +// // name: "Internasional", +// // slug: "internasional", +// // logo: "/assets/polda/internasional.png", +// // }, +// ]; + +// export default function PoldaAllImagePage() { +// return ( +// +// ); +// } diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/video/regional/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/video/regional/page.tsx new file mode 100644 index 00000000..1af0ecb0 --- /dev/null +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/video/regional/page.tsx @@ -0,0 +1,987 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { + formatDateToIndonesian, + getOnlyDate, + getOnlyMonthAndYear, +} from "@/utils/globals"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; +import { + getPublicCategoryData, + getUserLevelListByParent, + listData, + listDataRegional, +} from "@/service/landing/landing"; +import { + ColumnDef, + ColumnFiltersState, + PaginationState, + SortingState, + VisibilityState, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from "@tanstack/react-table"; +import LandingPagination from "@/components/landing-page/pagination"; +import { Reveal } from "@/components/landing-page/Reveal"; +import { Link, useRouter } from "@/i18n/routing"; +import { Input } from "@/components/ui/input"; +import ReactDatePicker from "react-datepicker"; +import "react-datepicker/dist/react-datepicker.css"; +import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import ImageBlurry from "@/components/ui/image-blurry"; +import { Skeleton } from "@/components/ui/skeleton"; +import Image from "next/image"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => {row.getValue("no")}, + }, +]; + +export default function FilterPage() { + const router = useRouter(); + const asPath = usePathname(); + const params = useParams(); + const searchParams = useSearchParams(); + const locale = params?.locale; + const t = useTranslations("FilterPage"); + const [isLoading, setIsLoading] = useState(true); + const [videoData, setVideoData] = useState([]); + const [totalData, setTotalData] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const [sorting, setSorting] = useState([]); + const [columnFilters, setColumnFilters] = useState([]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [page, setPage] = useState(1); + const [totalContent, setTotalContent] = useState(0); + const [change, setChange] = useState(false); + const sortBy = searchParams?.get("sortBy"); + const title = searchParams?.get("title"); + const categorie = searchParams?.get("category"); + const group = searchParams?.get("group"); + const [categoryFilter, setCategoryFilter] = useState([]); + const [monthYearFilter, setMonthYearFilter] = useState(); + const [searchTitle, setSearchTitle] = useState(""); + const [sortByOpt, setSortByOpt] = useState( + sortBy === "popular" ? "clickCount" : "createdAt" + ); + const [formatFilter, setFormatFilter] = useState([]); + const pages = page ? page - 1 : 0; + const [startDateString, setStartDateString] = useState(); + const [endDateString, setEndDateString] = useState(); + const [dateRange, setDateRange] = useState([null, null]); + const [handleClose, setHandleClose] = useState(false); + const [categories, setCategories] = useState([]); + const [isFilterOpen, setIsFilterOpen] = useState(true); + + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + + // === INIT === + useEffect(() => { + const timer = setTimeout(() => setIsLoading(false), 1200); + return () => clearTimeout(timer); + }, []); + + useEffect(() => { + const pageFromUrl = searchParams?.get("page"); + if (pageFromUrl) setPage(Number(pageFromUrl)); + }, [searchParams]); + + useEffect(() => { + if (categorie) { + setCategoryFilter( + categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie] + ); + } + }, [categorie]); + + useEffect(() => { + fetchCategories(categoryPage); + }, []); + + const fetchCategories = async (pageNumber: number) => { + const groupParam = + poldaName && poldaName.length > 1 + ? poldaName + : satkerName && satkerName.length > 1 + ? "satker-" + satkerName + : ""; + + const isInt = locale === "en"; + + const response = await getPublicCategoryData( + groupParam, + "", + isInt, + pageNumber + ); // halaman 1-based + + const content = response?.data?.data?.content || []; + const total = response?.data?.data?.totalPages || 1; + + setCategories(content); + setCategoryTotalPages(total); + }; + + useEffect(() => { + if (asPath?.includes("/regional")) getDataRegional(); + else getDataAll(); + }, [ + asPath, + monthYearFilter, + page, + sortBy, + sortByOpt, + title, + startDateString, + endDateString, + categorie, + formatFilter, + ]); + + async function getDataAll() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listData( + "2", + name, + filter, + 12, + pages, + sortByOpt, + format, + "", + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + locale == "en" ? true : false + ); + close(); + + const data = response?.data?.data; + setVideoData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + async function getDataRegional() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listDataRegional( + "2", + name, + filter, + format, + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + 12, + pages, + sortByOpt + ); + close(); + + const data = response?.data?.data; + setVideoData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + const handleCategoryFilter = (e: boolean, id: string) => { + let filter = [...categoryFilter]; + if (e) filter.push(String(id)); + else filter = filter.filter((item) => item !== String(id)); + router.push(`?category=${filter.join("&")}`); + }; + + const handleFormatFilter = (e: boolean, id: string) => { + let filter = [...formatFilter]; + if (e) filter.push(id); + else filter = filter.filter((item) => item !== id); + setFormatFilter(filter); + }; + + const handleSorting = (e: any) => { + const value = e.target.value; + setSortByOpt(value === "latest" ? "createdAt" : "clickCount"); + }; + + const handleDeleteDate = () => { + setDateRange([null, null]); + setStartDateString(""); + setEndDateString(""); + setHandleClose(false); + }; + + const handleKeyUp = () => { + if (!searchTitle) router.push("?title="); + else router.push(`?title=${searchTitle.toLowerCase()}`); + }; + + // === REACT TABLE === + const table = useReactTable({ + data: videoData, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + onRowSelectionChange: setRowSelection, + onPaginationChange: setPagination, + state: { + sorting, + columnFilters, + columnVisibility, + rowSelection, + pagination, + }, + }); + + const [calenderState, setCalenderState] = useState(false); + const [categoryPage, setCategoryPage] = useState(1); + const [categoryTotalPages, setCategoryTotalPages] = useState(1); + let typingTimer: any; + + const cleanCheckbox = () => { + setCategoryFilter([]); + setFormatFilter([]); + router.push(`?category=&title=`); + setDateRange([null, null]); + setMonthYearFilter(null); + setChange(!change); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + return ( +
+ {/* Header */} +
+

{t("video", { defaultValue: "Video" })}

{">"} +

+ + {t("allVideo", { defaultValue: "All Video" })} + +

+

|

+ {!title ? ( +

+ {`${t("thereIs", { defaultValue: "Terdapat" })} ${totalContent} ${t( + "downloadablevideo", + { defaultValue: "artikel berisi Foto yang dapat diunduh" } + )}`} +

+ ) : ( +

+ {t("search-results", { defaultValue: "Hasil pencarian untuk" })}{" "} + "{title}" +

+ )} +
+ +
+
+

+ + Filter +

+
+
+
+ + setSearchTitle(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + id="search" + placeholder={t("searchTitle", { defaultValue: "Search Title" })} + className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" + /> +
+ +
+ + setMonthYearFilter(date)} + dateFormat="MM | yyyy" + placeholderText={t("selectYear", { + defaultValue: "Select Year", + })} + showMonthYearPicker + /> +
+ +
+ +
+ { + setDateRange(update); + }} + placeholderText={t("selectDate", { + defaultValue: "Select Date", + })} + onCalendarClose={() => setCalenderState(!calenderState)} + /> +
+ {handleClose ? ( + + ) : ( + "" + )} +
+
+
+ +
+

+ {t("categories", { defaultValue: "Categories" })} +

+ +
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
+ + {/* ⬇️ Pagination kategori (rata sejajar) */} +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+
+ + {/*
+

+ {t("categories", { defaultValue: "Categories" })} +

+
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
    + + + {Array.from({ length: categoryTotalPages }, (_, i) => ( + + ))} + + +
    +
+
*/} + {/* Garis */} +
+ {/* Garis */} +
+

+ Format +

+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+ + {/* CONTENT */} +
+ +
+

Sort By

+ +
+ + {isLoading ? ( +
+ + +
+ ) : videoData?.length > 0 ? ( +
+ {videoData.map((video: any) => ( + + + +
+ +
+
+
+

+ {video?.categoryName?.toUpperCase() ?? + "Giat Pimpinan"} +

+

+ {formatDateToIndonesian( + new Date(video?.createdAt) + )}{" "} + {video?.timezone ?? "WIB"} | + {" "} + {video.clickCount} +

+
+

+ {video?.title} +

+
+ +
+
+ ))} +
+ ) : ( +
+ empty +
+ )} + + {totalPage > 1 && ( + + )} +
+
+
+
+ ); +} + +// import AllContentPage from "@/components/landing-page/all-content-page"; + +// const regions = [ +// { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, +// { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, +// { +// name: "Polda Bangka Belitung", +// slug: "bangka-belitung", +// logo: "/logo/polda/polda-bangka-belitung.png", +// }, +// { +// name: "Polda Banten", +// slug: "banten", +// logo: "/logo/polda/polda-banten.png", +// }, +// { +// name: "Polda Bengkulu", +// slug: "bengkulu", +// logo: "/logo/polda/polda-bengkulu.png", +// }, +// { +// name: "Polda DIY", +// slug: "jogja", +// logo: "/logo/polda/polda-jogja.png", +// }, +// { +// name: "Polda Gorontalo", +// slug: "gorontalo", +// logo: "/logo/polda/polda-gorontalo.png", +// }, +// { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, +// { +// name: "Polda Jawa Barat", +// slug: "jawa-barat", +// logo: "/logo/polda/polda-jawa-barat.png", +// }, +// { +// name: "Polda Jawa Tengah", +// slug: "jawa-tengah", +// logo: "/logo/polda/polda-jawa-tengah.png", +// }, +// { +// name: "Polda Jawa Timur", +// slug: "jawa-timur", +// logo: "/logo/polda/polda-jawa-timur.png", +// }, +// { +// name: "Polda Kalimantan Barat", +// slug: "kalimantan-barat", +// logo: "/logo/polda/polda-kalimantan-barat.png", +// }, +// { +// name: "Polda Kalimantan Selatan", +// slug: "kalimantan-selatan", +// logo: "/logo/polda/polda-kalimantan-selatan.png", +// }, +// { +// name: "Polda Kalimantan Tengah", +// slug: "kalimantan-tengah", +// logo: "/logo/polda/polda-kalimantan-tengah.png", +// }, +// { +// name: "Polda Kalimantan Timur", +// slug: "kalimantan-timur", +// logo: "/logo/polda/polda-kalimantan-timur.png", +// }, +// { +// name: "Polda Kalimantan Utara", +// slug: "kalimantan-utara", +// logo: "/logo/polda/polda-kalimantan-utara.png", +// }, +// { +// name: "Polda Kepulauan Riau", +// slug: "kepulauan-riau", +// logo: "/logo/polda/polda-kepulauan-riau.png", +// }, +// { +// name: "Polda Lampung", +// slug: "lampung", +// logo: "/logo/polda/polda-lampung.png", +// }, +// { +// name: "Polda Maluku", +// slug: "maluku", +// logo: "/logo/polda/polda-maluku.png", +// }, +// { +// name: "Polda Maluku Utara", +// slug: "maluku-utara", +// logo: "/logo/polda/polda-maluku-utara.png", +// }, +// { +// name: "Polda Metro Jaya", +// slug: "metro-jaya", +// logo: "/logo/polda/polda-metro-jaya.png", +// }, +// { +// name: "Polda NTB", +// slug: "ntb", +// logo: "/logo/polda/polda-ntb.png", +// }, +// { +// name: "Polda NTT", +// slug: "ntt", +// logo: "/logo/polda/polda-ntt.png", +// }, +// { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, +// { +// name: "Polda Papua Barat", +// slug: "papua-barat", +// logo: "/logo/polda/polda-papua-barat.png", +// }, +// { +// name: "Polda Papua Barat Daya", +// slug: "papua-barat-daya", +// logo: "/logo/polda/polda-papua-barat-daya.png", +// }, +// { +// name: "Polda Papua Tengah", +// slug: "papua-tengah", +// logo: "/logo/polda/polda-papua-tengah.png", +// }, +// { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, +// { +// name: "Polda Sulawesi Barat", +// slug: "sulawesi-barat", +// logo: "/logo/polda/polda-sulawesi-barat.png", +// }, +// { +// name: "Polda Sulawesi Selatan", +// slug: "sulawesi-selatan", +// logo: "/logo/polda/polda-sulawesi-selatan.png", +// }, +// { +// name: "Polda Sulawesi Tengah", +// slug: "sulawesi-tengah", +// logo: "/logo/polda/polda-sulawesi-tengah.png", +// }, +// { +// name: "Polda Sulawesi Tenggara", +// slug: "sulawesi-tenggara", +// logo: "/logo/polda/polda-sulawesi-tenggara.png", +// }, +// { +// name: "Polda Sulawesi Utara", +// slug: "sulawesi-utara", +// logo: "/logo/polda/polda-sulawesi-utara.png", +// }, +// { +// name: "Polda Sumatera Barat", +// slug: "sumatera-barat", +// logo: "/logo/polda/polda-sumatera-barat.png", +// }, +// { +// name: "Polda Sumatera Selatan", +// slug: "sumatera-selatan", +// logo: "/logo/polda/polda-sumatera-selatan.png", +// }, +// { +// name: "Polda Sumatera Utara", +// slug: "sumatera-utara", +// logo: "/logo/polda/polda-sumatera-utara.png", +// }, +// // { +// // name: "Satuan Kerja POLRI", +// // slug: "satker-polri", +// // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", +// // }, +// // { +// // name: "Internasional", +// // slug: "internasional", +// // logo: "/assets/polda/internasional.png", +// // }, +// ]; + +// export default function PoldaAllVideoPage() { +// return ( +// +// ); +// } diff --git a/app/[locale]/(public)/audio/filter/page.tsx b/app/[locale]/(public)/audio/filter/page.tsx index 9b4de003..338c43dd 100644 --- a/app/[locale]/(public)/audio/filter/page.tsx +++ b/app/[locale]/(public)/audio/filter/page.tsx @@ -511,8 +511,8 @@ const FilterPage = () => { )} - {/* Left */}
+ {/* Left */}

diff --git a/app/[locale]/(public)/document/filter/page.tsx b/app/[locale]/(public)/document/filter/page.tsx index 060827af..98b94829 100644 --- a/app/[locale]/(public)/document/filter/page.tsx +++ b/app/[locale]/(public)/document/filter/page.tsx @@ -500,7 +500,6 @@ const FilterPage = () => { return (
{/* Header */} -

{" "} @@ -527,8 +526,8 @@ const FilterPage = () => { )}

- {/* Left */}
+ {/* Left */}

diff --git a/app/[locale]/(public)/regional/all-polda/audio/all/page.tsx b/app/[locale]/(public)/regional/all-polda/audio/all/page.tsx deleted file mode 100644 index b9d33eee..00000000 --- a/app/[locale]/(public)/regional/all-polda/audio/all/page.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import AllContentPage from "@/components/landing-page/all-content-page"; - -const regions = [ - { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, - { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, - { - name: "Polda Bangka Belitung", - slug: "bangka-belitung", - logo: "/logo/polda/polda-bangka-belitung.png", - }, - { - name: "Polda Banten", - slug: "banten", - logo: "/logo/polda/polda-banten.png", - }, - { - name: "Polda Bengkulu", - slug: "bengkulu", - logo: "/logo/polda/polda-bengkulu.png", - }, - { - name: "Polda DIY", - slug: "jogja", - logo: "/logo/polda/polda-jogja.png", - }, - { - name: "Polda Gorontalo", - slug: "gorontalo", - logo: "/logo/polda/polda-gorontalo.png", - }, - { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, - { - name: "Polda Jawa Barat", - slug: "jawa-barat", - logo: "/logo/polda/polda-jawa-barat.png", - }, - { - name: "Polda Jawa Tengah", - slug: "jawa-tengah", - logo: "/logo/polda/polda-jawa-tengah.png", - }, - { - name: "Polda Jawa Timur", - slug: "jawa-timur", - logo: "/logo/polda/polda-jawa-timur.png", - }, - { - name: "Polda Kalimantan Barat", - slug: "kalimantan-barat", - logo: "/logo/polda/polda-kalimantan-barat.png", - }, - { - name: "Polda Kalimantan Selatan", - slug: "kalimantan-selatan", - logo: "/logo/polda/polda-kalimantan-selatan.png", - }, - { - name: "Polda Kalimantan Tengah", - slug: "kalimantan-tengah", - logo: "/logo/polda/polda-kalimantan-tengah.png", - }, - { - name: "Polda Kalimantan Timur", - slug: "kalimantan-timur", - logo: "/logo/polda/polda-kalimantan-timur.png", - }, - { - name: "Polda Kalimantan Utara", - slug: "kalimantan-utara", - logo: "/logo/polda/polda-kalimantan-utara.png", - }, - { - name: "Polda Kepulauan Riau", - slug: "kepulauan-riau", - logo: "/logo/polda/polda-kepulauan-riau.png", - }, - { - name: "Polda Lampung", - slug: "lampung", - logo: "/logo/polda/polda-lampung.png", - }, - { - name: "Polda Maluku", - slug: "maluku", - logo: "/logo/polda/polda-maluku.png", - }, - { - name: "Polda Maluku Utara", - slug: "maluku-utara", - logo: "/logo/polda/polda-maluku-utara.png", - }, - { - name: "Polda Metro Jaya", - slug: "metro-jaya", - logo: "/logo/polda/polda-metro-jaya.png", - }, - { - name: "Polda NTB", - slug: "ntb", - logo: "/logo/polda/polda-ntb.png", - }, - { - name: "Polda NTT", - slug: "ntt", - logo: "/logo/polda/polda-ntt.png", - }, - { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, - { - name: "Polda Papua Barat", - slug: "papua-barat", - logo: "/logo/polda/polda-papua-barat.png", - }, - { - name: "Polda Papua Barat Daya", - slug: "papua-barat-daya", - logo: "/logo/polda/polda-papua-barat-daya.png", - }, - { - name: "Polda Papua Tengah", - slug: "papua-tengah", - logo: "/logo/polda/polda-papua-tengah.png", - }, - { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, - { - name: "Polda Sulawesi Barat", - slug: "sulawesi-barat", - logo: "/logo/polda/polda-sulawesi-barat.png", - }, - { - name: "Polda Sulawesi Selatan", - slug: "sulawesi-selatan", - logo: "/logo/polda/polda-sulawesi-selatan.png", - }, - { - name: "Polda Sulawesi Tengah", - slug: "sulawesi-tengah", - logo: "/logo/polda/polda-sulawesi-tengah.png", - }, - { - name: "Polda Sulawesi Tenggara", - slug: "sulawesi-tenggara", - logo: "/logo/polda/polda-sulawesi-tenggara.png", - }, - { - name: "Polda Sulawesi Utara", - slug: "sulawesi-utara", - logo: "/logo/polda/polda-sulawesi-utara.png", - }, - { - name: "Polda Sumatera Barat", - slug: "sumatera-barat", - logo: "/logo/polda/polda-sumatera-barat.png", - }, - { - name: "Polda Sumatera Selatan", - slug: "sumatera-selatan", - logo: "/logo/polda/polda-sumatera-selatan.png", - }, - { - name: "Polda Sumatera Utara", - slug: "sumatera-utara", - logo: "/logo/polda/polda-sumatera-utara.png", - }, - // { - // name: "Satuan Kerja POLRI", - // slug: "satker-polri", - // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", - // }, - // { - // name: "Internasional", - // slug: "internasional", - // logo: "/assets/polda/internasional.png", - // }, -]; - -export default function PoldaAllAudioPage() { - return ( - - ); -} diff --git a/app/[locale]/(public)/regional/all-polda/audio/regional/page.tsx b/app/[locale]/(public)/regional/all-polda/audio/regional/page.tsx new file mode 100644 index 00000000..71c90bf5 --- /dev/null +++ b/app/[locale]/(public)/regional/all-polda/audio/regional/page.tsx @@ -0,0 +1,942 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { + formatDateToIndonesian, + getOnlyDate, + getOnlyMonthAndYear, +} from "@/utils/globals"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; +import { + getPublicCategoryData, + getUserLevelListByParent, + listData, + listDataRegional, +} from "@/service/landing/landing"; +import { + ColumnDef, + ColumnFiltersState, + PaginationState, + SortingState, + VisibilityState, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from "@tanstack/react-table"; +import LandingPagination from "@/components/landing-page/pagination"; +import { Reveal } from "@/components/landing-page/Reveal"; +import { Link, useRouter } from "@/i18n/routing"; +import { Input } from "@/components/ui/input"; +import ReactDatePicker from "react-datepicker"; +import "react-datepicker/dist/react-datepicker.css"; +import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import ImageBlurry from "@/components/ui/image-blurry"; +import { Skeleton } from "@/components/ui/skeleton"; +import Image from "next/image"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => {row.getValue("no")}, + }, +]; + +export default function FilterPage() { + const router = useRouter(); + const asPath = usePathname(); + const params = useParams(); + const searchParams = useSearchParams(); + const locale = params?.locale; + const t = useTranslations("FilterPage"); + const [isLoading, setIsLoading] = useState(true); + const [audioData, setAudioData] = useState([]); + const [totalData, setTotalData] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const [sorting, setSorting] = useState([]); + const [columnFilters, setColumnFilters] = useState([]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [page, setPage] = useState(1); + const [totalContent, setTotalContent] = useState(0); + const [change, setChange] = useState(false); + const sortBy = searchParams?.get("sortBy"); + const title = searchParams?.get("title"); + const categorie = searchParams?.get("category"); + const group = searchParams?.get("group"); + const [categoryFilter, setCategoryFilter] = useState([]); + const [monthYearFilter, setMonthYearFilter] = useState(); + const [searchTitle, setSearchTitle] = useState(""); + const [sortByOpt, setSortByOpt] = useState( + sortBy === "popular" ? "clickCount" : "createdAt" + ); + const [formatFilter, setFormatFilter] = useState([]); + const pages = page ? page - 1 : 0; + const [startDateString, setStartDateString] = useState(); + const [endDateString, setEndDateString] = useState(); + const [dateRange, setDateRange] = useState([null, null]); + const [handleClose, setHandleClose] = useState(false); + const [categories, setCategories] = useState([]); + const [isFilterOpen, setIsFilterOpen] = useState(true); + + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + + // === INIT === + useEffect(() => { + const timer = setTimeout(() => setIsLoading(false), 1200); + return () => clearTimeout(timer); + }, []); + + useEffect(() => { + const pageFromUrl = searchParams?.get("page"); + if (pageFromUrl) setPage(Number(pageFromUrl)); + }, [searchParams]); + + useEffect(() => { + if (categorie) { + setCategoryFilter( + categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie] + ); + } + }, [categorie]); + + useEffect(() => { + fetchCategories(categoryPage); + }, []); + + const fetchCategories = async (pageNumber: number) => { + const groupParam = + poldaName && poldaName.length > 1 + ? poldaName + : satkerName && satkerName.length > 1 + ? "satker-" + satkerName + : ""; + + const isInt = locale === "en"; + + const response = await getPublicCategoryData( + groupParam, + "", + isInt, + pageNumber + ); // halaman 1-based + + const content = response?.data?.data?.content || []; + const total = response?.data?.data?.totalPages || 1; + + setCategories(content); + setCategoryTotalPages(total); + }; + useEffect(() => { + if (asPath?.includes("/regional")) getDataRegional(); + else getDataAll(); + }, [ + asPath, + monthYearFilter, + page, + sortBy, + sortByOpt, + title, + startDateString, + endDateString, + categorie, + formatFilter, + ]); + + async function getDataAll() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listData( + "4", + name, + filter, + 12, + pages, + sortByOpt, + format, + "", + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + locale == "en" ? true : false + ); + close(); + + const data = response?.data?.data; + setAudioData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + async function getDataRegional() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listDataRegional( + "4", + name, + filter, + format, + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + 12, + pages, + sortByOpt + ); + close(); + + const data = response?.data?.data; + setAudioData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + const handleCategoryFilter = (e: boolean, id: string) => { + let filter = [...categoryFilter]; + if (e) filter.push(String(id)); + else filter = filter.filter((item) => item !== String(id)); + router.push(`?category=${filter.join("&")}`); + }; + + const handleFormatFilter = (e: boolean, id: string) => { + let filter = [...formatFilter]; + if (e) filter.push(id); + else filter = filter.filter((item) => item !== id); + setFormatFilter(filter); + }; + + const handleSorting = (e: any) => { + const value = e.target.value; + setSortByOpt(value === "latest" ? "createdAt" : "clickCount"); + }; + + const handleDeleteDate = () => { + setDateRange([null, null]); + setStartDateString(""); + setEndDateString(""); + setHandleClose(false); + }; + + const handleKeyUp = () => { + if (!searchTitle) router.push("?title="); + else router.push(`?title=${searchTitle.toLowerCase()}`); + }; + + // === REACT TABLE === + const table = useReactTable({ + data: audioData, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + onRowSelectionChange: setRowSelection, + onPaginationChange: setPagination, + state: { + sorting, + columnFilters, + columnVisibility, + rowSelection, + pagination, + }, + }); + + const [calenderState, setCalenderState] = useState(false); + const [categoryPage, setCategoryPage] = useState(1); + const [categoryTotalPages, setCategoryTotalPages] = useState(1); + let typingTimer: any; + + const cleanCheckbox = () => { + setCategoryFilter([]); + setFormatFilter([]); + router.push(`?category=&title=`); + setDateRange([null, null]); + setMonthYearFilter(null); + setChange(!change); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + return ( +
+ {/* Header */} +
+

+ {" "} + Audio {">"}{" "} + + {t("allAudio", { defaultValue: "All Audio" })} + +

+

|

+ {!title ? ( +

+ {`${t("thereIs", { defaultValue: "Terdapat" })} ${totalContent} ${t( + "downloadableImage", + { defaultValue: "artikel berisi Foto yang dapat diunduh" } + )}`} +

+ ) : ( +

+ {t("search-results", { defaultValue: "Hasil pencarian untuk" })}{" "} + "{title}" +

+ )} +
+ +
+ {/* Left */} +
+

+ + Filter +

+
+
+
+ + setSearchTitle(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + id="search" + placeholder={t("searchTitle", { defaultValue: "Search Title" })} + className="mt-1 w-full text-sm border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" + /> +
+ +
+ + setMonthYearFilter(date)} + dateFormat="MM | yyyy" + placeholderText={t("selectYear", { + defaultValue: "Select Year", + })} + showMonthYearPicker + /> +
+ +
+ +
+ { + setDateRange(update); + }} + placeholderText={t("searchDate", { + defaultValue: "Search Date", + })} + onCalendarClose={() => setCalenderState(!calenderState)} + /> +
+ {handleClose ? ( + + ) : ( + "" + )} +
+
+
+ +
+

+ {t("categories", { defaultValue: "Categories" })} +

+ +
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
+ + {/* ⬇️ Pagination kategori (rata sejajar) */} +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+
+ + {/*
+

+ {t("categories", { defaultValue: "Categories" })} +

+
    + {categories?.map((category: any) => ( +
  • + +
  • + ))} +
    + + + {Array.from({ length: categoryTotalPages }, (_, i) => ( + + ))} + + +
    +
+
*/} + {/* Garis */} +
+ {/* Garis */} +
+

+ Format +

+
    +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+ + {/* CONTENT */} +
+ +
+

Sort By

+ +
+ + {isLoading ? ( +
+ + +
+ ) : audioData?.length > 0 ? ( +
+ {audioData?.map((audio: any) => ( + + + + // router.push(prefixPath + `/document/detail/${text?.slug}`) + // } + className="cursor-pointer rounded-lg shadow-md overflow-hidden bg-white dark:bg-black dark:border dark:border-gray-500" + > + {/* Ikon di tengah dengan latar kuning */} +
+ + + {" "} +
+ + {/* Konten bawah */} +
+ {/* Kategori merah */} +
+ {audio?.categoryName?.toUpperCase() ?? "Text"} +
+ + {/* Judul */} +
+ {audio?.title} +
+
+ +
+
+ ))} +
+ ) : ( +
+ empty +
+ )} + + {totalPage > 1 && ( + + )} +
+
+
+
+ ); +} + +// import AllContentPage from "@/components/landing-page/all-content-page"; + +// const regions = [ +// { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, +// { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, +// { +// name: "Polda Bangka Belitung", +// slug: "bangka-belitung", +// logo: "/logo/polda/polda-bangka-belitung.png", +// }, +// { +// name: "Polda Banten", +// slug: "banten", +// logo: "/logo/polda/polda-banten.png", +// }, +// { +// name: "Polda Bengkulu", +// slug: "bengkulu", +// logo: "/logo/polda/polda-bengkulu.png", +// }, +// { +// name: "Polda DIY", +// slug: "jogja", +// logo: "/logo/polda/polda-jogja.png", +// }, +// { +// name: "Polda Gorontalo", +// slug: "gorontalo", +// logo: "/logo/polda/polda-gorontalo.png", +// }, +// { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, +// { +// name: "Polda Jawa Barat", +// slug: "jawa-barat", +// logo: "/logo/polda/polda-jawa-barat.png", +// }, +// { +// name: "Polda Jawa Tengah", +// slug: "jawa-tengah", +// logo: "/logo/polda/polda-jawa-tengah.png", +// }, +// { +// name: "Polda Jawa Timur", +// slug: "jawa-timur", +// logo: "/logo/polda/polda-jawa-timur.png", +// }, +// { +// name: "Polda Kalimantan Barat", +// slug: "kalimantan-barat", +// logo: "/logo/polda/polda-kalimantan-barat.png", +// }, +// { +// name: "Polda Kalimantan Selatan", +// slug: "kalimantan-selatan", +// logo: "/logo/polda/polda-kalimantan-selatan.png", +// }, +// { +// name: "Polda Kalimantan Tengah", +// slug: "kalimantan-tengah", +// logo: "/logo/polda/polda-kalimantan-tengah.png", +// }, +// { +// name: "Polda Kalimantan Timur", +// slug: "kalimantan-timur", +// logo: "/logo/polda/polda-kalimantan-timur.png", +// }, +// { +// name: "Polda Kalimantan Utara", +// slug: "kalimantan-utara", +// logo: "/logo/polda/polda-kalimantan-utara.png", +// }, +// { +// name: "Polda Kepulauan Riau", +// slug: "kepulauan-riau", +// logo: "/logo/polda/polda-kepulauan-riau.png", +// }, +// { +// name: "Polda Lampung", +// slug: "lampung", +// logo: "/logo/polda/polda-lampung.png", +// }, +// { +// name: "Polda Maluku", +// slug: "maluku", +// logo: "/logo/polda/polda-maluku.png", +// }, +// { +// name: "Polda Maluku Utara", +// slug: "maluku-utara", +// logo: "/logo/polda/polda-maluku-utara.png", +// }, +// { +// name: "Polda Metro Jaya", +// slug: "metro-jaya", +// logo: "/logo/polda/polda-metro-jaya.png", +// }, +// { +// name: "Polda NTB", +// slug: "ntb", +// logo: "/logo/polda/polda-ntb.png", +// }, +// { +// name: "Polda NTT", +// slug: "ntt", +// logo: "/logo/polda/polda-ntt.png", +// }, +// { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, +// { +// name: "Polda Papua Barat", +// slug: "papua-barat", +// logo: "/logo/polda/polda-papua-barat.png", +// }, +// { +// name: "Polda Papua Barat Daya", +// slug: "papua-barat-daya", +// logo: "/logo/polda/polda-papua-barat-daya.png", +// }, +// { +// name: "Polda Papua Tengah", +// slug: "papua-tengah", +// logo: "/logo/polda/polda-papua-tengah.png", +// }, +// { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, +// { +// name: "Polda Sulawesi Barat", +// slug: "sulawesi-barat", +// logo: "/logo/polda/polda-sulawesi-barat.png", +// }, +// { +// name: "Polda Sulawesi Selatan", +// slug: "sulawesi-selatan", +// logo: "/logo/polda/polda-sulawesi-selatan.png", +// }, +// { +// name: "Polda Sulawesi Tengah", +// slug: "sulawesi-tengah", +// logo: "/logo/polda/polda-sulawesi-tengah.png", +// }, +// { +// name: "Polda Sulawesi Tenggara", +// slug: "sulawesi-tenggara", +// logo: "/logo/polda/polda-sulawesi-tenggara.png", +// }, +// { +// name: "Polda Sulawesi Utara", +// slug: "sulawesi-utara", +// logo: "/logo/polda/polda-sulawesi-utara.png", +// }, +// { +// name: "Polda Sumatera Barat", +// slug: "sumatera-barat", +// logo: "/logo/polda/polda-sumatera-barat.png", +// }, +// { +// name: "Polda Sumatera Selatan", +// slug: "sumatera-selatan", +// logo: "/logo/polda/polda-sumatera-selatan.png", +// }, +// { +// name: "Polda Sumatera Utara", +// slug: "sumatera-utara", +// logo: "/logo/polda/polda-sumatera-utara.png", +// }, +// // { +// // name: "Satuan Kerja POLRI", +// // slug: "satker-polri", +// // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", +// // }, +// // { +// // name: "Internasional", +// // slug: "internasional", +// // logo: "/assets/polda/internasional.png", +// // }, +// ]; + +// export default function PoldaAllAudioPage() { +// return ( +// +// ); +// } diff --git a/app/[locale]/(public)/regional/all-polda/document/all/page.tsx b/app/[locale]/(public)/regional/all-polda/document/all/page.tsx deleted file mode 100644 index a56e2e67..00000000 --- a/app/[locale]/(public)/regional/all-polda/document/all/page.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import AllContentPage from "@/components/landing-page/all-content-page"; - -const regions = [ - { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, - { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, - { - name: "Polda Bangka Belitung", - slug: "bangka-belitung", - logo: "/logo/polda/polda-bangka-belitung.png", - }, - { - name: "Polda Banten", - slug: "banten", - logo: "/logo/polda/polda-banten.png", - }, - { - name: "Polda Bengkulu", - slug: "bengkulu", - logo: "/logo/polda/polda-bengkulu.png", - }, - { - name: "Polda DIY", - slug: "jogja", - logo: "/logo/polda/polda-jogja.png", - }, - { - name: "Polda Gorontalo", - slug: "gorontalo", - logo: "/logo/polda/polda-gorontalo.png", - }, - { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, - { - name: "Polda Jawa Barat", - slug: "jawa-barat", - logo: "/logo/polda/polda-jawa-barat.png", - }, - { - name: "Polda Jawa Tengah", - slug: "jawa-tengah", - logo: "/logo/polda/polda-jawa-tengah.png", - }, - { - name: "Polda Jawa Timur", - slug: "jawa-timur", - logo: "/logo/polda/polda-jawa-timur.png", - }, - { - name: "Polda Kalimantan Barat", - slug: "kalimantan-barat", - logo: "/logo/polda/polda-kalimantan-barat.png", - }, - { - name: "Polda Kalimantan Selatan", - slug: "kalimantan-selatan", - logo: "/logo/polda/polda-kalimantan-selatan.png", - }, - { - name: "Polda Kalimantan Tengah", - slug: "kalimantan-tengah", - logo: "/logo/polda/polda-kalimantan-tengah.png", - }, - { - name: "Polda Kalimantan Timur", - slug: "kalimantan-timur", - logo: "/logo/polda/polda-kalimantan-timur.png", - }, - { - name: "Polda Kalimantan Utara", - slug: "kalimantan-utara", - logo: "/logo/polda/polda-kalimantan-utara.png", - }, - { - name: "Polda Kepulauan Riau", - slug: "kepulauan-riau", - logo: "/logo/polda/polda-kepulauan-riau.png", - }, - { - name: "Polda Lampung", - slug: "lampung", - logo: "/logo/polda/polda-lampung.png", - }, - { - name: "Polda Maluku", - slug: "maluku", - logo: "/logo/polda/polda-maluku.png", - }, - { - name: "Polda Maluku Utara", - slug: "maluku-utara", - logo: "/logo/polda/polda-maluku-utara.png", - }, - { - name: "Polda Metro Jaya", - slug: "metro-jaya", - logo: "/logo/polda/polda-metro-jaya.png", - }, - { - name: "Polda NTB", - slug: "ntb", - logo: "/logo/polda/polda-ntb.png", - }, - { - name: "Polda NTT", - slug: "ntt", - logo: "/logo/polda/polda-ntt.png", - }, - { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, - { - name: "Polda Papua Barat", - slug: "papua-barat", - logo: "/logo/polda/polda-papua-barat.png", - }, - { - name: "Polda Papua Barat Daya", - slug: "papua-barat-daya", - logo: "/logo/polda/polda-papua-barat-daya.png", - }, - { - name: "Polda Papua Tengah", - slug: "papua-tengah", - logo: "/logo/polda/polda-papua-tengah.png", - }, - { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, - { - name: "Polda Sulawesi Barat", - slug: "sulawesi-barat", - logo: "/logo/polda/polda-sulawesi-barat.png", - }, - { - name: "Polda Sulawesi Selatan", - slug: "sulawesi-selatan", - logo: "/logo/polda/polda-sulawesi-selatan.png", - }, - { - name: "Polda Sulawesi Tengah", - slug: "sulawesi-tengah", - logo: "/logo/polda/polda-sulawesi-tengah.png", - }, - { - name: "Polda Sulawesi Tenggara", - slug: "sulawesi-tenggara", - logo: "/logo/polda/polda-sulawesi-tenggara.png", - }, - { - name: "Polda Sulawesi Utara", - slug: "sulawesi-utara", - logo: "/logo/polda/polda-sulawesi-utara.png", - }, - { - name: "Polda Sumatera Barat", - slug: "sumatera-barat", - logo: "/logo/polda/polda-sumatera-barat.png", - }, - { - name: "Polda Sumatera Selatan", - slug: "sumatera-selatan", - logo: "/logo/polda/polda-sumatera-selatan.png", - }, - { - name: "Polda Sumatera Utara", - slug: "sumatera-utara", - logo: "/logo/polda/polda-sumatera-utara.png", - }, - // { - // name: "Satuan Kerja POLRI", - // slug: "satker-polri", - // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", - // }, - // { - // name: "Internasional", - // slug: "internasional", - // logo: "/assets/polda/internasional.png", - // }, -]; - -export default function PoldaAllDocumentPage() { - return ( - - ); -} diff --git a/app/[locale]/(public)/regional/all-polda/document/regional/page.tsx b/app/[locale]/(public)/regional/all-polda/document/regional/page.tsx new file mode 100644 index 00000000..aa7c7f47 --- /dev/null +++ b/app/[locale]/(public)/regional/all-polda/document/regional/page.tsx @@ -0,0 +1,988 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { + formatDateToIndonesian, + getOnlyDate, + getOnlyMonthAndYear, +} from "@/utils/globals"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; +import { + getPublicCategoryData, + getUserLevelListByParent, + listData, + listDataRegional, +} from "@/service/landing/landing"; +import { + ColumnDef, + ColumnFiltersState, + PaginationState, + SortingState, + VisibilityState, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from "@tanstack/react-table"; +import LandingPagination from "@/components/landing-page/pagination"; +import { Reveal } from "@/components/landing-page/Reveal"; +import { Link, useRouter } from "@/i18n/routing"; +import { Input } from "@/components/ui/input"; +import ReactDatePicker from "react-datepicker"; +import "react-datepicker/dist/react-datepicker.css"; +import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import ImageBlurry from "@/components/ui/image-blurry"; +import { Skeleton } from "@/components/ui/skeleton"; +import Image from "next/image"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => {row.getValue("no")}, + }, +]; + +export default function FilterPage() { + const router = useRouter(); + const asPath = usePathname(); + const params = useParams(); + const searchParams = useSearchParams(); + const locale = params?.locale; + const t = useTranslations("FilterPage"); + const [isLoading, setIsLoading] = useState(true); + const [documentData, setDocumentData] = useState([]); + const [totalData, setTotalData] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const [sorting, setSorting] = useState([]); + const [columnFilters, setColumnFilters] = useState([]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [page, setPage] = useState(1); + const [totalContent, setTotalContent] = useState(0); + const [change, setChange] = useState(false); + const sortBy = searchParams?.get("sortBy"); + const title = searchParams?.get("title"); + const categorie = searchParams?.get("category"); + const group = searchParams?.get("group"); + const [categoryFilter, setCategoryFilter] = useState([]); + const [monthYearFilter, setMonthYearFilter] = useState(); + const [searchTitle, setSearchTitle] = useState(""); + const [sortByOpt, setSortByOpt] = useState( + sortBy === "popular" ? "clickCount" : "createdAt" + ); + const [formatFilter, setFormatFilter] = useState([]); + const pages = page ? page - 1 : 0; + const [startDateString, setStartDateString] = useState(); + const [endDateString, setEndDateString] = useState(); + const [dateRange, setDateRange] = useState([null, null]); + const [handleClose, setHandleClose] = useState(false); + const [categories, setCategories] = useState([]); + const [isFilterOpen, setIsFilterOpen] = useState(true); + + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + + // === INIT === + useEffect(() => { + const timer = setTimeout(() => setIsLoading(false), 1200); + return () => clearTimeout(timer); + }, []); + + useEffect(() => { + const pageFromUrl = searchParams?.get("page"); + if (pageFromUrl) setPage(Number(pageFromUrl)); + }, [searchParams]); + + useEffect(() => { + if (categorie) { + setCategoryFilter( + categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie] + ); + } + }, [categorie]); + + useEffect(() => { + fetchCategories(categoryPage); + }, []); + + const fetchCategories = async (pageNumber: number) => { + const groupParam = + poldaName && poldaName.length > 1 + ? poldaName + : satkerName && satkerName.length > 1 + ? "satker-" + satkerName + : ""; + + const isInt = locale === "en"; + + const response = await getPublicCategoryData( + groupParam, + "", + isInt, + pageNumber + ); // halaman 1-based + + const content = response?.data?.data?.content || []; + const total = response?.data?.data?.totalPages || 1; + + setCategories(content); + setCategoryTotalPages(total); + }; + + useEffect(() => { + if (asPath?.includes("/regional")) getDataRegional(); + else getDataAll(); + }, [ + asPath, + monthYearFilter, + page, + sortBy, + sortByOpt, + title, + startDateString, + endDateString, + categorie, + formatFilter, + ]); + + async function getDataAll() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listData( + "3", + name, + filter, + 12, + pages, + sortByOpt, + format, + "", + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + locale == "en" ? true : false + ); + close(); + + const data = response?.data?.data; + setDocumentData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + async function getDataRegional() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listDataRegional( + "3", + name, + filter, + format, + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + 12, + pages, + sortByOpt + ); + close(); + + const data = response?.data?.data; + setDocumentData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + const handleCategoryFilter = (e: boolean, id: string) => { + let filter = [...categoryFilter]; + if (e) filter.push(String(id)); + else filter = filter.filter((item) => item !== String(id)); + router.push(`?category=${filter.join("&")}`); + }; + + const handleFormatFilter = (e: boolean, id: string) => { + let filter = [...formatFilter]; + if (e) filter.push(id); + else filter = filter.filter((item) => item !== id); + setFormatFilter(filter); + }; + + const handleSorting = (e: any) => { + const value = e.target.value; + setSortByOpt(value === "latest" ? "createdAt" : "clickCount"); + }; + + const handleDeleteDate = () => { + setDateRange([null, null]); + setStartDateString(""); + setEndDateString(""); + setHandleClose(false); + }; + + const handleKeyUp = () => { + if (!searchTitle) router.push("?title="); + else router.push(`?title=${searchTitle.toLowerCase()}`); + }; + + // === REACT TABLE === + const table = useReactTable({ + data: documentData, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + onRowSelectionChange: setRowSelection, + onPaginationChange: setPagination, + state: { + sorting, + columnFilters, + columnVisibility, + rowSelection, + pagination, + }, + }); + + const [calenderState, setCalenderState] = useState(false); + const [categoryPage, setCategoryPage] = useState(1); + const [categoryTotalPages, setCategoryTotalPages] = useState(1); + let typingTimer: any; + + const cleanCheckbox = () => { + setCategoryFilter([]); + setFormatFilter([]); + router.push(`?category=&title=`); + setDateRange([null, null]); + setMonthYearFilter(null); + setChange(!change); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + return ( +
+ {/* Header */} +
+

+ {" "} + {t("text", { defaultValue: "Text" })} {">"}{" "} + + {t("allText", { defaultValue: "All Text" })} + +

+

|

+ {!title ? ( +

+ {`${t("thereIs", { defaultValue: "Terdapat" })} ${totalContent} ${t( + "downloadableImage", + { defaultValue: "artikel berisi Foto yang dapat diunduh" } + )}`} +

+ ) : ( +

+ {t("search-results", { defaultValue: "Hasil pencarian untuk" })}{" "} + "{title}" +

+ )} +
+ +
+ {/* Left */} +
+

+ + Filter +

+
+
+
+ + setSearchTitle(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + id="search" + placeholder={t("searchTitle", { defaultValue: "Search Title" })} + className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" + /> +
+ +
+ + setMonthYearFilter(date)} + dateFormat="MM | yyyy" + placeholderText={t("selectYear", { + defaultValue: "Select Year", + })} + showMonthYearPicker + /> +
+ +
+ +
+ { + setDateRange(update); + }} + placeholderText={t("selectDate", { + defaultValue: "Select Date", + })} + onCalendarClose={() => setCalenderState(!calenderState)} + /> +
+ {handleClose ? ( + + ) : ( + "" + )} +
+
+
+ +
+

+ {t("categories", { defaultValue: "Categories" })} +

+ +
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
+ + {/* ⬇️ Pagination kategori (rata sejajar) */} +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+
+ + {/*
+

+ {t("categories", { defaultValue: "Categories" })} +

+
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
    + + + {Array.from({ length: categoryTotalPages }, (_, i) => ( + + ))} + + +
    +
+
*/} + {/* Garis */} +
+ {/* Garis */} +
+

+ Format +

+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+ + {/* RIGHT */} +
+ +
+

Sort By

+ +
+ + {isLoading ? ( +
+ + +
+ ) : documentData?.length > 0 ? ( +
+ {documentData?.map((document: any) => ( + + + + // router.push(prefixPath + `/document/detail/${text?.slug}`) + // } + className="cursor-pointer rounded-lg shadow-md overflow-hidden bg-white dark:bg-black dark:border dark:border-gray-500" + > + {/* Ikon di tengah dengan latar kuning */} +
+ + + +
+ + {/* Konten bawah */} +
+ {/* Kategori merah */} +
+ {document?.categoryName?.toUpperCase() ?? "Text"} +
+ + {/* Judul */} +
+ {document?.title} +
+
+ +
+
+ ))} +
+ ) : ( +
+ empty +
+ )} + + {totalPage > 1 && ( + + )} +
+
+
+
+ ); +} + +// import AllContentPage from "@/components/landing-page/all-content-page"; + +// const regions = [ +// { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, +// { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, +// { +// name: "Polda Bangka Belitung", +// slug: "bangka-belitung", +// logo: "/logo/polda/polda-bangka-belitung.png", +// }, +// { +// name: "Polda Banten", +// slug: "banten", +// logo: "/logo/polda/polda-banten.png", +// }, +// { +// name: "Polda Bengkulu", +// slug: "bengkulu", +// logo: "/logo/polda/polda-bengkulu.png", +// }, +// { +// name: "Polda DIY", +// slug: "jogja", +// logo: "/logo/polda/polda-jogja.png", +// }, +// { +// name: "Polda Gorontalo", +// slug: "gorontalo", +// logo: "/logo/polda/polda-gorontalo.png", +// }, +// { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, +// { +// name: "Polda Jawa Barat", +// slug: "jawa-barat", +// logo: "/logo/polda/polda-jawa-barat.png", +// }, +// { +// name: "Polda Jawa Tengah", +// slug: "jawa-tengah", +// logo: "/logo/polda/polda-jawa-tengah.png", +// }, +// { +// name: "Polda Jawa Timur", +// slug: "jawa-timur", +// logo: "/logo/polda/polda-jawa-timur.png", +// }, +// { +// name: "Polda Kalimantan Barat", +// slug: "kalimantan-barat", +// logo: "/logo/polda/polda-kalimantan-barat.png", +// }, +// { +// name: "Polda Kalimantan Selatan", +// slug: "kalimantan-selatan", +// logo: "/logo/polda/polda-kalimantan-selatan.png", +// }, +// { +// name: "Polda Kalimantan Tengah", +// slug: "kalimantan-tengah", +// logo: "/logo/polda/polda-kalimantan-tengah.png", +// }, +// { +// name: "Polda Kalimantan Timur", +// slug: "kalimantan-timur", +// logo: "/logo/polda/polda-kalimantan-timur.png", +// }, +// { +// name: "Polda Kalimantan Utara", +// slug: "kalimantan-utara", +// logo: "/logo/polda/polda-kalimantan-utara.png", +// }, +// { +// name: "Polda Kepulauan Riau", +// slug: "kepulauan-riau", +// logo: "/logo/polda/polda-kepulauan-riau.png", +// }, +// { +// name: "Polda Lampung", +// slug: "lampung", +// logo: "/logo/polda/polda-lampung.png", +// }, +// { +// name: "Polda Maluku", +// slug: "maluku", +// logo: "/logo/polda/polda-maluku.png", +// }, +// { +// name: "Polda Maluku Utara", +// slug: "maluku-utara", +// logo: "/logo/polda/polda-maluku-utara.png", +// }, +// { +// name: "Polda Metro Jaya", +// slug: "metro-jaya", +// logo: "/logo/polda/polda-metro-jaya.png", +// }, +// { +// name: "Polda NTB", +// slug: "ntb", +// logo: "/logo/polda/polda-ntb.png", +// }, +// { +// name: "Polda NTT", +// slug: "ntt", +// logo: "/logo/polda/polda-ntt.png", +// }, +// { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, +// { +// name: "Polda Papua Barat", +// slug: "papua-barat", +// logo: "/logo/polda/polda-papua-barat.png", +// }, +// { +// name: "Polda Papua Barat Daya", +// slug: "papua-barat-daya", +// logo: "/logo/polda/polda-papua-barat-daya.png", +// }, +// { +// name: "Polda Papua Tengah", +// slug: "papua-tengah", +// logo: "/logo/polda/polda-papua-tengah.png", +// }, +// { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, +// { +// name: "Polda Sulawesi Barat", +// slug: "sulawesi-barat", +// logo: "/logo/polda/polda-sulawesi-barat.png", +// }, +// { +// name: "Polda Sulawesi Selatan", +// slug: "sulawesi-selatan", +// logo: "/logo/polda/polda-sulawesi-selatan.png", +// }, +// { +// name: "Polda Sulawesi Tengah", +// slug: "sulawesi-tengah", +// logo: "/logo/polda/polda-sulawesi-tengah.png", +// }, +// { +// name: "Polda Sulawesi Tenggara", +// slug: "sulawesi-tenggara", +// logo: "/logo/polda/polda-sulawesi-tenggara.png", +// }, +// { +// name: "Polda Sulawesi Utara", +// slug: "sulawesi-utara", +// logo: "/logo/polda/polda-sulawesi-utara.png", +// }, +// { +// name: "Polda Sumatera Barat", +// slug: "sumatera-barat", +// logo: "/logo/polda/polda-sumatera-barat.png", +// }, +// { +// name: "Polda Sumatera Selatan", +// slug: "sumatera-selatan", +// logo: "/logo/polda/polda-sumatera-selatan.png", +// }, +// { +// name: "Polda Sumatera Utara", +// slug: "sumatera-utara", +// logo: "/logo/polda/polda-sumatera-utara.png", +// }, +// // { +// // name: "Satuan Kerja POLRI", +// // slug: "satker-polri", +// // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", +// // }, +// // { +// // name: "Internasional", +// // slug: "internasional", +// // logo: "/assets/polda/internasional.png", +// // }, +// ]; + +// export default function PoldaAllDocumentPage() { +// return ( +// +// ); +// } diff --git a/app/[locale]/(public)/regional/all-polda/image/all/page.tsx b/app/[locale]/(public)/regional/all-polda/image/all/page.tsx deleted file mode 100644 index f00cceca..00000000 --- a/app/[locale]/(public)/regional/all-polda/image/all/page.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import AllContentPage from "@/components/landing-page/all-content-page"; - -const regions = [ - { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, - { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, - { - name: "Polda Bangka Belitung", - slug: "bangka-belitung", - logo: "/logo/polda/polda-bangka-belitung.png", - }, - { - name: "Polda Banten", - slug: "banten", - logo: "/logo/polda/polda-banten.png", - }, - { - name: "Polda Bengkulu", - slug: "bengkulu", - logo: "/logo/polda/polda-bengkulu.png", - }, - { - name: "Polda DIY", - slug: "jogja", - logo: "/logo/polda/polda-jogja.png", - }, - { - name: "Polda Gorontalo", - slug: "gorontalo", - logo: "/logo/polda/polda-gorontalo.png", - }, - { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, - { - name: "Polda Jawa Barat", - slug: "jawa-barat", - logo: "/logo/polda/polda-jawa-barat.png", - }, - { - name: "Polda Jawa Tengah", - slug: "jawa-tengah", - logo: "/logo/polda/polda-jawa-tengah.png", - }, - { - name: "Polda Jawa Timur", - slug: "jawa-timur", - logo: "/logo/polda/polda-jawa-timur.png", - }, - { - name: "Polda Kalimantan Barat", - slug: "kalimantan-barat", - logo: "/logo/polda/polda-kalimantan-barat.png", - }, - { - name: "Polda Kalimantan Selatan", - slug: "kalimantan-selatan", - logo: "/logo/polda/polda-kalimantan-selatan.png", - }, - { - name: "Polda Kalimantan Tengah", - slug: "kalimantan-tengah", - logo: "/logo/polda/polda-kalimantan-tengah.png", - }, - { - name: "Polda Kalimantan Timur", - slug: "kalimantan-timur", - logo: "/logo/polda/polda-kalimantan-timur.png", - }, - { - name: "Polda Kalimantan Utara", - slug: "kalimantan-utara", - logo: "/logo/polda/polda-kalimantan-utara.png", - }, - { - name: "Polda Kepulauan Riau", - slug: "kepulauan-riau", - logo: "/logo/polda/polda-kepulauan-riau.png", - }, - { - name: "Polda Lampung", - slug: "lampung", - logo: "/logo/polda/polda-lampung.png", - }, - { - name: "Polda Maluku", - slug: "maluku", - logo: "/logo/polda/polda-maluku.png", - }, - { - name: "Polda Maluku Utara", - slug: "maluku-utara", - logo: "/logo/polda/polda-maluku-utara.png", - }, - { - name: "Polda Metro Jaya", - slug: "metro-jaya", - logo: "/logo/polda/polda-metro-jaya.png", - }, - { - name: "Polda NTB", - slug: "ntb", - logo: "/logo/polda/polda-ntb.png", - }, - { - name: "Polda NTT", - slug: "ntt", - logo: "/logo/polda/polda-ntt.png", - }, - { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, - { - name: "Polda Papua Barat", - slug: "papua-barat", - logo: "/logo/polda/polda-papua-barat.png", - }, - { - name: "Polda Papua Barat Daya", - slug: "papua-barat-daya", - logo: "/logo/polda/polda-papua-barat-daya.png", - }, - { - name: "Polda Papua Tengah", - slug: "papua-tengah", - logo: "/logo/polda/polda-papua-tengah.png", - }, - { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, - { - name: "Polda Sulawesi Barat", - slug: "sulawesi-barat", - logo: "/logo/polda/polda-sulawesi-barat.png", - }, - { - name: "Polda Sulawesi Selatan", - slug: "sulawesi-selatan", - logo: "/logo/polda/polda-sulawesi-selatan.png", - }, - { - name: "Polda Sulawesi Tengah", - slug: "sulawesi-tengah", - logo: "/logo/polda/polda-sulawesi-tengah.png", - }, - { - name: "Polda Sulawesi Tenggara", - slug: "sulawesi-tenggara", - logo: "/logo/polda/polda-sulawesi-tenggara.png", - }, - { - name: "Polda Sulawesi Utara", - slug: "sulawesi-utara", - logo: "/logo/polda/polda-sulawesi-utara.png", - }, - { - name: "Polda Sumatera Barat", - slug: "sumatera-barat", - logo: "/logo/polda/polda-sumatera-barat.png", - }, - { - name: "Polda Sumatera Selatan", - slug: "sumatera-selatan", - logo: "/logo/polda/polda-sumatera-selatan.png", - }, - { - name: "Polda Sumatera Utara", - slug: "sumatera-utara", - logo: "/logo/polda/polda-sumatera-utara.png", - }, - // { - // name: "Satuan Kerja POLRI", - // slug: "satker-polri", - // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", - // }, - // { - // name: "Internasional", - // slug: "internasional", - // logo: "/assets/polda/internasional.png", - // }, -]; - -export default function PoldaAllImagePage() { - return ( - - ); -} diff --git a/app/[locale]/(public)/regional/all-polda/image/regional/page.tsx b/app/[locale]/(public)/regional/all-polda/image/regional/page.tsx new file mode 100644 index 00000000..d83a0de5 --- /dev/null +++ b/app/[locale]/(public)/regional/all-polda/image/regional/page.tsx @@ -0,0 +1,895 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { + formatDateToIndonesian, + getOnlyDate, + getOnlyMonthAndYear, +} from "@/utils/globals"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; +import { + getPublicCategoryData, + getUserLevelListByParent, + listData, + listDataRegional, +} from "@/service/landing/landing"; +import { + ColumnDef, + ColumnFiltersState, + PaginationState, + SortingState, + VisibilityState, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from "@tanstack/react-table"; +import LandingPagination from "@/components/landing-page/pagination"; +import { Reveal } from "@/components/landing-page/Reveal"; +import { Link, useRouter } from "@/i18n/routing"; +import { Input } from "@/components/ui/input"; +import ReactDatePicker from "react-datepicker"; +import "react-datepicker/dist/react-datepicker.css"; +import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import ImageBlurry from "@/components/ui/image-blurry"; +import { Skeleton } from "@/components/ui/skeleton"; +import Image from "next/image"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => {row.getValue("no")}, + }, +]; + +export default function FilterPage() { + const router = useRouter(); + const asPath = usePathname(); + const params = useParams(); + const searchParams = useSearchParams(); + const locale = params?.locale; + const t = useTranslations("FilterPage"); + + const [isLoading, setIsLoading] = useState(true); + const [imageData, setImageData] = useState([]); + const [totalData, setTotalData] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const [sorting, setSorting] = useState([]); + const [columnFilters, setColumnFilters] = useState([]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [page, setPage] = useState(1); + const [totalContent, setTotalContent] = useState(0); + const [change, setChange] = useState(false); + const sortBy = searchParams?.get("sortBy"); + const title = searchParams?.get("title"); + const categorie = searchParams?.get("category"); + const group = searchParams?.get("group"); + const [categoryFilter, setCategoryFilter] = useState([]); + const [monthYearFilter, setMonthYearFilter] = useState(); + const [searchTitle, setSearchTitle] = useState(""); + const [sortByOpt, setSortByOpt] = useState( + sortBy === "popular" ? "clickCount" : "createdAt" + ); + const [formatFilter, setFormatFilter] = useState([]); + const pages = page ? page - 1 : 0; + const [startDateString, setStartDateString] = useState(); + const [endDateString, setEndDateString] = useState(); + const [dateRange, setDateRange] = useState([null, null]); + const [handleClose, setHandleClose] = useState(false); + const [categories, setCategories] = useState([]); + const [isFilterOpen, setIsFilterOpen] = useState(true); + + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + + // === INIT === + useEffect(() => { + const timer = setTimeout(() => setIsLoading(false), 1200); + return () => clearTimeout(timer); + }, []); + + useEffect(() => { + const pageFromUrl = searchParams?.get("page"); + if (pageFromUrl) setPage(Number(pageFromUrl)); + }, [searchParams]); + + useEffect(() => { + if (categorie) { + setCategoryFilter( + categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie] + ); + } + }, [categorie]); + + useEffect(() => { + fetchCategories(categoryPage); + }, []); + + const fetchCategories = async (pageNumber: number) => { + const groupParam = + poldaName && poldaName.length > 1 + ? poldaName + : satkerName && satkerName.length > 1 + ? "satker-" + satkerName + : ""; + + const isInt = locale === "en"; + + const response = await getPublicCategoryData( + groupParam, + "", + isInt, + pageNumber + ); // halaman 1-based + + const content = response?.data?.data?.content || []; + const total = response?.data?.data?.totalPages || 1; + + setCategories(content); + setCategoryTotalPages(total); + }; + + // async function fetchCategories() { + // const response = await getPublicCategoryData("", "", locale === "en"); + // setCategories(response?.data?.data?.content || []); + // } + + useEffect(() => { + if (asPath?.includes("/regional")) getDataRegional(); + else getDataAll(); + }, [ + asPath, + monthYearFilter, + page, + sortBy, + sortByOpt, + title, + startDateString, + endDateString, + categorie, + formatFilter, + ]); + + async function getDataAll() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listData( + "1", + name, + filter, + 12, + pages, + sortByOpt, + format, + "", + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + locale == "en" ? true : false + ); + close(); + + const data = response?.data?.data; + setImageData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + async function getDataRegional() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listDataRegional( + "1", + name, + filter, + format, + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + 12, + pages, + sortByOpt + ); + close(); + + const data = response?.data?.data; + setImageData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + const handleCategoryFilter = (e: boolean, id: string) => { + let filter = [...categoryFilter]; + if (e) filter.push(String(id)); + else filter = filter.filter((item) => item !== String(id)); + router.push(`?category=${filter.join("&")}`); + }; + + const handleFormatFilter = (e: boolean, id: string) => { + let filter = [...formatFilter]; + if (e) filter.push(id); + else filter = filter.filter((item) => item !== id); + setFormatFilter(filter); + }; + + const handleSorting = (e: any) => { + const value = e.target.value; + setSortByOpt(value === "latest" ? "createdAt" : "clickCount"); + }; + + const handleDeleteDate = () => { + setDateRange([null, null]); + setStartDateString(""); + setEndDateString(""); + setHandleClose(false); + }; + + const handleKeyUp = () => { + if (!searchTitle) router.push("?title="); + else router.push(`?title=${searchTitle.toLowerCase()}`); + }; + + // === REACT TABLE === + const table = useReactTable({ + data: imageData, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + onRowSelectionChange: setRowSelection, + onPaginationChange: setPagination, + state: { + sorting, + columnFilters, + columnVisibility, + rowSelection, + pagination, + }, + }); + + const [calenderState, setCalenderState] = useState(false); + const [categoryPage, setCategoryPage] = useState(1); + const [categoryTotalPages, setCategoryTotalPages] = useState(1); + let typingTimer: any; + + const cleanCheckbox = () => { + setCategoryFilter([]); + setFormatFilter([]); + router.push(`?category=&title=`); + setDateRange([null, null]); + setMonthYearFilter(null); + setChange(!change); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + return ( +
+ {/* Header */} +
+

{t("image", { defaultValue: "Image" })}

{">"} +

+ + {t("allImage", { defaultValue: "All Image" })} + +

+

|

+ {!title ? ( +

+ {`${t("thereIs", { defaultValue: "Terdapat" })} ${totalContent} ${t( + "downloadableImage", + { defaultValue: "artikel berisi Foto yang dapat diunduh" } + )}`} +

+ ) : ( +

+ {t("search-results", { defaultValue: "Hasil pencarian untuk" })}{" "} + "{title}" +

+ )} +
+ +
+ {/* Left */} +
+ +
+ + {isFilterOpen && ( +
+

+ + Filter +

+
+
+
+ + setSearchTitle(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + id="search" + placeholder={t("searchTitle", { + defaultValue: "Search Title", + })} + className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" + /> +
+ +
+ + setMonthYearFilter(date)} + dateFormat="MM | yyyy" + placeholderText={t("selectYear", { + defaultValue: "Select Year", + })} + showMonthYearPicker + /> +
+ +
+ +
+ { + setDateRange(update); + }} + placeholderText={t("selectDate", { + defaultValue: "Select Date", + })} + onCalendarClose={() => setCalenderState(!calenderState)} + /> +
+ {handleClose ? ( + + ) : ( + "" + )} +
+
+
+ +
+

+ {t("categories", { defaultValue: "Categories" })} +

+ +
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
+ + {/* ⬇️ Pagination kategori (rata sejajar) */} +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+
+ + {/* Garis */} +
+ {/* Garis */} +
+

+ Format +

+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+ )} + + {/* CONTENT */} +
+ +
+

Sort By

+ +
+ + {isLoading ? ( +
+ + +
+ ) : imageData?.length > 0 ? ( +
+ {imageData.map((image: any) => ( + + + +
+ +
+
+
+

+ {image?.categoryName?.toUpperCase() ?? + "Giat Pimpinan"} +

+

+ {formatDateToIndonesian( + new Date(image?.createdAt) + )}{" "} + {image?.timezone ?? "WIB"} | + {" "} + {image.clickCount} +

+
+

+ {image?.title} +

+
+ +
+
+ ))} +
+ ) : ( +
+ empty +
+ )} + + {totalPage > 1 && ( + + )} +
+
+
+
+ ); +} + +// import AllContentPage from "@/components/landing-page/all-content-page"; + +// const regions = [ +// { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, +// { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, +// { +// name: "Polda Bangka Belitung", +// slug: "bangka-belitung", +// logo: "/logo/polda/polda-bangka-belitung.png", +// }, +// { +// name: "Polda Banten", +// slug: "banten", +// logo: "/logo/polda/polda-banten.png", +// }, +// { +// name: "Polda Bengkulu", +// slug: "bengkulu", +// logo: "/logo/polda/polda-bengkulu.png", +// }, +// { +// name: "Polda DIY", +// slug: "jogja", +// logo: "/logo/polda/polda-jogja.png", +// }, +// { +// name: "Polda Gorontalo", +// slug: "gorontalo", +// logo: "/logo/polda/polda-gorontalo.png", +// }, +// { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, +// { +// name: "Polda Jawa Barat", +// slug: "jawa-barat", +// logo: "/logo/polda/polda-jawa-barat.png", +// }, +// { +// name: "Polda Jawa Tengah", +// slug: "jawa-tengah", +// logo: "/logo/polda/polda-jawa-tengah.png", +// }, +// { +// name: "Polda Jawa Timur", +// slug: "jawa-timur", +// logo: "/logo/polda/polda-jawa-timur.png", +// }, +// { +// name: "Polda Kalimantan Barat", +// slug: "kalimantan-barat", +// logo: "/logo/polda/polda-kalimantan-barat.png", +// }, +// { +// name: "Polda Kalimantan Selatan", +// slug: "kalimantan-selatan", +// logo: "/logo/polda/polda-kalimantan-selatan.png", +// }, +// { +// name: "Polda Kalimantan Tengah", +// slug: "kalimantan-tengah", +// logo: "/logo/polda/polda-kalimantan-tengah.png", +// }, +// { +// name: "Polda Kalimantan Timur", +// slug: "kalimantan-timur", +// logo: "/logo/polda/polda-kalimantan-timur.png", +// }, +// { +// name: "Polda Kalimantan Utara", +// slug: "kalimantan-utara", +// logo: "/logo/polda/polda-kalimantan-utara.png", +// }, +// { +// name: "Polda Kepulauan Riau", +// slug: "kepulauan-riau", +// logo: "/logo/polda/polda-kepulauan-riau.png", +// }, +// { +// name: "Polda Lampung", +// slug: "lampung", +// logo: "/logo/polda/polda-lampung.png", +// }, +// { +// name: "Polda Maluku", +// slug: "maluku", +// logo: "/logo/polda/polda-maluku.png", +// }, +// { +// name: "Polda Maluku Utara", +// slug: "maluku-utara", +// logo: "/logo/polda/polda-maluku-utara.png", +// }, +// { +// name: "Polda Metro Jaya", +// slug: "metro-jaya", +// logo: "/logo/polda/polda-metro-jaya.png", +// }, +// { +// name: "Polda NTB", +// slug: "ntb", +// logo: "/logo/polda/polda-ntb.png", +// }, +// { +// name: "Polda NTT", +// slug: "ntt", +// logo: "/logo/polda/polda-ntt.png", +// }, +// { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, +// { +// name: "Polda Papua Barat", +// slug: "papua-barat", +// logo: "/logo/polda/polda-papua-barat.png", +// }, +// { +// name: "Polda Papua Barat Daya", +// slug: "papua-barat-daya", +// logo: "/logo/polda/polda-papua-barat-daya.png", +// }, +// { +// name: "Polda Papua Tengah", +// slug: "papua-tengah", +// logo: "/logo/polda/polda-papua-tengah.png", +// }, +// { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, +// { +// name: "Polda Sulawesi Barat", +// slug: "sulawesi-barat", +// logo: "/logo/polda/polda-sulawesi-barat.png", +// }, +// { +// name: "Polda Sulawesi Selatan", +// slug: "sulawesi-selatan", +// logo: "/logo/polda/polda-sulawesi-selatan.png", +// }, +// { +// name: "Polda Sulawesi Tengah", +// slug: "sulawesi-tengah", +// logo: "/logo/polda/polda-sulawesi-tengah.png", +// }, +// { +// name: "Polda Sulawesi Tenggara", +// slug: "sulawesi-tenggara", +// logo: "/logo/polda/polda-sulawesi-tenggara.png", +// }, +// { +// name: "Polda Sulawesi Utara", +// slug: "sulawesi-utara", +// logo: "/logo/polda/polda-sulawesi-utara.png", +// }, +// { +// name: "Polda Sumatera Barat", +// slug: "sumatera-barat", +// logo: "/logo/polda/polda-sumatera-barat.png", +// }, +// { +// name: "Polda Sumatera Selatan", +// slug: "sumatera-selatan", +// logo: "/logo/polda/polda-sumatera-selatan.png", +// }, +// { +// name: "Polda Sumatera Utara", +// slug: "sumatera-utara", +// logo: "/logo/polda/polda-sumatera-utara.png", +// }, +// // { +// // name: "Satuan Kerja POLRI", +// // slug: "satker-polri", +// // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", +// // }, +// // { +// // name: "Internasional", +// // slug: "internasional", +// // logo: "/assets/polda/internasional.png", +// // }, +// ]; + +// export default function PoldaAllImagePage() { +// return ( +// +// ); +// } diff --git a/app/[locale]/(public)/regional/all-polda/video/all/page.tsx b/app/[locale]/(public)/regional/all-polda/video/all/page.tsx deleted file mode 100644 index c39b75c7..00000000 --- a/app/[locale]/(public)/regional/all-polda/video/all/page.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import AllContentPage from "@/components/landing-page/all-content-page"; - -const regions = [ - { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, - { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, - { - name: "Polda Bangka Belitung", - slug: "bangka-belitung", - logo: "/logo/polda/polda-bangka-belitung.png", - }, - { - name: "Polda Banten", - slug: "banten", - logo: "/logo/polda/polda-banten.png", - }, - { - name: "Polda Bengkulu", - slug: "bengkulu", - logo: "/logo/polda/polda-bengkulu.png", - }, - { - name: "Polda DIY", - slug: "jogja", - logo: "/logo/polda/polda-jogja.png", - }, - { - name: "Polda Gorontalo", - slug: "gorontalo", - logo: "/logo/polda/polda-gorontalo.png", - }, - { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, - { - name: "Polda Jawa Barat", - slug: "jawa-barat", - logo: "/logo/polda/polda-jawa-barat.png", - }, - { - name: "Polda Jawa Tengah", - slug: "jawa-tengah", - logo: "/logo/polda/polda-jawa-tengah.png", - }, - { - name: "Polda Jawa Timur", - slug: "jawa-timur", - logo: "/logo/polda/polda-jawa-timur.png", - }, - { - name: "Polda Kalimantan Barat", - slug: "kalimantan-barat", - logo: "/logo/polda/polda-kalimantan-barat.png", - }, - { - name: "Polda Kalimantan Selatan", - slug: "kalimantan-selatan", - logo: "/logo/polda/polda-kalimantan-selatan.png", - }, - { - name: "Polda Kalimantan Tengah", - slug: "kalimantan-tengah", - logo: "/logo/polda/polda-kalimantan-tengah.png", - }, - { - name: "Polda Kalimantan Timur", - slug: "kalimantan-timur", - logo: "/logo/polda/polda-kalimantan-timur.png", - }, - { - name: "Polda Kalimantan Utara", - slug: "kalimantan-utara", - logo: "/logo/polda/polda-kalimantan-utara.png", - }, - { - name: "Polda Kepulauan Riau", - slug: "kepulauan-riau", - logo: "/logo/polda/polda-kepulauan-riau.png", - }, - { - name: "Polda Lampung", - slug: "lampung", - logo: "/logo/polda/polda-lampung.png", - }, - { - name: "Polda Maluku", - slug: "maluku", - logo: "/logo/polda/polda-maluku.png", - }, - { - name: "Polda Maluku Utara", - slug: "maluku-utara", - logo: "/logo/polda/polda-maluku-utara.png", - }, - { - name: "Polda Metro Jaya", - slug: "metro-jaya", - logo: "/logo/polda/polda-metro-jaya.png", - }, - { - name: "Polda NTB", - slug: "ntb", - logo: "/logo/polda/polda-ntb.png", - }, - { - name: "Polda NTT", - slug: "ntt", - logo: "/logo/polda/polda-ntt.png", - }, - { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, - { - name: "Polda Papua Barat", - slug: "papua-barat", - logo: "/logo/polda/polda-papua-barat.png", - }, - { - name: "Polda Papua Barat Daya", - slug: "papua-barat-daya", - logo: "/logo/polda/polda-papua-barat-daya.png", - }, - { - name: "Polda Papua Tengah", - slug: "papua-tengah", - logo: "/logo/polda/polda-papua-tengah.png", - }, - { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, - { - name: "Polda Sulawesi Barat", - slug: "sulawesi-barat", - logo: "/logo/polda/polda-sulawesi-barat.png", - }, - { - name: "Polda Sulawesi Selatan", - slug: "sulawesi-selatan", - logo: "/logo/polda/polda-sulawesi-selatan.png", - }, - { - name: "Polda Sulawesi Tengah", - slug: "sulawesi-tengah", - logo: "/logo/polda/polda-sulawesi-tengah.png", - }, - { - name: "Polda Sulawesi Tenggara", - slug: "sulawesi-tenggara", - logo: "/logo/polda/polda-sulawesi-tenggara.png", - }, - { - name: "Polda Sulawesi Utara", - slug: "sulawesi-utara", - logo: "/logo/polda/polda-sulawesi-utara.png", - }, - { - name: "Polda Sumatera Barat", - slug: "sumatera-barat", - logo: "/logo/polda/polda-sumatera-barat.png", - }, - { - name: "Polda Sumatera Selatan", - slug: "sumatera-selatan", - logo: "/logo/polda/polda-sumatera-selatan.png", - }, - { - name: "Polda Sumatera Utara", - slug: "sumatera-utara", - logo: "/logo/polda/polda-sumatera-utara.png", - }, - // { - // name: "Satuan Kerja POLRI", - // slug: "satker-polri", - // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", - // }, - // { - // name: "Internasional", - // slug: "internasional", - // logo: "/assets/polda/internasional.png", - // }, -]; - -export default function PoldaAllVideoPage() { - return ( - - ); -} diff --git a/app/[locale]/(public)/regional/all-polda/video/regional/page.tsx b/app/[locale]/(public)/regional/all-polda/video/regional/page.tsx new file mode 100644 index 00000000..1af0ecb0 --- /dev/null +++ b/app/[locale]/(public)/regional/all-polda/video/regional/page.tsx @@ -0,0 +1,987 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { + formatDateToIndonesian, + getOnlyDate, + getOnlyMonthAndYear, +} from "@/utils/globals"; +import { useParams, usePathname, useSearchParams } from "next/navigation"; +import { + getPublicCategoryData, + getUserLevelListByParent, + listData, + listDataRegional, +} from "@/service/landing/landing"; +import { + ColumnDef, + ColumnFiltersState, + PaginationState, + SortingState, + VisibilityState, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from "@tanstack/react-table"; +import LandingPagination from "@/components/landing-page/pagination"; +import { Reveal } from "@/components/landing-page/Reveal"; +import { Link, useRouter } from "@/i18n/routing"; +import { Input } from "@/components/ui/input"; +import ReactDatePicker from "react-datepicker"; +import "react-datepicker/dist/react-datepicker.css"; +import { close, loading } from "@/config/swal"; +import { useTranslations } from "next-intl"; +import ImageBlurry from "@/components/ui/image-blurry"; +import { Skeleton } from "@/components/ui/skeleton"; +import Image from "next/image"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "No", + cell: ({ row }) => {row.getValue("no")}, + }, +]; + +export default function FilterPage() { + const router = useRouter(); + const asPath = usePathname(); + const params = useParams(); + const searchParams = useSearchParams(); + const locale = params?.locale; + const t = useTranslations("FilterPage"); + const [isLoading, setIsLoading] = useState(true); + const [videoData, setVideoData] = useState([]); + const [totalData, setTotalData] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const [sorting, setSorting] = useState([]); + const [columnFilters, setColumnFilters] = useState([]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [page, setPage] = useState(1); + const [totalContent, setTotalContent] = useState(0); + const [change, setChange] = useState(false); + const sortBy = searchParams?.get("sortBy"); + const title = searchParams?.get("title"); + const categorie = searchParams?.get("category"); + const group = searchParams?.get("group"); + const [categoryFilter, setCategoryFilter] = useState([]); + const [monthYearFilter, setMonthYearFilter] = useState(); + const [searchTitle, setSearchTitle] = useState(""); + const [sortByOpt, setSortByOpt] = useState( + sortBy === "popular" ? "clickCount" : "createdAt" + ); + const [formatFilter, setFormatFilter] = useState([]); + const pages = page ? page - 1 : 0; + const [startDateString, setStartDateString] = useState(); + const [endDateString, setEndDateString] = useState(); + const [dateRange, setDateRange] = useState([null, null]); + const [handleClose, setHandleClose] = useState(false); + const [categories, setCategories] = useState([]); + const [isFilterOpen, setIsFilterOpen] = useState(true); + + const poldaName = params?.polda_name; + const satkerName = params?.satker_name; + + let prefixPath = poldaName + ? `/polda/${poldaName}` + : satkerName + ? `/satker/${satkerName}` + : ""; + + // === INIT === + useEffect(() => { + const timer = setTimeout(() => setIsLoading(false), 1200); + return () => clearTimeout(timer); + }, []); + + useEffect(() => { + const pageFromUrl = searchParams?.get("page"); + if (pageFromUrl) setPage(Number(pageFromUrl)); + }, [searchParams]); + + useEffect(() => { + if (categorie) { + setCategoryFilter( + categorie?.split("&")?.length > 1 ? categorie?.split("&") : [categorie] + ); + } + }, [categorie]); + + useEffect(() => { + fetchCategories(categoryPage); + }, []); + + const fetchCategories = async (pageNumber: number) => { + const groupParam = + poldaName && poldaName.length > 1 + ? poldaName + : satkerName && satkerName.length > 1 + ? "satker-" + satkerName + : ""; + + const isInt = locale === "en"; + + const response = await getPublicCategoryData( + groupParam, + "", + isInt, + pageNumber + ); // halaman 1-based + + const content = response?.data?.data?.content || []; + const total = response?.data?.data?.totalPages || 1; + + setCategories(content); + setCategoryTotalPages(total); + }; + + useEffect(() => { + if (asPath?.includes("/regional")) getDataRegional(); + else getDataAll(); + }, [ + asPath, + monthYearFilter, + page, + sortBy, + sortByOpt, + title, + startDateString, + endDateString, + categorie, + formatFilter, + ]); + + async function getDataAll() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listData( + "2", + name, + filter, + 12, + pages, + sortByOpt, + format, + "", + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + locale == "en" ? true : false + ); + close(); + + const data = response?.data?.data; + setVideoData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + async function getDataRegional() { + const filter = + categoryFilter?.length > 0 + ? categoryFilter?.sort().join(",") + : categorie || ""; + + const name = title || ""; + const format = formatFilter?.length > 0 ? formatFilter.join(",") : ""; + + loading(); + const response = await listDataRegional( + "2", + name, + filter, + format, + "", + startDateString, + endDateString, + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[0]?.replace("", "") + : "", + monthYearFilter + ? getOnlyMonthAndYear(monthYearFilter)?.split("/")[1] + : "", + 12, + pages, + sortByOpt + ); + close(); + + const data = response?.data?.data; + setVideoData(data?.content || []); + setTotalData(data?.totalElements || 0); + setTotalPage(data?.totalPages || 1); + setTotalContent(data?.totalElements || 0); + } + + const handleCategoryFilter = (e: boolean, id: string) => { + let filter = [...categoryFilter]; + if (e) filter.push(String(id)); + else filter = filter.filter((item) => item !== String(id)); + router.push(`?category=${filter.join("&")}`); + }; + + const handleFormatFilter = (e: boolean, id: string) => { + let filter = [...formatFilter]; + if (e) filter.push(id); + else filter = filter.filter((item) => item !== id); + setFormatFilter(filter); + }; + + const handleSorting = (e: any) => { + const value = e.target.value; + setSortByOpt(value === "latest" ? "createdAt" : "clickCount"); + }; + + const handleDeleteDate = () => { + setDateRange([null, null]); + setStartDateString(""); + setEndDateString(""); + setHandleClose(false); + }; + + const handleKeyUp = () => { + if (!searchTitle) router.push("?title="); + else router.push(`?title=${searchTitle.toLowerCase()}`); + }; + + // === REACT TABLE === + const table = useReactTable({ + data: videoData, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + onRowSelectionChange: setRowSelection, + onPaginationChange: setPagination, + state: { + sorting, + columnFilters, + columnVisibility, + rowSelection, + pagination, + }, + }); + + const [calenderState, setCalenderState] = useState(false); + const [categoryPage, setCategoryPage] = useState(1); + const [categoryTotalPages, setCategoryTotalPages] = useState(1); + let typingTimer: any; + + const cleanCheckbox = () => { + setCategoryFilter([]); + setFormatFilter([]); + router.push(`?category=&title=`); + setDateRange([null, null]); + setMonthYearFilter(null); + setChange(!change); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + return ( +
+ {/* Header */} +
+

{t("video", { defaultValue: "Video" })}

{">"} +

+ + {t("allVideo", { defaultValue: "All Video" })} + +

+

|

+ {!title ? ( +

+ {`${t("thereIs", { defaultValue: "Terdapat" })} ${totalContent} ${t( + "downloadablevideo", + { defaultValue: "artikel berisi Foto yang dapat diunduh" } + )}`} +

+ ) : ( +

+ {t("search-results", { defaultValue: "Hasil pencarian untuk" })}{" "} + "{title}" +

+ )} +
+ +
+
+

+ + Filter +

+
+
+
+ + setSearchTitle(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} + type="text" + id="search" + placeholder={t("searchTitle", { defaultValue: "Search Title" })} + className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" + /> +
+ +
+ + setMonthYearFilter(date)} + dateFormat="MM | yyyy" + placeholderText={t("selectYear", { + defaultValue: "Select Year", + })} + showMonthYearPicker + /> +
+ +
+ +
+ { + setDateRange(update); + }} + placeholderText={t("selectDate", { + defaultValue: "Select Date", + })} + onCalendarClose={() => setCalenderState(!calenderState)} + /> +
+ {handleClose ? ( + + ) : ( + "" + )} +
+
+
+ +
+

+ {t("categories", { defaultValue: "Categories" })} +

+ +
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
+ + {/* ⬇️ Pagination kategori (rata sejajar) */} +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+
+ + {/*
+

+ {t("categories", { defaultValue: "Categories" })} +

+
    + {categories.map((category: any) => ( +
  • + +
  • + ))} +
    + + + {Array.from({ length: categoryTotalPages }, (_, i) => ( + + ))} + + +
    +
+
*/} + {/* Garis */} +
+ {/* Garis */} +
+

+ Format +

+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+ + {/* CONTENT */} +
+ +
+

Sort By

+ +
+ + {isLoading ? ( +
+ + +
+ ) : videoData?.length > 0 ? ( +
+ {videoData.map((video: any) => ( + + + +
+ +
+
+
+

+ {video?.categoryName?.toUpperCase() ?? + "Giat Pimpinan"} +

+

+ {formatDateToIndonesian( + new Date(video?.createdAt) + )}{" "} + {video?.timezone ?? "WIB"} | + {" "} + {video.clickCount} +

+
+

+ {video?.title} +

+
+ +
+
+ ))} +
+ ) : ( +
+ empty +
+ )} + + {totalPage > 1 && ( + + )} +
+
+
+
+ ); +} + +// import AllContentPage from "@/components/landing-page/all-content-page"; + +// const regions = [ +// { name: "Polda Aceh", slug: "aceh", logo: "/logo/polda/polda-aceh.png" }, +// { name: "Polda Bali", slug: "bali", logo: "/logo/polda/polda-bali.png" }, +// { +// name: "Polda Bangka Belitung", +// slug: "bangka-belitung", +// logo: "/logo/polda/polda-bangka-belitung.png", +// }, +// { +// name: "Polda Banten", +// slug: "banten", +// logo: "/logo/polda/polda-banten.png", +// }, +// { +// name: "Polda Bengkulu", +// slug: "bengkulu", +// logo: "/logo/polda/polda-bengkulu.png", +// }, +// { +// name: "Polda DIY", +// slug: "jogja", +// logo: "/logo/polda/polda-jogja.png", +// }, +// { +// name: "Polda Gorontalo", +// slug: "gorontalo", +// logo: "/logo/polda/polda-gorontalo.png", +// }, +// { name: "Polda Jambi", slug: "jambi", logo: "/logo/polda/polda-jambi.png" }, +// { +// name: "Polda Jawa Barat", +// slug: "jawa-barat", +// logo: "/logo/polda/polda-jawa-barat.png", +// }, +// { +// name: "Polda Jawa Tengah", +// slug: "jawa-tengah", +// logo: "/logo/polda/polda-jawa-tengah.png", +// }, +// { +// name: "Polda Jawa Timur", +// slug: "jawa-timur", +// logo: "/logo/polda/polda-jawa-timur.png", +// }, +// { +// name: "Polda Kalimantan Barat", +// slug: "kalimantan-barat", +// logo: "/logo/polda/polda-kalimantan-barat.png", +// }, +// { +// name: "Polda Kalimantan Selatan", +// slug: "kalimantan-selatan", +// logo: "/logo/polda/polda-kalimantan-selatan.png", +// }, +// { +// name: "Polda Kalimantan Tengah", +// slug: "kalimantan-tengah", +// logo: "/logo/polda/polda-kalimantan-tengah.png", +// }, +// { +// name: "Polda Kalimantan Timur", +// slug: "kalimantan-timur", +// logo: "/logo/polda/polda-kalimantan-timur.png", +// }, +// { +// name: "Polda Kalimantan Utara", +// slug: "kalimantan-utara", +// logo: "/logo/polda/polda-kalimantan-utara.png", +// }, +// { +// name: "Polda Kepulauan Riau", +// slug: "kepulauan-riau", +// logo: "/logo/polda/polda-kepulauan-riau.png", +// }, +// { +// name: "Polda Lampung", +// slug: "lampung", +// logo: "/logo/polda/polda-lampung.png", +// }, +// { +// name: "Polda Maluku", +// slug: "maluku", +// logo: "/logo/polda/polda-maluku.png", +// }, +// { +// name: "Polda Maluku Utara", +// slug: "maluku-utara", +// logo: "/logo/polda/polda-maluku-utara.png", +// }, +// { +// name: "Polda Metro Jaya", +// slug: "metro-jaya", +// logo: "/logo/polda/polda-metro-jaya.png", +// }, +// { +// name: "Polda NTB", +// slug: "ntb", +// logo: "/logo/polda/polda-ntb.png", +// }, +// { +// name: "Polda NTT", +// slug: "ntt", +// logo: "/logo/polda/polda-ntt.png", +// }, +// { name: "Polda Papua", slug: "papua", logo: "/logo/polda/polda-papua.png" }, +// { +// name: "Polda Papua Barat", +// slug: "papua-barat", +// logo: "/logo/polda/polda-papua-barat.png", +// }, +// { +// name: "Polda Papua Barat Daya", +// slug: "papua-barat-daya", +// logo: "/logo/polda/polda-papua-barat-daya.png", +// }, +// { +// name: "Polda Papua Tengah", +// slug: "papua-tengah", +// logo: "/logo/polda/polda-papua-tengah.png", +// }, +// { name: "Polda Riau", slug: "riau", logo: "/logo/polda/polda-riau.png" }, +// { +// name: "Polda Sulawesi Barat", +// slug: "sulawesi-barat", +// logo: "/logo/polda/polda-sulawesi-barat.png", +// }, +// { +// name: "Polda Sulawesi Selatan", +// slug: "sulawesi-selatan", +// logo: "/logo/polda/polda-sulawesi-selatan.png", +// }, +// { +// name: "Polda Sulawesi Tengah", +// slug: "sulawesi-tengah", +// logo: "/logo/polda/polda-sulawesi-tengah.png", +// }, +// { +// name: "Polda Sulawesi Tenggara", +// slug: "sulawesi-tenggara", +// logo: "/logo/polda/polda-sulawesi-tenggara.png", +// }, +// { +// name: "Polda Sulawesi Utara", +// slug: "sulawesi-utara", +// logo: "/logo/polda/polda-sulawesi-utara.png", +// }, +// { +// name: "Polda Sumatera Barat", +// slug: "sumatera-barat", +// logo: "/logo/polda/polda-sumatera-barat.png", +// }, +// { +// name: "Polda Sumatera Selatan", +// slug: "sumatera-selatan", +// logo: "/logo/polda/polda-sumatera-selatan.png", +// }, +// { +// name: "Polda Sumatera Utara", +// slug: "sumatera-utara", +// logo: "/logo/polda/polda-sumatera-utara.png", +// }, +// // { +// // name: "Satuan Kerja POLRI", +// // slug: "satker-polri", +// // logo: "/logo/satker/SATUAN-KERJA-POLRI.png", +// // }, +// // { +// // name: "Internasional", +// // slug: "internasional", +// // logo: "/assets/polda/internasional.png", +// // }, +// ]; + +// export default function PoldaAllVideoPage() { +// return ( +// +// ); +// } diff --git a/app/[locale]/(public)/regional/filter/page.tsx b/app/[locale]/(public)/regional/filter/page.tsx index 5256c00b..9301ee6d 100644 --- a/app/[locale]/(public)/regional/filter/page.tsx +++ b/app/[locale]/(public)/regional/filter/page.tsx @@ -559,7 +559,88 @@ export default function FilterPage() { ))} -
+ +
+ {/* Tombol Prev */} + + + {(() => { + const maxVisible = 4; + let startPage = Math.max( + 1, + Math.min( + categoryPage - Math.floor(maxVisible / 2), + categoryTotalPages - maxVisible + 1 + ) + ); + const endPage = Math.min( + categoryTotalPages, + startPage + maxVisible - 1 + ); + + const visiblePages = []; + for (let i = startPage; i <= endPage; i++) { + visiblePages.push(i); + } + + return visiblePages.map((pageNum) => ( + + )); + })()} + + {/* Tombol Next */} + +
+ + {/*
-
+
*/}

{/* Garis */}
{/* Garis */} -
+ {/*

Format

@@ -672,8 +753,8 @@ export default function FilterPage() { -
-
+
*/} + {/*
*/} ) : ( diff --git a/components/landing-page/filter-all/document-filter-card.tsx b/components/landing-page/filter-all/document-filter-card.tsx index 44898b75..69630cfc 100644 --- a/components/landing-page/filter-all/document-filter-card.tsx +++ b/components/landing-page/filter-all/document-filter-card.tsx @@ -278,6 +278,34 @@ export default function FilterDocumentComponent(props: {
+ Lihat Semua + + {/* Lihat Semua - + */}
) : ( diff --git a/components/landing-page/filter-all/image-filter-card.tsx b/components/landing-page/filter-all/image-filter-card.tsx index 9a097743..2ce7cfa6 100644 --- a/components/landing-page/filter-all/image-filter-card.tsx +++ b/components/landing-page/filter-all/image-filter-card.tsx @@ -289,6 +289,35 @@ export default function FilterImageComponent(props: {
+ Lihat Semua + + + {/* Lihat Semua - + */}
) : ( diff --git a/components/landing-page/filter-all/video-filter-card.tsx b/components/landing-page/filter-all/video-filter-card.tsx index 794cfc44..0ff1eefa 100644 --- a/components/landing-page/filter-all/video-filter-card.tsx +++ b/components/landing-page/filter-all/video-filter-card.tsx @@ -258,6 +258,34 @@ export default function FilterVideoComponent(props: {
+ Lihat Semua + + {/* Lihat Semua - + */}

) : (