2025-01-13 00:35:40 +00:00
|
|
|
import { getCategoryData, getPublicCategoryData } from "@/service/landing/landing";
|
2024-12-04 14:12:10 +00:00
|
|
|
import Link from "next/link";
|
2024-12-09 16:09:42 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2024-12-13 14:33:59 +00:00
|
|
|
import { Button } from "../ui/button";
|
2024-12-17 14:27:48 +00:00
|
|
|
import { Reveal } from "./Reveal";
|
2025-01-05 13:46:18 +00:00
|
|
|
import { useTranslations } from "next-intl";
|
|
|
|
|
import { usePathname } from "next/navigation";
|
2025-01-13 00:35:40 +00:00
|
|
|
import { useParams } from "next/navigation";
|
2024-12-04 14:12:10 +00:00
|
|
|
|
2025-01-13 00:35:40 +00:00
|
|
|
const ContentCategory = (props: { group?: string }) => {
|
2024-12-09 16:09:42 +00:00
|
|
|
const [categories, setCategories] = useState<any>();
|
2025-01-05 13:46:18 +00:00
|
|
|
const t = useTranslations("LandingPage");
|
2025-01-13 00:35:40 +00:00
|
|
|
const params = useParams();
|
|
|
|
|
const locale = params?.locale;
|
|
|
|
|
const poldaName = params?.polda_name;
|
|
|
|
|
const satkerName = params?.satker_name;
|
2025-01-05 13:46:18 +00:00
|
|
|
|
2024-12-09 16:09:42 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
initFetch();
|
|
|
|
|
}, []);
|
|
|
|
|
const initFetch = async () => {
|
2025-01-13 00:35:40 +00:00
|
|
|
const response = await getPublicCategoryData(
|
2025-01-31 12:51:04 +00:00
|
|
|
props.group == "mabes" ? "" : props.group == "polda" && poldaName && String(poldaName)?.length > 1 ? poldaName : props.group == "satker" && satkerName && String(satkerName)?.length > 1 ? "satker-" + satkerName : "",
|
2025-01-13 00:35:40 +00:00
|
|
|
"",
|
|
|
|
|
locale == "en" ? true : false
|
|
|
|
|
);
|
2024-12-10 13:51:14 +00:00
|
|
|
console.log("category", response);
|
2024-12-09 16:09:42 +00:00
|
|
|
setCategories(response?.data?.data?.content);
|
|
|
|
|
};
|
2024-12-04 14:12:10 +00:00
|
|
|
|
2024-12-11 15:08:03 +00:00
|
|
|
const [searchTerm, setSearchTerm] = useState("");
|
|
|
|
|
const [seeAllValue, setSeeAllValue] = useState(false);
|
2025-01-05 13:46:18 +00:00
|
|
|
const pathname = usePathname();
|
2025-01-06 14:36:37 +00:00
|
|
|
|
2024-12-04 14:12:10 +00:00
|
|
|
return (
|
2024-12-11 15:08:03 +00:00
|
|
|
<div className="mx-auto px-4 lg:px-20 py-10 max-w-screen-2xl ">
|
2024-12-17 14:27:48 +00:00
|
|
|
<Reveal>
|
|
|
|
|
<h2 className="text-center text-xl lg:text-2xl font-bold text-[#bb3523] mb-4">
|
2025-01-05 13:46:18 +00:00
|
|
|
{pathname?.split("/")[1] == "in" ? (
|
|
|
|
|
<>
|
|
|
|
|
<span className="text-black dark:text-white">{t("category")} </span>
|
|
|
|
|
{t("content")}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<span className="text-black dark:text-white">{t("content")} </span>
|
|
|
|
|
{t("category")}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-12-17 14:27:48 +00:00
|
|
|
</h2>
|
|
|
|
|
<div className="h-1 w-48 bg-[#bb3523] mx-auto mb-6 rounded"></div>
|
2024-12-04 14:12:10 +00:00
|
|
|
|
2024-12-17 14:27:48 +00:00
|
|
|
<div className="grid my-3 grid-cols-2 lg:grid-cols-4 gap-4">
|
|
|
|
|
{categories?.map((category: any, index: number) =>
|
|
|
|
|
!seeAllValue ? (
|
2025-01-31 12:51:04 +00:00
|
|
|
index < 4 ? (
|
2024-12-17 14:27:48 +00:00
|
|
|
<Link key={category?.id} href={`all/filter?category=${category?.id}`} className="relative group rounded-md overflow-hidden shadow-md hover:shadow-lg">
|
|
|
|
|
<img src={category?.thumbnailLink} className="w-full h-48 sm:h-40 object-cover group-hover:scale-110 transition-transform duration-300" />
|
2024-12-18 16:28:31 +00:00
|
|
|
<div className="absolute bottom-0 rounded-lg left-0 right-0 bg-gray-400 border-l-4 mb-4 border-[#bb3523] text-white p-2">
|
2024-12-17 14:27:48 +00:00
|
|
|
<h3 className="text-sm font-semibold truncate">{category?.name}</h3>
|
|
|
|
|
</div>
|
|
|
|
|
</Link>
|
|
|
|
|
) : (
|
|
|
|
|
""
|
|
|
|
|
)
|
|
|
|
|
) : (
|
2024-12-13 14:33:59 +00:00
|
|
|
<Link key={category?.id} href={`all/filter?category=${category?.id}`} className="relative group rounded-md overflow-hidden shadow-md hover:shadow-lg">
|
|
|
|
|
<img src={category?.thumbnailLink} className="w-full h-48 sm:h-40 object-cover group-hover:scale-110 transition-transform duration-300" />
|
2024-12-18 16:28:31 +00:00
|
|
|
<div className="absolute bottom-0 left-0 right-0 bg-gray-400 border-l-4 mb-4 border-[#bb3523] rounded-lg text-white p-2">
|
2024-12-13 14:33:59 +00:00
|
|
|
<h3 className="text-sm font-semibold truncate">{category?.name}</h3>
|
|
|
|
|
</div>
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
2024-12-17 14:27:48 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center flex-row justify-center">
|
|
|
|
|
<Button onClick={() => setSeeAllValue(!seeAllValue)} className="bg-white hover:bg-[#bb3523] text-[#bb3523] hover:text-white border-2 border-[#bb3523]">
|
2025-01-05 13:46:18 +00:00
|
|
|
{seeAllValue ? t("seeLess") : t("seeMore")}
|
2024-12-17 14:27:48 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Reveal>
|
2024-12-04 14:12:10 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ContentCategory;
|