+
- {articles[0].categories[0]?.title || "Uncategorized"}
+ {articles[0]?.categories?.[0]?.title || "Uncategorized"}
-
{articles[0].title}
+
{articles[0]?.title}
- {articles[0].createdByName}{" "}
+
+ {articles[0]?.createdByName}
+ {" "}
•{" "}
- {new Date(articles[0].createdAt).toLocaleDateString("id-ID", {
- day: "numeric",
- month: "long",
- year: "numeric",
- })}
+ {articles[0]?.createdAt &&
+ new Date(articles[0].createdAt).toLocaleDateString("id-ID", {
+ day: "numeric",
+ month: "long",
+ year: "numeric",
+ })}
@@ -74,67 +79,84 @@ export default function HeaderNews() {
{/* Atas: 2 berita kecil */}
- {articles.slice(1, 3).map((item) => (
-
-
-
-
-
- {item.categories[0]?.title || "Uncategorized"}
-
-
- {item.title}
-
-
- {item.createdByName}{" "}
- •{" "}
- {new Date(item.createdAt).toLocaleDateString("id-ID", {
- day: "numeric",
- month: "short",
- year: "numeric",
- })}
-
-
-
- ))}
+ {[articles[1], articles[2]].map(
+ (item, idx) =>
+ item && (
+
+
+
+
+
+ {item.categories?.[0]?.title || "Uncategorized"}
+
+
+ {item.title}
+
+
+
+ {item.createdByName}
+ {" "}
+ •{" "}
+ {item.createdAt &&
+ new Date(item.createdAt).toLocaleDateString("id-ID", {
+ day: "numeric",
+ month: "short",
+ year: "numeric",
+ })}
+
+
+
+ )
+ )}
{/* Bawah: 1 berita besar */}
-
-
-
-
-
- {articles[3].categories[0]?.title || "Uncategorized"}
-
-
- {articles[3].title}
-
-
-
- {articles[3].createdByName}
- {" "}
- •{" "}
- {new Date(articles[3].createdAt).toLocaleDateString("id-ID", {
- day: "numeric",
- month: "long",
- year: "numeric",
- })}
-
+ {articles[3] && (
+
+
+
+
+
+ {articles[3]?.categories?.[0]?.title || "Uncategorized"}
+
+
+ {articles[3]?.title}
+
+
+
+ {articles[3]?.createdByName}
+ {" "}
+ •{" "}
+ {articles[3]?.createdAt &&
+ new Date(articles[3].createdAt).toLocaleDateString(
+ "id-ID",
+ {
+ day: "numeric",
+ month: "long",
+ year: "numeric",
+ }
+ )}
+
+
-
+ )}
+
+ {/* Banner bawah */}
error.response);
@@ -35,7 +35,11 @@ export async function httpGetInterceptor(pathUrl: any) {
}
}
-export async function httpPostInterceptor(pathUrl: any, data: any, headers?: any) {
+export async function httpPostInterceptor(
+ pathUrl: any,
+ data: any,
+ headers?: any
+) {
const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.csrf_token;
@@ -67,7 +71,11 @@ export async function httpPostInterceptor(pathUrl: any, data: any, headers?: any
}
}
-export async function httpPutInterceptor(pathUrl: any, data: any, headers?: any) {
+export async function httpPutInterceptor(
+ pathUrl: any,
+ data: any,
+ headers?: any
+) {
const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.csrf_token;
@@ -99,7 +107,7 @@ export async function httpPutInterceptor(pathUrl: any, data: any, headers?: any)
}
export async function httpDeleteInterceptor(pathUrl: any, headers?: any) {
- const resCsrf = await getCsrfToken();
+ const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.csrf_token;
const mergedHeaders = {