@@ -873,38 +963,42 @@ export default function FormTeks() {
-
(
-
+ (
+
+
+
+
+ {errors.categoryId && (
+
+ {errors.categoryId.message}
+
)}
- />
- {errors.category?.message && (
-
- {errors.category.message}
-
- )}
+
+ )}
+ />
diff --git a/components/landing-page/header.tsx b/components/landing-page/header.tsx
index 2cf0ad6..fa18a64 100644
--- a/components/landing-page/header.tsx
+++ b/components/landing-page/header.tsx
@@ -6,6 +6,7 @@ import { useEffect, useState } from "react";
import {
getListContent,
listData,
+ listArticles,
listStaticBanner,
} from "@/service/landing/landing";
import { data } from "framer-motion/client";
@@ -17,25 +18,66 @@ export default function Header() {
useEffect(() => {
const fetchData = async () => {
try {
- // const request = {
- // group: "mabes",
- // };
- const response = await listData(
- "",
- "",
- "",
- 5,
- 0,
- "createdAt",
- "",
- "",
- ""
- );
- const content = response?.data?.data?.content || [];
- console.log("data", content);
- setData(content);
+ // Use new Articles API
+ const response = await listArticles(1, 5, undefined, undefined, undefined, "createdAt");
+ console.log("Articles API response:", response);
+
+ if (response?.error) {
+ console.error("Articles API failed, falling back to old API");
+ // Fallback to old API
+ const fallbackResponse = await listData(
+ "",
+ "",
+ "",
+ 5,
+ 0,
+ "createdAt",
+ "",
+ "",
+ ""
+ );
+ const content = fallbackResponse?.data?.data?.content || [];
+ setData(content);
+ return;
+ }
+
+ // Handle new API response structure
+ const articlesData = response?.data?.data || [];
+ console.log("Articles data:", articlesData);
+
+ // Transform articles data to match old structure for backward compatibility
+ const transformedData = articlesData.map((article: any) => ({
+ id: article.id,
+ title: article.title,
+ categoryName: article.categoryName || (article.categories && article.categories[0]?.title) || "",
+ createdAt: article.createdAt,
+ smallThumbnailLink: article.thumbnailUrl,
+ fileTypeId: article.typeId,
+ label: article.typeId === 1 ? "Image" : article.typeId === 2 ? "Video" : article.typeId === 3 ? "Text" : article.typeId === 4 ? "Audio" : "",
+ ...article
+ }));
+
+ setData(transformedData);
} catch (error) {
console.error("Gagal memuat data:", error);
+ // Try fallback to old API if new API fails
+ try {
+ const fallbackResponse = await listData(
+ "",
+ "",
+ "",
+ 5,
+ 0,
+ "createdAt",
+ "",
+ "",
+ ""
+ );
+ const content = fallbackResponse?.data?.data?.content || [];
+ setData(content);
+ } catch (fallbackError) {
+ console.error("Fallback API also failed:", fallbackError);
+ }
}
};
@@ -70,13 +112,13 @@ function Card({ item, isBig = false }: { item: any; isBig?: boolean }) {
const getLink = () => {
switch (item?.fileTypeId) {
case 1:
- return `/public/content/image/detail/${item?.id}`;
+ return `/content/image/detail/${item?.id}`;
case 2:
- return `/public/content/video/detail/${item?.id}`;
+ return `/content/video/detail/${item?.id}`;
case 3:
- return `/public/content/text/detail/${item?.id}`;
+ return `/content/text/detail/${item?.id}`;
case 4:
- return `/public/content/audio/detail/${item?.id}`;
+ return `/content/audio/detail/${item?.id}`;
default:
return "#"; // fallback kalau type tidak dikenali
}
diff --git a/components/landing-page/media-update.tsx b/components/landing-page/media-update.tsx
index 98861c6..f76d8a0 100644
--- a/components/landing-page/media-update.tsx
+++ b/components/landing-page/media-update.tsx
@@ -6,7 +6,7 @@ import { Button } from "@/components/ui/button";
import { ThumbsUp, ThumbsDown } from "lucide-react";
import { Card } from "../ui/card";
import Link from "next/link";
-import { listData } from "@/service/landing/landing";
+import { listData, listArticles } from "@/service/landing/landing";
import { Swiper, SwiperSlide } from "swiper/react";
import "swiper/css";
import "swiper/css/navigation";
@@ -42,20 +42,71 @@ export default function MediaUpdate() {
async function fetchData(section: "latest" | "popular") {
try {
setLoading(true);
- const res = await listData(
- "1",
- "",
- "",
- 20,
- 0,
- section === "latest" ? "createdAt" : "clickCount",
- "",
- "",
- ""
+
+ // Use new Articles API
+ const response = await listArticles(
+ 1,
+ 20,
+ 1, // typeId for images
+ undefined,
+ undefined,
+ section === "latest" ? "createdAt" : "viewCount"
);
- setDataToRender(res?.data?.data?.content || []);
+
+ console.log("Media Update Articles API response:", response);
+
+ if (response?.error) {
+ console.error("Articles API failed, falling back to old API");
+ // Fallback to old API
+ const fallbackRes = await listData(
+ "1",
+ "",
+ "",
+ 20,
+ 0,
+ section === "latest" ? "createdAt" : "clickCount",
+ "",
+ "",
+ ""
+ );
+ setDataToRender(fallbackRes?.data?.data?.content || []);
+ return;
+ }
+
+ // Handle new API response structure
+ const articlesData = response?.data?.data || [];
+
+ // Transform articles data to match old structure for backward compatibility
+ const transformedData = articlesData.map((article: any) => ({
+ id: article.id,
+ title: article.title,
+ category: article.categoryName || (article.categories && article.categories[0]?.title) || "Tanpa Kategori",
+ createdAt: article.createdAt,
+ smallThumbnailLink: article.thumbnailUrl,
+ label: article.typeId === 1 ? "Image" : article.typeId === 2 ? "Video" : article.typeId === 3 ? "Text" : article.typeId === 4 ? "Audio" : "",
+ ...article
+ }));
+
+ setDataToRender(transformedData);
} catch (err) {
console.error("Gagal memuat data:", err);
+ // Try fallback to old API if new API fails
+ try {
+ const fallbackRes = await listData(
+ "1",
+ "",
+ "",
+ 20,
+ 0,
+ section === "latest" ? "createdAt" : "clickCount",
+ "",
+ "",
+ ""
+ );
+ setDataToRender(fallbackRes?.data?.data?.content || []);
+ } catch (fallbackError) {
+ console.error("Fallback API also failed:", fallbackError);
+ }
} finally {
setLoading(false);
}
diff --git a/components/main/content/audio-detail.tsx b/components/main/content/audio-detail.tsx
index c1370e7..d97fcc9 100644
--- a/components/main/content/audio-detail.tsx
+++ b/components/main/content/audio-detail.tsx
@@ -15,7 +15,7 @@ import {
FaLink,
FaShareAlt,
} from "react-icons/fa";
-import { getDetail } from "@/service/landing/landing";
+import { getDetail, getArticleDetail } from "@/service/landing/landing";
export default function AudioDetail({ id }: { id: string }) {
const [copied, setCopied] = useState(false);
@@ -60,14 +60,75 @@ export default function AudioDetail({ id }: { id: string }) {
const fetchDetail = async () => {
try {
setLoading(true);
- const response = await getDetail(id);
- setData(response?.data?.data);
- console.log(
- "doc",
- response?.data?.data.files[selectedDoc]?.secondaryUrl
- );
+
+ // Try new Articles API first
+ const response = await getArticleDetail(id);
+ console.log("Article Detail API response:", response);
+
+ if (response?.error) {
+ console.error("Articles API failed, falling back to old API");
+ // Fallback to old API
+ const fallbackResponse = await getDetail(id);
+ setData(fallbackResponse?.data?.data);
+ console.log(
+ "doc",
+ fallbackResponse?.data?.data.files[selectedDoc]?.secondaryUrl
+ );
+ return;
+ }
+
+ // Handle new API response structure
+ const articleData = response?.data?.data;
+ if (articleData) {
+ // Transform article data to match old structure for backward compatibility
+ const transformedData = {
+ id: articleData.id,
+ title: articleData.title,
+ description: articleData.description,
+ createdAt: articleData.createdAt,
+ clickCount: articleData.viewCount,
+ creatorGroupLevelName: articleData.createdByName || "Unknown",
+ uploadedBy: {
+ publisher: articleData.createdByName || "MABES POLRI"
+ },
+ files: articleData.files?.map((file: any) => ({
+ id: file.id,
+ url: file.file_url,
+ fileName: file.file_name,
+ filePath: file.file_path,
+ fileThumbnail: file.file_thumbnail,
+ fileAlt: file.file_alt,
+ widthPixel: file.width_pixel,
+ heightPixel: file.height_pixel,
+ size: file.size,
+ downloadCount: file.download_count,
+ createdAt: file.created_at,
+ updatedAt: file.updated_at,
+ secondaryUrl: file.file_url, // For audio files, use same URL
+ ...file
+ })) || [],
+ ...articleData
+ };
+
+ setData(transformedData);
+ console.log(
+ "doc",
+ transformedData.files[selectedDoc]?.secondaryUrl
+ );
+ }
} catch (error) {
console.error("Error fetching detail:", error);
+ // Try fallback to old API if new API fails
+ try {
+ const fallbackResponse = await getDetail(id);
+ setData(fallbackResponse?.data?.data);
+ console.log(
+ "doc",
+ fallbackResponse?.data?.data.files[selectedDoc]?.secondaryUrl
+ );
+ } catch (fallbackError) {
+ console.error("Fallback API also failed:", fallbackError);
+ }
} finally {
setLoading(false);
}
@@ -185,7 +246,7 @@ export default function AudioDetail({ id }: { id: string }) {
-
+
-
+
-
+
-
+