diff --git a/components/details/details-content.tsx b/components/details/details-content.tsx index 7a4106b..d306527 100644 --- a/components/details/details-content.tsx +++ b/components/details/details-content.tsx @@ -7,6 +7,7 @@ import { close, loading } from "@/config/swal"; import { useParams } from "next/navigation"; import Author from "../landing-page/author"; import { Link2, MailIcon } from "lucide-react"; +import { getAdvertise } from "@/service/advertisement"; type TabKey = "trending" | "comments" | "latest"; @@ -17,6 +18,7 @@ type Article = { categoryName: string; createdAt: string; createdByName: string; + customCreatorName: string; thumbnailUrl: string; categories: { title: string; @@ -27,6 +29,15 @@ type Article = { }[]; }; +type Advertise = { + id: number; + title: string; + description: string; + placement: string; + contentFileUrl: string; + redirectLink: string; +}; + interface CategoryType { id: number; label: string; @@ -69,6 +80,36 @@ export default function DetailContent() { { id: "latest", label: "Latest" }, ]; + const [bannerAd, setBannerAd] = useState(null); + + useEffect(() => { + initStateAdver(); + }, []); + + async function initStateAdver() { + const req = { + limit: 100, + page: 1, + sort: "desc", + sortBy: "created_at", + isPublish: true, + }; + + try { + const res = await getAdvertise(req); + const data: Advertise[] = res?.data?.data || [1]; + + // filter iklan dengan placement = "banner" + const banner = data.find((ad) => ad.placement === "jumbotron"); + + if (banner) { + setBannerAd(banner); + } + } catch (err) { + console.error("Error fetching advertisement:", err); + } + } + useEffect(() => { fetchTabArticles(); }, [activeTab]); @@ -234,7 +275,7 @@ export default function DetailContent() { - {articleDetail?.createdByName} + {articleDetail?.customCreatorName || articleDetail?.createdByName} @@ -384,7 +425,8 @@ export default function DetailContent() { {/* Info Author */}

- {articleDetail?.createdByName} + {articleDetail?.customCreatorName || + articleDetail?.createdByName}

@@ -519,13 +561,32 @@ export default function DetailContent() {
- Iklan + {bannerAd ? ( + +
+ {bannerAd.title +
+
+ ) : ( + Berita Utama + )} diff --git a/components/form/article/create-article-form.tsx b/components/form/article/create-article-form.tsx index e7a4270..a8fbe78 100644 --- a/components/form/article/create-article-form.tsx +++ b/components/form/article/create-article-form.tsx @@ -9,7 +9,7 @@ import { CloudUploadIcon, TimesIcon } from "@/components/icons"; import Image from "next/image"; import ReactSelect from "react-select"; import makeAnimated from "react-select/animated"; -import { htmlToString } from "@/utils/global"; +import { convertDateFormatNoTime, htmlToString } from "@/utils/global"; import { close, error, loading, successToast } from "@/config/swal"; import { useRouter } from "next/navigation"; import Link from "next/link"; @@ -44,6 +44,13 @@ import GenerateSingleArticleForm from "./generate-ai-single-form"; import GenerateContentRewriteForm from "./generate-ai-content-rewrite-form"; import { Textarea } from "@/components/ui/textarea"; import { Badge } from "@/components/ui/badge"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; +import { Calendar } from "@/components/ui/calendar"; +import DatePicker from "react-datepicker"; const CustomEditor = dynamic( () => { @@ -82,6 +89,9 @@ const createArticleSchema = z.object({ title: z.string().min(2, { message: "Judul harus diisi", }), + customCreatorName: z.string().min(2, { + message: "Judul harus diisi", + }), slug: z.string().min(2, { message: "Slug harus diisi", }), @@ -94,6 +104,7 @@ const createArticleSchema = z.object({ tags: z.array(z.string()).nonempty({ message: "Minimal 1 tag", }), + source: z.enum(["internal", "external"]).optional(), }); export default function CreateArticleForm() { @@ -117,8 +128,8 @@ export default function CreateArticleForm() { "publish" ); const [isScheduled, setIsScheduled] = useState(false); - - const [startDateValue, setStartDateValue] = useState(null); + const [startDateValue, setStartDateValue] = useState(); + const [startTimeValue, setStartTimeValue] = useState(""); const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { @@ -225,6 +236,8 @@ export default function CreateArticleForm() { const request = { id: diseData?.id, title: values.title, + customCreatorName: values.customCreatorName, + source: values.source, articleBody: removeImgTags(values.description), metaDescription: diseData?.metaDescription, metaTitle: diseData?.metaTitle, @@ -280,6 +293,8 @@ export default function CreateArticleForm() { title: values.title, typeId: 1, slug: values.slug, + customCreatorName: values.customCreatorName, + source: values.source, categoryIds: values.category.map((a) => a.id).join(","), tags: values.tags.join(","), description: htmlToString(removeImgTags(values.description)), @@ -324,12 +339,34 @@ export default function CreateArticleForm() { } } - if (status === "scheduled") { + if (status === "scheduled" && startDateValue) { + // ambil waktu, default 00:00 jika belum diisi + const [hours, minutes] = startTimeValue + ? startTimeValue.split(":").map(Number) + : [0, 0]; + + // gabungkan tanggal + waktu + const combinedDate = new Date(startDateValue); + combinedDate.setHours(hours, minutes, 0, 0); + + // format: 2025-10-08 14:30:00 + const formattedDateTime = `${combinedDate.getFullYear()}-${String( + combinedDate.getMonth() + 1 + ).padStart(2, "0")}-${String(combinedDate.getDate()).padStart( + 2, + "0" + )} ${String(combinedDate.getHours()).padStart(2, "0")}:${String( + combinedDate.getMinutes() + ).padStart(2, "0")}:00`; + const request = { id: articleId, - date: `${startDateValue?.year}-${startDateValue?.month}-${startDateValue?.day}`, + date: formattedDateTime, }; + + console.log("📤 Sending schedule request:", request); const res = await createArticleSchedule(request); + console.log("✅ Schedule response:", res); } close(); @@ -659,7 +696,38 @@ export default function CreateArticleForm() { )} )} - +

Kreator

+ ( + + )} + /> +
+

Tipe Kreator

+ ( + + )} + /> +

Kategori

- {/* {isScheduled && ( -
-
+ {isScheduled && ( +
+ {/* Pilih tanggal */} +

Tanggal

- + setStartDateValue(date ?? undefined) + } + dateFormat="yyyy-MM-dd" + className="w-full border rounded-lg px-2 py-1 text-black cursor-pointer h-[150px]" + placeholderText="Pilih tanggal" />
+ + {/* Pilih waktu */} +
+

Waktu

+ setStartTimeValue(e.target.value)} + className="w-full border rounded-lg px-2 py-[6px] text-black" + /> +
- )} */} + )}
diff --git a/components/form/article/edit-article-form.tsx b/components/form/article/edit-article-form.tsx index d55147c..06b15bd 100644 --- a/components/form/article/edit-article-form.tsx +++ b/components/form/article/edit-article-form.tsx @@ -48,6 +48,13 @@ import { DialogTitle, DialogClose, } from "@/components/ui/dialog"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; const ViewEditor = dynamic( () => { @@ -81,6 +88,9 @@ const createArticleSchema = z.object({ title: z.string().min(2, { message: "Judul harus diisi", }), + customCreatorName: z.string().min(2, { + message: "Judul harus diisi", + }), slug: z.string().min(2, { message: "Slug harus diisi", }), @@ -92,7 +102,8 @@ const createArticleSchema = z.object({ }), tags: z.array(z.string()).nonempty({ message: "Minimal 1 tag", - }), // Array berisi string + }), + source: z.enum(["internal", "external"]).optional(), }); interface DiseData { @@ -179,7 +190,9 @@ export default function EditArticleForm(props: { isDetail: boolean }) { const data = res.data?.data; setDetailData(data); setValue("title", data?.title); + setValue("customCreatorName", data?.customCreatorName); setValue("slug", data?.slug); + setValue("source", data?.source); setValue("description", data?.htmlDescription); setValue("tags", data?.tags ? data.tags.split(",") : []); setThumbnail(data?.thumbnailUrl); @@ -783,6 +796,43 @@ export default function EditArticleForm(props: { isDetail: boolean }) { )} )} +

Kreator

+ ( + + )} + /> +
+

Tipe Kreator

+ ( + + )} + /> +

Kategori

void; }) { - const [selectedWritingSyle, setSelectedWritingStyle] = - useState("Informational"); - const [selectedArticleSize, setSelectedArticleSize] = useState("News"); - const [selectedLanguage, setSelectedLanguage] = useState("id"); + const [selectedWritingSyle, setSelectedWritingStyle] = useState(""); + const [selectedArticleSize, setSelectedArticleSize] = useState(""); + const [selectedLanguage, setSelectedLanguage] = useState(""); const [mainKeyword, setMainKeyword] = useState(""); const [title, setTitle] = useState(""); const [additionalKeyword, setAdditionalKeyword] = useState(""); @@ -271,11 +270,11 @@ export default function GenerateSingleArticleForm(props: { }} > - + {articleSize.map((style) => ( - + {style.name} ))} @@ -307,7 +306,7 @@ export default function GenerateSingleArticleForm(props: { }} > - + Indonesia diff --git a/components/landing-page/news.tsx b/components/landing-page/news.tsx index 631234a..31e0538 100644 --- a/components/landing-page/news.tsx +++ b/components/landing-page/news.tsx @@ -6,6 +6,7 @@ import { getListArticle } from "@/service/article"; import { ScrollArea } from "@/components/ui/scroll-area"; // pastikan ada komponen ini import { Calendar } from "lucide-react"; import Link from "next/link"; +import { getAdvertise } from "@/service/advertisement"; type Article = { id: number; @@ -18,9 +19,48 @@ type Article = { files: { fileUrl: string; file_alt: string }[]; }; +type Advertise = { + id: number; + title: string; + description: string; + placement: string; + contentFileUrl: string; + redirectLink: string; +}; + export default function News() { const [articles, setArticles] = useState([]); const [recentPosts, setRecentPosts] = useState([]); + const [bannerAd, setBannerAd] = useState(null); + const [bannerImageAd, setBannerImageAd] = useState(null); + useEffect(() => { + initStateAdver(); + }, []); + + async function initStateAdver() { + const req = { + limit: 100, + page: 1, + sort: "desc", + sortBy: "created_at", + isPublish: true, + }; + + try { + const res = await getAdvertise(req); + const data: Advertise[] = res?.data?.data || []; + + // ambil iklan placement jumbotron + const jumbotron = data.find((ad) => ad.placement === "jumbotron"); + if (jumbotron) setBannerAd(jumbotron); + + // ambil iklan placement banner + const banner = data.find((ad) => ad.placement === "banner"); + if (banner) setBannerImageAd(banner); + } catch (err) { + console.error("Error fetching advertisement:", err); + } + } useEffect(() => { fetchArticles(); @@ -116,12 +156,28 @@ export default function News() { {/* Banner */}
- Berita Utama + {bannerImageAd ? ( + + {bannerImageAd.title + + ) : ( + Banner Default + )}
{/* Artikel kedua */} @@ -172,12 +228,28 @@ export default function News() { {/* Banner */}
- Berita Utama + {bannerImageAd ? ( + + {bannerImageAd.title + + ) : ( + Banner Default + )}
{/* Pagination (sementara statis, bisa pakai API meta untuk dinamis) */} @@ -258,13 +330,32 @@ export default function News() { {/* Ads / Subscribe */}
- Iklan 2 + {bannerAd ? ( + +
+ {bannerAd.title +
+
+ ) : ( + Berita Utama + )}

@@ -284,13 +375,32 @@ export default function News() {

- Iklan 2 + {bannerAd ? ( + +
+ {bannerAd.title +
+
+ ) : ( + Berita Utama + )}
diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index a562193..2f0907a 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -106,7 +106,7 @@ export default function DashboardContainer() { async function initState() { const req = { - limit: "4", + limit: "5", page: page, search: "", }; @@ -195,7 +195,7 @@ export default function DashboardContainer() { {/* Stats Cards */}
{/* User Profile Card */} - {username}

-

{summary?.totalToday}

+

+ {summary?.totalToday} +

Today

-

{summary?.totalThisWeek}

+

+ {summary?.totalThisWeek} +

This Week

@@ -223,7 +227,7 @@ export default function DashboardContainer() {
{/* Total Posts */} -
-

{summary?.totalAll}

+

+ {summary?.totalAll} +

Total Posts

{/* Total Views */} -
-

{summary?.totalViews}

+

+ {summary?.totalViews} +

Total Views

{/* Total Shares */} -
-

{summary?.totalShares}

+

+ {summary?.totalShares} +

Total Shares

{/* Total Comments */} -
-

{summary?.totalComments}

+

+ {summary?.totalComments} +

Total Comments

@@ -298,20 +310,27 @@ export default function DashboardContainer() { {/* Content Section */}
{/* Analytics Chart */} -
-

Analytics Overview

+

+ Analytics Overview +

{options.map((option) => ( -
- -
+ +
{/* Recent Articles */} -
-

Recent Articles

- +

+ Recent Articles +

+ {/* - + */}
- +
{article?.map((list: any) => ( ))}
- +
([]); const [selectedCategories, setSelectedCategories] = useState(""); + const [selectedCategoryId, setSelectedCategoryId] = useState(""); const [selectedSource, setSelectedSource] = useState(""); const [selectedStatus, setSelectedStatus] = useState(""); const [dateRange, setDateRange] = useState({ @@ -111,7 +112,7 @@ export default function ArticleTable() { page, showData, search, - selectedCategories, + selectedCategoryId, selectedSource, dateRange, selectedStatus, @@ -123,16 +124,12 @@ export default function ArticleTable() { limit: showData, page: page, search: search, - category: selectedCategories || "", + category: selectedCategoryId || "", source: selectedSource || "", isPublish: selectedStatus !== "" ? selectedStatus === "publish" : undefined, - startDate: dateRange.startDate - ? new Date(dateRange.startDate).toISOString() - : "", - endDate: dateRange.endDate - ? new Date(dateRange.endDate).toISOString() - : "", + startDate: formatDate(dateRange.startDate), + endDate: formatDate(dateRange.endDate), sort: "desc", sortBy: "created_at", }; @@ -221,6 +218,15 @@ export default function ArticleTable() { const cellValue = article[columnKey as keyof any]; switch (columnKey) { + case "customCreatorName": + return ( +

+ {article.customCreatorName && + article.customCreatorName.trim() !== "" + ? article.customCreatorName + : article.createdByName} +

+ ); case "isPublish": return ( //

Kategori

diff --git a/service/article.ts b/service/article.ts index 5a4c803..5682e6f 100644 --- a/service/article.ts +++ b/service/article.ts @@ -21,13 +21,14 @@ export async function getListArticle(props: PaginationRequest) { categorySlug, isBanner, } = props; + return await httpGet( `/articles?limit=${limit}&page=${page}&isPublish=${ isPublish === undefined ? "" : isPublish }&title=${search}&startDate=${startDate || ""}&endDate=${ endDate || "" }&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${ - sort || "asc" + sort || "desc" }&category=${categorySlug || ""}&isBanner=${isBanner || ""}`, null ); diff --git a/service/http-config/axios-base-instance.ts b/service/http-config/axios-base-instance.ts index c4342d5..2e40aa2 100644 --- a/service/http-config/axios-base-instance.ts +++ b/service/http-config/axios-base-instance.ts @@ -6,7 +6,7 @@ const axiosBaseInstance = axios.create({ baseURL, headers: { "Content-Type": "application/json", - "X-Client-Key": "e41eefe6-70da-4cb2-bf90-aa033fd082be", + "X-Client-Key": "59cbca27-ce92-40b7-866a-218a4936e701", }, }); diff --git a/service/http-config/axios-interceptor-instance.ts b/service/http-config/axios-interceptor-instance.ts index 6cdcefd..5be3805 100644 --- a/service/http-config/axios-interceptor-instance.ts +++ b/service/http-config/axios-interceptor-instance.ts @@ -10,7 +10,7 @@ const axiosInterceptorInstance = axios.create({ baseURL, headers: { "Content-Type": "application/json", - "X-Client-Key": "e41eefe6-70da-4cb2-bf90-aa033fd082be", + "X-Client-Key": "59cbca27-ce92-40b7-866a-218a4936e701", }, withCredentials: true, }); diff --git a/service/http-config/http-base-services.ts b/service/http-config/http-base-services.ts index c4af37d..a835958 100644 --- a/service/http-config/http-base-services.ts +++ b/service/http-config/http-base-services.ts @@ -2,7 +2,7 @@ import axiosBaseInstance from "./axios-base-instance"; const defaultHeaders = { "Content-Type": "application/json", - "X-Client-Key": "e41eefe6-70da-4cb2-bf90-aa033fd082be", + "X-Client-Key": "59cbca27-ce92-40b7-866a-218a4936e701", }; export async function httpGet(pathUrl: any, headers?: any) { diff --git a/service/http-config/http-interceptor-services.ts b/service/http-config/http-interceptor-services.ts index 2f88d2b..955960c 100644 --- a/service/http-config/http-interceptor-services.ts +++ b/service/http-config/http-interceptor-services.ts @@ -5,7 +5,7 @@ import { getCsrfToken } from "../master-user"; const defaultHeaders = { "Content-Type": "application/json", - "X-Client-Key": "e41eefe6-70da-4cb2-bf90-aa033fd082be", + "X-Client-Key": "59cbca27-ce92-40b7-866a-218a4936e701", }; export async function httpGetInterceptor(pathUrl: any) { diff --git a/utils/global.tsx b/utils/global.tsx index 527b80d..68830b0 100644 --- a/utils/global.tsx +++ b/utils/global.tsx @@ -164,3 +164,11 @@ export function convertDateFormatNoTime(date: Date): string { const day = `${date.getDate()}`.padStart(2, "0"); return `${year}-${month}-${day}`; } + +export function formatDate(date: Date | null) { + if (!date) return ""; + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, "0"); + const day = String(date.getDate()).padStart(2, "0"); + return `${year}-${month}-${day}`; +}