diff --git a/components/details/details-content.tsx b/components/details/details-content.tsx index a1b8c51..bfa8d65 100644 --- a/components/details/details-content.tsx +++ b/components/details/details-content.tsx @@ -234,7 +234,7 @@ export default function DetailContent() { - {articleDetail?.createdByName} + {articleDetail?.customCreatorName || articleDetail?.createdByName} @@ -384,7 +384,8 @@ export default function DetailContent() { {/* Info Author */}

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

diff --git a/components/form/article/create-article-form.tsx b/components/form/article/create-article-form.tsx index 40f25d6..4ef5c90 100644 --- a/components/form/article/create-article-form.tsx +++ b/components/form/article/create-article-form.tsx @@ -82,6 +82,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 +97,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() { @@ -225,6 +229,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 +286,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)), @@ -524,13 +532,21 @@ export default function CreateArticleForm() { Single Article - Content Rewrite + {/* Content Rewrite */} {selectedWritingType === "single" ? ( { setDiseData(data); + // setValue("title", data?.title ?? "", { + // shouldValidate: true, + // shouldDirty: true, + // }); + // setValue("slug", generateSlug(data?.title ?? ""), { + // shouldValidate: true, + // shouldDirty: true, + // }); setValue( "description", data?.articleBody ? data?.articleBody : "" @@ -651,7 +667,38 @@ export default function CreateArticleForm() { )} )} - +

Kreator

+ ( + + )} + /> +
+

Tipe Kreator

+ ( + + )} + /> +

Kategori

{ @@ -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); @@ -681,6 +694,7 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
{/* 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/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}`; +}