diff --git a/components/details/details-content.tsx b/components/details/details-content.tsx index a70e778..a692045 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 { CommentIcon } from "../icons/sidebar-icon"; 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; @@ -33,6 +35,15 @@ interface CategoryType { value: number; } +type Advertise = { + id: number; + title: string; + description: string; + placement: string; + contentFileUrl: string; + redirectLink: string; +}; + export default function DetailContent() { const params = useParams(); const id = params?.id; @@ -68,6 +79,36 @@ export default function DetailContent() { { id: "latest", label: "Latest" }, ]; + 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(() => { initState(); }, [page, showData, startDateValue, selectedCategories]); @@ -184,7 +225,8 @@ export default function DetailContent() { - {articleDetail?.createdByName} + {articleDetail?.customCreatorName || + articleDetail?.createdByName} - @@ -382,7 +424,8 @@ export default function DetailContent() { {/* Info Author */}

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

@@ -424,12 +467,28 @@ export default function DetailContent() {
- Berita Utama + {bannerImageAd ? ( + + {bannerImageAd.title + + ) : ( + Banner Default + )}

Tinggalkan Balasan

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 50d08e8..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,10 +88,13 @@ 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", }), - htmlDescription: z.string().min(2, { + description: z.string().min(2, { message: "Deskripsi harus diisi", }), category: z.array(categorySchema).nonempty({ @@ -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,8 +190,10 @@ 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("htmlDescription", data?.htmlDescription); + setValue("source", data?.source); + setValue("description", data?.htmlDescription); setValue("tags", data?.tags ? data.tags.split(",") : []); setThumbnail(data?.thumbnailUrl); setDiseId(data?.aiArticleId); @@ -267,8 +280,8 @@ export default function EditArticleForm(props: { isDetail: boolean }) { .map((val) => val.id) .join(","), tags: getValues("tags").join(","), - description: htmlToString(getValues("htmlDescription")), - htmlDescription: getValues("htmlDescription"), + description: htmlToString(getValues("description")), + htmlDescription: getValues("description"), }); if (response?.error) { @@ -287,8 +300,8 @@ export default function EditArticleForm(props: { isDetail: boolean }) { slug: values.slug, categoryIds: values.category.map((val) => val.id).join(","), tags: values.tags.join(","), - description: htmlToString(values.htmlDescription), - htmlDescription: values.htmlDescription, + description: htmlToString(values.description), + htmlDescription: values.description, // createdAt: `${startDateValue} ${timeValue}:00`, }; @@ -544,7 +557,7 @@ export default function EditArticleForm(props: { isDetail: boolean }) { {useAi && ( setValue("htmlDescription", data?.articleBody)} + content={(data) => setValue("description", data?.articleBody)} /> )} @@ -575,15 +588,13 @@ export default function EditArticleForm(props: { isDetail: boolean }) { )} */} ( )} /> - {errors.htmlDescription?.message && ( -

- {errors.htmlDescription.message} -

+ {errors.description?.message && ( +

{errors.description.message}

)}

File Media

{!isDetail && ( @@ -785,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 b06a655..3af00b9 100644 --- a/components/landing-page/news.tsx +++ b/components/landing-page/news.tsx @@ -5,6 +5,7 @@ import Image from "next/image"; import { useEffect, useRef, useState } from "react"; import { getListArticle } from "@/service/article"; import Link from "next/link"; +import { getAdvertise } from "@/service/advertisement"; type Article = { id: number; @@ -23,6 +24,15 @@ type Article = { }[]; }; +type Advertise = { + id: number; + title: string; + description: string; + placement: string; + contentFileUrl: string; + redirectLink: string; +}; + export default function Beranda() { const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); @@ -35,6 +45,37 @@ export default function Beranda() { endDate: null, }); + 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(() => { initState(); }, [page, showData, startDateValue, selectedCategories]); @@ -222,12 +263,32 @@ export default function Beranda() {
- Berita Utama + {bannerAd ? ( + +
+ {bannerAd.title +
+
+ ) : ( + Berita Utama + )}
@@ -339,12 +400,28 @@ export default function Beranda() {
- Berita Utama + {bannerImageAd ? ( + + {bannerImageAd.title + + ) : ( + Banner Default + )}
@@ -416,12 +493,28 @@ export default function Beranda() {
- Berita Utama + {bannerImageAd ? ( + + {bannerImageAd.title + + ) : ( + Banner Default + )}
@@ -466,12 +559,28 @@ export default function Beranda() {
- Berita Utama + {bannerImageAd ? ( + + {bannerImageAd.title + + ) : ( + Banner Default + )}
@@ -517,12 +626,32 @@ export default function Beranda() {
))}
- Berita Utama + {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 de3efbe..bdd309d 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": "bb65b1ad-e954-4a1a-b4d0-74df5bb0b640" + "X-Client-Key": "e934614d-867a-4ff2-9c11-f782ee76624e", }, }); diff --git a/service/http-config/axios-interceptor-instance.ts b/service/http-config/axios-interceptor-instance.ts index 422a192..fbdb995 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": "bb65b1ad-e954-4a1a-b4d0-74df5bb0b640" + "X-Client-Key": "e934614d-867a-4ff2-9c11-f782ee76624e", }, withCredentials: true, }); diff --git a/service/http-config/http-base-services.ts b/service/http-config/http-base-services.ts index 755d158..cf4be8a 100644 --- a/service/http-config/http-base-services.ts +++ b/service/http-config/http-base-services.ts @@ -2,11 +2,11 @@ import axiosBaseInstance from "./axios-base-instance"; const defaultHeaders = { "Content-Type": "application/json", - "X-Client-Key": "bb65b1ad-e954-4a1a-b4d0-74df5bb0b640" + "X-Client-Key": "e934614d-867a-4ff2-9c11-f782ee76624e", }; -export async function httpGet(pathUrl: any, headers?: any) { - console.log("X-HEADERS : ", defaultHeaders) +export async function httpGet(pathUrl: any, headers?: any) { + console.log("X-HEADERS : ", defaultHeaders); const mergedHeaders = { ...defaultHeaders, ...headers, diff --git a/service/http-config/http-interceptor-services.ts b/service/http-config/http-interceptor-services.ts index 4d33d96..9c5e26f 100644 --- a/service/http-config/http-interceptor-services.ts +++ b/service/http-config/http-interceptor-services.ts @@ -5,11 +5,11 @@ import { getCsrfToken } from "../master-user"; const defaultHeaders = { "Content-Type": "application/json", - "X-Client-Key": "bb65b1ad-e954-4a1a-b4d0-74df5bb0b640" + "X-Client-Key": "e934614d-867a-4ff2-9c11-f782ee76624e", }; export async function httpGetInterceptor(pathUrl: any) { - console.log("X-HEADERS : ", defaultHeaders) + console.log("X-HEADERS : ", defaultHeaders); const response = await axiosInterceptorInstance .get(pathUrl, { headers: defaultHeaders }) .catch((error) => 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 = { 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}`; +}