From 9b4016af8029bc227cf89d44f7a6a09c9f37e051 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Fri, 30 May 2025 23:08:12 +0700 Subject: [PATCH 1/8] feat:news all filter, document attach article --- .../admin/comment/review/[id]/page.tsx | 3 +- .../form/article/create-article-form.tsx | 367 ++++++++++++++---- components/form/article/edit-article-form.tsx | 361 +++++++++++++---- components/form/login.tsx | 162 ++++---- components/landing/HeaderNews.tsx | 154 +++++--- components/landing/NewsTicker.tsx | 8 +- components/landing/footer-new.tsx | 8 + components/layout/navbar/NavbarHumas.tsx | 20 + components/main/detail/e-magazine-detail.tsx | 6 +- components/main/detail/list-news.tsx | 236 +++++++++-- components/main/detail/new-detail.tsx | 5 +- components/page/detail-news.tsx | 106 ++++- components/page/related-news.tsx | 13 +- components/page/sidebar-detail.tsx | 210 +++++----- components/table/comment/comment-table.tsx | 3 + components/table/tabel-emajalah-polri.tsx | 19 +- services/article.ts | 15 +- 17 files changed, 1217 insertions(+), 479 deletions(-) diff --git a/app/(admin)/admin/comment/review/[id]/page.tsx b/app/(admin)/admin/comment/review/[id]/page.tsx index 65fadc3..62adf39 100644 --- a/app/(admin)/admin/comment/review/[id]/page.tsx +++ b/app/(admin)/admin/comment/review/[id]/page.tsx @@ -54,7 +54,6 @@ export default function ReviewComment() { setDetailData(res?.data?.data); const resArticle = await getArticleById(res?.data?.data?.articleId); setDetailArticle(resArticle?.data?.data); - console.log("iddd", res?.data?.data); close(); }; @@ -115,7 +114,7 @@ export default function ReviewComment() { return (
-
+

Artikel

{ @@ -112,6 +115,20 @@ const createArticleSchema = z.object({ }), }); +const renderPreview = (file: File) => { + if (file.type === "application/pdf") { + return ; + } else if ( + file.type === + "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || + file.type === "application/msword" + ) { + return ; + } else { + return "File"; + } +}; + export default function CreateArticleForm() { const { isOpen, onOpen, onOpenChange } = useDisclosure(); const userLevel = Cookies.get("ulne"); @@ -124,11 +141,16 @@ export default function CreateArticleForm() { const [listCategory, setListCategory] = useState([]); const [tag, setTag] = useState(""); const [thumbnailImg, setThumbnailImg] = useState([]); + const [thumbnailDocumentImg, setThumbnailDocumentImg] = useState([]); + const [documentFiles, setDocumentFiles] = useState([]); const [selectedMainImage, setSelectedMainImage] = useState( null ); const [thumbnailValidation, setThumbnailValidation] = useState(""); + const [thumbnailDocumentValidation, setThumbnailDocumentValidation] = + useState(""); const [filesValidation, setFileValidation] = useState(""); + const [documentValidation, setDocumentValidation] = useState(""); const [diseData, setDiseData] = useState(); const [selectedWritingType, setSelectedWritingType] = useState("single"); const [status, setStatus] = useState<"publish" | "draft" | "scheduled">( @@ -139,17 +161,37 @@ export default function CreateArticleForm() { const [startDateValue, setStartDateValue] = useState(null); + const [selectedFileType, setSelectedFileType] = useState("image"); + const { getRootProps, getInputProps } = useDropzone({ + accept: + selectedFileType === "image" + ? { + "image/*": [], + } + : { + "application/pdf": [], + "application/msword": [], + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + [], + "application/vnd.ms-powerpoint": [], + "application/vnd.openxmlformats-officedocument.presentationml.presentation": + [], + }, onDrop: (acceptedFiles) => { - setFiles((prevFiles) => [ - ...prevFiles, - ...acceptedFiles.map((file) => Object.assign(file)), - ]); + if (selectedFileType === "image") { + setFiles((prevFiles) => [ + ...prevFiles, + ...acceptedFiles.map((file) => Object.assign(file)), + ]); + } else { + setDocumentFiles((prevFiles) => [ + ...prevFiles, + ...acceptedFiles.map((file) => Object.assign(file)), + ]); + } }, multiple: true, - accept: { - "image/*": [], - }, }); const formOptions = { @@ -193,17 +235,33 @@ export default function CreateArticleForm() { }; const onSubmit = async (values: z.infer) => { - if ((thumbnailImg.length < 1 && !selectedMainImage) || files.length < 1) { + if ( + (selectedFileType === "image" && + ((thumbnailImg.length < 1 && !selectedMainImage) || + files.length < 1)) || + (selectedFileType === "document" && + (documentFiles.length < 1 || thumbnailDocumentImg.length < 1)) + ) { if (files.length < 1) { setFileValidation("Required"); } else { setFileValidation(""); } + if (documentFiles.length < 1) { + setDocumentValidation("Required"); + } else { + setDocumentValidation(""); + } if (thumbnailImg.length < 1 && !selectedMainImage) { setThumbnailValidation("Required"); } else { setThumbnailValidation(""); } + if (thumbnailDocumentImg.length < 1) { + setThumbnailDocumentValidation("Required"); + } else { + setThumbnailDocumentValidation(""); + } } else { setThumbnailValidation(""); setFileValidation(""); @@ -293,9 +351,9 @@ export default function CreateArticleForm() { }; const save = async (values: z.infer) => { + // const userLevelStatus = await getUserLevelApprovalStatus(); loading(); - const userLevelStatus = await getUserLevelApprovalStatus(); const formData = { title: values.title, typeId: 1, @@ -311,6 +369,8 @@ export default function CreateArticleForm() { isPublish: status === "publish", }; + console.log("formData", formData); + const response = await createArticle(formData); if (response?.error) { @@ -319,31 +379,51 @@ export default function CreateArticleForm() { } const articleId = response?.data?.data?.id; - if (files?.length > 0) { + if (files?.length > 0 || documentFiles.length > 0) { const formFiles = new FormData(); - for (const element of files) { - formFiles.append("file", element); - const resFile = await uploadArticleFile(articleId, formFiles); + if (selectedFileType === "image") { + for (const element of files) { + formFiles.append("file", element); + const resFile = await uploadArticleFile(articleId, formFiles); + } + } + + if (selectedFileType === "document") { + for (const element of documentFiles) { + formFiles.append("file", element); + const resFile = await uploadArticleFile(articleId, formFiles); + } } } - if (thumbnailImg?.length > 0 || files?.length > 0) { - if (thumbnailImg?.length > 0) { - const formFiles = new FormData(); - - formFiles.append("files", thumbnailImg[0]); - const resFile = await uploadArticleThumbnail(articleId, formFiles); - } else { - const formFiles = new FormData(); - - if (selectedMainImage) { - formFiles.append("files", files[selectedMainImage - 1]); + if (selectedFileType === "image") { + if (thumbnailImg?.length > 0 || files?.length > 0) { + if (thumbnailImg?.length > 0) { + const formFiles = new FormData(); + formFiles.append("files", thumbnailImg[0]); const resFile = await uploadArticleThumbnail(articleId, formFiles); + } else { + const formFiles = new FormData(); + + if (selectedMainImage) { + formFiles.append("files", files[selectedMainImage - 1]); + + const resFile = await uploadArticleThumbnail(articleId, formFiles); + } } } } + if (selectedFileType === "document") { + if (thumbnailDocumentImg?.length > 0) { + const formFiles = new FormData(); + + formFiles.append("files", thumbnailDocumentImg[0]); + const resFile = await uploadArticleThumbnail(articleId, formFiles); + } + } + if (status === "scheduled") { const request = { id: articleId, @@ -406,10 +486,18 @@ export default function CreateArticleForm() { } }; - const handleRemoveFile = (file: FileWithPreview) => { - const uploadedFiles = files; - const filtered = uploadedFiles.filter((i) => i.name !== file.name); - setFiles([...filtered]); + const handleRemoveFile = (file: FileWithPreview | File, type: string) => { + if (type === "image") { + const uploadedFiles = files; + const filtered = uploadedFiles.filter((i) => i.name !== file.name); + setFiles([...filtered]); + } + + if (type === "document") { + const uploadedFiles = documentFiles; + const filtered = uploadedFiles.filter((i) => i.name !== file.name); + setDocumentFiles([...filtered]); + } }; const fileList = files.map((file, index) => ( @@ -444,17 +532,55 @@ export default function CreateArticleForm() {
)); - const handleFileChange = (event: React.ChangeEvent) => { + const documentList = documentFiles.map((file, index) => ( +
+
+
{renderPreview(file)}
+
+
{file.name}
+
+ {Math.round(file.size / 100) / 10 > 1000 ? ( + <>{(Math.round(file.size / 100) / 10000).toFixed(1)} + ) : ( + <>{(Math.round(file.size / 100) / 10).toFixed(1)} + )} + {" kb"} +
+
+
+ + +
+ )); + + const handleFileChange = ( + event: React.ChangeEvent, + type: string + ) => { const selectedFiles = event.target.files; if (selectedFiles) { - setThumbnailImg(Array.from(selectedFiles)); + if (type === "image") { + setThumbnailImg(Array.from(selectedFiles)); + } + if (type === "document") { + setThumbnailDocumentImg(Array.from(selectedFiles)); + } } }; @@ -612,43 +738,134 @@ export default function CreateArticleForm() { )}

File Media

- -
- -
- -

- Tarik file disini atau klik untuk upload. -

-
- ( Upload file dengan format .jpg, .jpeg, atau .png. Ukuran - maksimal 100mb.) -
-
-
- {files.length ? ( + { + setSelectedFileType(String(e)); + }} + > + -
{fileList}
-
- +
+ +
+ +

+ Tarik file disini atau klik untuk upload. +

+
+ ( Upload file dengan format .jpg, .jpeg, atau .png. Ukuran + maksimal 100mb.) +
+
+ {files.length ? ( + +
{fileList}
+
+ +
+
+ ) : null} - ) : null} - - {filesValidation !== "" && files.length < 1 && ( -

Upload File Media

- )} + {filesValidation !== "" && files.length < 1 && ( +

Upload File Media

+ )} + + + +
+ +
+ +

+ Tarik file disini atau klik untuk upload. +

+
+ ( Upload file dengan format .pdf, atau .docx. Ukuran + maksimal 100mb.) +
+
+
+ {documentFiles.length ? ( + +
{documentList}
+
+ +
+
+ ) : null} +
+ {documentValidation !== "" && documentFiles.length < 1 && ( +

Upload Document

+ )} +
+

Thubmnail

- {selectedMainImage && files.length >= selectedMainImage ? ( + {selectedFileType === "image" ? ( + selectedMainImage && files.length >= selectedMainImage ? ( +
+ thumbnail + +
+ ) : thumbnailImg.length > 0 ? ( +
+ thumbnail + +
+ ) : ( + <> + handleFileChange(e, "image")} + /> + {thumbnailValidation !== "" && ( +

+ Upload thumbnail atau pilih dari File Media +

+ )} + + ) + ) : thumbnailDocumentImg.length > 0 ? (
thumbnail @@ -657,45 +874,23 @@ export default function CreateArticleForm() { variant="bordered" size="sm" color="danger" - onClick={() => setSelectedMainImage(null)} - > - - -
- ) : thumbnailImg.length > 0 ? ( -
- thumbnail -
) : ( <> - {/* {" "} */} handleFileChange(e, "document")} /> - {thumbnailValidation !== "" && ( -

- Upload thumbnail atau pilih dari File Media -

+ {thumbnailDocumentValidation !== "" && ( +

Upload thumbnail

)} )} diff --git a/components/form/article/edit-article-form.tsx b/components/form/article/edit-article-form.tsx index 61b7349..0b9316a 100644 --- a/components/form/article/edit-article-form.tsx +++ b/components/form/article/edit-article-form.tsx @@ -26,6 +26,8 @@ import { import ReactSelect from "react-select"; import makeAnimated from "react-select/animated"; import { + Accordion, + AccordionItem, Calendar, Chip, Modal, @@ -36,10 +38,16 @@ import { Popover, PopoverContent, PopoverTrigger, + Tab, + Tabs, useDisclosure, } from "@heroui/react"; import GenerateSingleArticleForm from "./generate-ai-single-form"; -import { convertDateFormatNoTime, htmlToString } from "@/utils/global"; +import { + convertDateFormatNoTime, + formatMonthString, + htmlToString, +} from "@/utils/global"; import { close, error, loading } from "@/config/swal"; import { useParams, useRouter } from "next/navigation"; import { fromJSON, list } from "postcss"; @@ -47,6 +55,7 @@ import GetSeoScore from "./get-seo-score-form"; import Link from "next/link"; import { stringify } from "querystring"; import Cookies from "js-cookie"; +import { PdfIcon, WordIcon } from "@/components/icons/globals"; const ViewEditor = dynamic( () => { @@ -105,6 +114,20 @@ interface DiseData { additionalKeywords: string; } +const renderPreview = (file: File) => { + if (file.type === "application/pdf") { + return ; + } else if ( + file.type === + "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || + file.type === "application/msword" + ) { + return ; + } else { + return "File"; + } +}; + export default function EditArticleForm(props: { isDetail: boolean }) { const { isDetail } = props; const params = useParams(); @@ -116,6 +139,8 @@ export default function EditArticleForm(props: { isDetail: boolean }) { const router = useRouter(); const editor = useRef(null); const [files, setFiles] = useState([]); + const [documentFiles, setDocumentFiles] = useState([]); + const [useAi, setUseAI] = useState(false); const [listCategory, setListCategory] = useState([]); const [tag, setTag] = useState(""); @@ -134,20 +159,40 @@ export default function EditArticleForm(props: { isDetail: boolean }) { const [detailData, setDetailData] = useState(); const [startDateValue, setStartDateValue] = useState(null); const [timeValue, setTimeValue] = useState("00:00"); + const [documentValidation, setDocumentValidation] = useState(""); + const [filesValidation, setFileValidation] = useState(""); + const [selectedFileType, setSelectedFileType] = useState("image"); const { getRootProps, getInputProps } = useDropzone({ + accept: + selectedFileType === "image" + ? { + "image/*": [], + } + : { + "application/pdf": [], + "application/msword": [], + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + [], + "application/vnd.ms-powerpoint": [], + "application/vnd.openxmlformats-officedocument.presentationml.presentation": + [], + }, onDrop: (acceptedFiles) => { - setFiles((prevFiles) => [ - ...prevFiles, - ...acceptedFiles.map((file) => Object.assign(file)), - ]); + if (selectedFileType === "image") { + setFiles((prevFiles) => [ + ...prevFiles, + ...acceptedFiles.map((file) => Object.assign(file)), + ]); + } else { + setDocumentFiles((prevFiles) => [ + ...prevFiles, + ...acceptedFiles.map((file) => Object.assign(file)), + ]); + } }, multiple: true, - accept: { - "image/*": [], - }, }); - const formOptions = { resolver: zodResolver(createArticleSchema), defaultValues: { title: "", description: "", category: [], tags: [] }, @@ -181,7 +226,14 @@ export default function EditArticleForm(props: { isDetail: boolean }) { setThumbnail(data?.thumbnailUrl); setDiseId(data?.aiArticleId); setDetailFiles(data?.files); - + if ( + data.files[0].file_name.split(".")[1].includes("doc") || + data.files[0].file_name.split(".")[1].includes("pdf") + ) { + setSelectedFileType("document"); + } else { + setSelectedFileType("image"); + } setupInitCategory(data?.categories); close(); } @@ -358,12 +410,19 @@ export default function EditArticleForm(props: { isDetail: boolean }) { } }; - const handleRemoveFile = (file: FileWithPreview) => { - const uploadedFiles = files; - const filtered = uploadedFiles.filter((i) => i.name !== file.name); - setFiles([...filtered]); - }; + const handleRemoveFile = (file: FileWithPreview | File, type: string) => { + if (type === "image") { + const uploadedFiles = files; + const filtered = uploadedFiles.filter((i) => i.name !== file.name); + setFiles([...filtered]); + } + if (type === "document") { + const uploadedFiles = documentFiles; + const filtered = uploadedFiles.filter((i) => i.name !== file.name); + setDocumentFiles([...filtered]); + } + }; const fileList = files.map((file) => (
handleRemoveFile(file)} + onPress={() => handleRemoveFile(file, "image")} >
)); + const documentList = documentFiles.map((file, index) => ( +
+
+
{renderPreview(file)}
+
+
{file.name}
+
+ {Math.round(file.size / 100) / 10 > 1000 ? ( + <>{(Math.round(file.size / 100) / 10000).toFixed(1)} + ) : ( + <>{(Math.round(file.size / 100) / 10).toFixed(1)} + )} + {" kb"} +
+
+
+ + +
+ )); + const handleDeleteFile = (id: number) => { MySwal.fire({ title: "Hapus File", @@ -559,14 +648,6 @@ export default function EditArticleForm(props: { isDetail: boolean }) { control={control} name="description" render={({ field: { onChange, value } }) => - // - // isDetail ? ( ) : ( @@ -582,66 +663,167 @@ export default function EditArticleForm(props: { isDetail: boolean }) {

File Media

{!isDetail && ( - -
- -
- -

- Tarik file disini atau klik untuk upload. -

-
- ( Upload file dengan format .jpg, .jpeg, atau .png. Ukuran - maksimal 100mb.) -
-
-
- {files.length ? ( + { + setSelectedFileType(String(e)); + }} + > + -
{fileList}
-
- {/*
- -
- +
+ +
+ +

+ Tarik file disini atau klik untuk upload. +

+
+ ( Upload file dengan format .jpg, .jpeg, atau .png. Ukuran + maksimal 100mb.) +
-
*/}
+ {files.length ? ( + +
{fileList}
+
+ +
+
+ ) : null} - ) : null} - + {filesValidation !== "" && files.length < 1 && ( +

Upload File Media

+ )} + + + +
+ +
+ +

+ Tarik file disini atau klik untuk upload. +

+
+ ( Upload file dengan format .pdf, atau .docx. Ukuran + maksimal 100mb.) +
+
+
+ {documentFiles.length ? ( + +
{documentList}
+
+ +
+
+ ) : null} +
+ {documentValidation !== "" && documentFiles.length < 1 && ( +

Upload Document

+ )} +
+ )} {isDetail ? ( detailfiles.length > 0 ? ( - <> -
- main -
- - +
+
+
Nama File
+
+ {file?.file_name} +
+
+
+
Ukuran File
+
+ {Math.round(file?.size / 100) / 10 > 1000 ? ( + <> + {(Math.round(file?.size / 100) / 10000).toFixed( + 1 + )} + + ) : ( + <> + {(Math.round(file?.size / 100) / 10).toFixed(1)} + + )} + {" kb"} +
+
+ +
+
+ Tanggal Publish +
+
+ {formatMonthString(file?.created_at)} +
+
+
+ + + + + + )) + ) : ( + <> +
+ main +
+
+ {detailfiles?.map((file: any, index: number) => ( + setMainImage(index)} + className="cursor-pointer" + > + {`image-${index}`} + + ))} +
+ + ) ) : (

Belum Ada File

) @@ -653,15 +835,22 @@ export default function EditArticleForm(props: { isDetail: boolean }) { className=" flex justify-between border px-3.5 py-3 rounded-md" >
-
- {`image-${index}`} -
+ {selectedFileType === "image" ? ( +
+ {`image-${index}`} +
+ ) : file.file_name.split(".")[1].includes("pdf") ? ( + + ) : ( + + )} +
{file?.file_name} @@ -735,7 +924,7 @@ export default function EditArticleForm(props: { isDetail: boolean }) { variant="bordered" size="sm" color="danger" - onClick={() => setThumbnail("")} + onPress={() => setThumbnail("")} > @@ -754,7 +943,7 @@ export default function EditArticleForm(props: { isDetail: boolean }) { variant="bordered" size="sm" color="danger" - onClick={() => setThumbnailImg([])} + onPress={() => setThumbnailImg([])} > diff --git a/components/form/login.tsx b/components/form/login.tsx index bd1735d..ccef5fa 100644 --- a/components/form/login.tsx +++ b/components/form/login.tsx @@ -69,90 +69,90 @@ export default function Login() { error("Username & Password Wajib Diisi !"); } else { // login dengan otp - const response = await emailValidation(data); - if (response?.error) { - error("Username / Password Tidak Sesuai"); - return false; - } - - if (response?.data?.messages[0] === "Continue to setup email") { - setFirstLogin(true); - } else { - setNeedOtp(true); - } - - // login tanpa otp - // loading(); - // const response = await postSignIn(data); + // const response = await emailValidation(data); // if (response?.error) { // error("Username / Password Tidak Sesuai"); - // } else { - // const profile = await getProfile(response?.data?.data?.access_token); - // const dateTime: any = new Date(); - - // const newTime: any = dateTime.getTime() + 10 * 60 * 1000; - - // Cookies.set("access_token", response?.data?.data?.access_token, { - // expires: 1, - // }); - // Cookies.set("refresh_token", response?.data?.data?.refresh_token, { - // expires: 1, - // }); - // Cookies.set("time_refresh", newTime, { - // expires: 1, - // }); - // Cookies.set("is_first_login", "true", { - // secure: true, - // sameSite: "strict", - // }); - // const resActivity = await saveActivity( - // { - // activityTypeId: 1, - // url: "https://kontenhumas.com/auth", - // userId: profile?.data?.data?.id, - // }, - // accessData?.id_token - // ); - // Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { - // expires: 1, - // }); - // Cookies.set("uie", profile?.data?.data?.id, { - // expires: 1, - // }); - // Cookies.set("ufne", profile?.data?.data?.fullname, { - // expires: 1, - // }); - // Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { - // expires: 1, - // }); - // Cookies.set("username", profile?.data?.data?.username, { - // expires: 1, - // }); - // Cookies.set("urie", profile?.data?.data?.roleId, { - // expires: 1, - // }); - // Cookies.set("roleName", profile?.data?.data?.roleName, { - // expires: 1, - // }); - // Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { - // expires: 1, - // }); - // Cookies.set("ulne", profile?.data?.data?.userLevelId, { - // expires: 1, - // }); - // Cookies.set("urce", profile?.data?.data?.roleCode, { - // expires: 1, - // }); - // Cookies.set("email", profile?.data?.data?.email, { - // expires: 1, - // }); - // router.push("/admin/dashboard"); - // Cookies.set("status", "login", { - // expires: 1, - // }); - - // close(); + // return false; // } + + // if (response?.data?.messages[0] === "Continue to setup email") { + // setFirstLogin(true); + // } else { + // setNeedOtp(true); + // } + + // login tanpa otp + loading(); + const response = await postSignIn(data); + if (response?.error) { + error("Username / Password Tidak Sesuai"); + } else { + const profile = await getProfile(response?.data?.data?.access_token); + const dateTime: any = new Date(); + + const newTime: any = dateTime.getTime() + 10 * 60 * 1000; + + Cookies.set("access_token", response?.data?.data?.access_token, { + expires: 1, + }); + Cookies.set("refresh_token", response?.data?.data?.refresh_token, { + expires: 1, + }); + Cookies.set("time_refresh", newTime, { + expires: 1, + }); + Cookies.set("is_first_login", "true", { + secure: true, + sameSite: "strict", + }); + const resActivity = await saveActivity( + { + activityTypeId: 1, + url: "https://kontenhumas.com/auth", + userId: profile?.data?.data?.id, + }, + accessData?.id_token + ); + Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { + expires: 1, + }); + Cookies.set("uie", profile?.data?.data?.id, { + expires: 1, + }); + Cookies.set("ufne", profile?.data?.data?.fullname, { + expires: 1, + }); + Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { + expires: 1, + }); + Cookies.set("username", profile?.data?.data?.username, { + expires: 1, + }); + Cookies.set("urie", profile?.data?.data?.roleId, { + expires: 1, + }); + Cookies.set("roleName", profile?.data?.data?.roleName, { + expires: 1, + }); + Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { + expires: 1, + }); + Cookies.set("ulne", profile?.data?.data?.userLevelId, { + expires: 1, + }); + Cookies.set("urce", profile?.data?.data?.roleCode, { + expires: 1, + }); + Cookies.set("email", profile?.data?.data?.email, { + expires: 1, + }); + router.push("/admin/dashboard"); + Cookies.set("status", "login", { + expires: 1, + }); + + close(); + } } }; diff --git a/components/landing/HeaderNews.tsx b/components/landing/HeaderNews.tsx index e2fb6b0..f8ce4b1 100644 --- a/components/landing/HeaderNews.tsx +++ b/components/landing/HeaderNews.tsx @@ -5,6 +5,7 @@ import { CardFooter, CircularProgress, ScrollShadow, + Skeleton, } from "@heroui/react"; import { ChevronLeftIcon, ChevronRightIcon, EyeIcon } from "../icons"; import { Swiper, SwiperSlide, useSwiper } from "swiper/react"; @@ -82,7 +83,7 @@ export default function HeaderNews() {
- {banner ? ( + {banner.length > 0 ? ( ) : ( - + +
+ )}
@@ -159,51 +162,57 @@ export default function HeaderNews() { Hot Topik

- {hotNews?.map((data: any, index: number) => ( -
- {/* headernews */} -
- - {textEllipsis(data.title, 40)} - - - {textEllipsis(data.title, 66)} - -
-

- {convertDateFormat(data.createdAt)} WIB -

-

- - {data.viewCount === null ? 0 : data.viewCount} -

+ {hotNews.length > 0 ? ( + hotNews.map((data: any, index: number) => ( +
+
+ + {textEllipsis(data.title, 40)} + + + {textEllipsis(data.title, 66)} + +
+

+ {convertDateFormat(data.createdAt)} WIB +

+

+ + {data.viewCount === null ? 0 : data.viewCount} +

+
+ )) + ) : ( +
+ +
+ + +
+ + +
+ + +
+
- ))} + )}
- +
-
- {banner ? ( +
+ {banner.length > 0 ? ( - {banner?.map((newsItem: any, index: number) => ( + {banner.map((newsItem: any, index: number) => ( ) : ( - + +
+ )}
@@ -315,25 +326,42 @@ export default function HeaderNews() {
- {article?.map((list: any, index: number) => ( -
- -

{list?.title}

- -
-

- {convertDateFormat(list?.createdAt)} WIB -

-

- - {list?.viewCount === null ? 0 : list?.viewCount} -

+ {article.length > 0 ? ( + article.map((list: any, index: number) => ( +
+ +

{list?.title}

+ +
+

+ {convertDateFormat(list?.createdAt)} WIB +

+

+ + {list?.viewCount === null ? 0 : list?.viewCount} +

+
+ )) + ) : ( +
+ +
+ + +
+ + +
+ + +
+
- ))} + )}
- {article && ( + {article.length > 0 ? (
+ ) : ( +
+

Loading...

+
)}
{ + setHasMounted(true); + }, []); + + // Render + if (!hasMounted) return null; return (
state.locale); const setLanguage = storedLanguage((state) => state.setLocale); @@ -88,6 +89,22 @@ export default function NavbarHumas(props: { size: string }) { }); }; + let typingTimer: NodeJS.Timeout; + const doneTypingInterval = 1500; + + const handleKeyUp = () => { + clearTimeout(typingTimer); + typingTimer = setTimeout(doneTyping, doneTypingInterval); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + async function doneTyping() { + router.push(`/news/all?search=${search}`); + } + const searchInput = ( setSearch(e.target.value)} + onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} startContent={ } diff --git a/components/main/detail/e-magazine-detail.tsx b/components/main/detail/e-magazine-detail.tsx index ea8dbb2..c02db8c 100644 --- a/components/main/detail/e-magazine-detail.tsx +++ b/components/main/detail/e-magazine-detail.tsx @@ -114,13 +114,13 @@ export default function EMagazineDetail() { {file?.fileName}
-
+
Deskripsi
{file?.description == "" ? "-" : file?.description}
-
+
Ukuran File
{Math.round(file?.size / 100) / 10 > 1000 ? ( @@ -134,7 +134,7 @@ export default function EMagazineDetail() {
-
+
Tanggal Publish
{formatMonthString(file?.createdAt)} diff --git a/components/main/detail/list-news.tsx b/components/main/detail/list-news.tsx index b31870d..d2a7411 100644 --- a/components/main/detail/list-news.tsx +++ b/components/main/detail/list-news.tsx @@ -1,31 +1,68 @@ "use client"; import { + Autocomplete, + AutocompleteItem, BreadcrumbItem, Breadcrumbs, Button, + DatePicker, Image, Input, + Listbox, + ListboxItem, Pagination, + Popover, + PopoverContent, + PopoverTrigger, + Select, + SelectItem, } from "@heroui/react"; import { CalendarIcon, Calender, + ChevronLeftIcon, ChevronRightIcon, ClockIcon, EyeFilledIcon, SearchIcon, + TimesIcon, UserIcon, } from "../../icons"; import Link from "next/link"; import { useEffect, useRef, useState } from "react"; -import { getListArticle } from "@/services/article"; -import { formatMonthString, htmlToString, textEllipsis } from "@/utils/global"; +import { + getArticleByCategoryLanding, + getListArticle, +} from "@/services/article"; +import { + convertDateFormatNoTimeV2, + formatMonthString, + htmlToString, + textEllipsis, +} from "@/utils/global"; import { useParams, usePathname, useRouter, useSearchParams, } from "next/navigation"; +import { close, loading } from "@/config/swal"; +import { format } from "date-fns"; + +const months = [ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", +]; export default function ListNews() { const [article, setArticle] = useState([]); @@ -37,35 +74,97 @@ export default function ListNews() { const params = useParams(); const category = params?.name; const searchParams = useSearchParams(); - const search = searchParams.get("search"); + const categoryIds = searchParams.get("category_id"); + const [categories, setCategories] = useState([]); + const [search, setSearch] = useState(searchParams.get("search") || ""); const [searchValue, setSearchValue] = useState(search || ""); + const [categorySearch, setCategorySearch] = useState(""); + const [debouncedValue, setDebouncedValue] = useState(""); + const [selectedCategoryId, setSelectedCategoryId] = useState(); + + const today = new Date(); + const [year, setYear] = useState(today.getFullYear()); + + const [selectedMonth, setSelectedMonth] = useState( + searchParams.get("month") ? Number(searchParams.get("month")) - 1 : null + ); + const [selectedDate, setSelectedDate] = useState(null); + + const handleMonthClick = (monthIndex: number) => { + setSelectedMonth(monthIndex); + setSelectedDate(new Date(year, monthIndex, 1)); + }; + + useEffect(() => { + setSearch(searchParams.get("search") || ""); + setSearchValue(searchParams.get("search") || ""); + console.log( + "ini", + searchParams.get("month") ? Number(searchParams.get("month")) : null + ); + setSelectedMonth( + searchParams.get("month") ? Number(searchParams.get("month")) : null + ); + }, [searchParams]); useEffect(() => { getArticle(); - }, [page, category]); + }, [page, category, search, searchParams]); + + useEffect(() => { + getCategory(); + }, [debouncedValue]); + + const getCategory = async () => { + const res = await getArticleByCategoryLanding({ + limit: debouncedValue === "" ? "5" : "", + title: debouncedValue, + }); + if (res?.data?.data) { + setCategories(res?.data?.data); + } + }; async function getArticle() { - // loading(); - topRef.current?.scrollIntoView({ behavior: "smooth" }); + loading(); + // topRef.current?.scrollIntoView({ behavior: "smooth" }); const req = { page: page, search: searchValue || "", limit: "9", - // isPublish: pathname.includes("polda") ? false : true, isPublish: true, sort: "desc", categorySlug: pathname.includes("polda") || pathname.includes("satker") ? String(category) : "", + categoryIds: categoryIds ? categoryIds : "", + startDate: selectedMonth + ? convertDateFormatNoTimeV2(new Date(year, selectedMonth, 1)) + : "", + endDate: selectedMonth + ? convertDateFormatNoTimeV2(new Date(year, selectedMonth + 1, 0)) + : "", }; const response = await getListArticle(req); setArticle(response?.data?.data); setTotalPage(response?.data?.meta?.totalPage); - // close(); + close(); } + useEffect(() => { + const timeout = setTimeout(() => { + setDebouncedValue(categorySearch); + }, 1500); + + return () => clearTimeout(timeout); + }, [categorySearch]); + + const onInputChange = (value: string) => { + setCategorySearch(value); + }; + return (
@@ -76,38 +175,109 @@ export default function ListNews() {

Berita

-
+
{ - if (event.key === "Enter") { - router.push(pathname + `?search=${searchValue}`); - getArticle(); - } - }} + // onKeyDown={(event) => { + // if (event.key === "Enter") { + // router.push(pathname + `?search=${searchValue}`); + // getArticle(); + // } + // }} labelPlacement="outside" - placeholder="Search..." - value={searchValue || ""} + placeholder="Judul..." + value={searchValue} onValueChange={setSearchValue} - endContent={ - - } type="search" /> +
+ setSelectedCategoryId(e)} + inputProps={{ classNames: { inputWrapper: "border-1" } }} + > + {categories.length > 0 && + categories.map((category: any) => ( + + {category.title} + + ))} + +
+
+ + +
-

{formatMonthString(news?.updatedAt)}

+

{formatMonthString(news?.createdAt)}

-

{`${new Date(news?.updatedAt) +

{`${new Date(news?.createdAt) .getHours() .toString() - .padStart(2, "0")}:${new Date(news?.updatedAt) + .padStart(2, "0")}:${new Date(news?.createdAt) .getMinutes() .toString() .padStart(2, "0")}`}

diff --git a/components/main/detail/new-detail.tsx b/components/main/detail/new-detail.tsx index aec025a..a359c82 100644 --- a/components/main/detail/new-detail.tsx +++ b/components/main/detail/new-detail.tsx @@ -24,13 +24,12 @@ export default function NewsDetailPage(props: { datas: any }) { const [articles, setArticles] = useState([]); useEffect(() => { - // initFetch(); getArticles(); sendActivity(); }, []); async function getArticles() { - const req = { page: 1, search: "", limit: "50" }; + const req = { page: 1, search: "", limit: "50", isPublish: true }; const response = await getListArticle(req); setArticles(response?.data?.data); } @@ -70,7 +69,7 @@ export default function NewsDetailPage(props: { datas: any }) {
- +
diff --git a/components/page/detail-news.tsx b/components/page/detail-news.tsx index 4056688..1408a41 100644 --- a/components/page/detail-news.tsx +++ b/components/page/detail-news.tsx @@ -25,7 +25,7 @@ import { useEffect, useState } from "react"; import { image } from "@heroui/theme"; import Cookies from "js-cookie"; import { saveActivity } from "@/services/activity-log"; -import { Image } from "@heroui/react"; +import { Accordion, AccordionItem, Image } from "@heroui/react"; const token = Cookies.get("access_token"); const uid = Cookies.get("uie"); @@ -153,35 +153,101 @@ export default function DetailNews(props: { data: any; listArticle: any }) {

- {data?.files?.length > 0 && ( + {data.files[0].file_name.split(".")[1].includes("doc") || + data.files[0].file_name.split(".")[1].includes("pdf") ? ( Main Image + ) : ( + data?.files?.length > 0 && ( + Main Image + ) )}
- {data?.files?.length > 0 && ( -
- {data?.files?.map((file: any, index: number) => ( - setImageNow(index)} - className="cursor-pointer" - > - NextUI hero Image - - ))} -
- )} + {data?.files?.length > 0 && + (data.files[0].file_name.split(".")[1].includes("doc") || + data.files[0].file_name.split(".")[1].includes("pdf") ? ( + data.files?.map((file: any, index: number) => ( + + + {`File ${index + 1}`} +

+ } + > +
+
+
Nama File
+
+ {file?.file_name} +
+
+
+
Ukuran File
+
+ {Math.round(file?.size / 100) / 10 > 1000 ? ( + <>{(Math.round(file?.size / 100) / 10000).toFixed(1)} + ) : ( + <>{(Math.round(file?.size / 100) / 10).toFixed(1)} + )} + {" kb"} +
+
+ +
+
Tanggal Publish
+
+ {formatMonthString(file?.created_at)} +
+
+
+ + + +
+
+ )) + ) : ( +
+ {data?.files?.map((file: any, index: number) => ( + setImageNow(index)} + className="cursor-pointer" + > + NextUI hero Image + + ))} +
+ ))}
([]); useEffect(() => { async function getArticle() { - const req = { page: 1, search: "", limit: "10" }; + console.log("categories", categories); + const idString = categories.map((item: any) => item.id).join(","); + const req = { + page: 1, + search: "", + limit: "10", + isPublish: true, + categoryIds: idString, + }; const response = await getListArticle(req); setArticle(response?.data?.data); } diff --git a/components/page/sidebar-detail.tsx b/components/page/sidebar-detail.tsx index 913e806..15580c6 100644 --- a/components/page/sidebar-detail.tsx +++ b/components/page/sidebar-detail.tsx @@ -8,22 +8,38 @@ import "swiper/css/effect-fade"; import "swiper/css/pagination"; import Link from "next/link"; import { getListArticle } from "@/services/article"; -import { Card, CardFooter } from "@heroui/react"; +import { Card, CardFooter, Skeleton } from "@heroui/react"; import { convertDateFormat, textEllipsis } from "@/utils/global"; import Image from "next/image"; export default function SidebarDetail() { + const [articleMabes, setArticleMabes] = useState([]); const [article, setArticle] = useState([]); useEffect(() => { - async function getArticle() { - const req = { page: 1, search: "", limit: "10" }; - - const response = await getListArticle(req); - setArticle(response?.data?.data); - } getArticle(); + getArticleMabes(); }, []); + + async function getArticle() { + const req = { page: 1, search: "", limit: "10", isPublish: true }; + + const response = await getListArticle(req); + setArticle(response?.data?.data); + } + + async function getArticleMabes() { + const req = { + page: 1, + search: "", + limit: "10", + isPublish: true, + category: "586", + }; + + const response = await getListArticle(req); + setArticleMabes(response?.data?.data); + } return (
@@ -33,49 +49,57 @@ export default function SidebarDetail() {
- - {article?.map((newsItem: any) => ( - -
- headernews -
- -

- {textEllipsis(newsItem.title, 45)} + {articleMabes?.length < 1 ? ( + +

+ + ) : ( + + {articleMabes?.map((newsItem: any) => ( + +
+ headernews +
+ +

+ {textEllipsis(newsItem.title, 45)} +

+ +

+ {convertDateFormat(newsItem.createdAt)} WIB

- -

- {convertDateFormat(newsItem.createdAt)} WIB -

+
-
- - ))} - + + ))} + + )}
@@ -85,49 +109,57 @@ export default function SidebarDetail() {
- - {article?.map((newsItem: any) => ( - -
- headernews -
- -

- {textEllipsis(newsItem.title, 45)} + {article?.length < 1 ? ( + +

+ + ) : ( + + {article?.map((newsItem: any) => ( + +
+ headernews +
+ +

+ {textEllipsis(newsItem.title, 45)} +

+ +

+ {convertDateFormat(newsItem.createdAt)} WIB

- -

- {convertDateFormat(newsItem.createdAt)} WIB -

+
-
- - ))} - + + ))} + + )}
diff --git a/components/table/comment/comment-table.tsx b/components/table/comment/comment-table.tsx index d839d55..2305e86 100644 --- a/components/table/comment/comment-table.tsx +++ b/components/table/comment/comment-table.tsx @@ -142,7 +142,10 @@ export default function CommentTable() { }; const openArticle = async (id: number) => { + loading(); const res = await getArticleById(id); + close(); + if (res?.error) { MySwal.fire({ title: "Artikel tidak ditemukan atau telah dihapus", diff --git a/components/table/tabel-emajalah-polri.tsx b/components/table/tabel-emajalah-polri.tsx index c2319f9..55793dc 100644 --- a/components/table/tabel-emajalah-polri.tsx +++ b/components/table/tabel-emajalah-polri.tsx @@ -116,9 +116,9 @@ export default function ListEnewsPolri() { -
+ {/*

Tanggal Publikasi

- {/* setStartDateValue(e)} inputClassName="z-50 w-full text-sm bg-white border-1 border-gray-200 px-2 py-[6px] rounded-xl h-[40px] text-black" - /> */} -
+ /> +
*/}
( - + {item.title} diff --git a/services/article.ts b/services/article.ts index 4264e1f..fdc5342 100644 --- a/services/article.ts +++ b/services/article.ts @@ -34,7 +34,7 @@ export async function getListArticle(props: PaginationRequest) { }&title=${search}&startDate=${startDate || ""}&endDate=${ endDate || "" }&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${ - sort || "asc" + sort || "desc" }&category=${categorySlug || ""}&isBanner=${isBanner || ""}&categoryIds=${ categoryIds || "" }&createdByIds=${createdByIds || ""}`, @@ -222,3 +222,16 @@ export async function updateIsBannerArticle(id: number, status: boolean) { const pathUrl = `/articles/banner/${id}?isBanner=${status}`; return await httpPut(pathUrl, headers); } + +export async function getArticleByCategoryLanding(props: { + limit: string; + title: string; +}) { + const headers = { + "content-type": "application/json", + }; + return await httpGet( + `/article-categories?limit=${props.limit}&title=${props.title}`, + headers + ); +} From a7eef2e1dc51be712f21016761d2cae4ac2827ca Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Sat, 31 May 2025 20:56:53 +0700 Subject: [PATCH 2/8] fix:news all filter, pagination collapse --- components/main/detail/list-news.tsx | 201 ++++++++++++++++----------- 1 file changed, 118 insertions(+), 83 deletions(-) diff --git a/components/main/detail/list-news.tsx b/components/main/detail/list-news.tsx index d2a7411..9e6fd28 100644 --- a/components/main/detail/list-news.tsx +++ b/components/main/detail/list-news.tsx @@ -48,6 +48,7 @@ import { } from "next/navigation"; import { close, loading } from "@/config/swal"; import { format } from "date-fns"; +import { getCategoryById } from "@/services/master-categories"; const months = [ "Jan", @@ -76,11 +77,16 @@ export default function ListNews() { const searchParams = useSearchParams(); const categoryIds = searchParams.get("category_id"); const [categories, setCategories] = useState([]); - const [search, setSearch] = useState(searchParams.get("search") || ""); - const [searchValue, setSearchValue] = useState(search || ""); + const [searchValue, setSearchValue] = useState( + searchParams.get("search") || "" + ); const [categorySearch, setCategorySearch] = useState(""); const [debouncedValue, setDebouncedValue] = useState(""); - const [selectedCategoryId, setSelectedCategoryId] = useState(); + const [selectedCategoryId, setSelectedCategoryId] = useState( + categoryIds ? categoryIds : "" + ); + + const [count, setCount] = useState(0); const today = new Date(); const [year, setYear] = useState(today.getFullYear()); @@ -95,26 +101,26 @@ export default function ListNews() { setSelectedDate(new Date(year, monthIndex, 1)); }; - useEffect(() => { - setSearch(searchParams.get("search") || ""); - setSearchValue(searchParams.get("search") || ""); - console.log( - "ini", - searchParams.get("month") ? Number(searchParams.get("month")) : null - ); - setSelectedMonth( - searchParams.get("month") ? Number(searchParams.get("month")) : null - ); - }, [searchParams]); - - useEffect(() => { - getArticle(); - }, [page, category, search, searchParams]); + const getCategoryId = async () => { + if (categoryIds) { + const res = await getCategoryById(Number(selectedCategoryId)); + setCategorySearch(res?.data?.data.title); + setCategories([res?.data?.data]); + setCount(1); + } + }; useEffect(() => { getCategory(); + if (categoryIds && count == 0) { + getCategoryId(); + } }, [debouncedValue]); + useEffect(() => { + getArticle(); + }, [page]); + const getCategory = async () => { const res = await getArticleByCategoryLanding({ limit: debouncedValue === "" ? "5" : "", @@ -128,7 +134,6 @@ export default function ListNews() { async function getArticle() { loading(); // topRef.current?.scrollIntoView({ behavior: "smooth" }); - const req = { page: page, search: searchValue || "", @@ -139,13 +144,17 @@ export default function ListNews() { pathname.includes("polda") || pathname.includes("satker") ? String(category) : "", - categoryIds: categoryIds ? categoryIds : "", - startDate: selectedMonth - ? convertDateFormatNoTimeV2(new Date(year, selectedMonth, 1)) - : "", - endDate: selectedMonth - ? convertDateFormatNoTimeV2(new Date(year, selectedMonth + 1, 0)) - : "", + categoryIds: selectedCategoryId, + // categoryIds: + // selectedCategoryId && categorySearch !== "" ? selectedCategoryId : "", + startDate: + selectedDate && selectedMonth !== null + ? convertDateFormatNoTimeV2(new Date(year, selectedMonth, 1)) + : "", + endDate: + selectedDate && selectedMonth !== null + ? convertDateFormatNoTimeV2(new Date(year, selectedMonth + 1, 0)) + : "", }; const response = await getListArticle(req); setArticle(response?.data?.data); @@ -163,6 +172,9 @@ export default function ListNews() { const onInputChange = (value: string) => { setCategorySearch(value); + if (value === "") { + setSelectedCategoryId(""); + } }; return ( @@ -202,18 +214,22 @@ export default function ListNews() { labelPlacement="outside" variant="bordered" placeholder="Kategori" - classNames={{ base: "!mt-0" }} inputValue={categorySearch} + // selectedKey={selectedCategoryId} onInputChange={onInputChange} onSelectionChange={(e) => setSelectedCategoryId(e)} inputProps={{ classNames: { inputWrapper: "border-1" } }} + defaultItems={categories} > - {categories.length > 0 && + {/* {categories.length > 0 && categories.map((category: any) => ( - + {category.title} - ))} + ))} */} + {(item: any) => ( + {item.title} + )}
@@ -271,67 +287,86 @@ export default function ListNews() { )}
- */} + - + Cari + + {/* */} -
- {article?.map((news: any) => ( - Tidak ada Data + ) : ( + <> +
-
- -
-
-
{news?.title}
-
-
- -

{formatMonthString(news?.createdAt)}

+ {article?.map((news: any) => ( + +
+
-
- -

{`${new Date(news?.createdAt) - .getHours() - .toString() - .padStart(2, "0")}:${new Date(news?.createdAt) - .getMinutes() - .toString() - .padStart(2, "0")}`}

+
+
{news?.title}
+
+
+ +

{formatMonthString(news?.createdAt)}

+
+
+ +

{`${new Date(news?.createdAt) + .getHours() + .toString() + .padStart(2, "0")}:${new Date(news?.createdAt) + .getMinutes() + .toString() + .padStart(2, "0")}`}

+
+
+ +

{news?.createdByName}

+
+
+
+ {textEllipsis(htmlToString(news?.description), 165)} +
-
- -

{news?.createdByName}

-
-
-
- {textEllipsis(htmlToString(news?.description), 165)} -
-
- - ))} -
-
- -
+ + ))} +
+
+ +
+ + )} ); From b740ca8c449da95181cfb5969e3ca2e171b9a72b Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Sat, 31 May 2025 21:52:58 +0700 Subject: [PATCH 3/8] fix:pagination width --- components/main/dashboard/dashboard-container.tsx | 4 ++++ components/main/detail/list-news.tsx | 2 +- components/page/detail-news.tsx | 5 +++-- components/table/article-table.tsx | 2 ++ components/table/comment/comment-table.tsx | 2 ++ components/table/disestages/transcript-draft-table.tsx | 2 ++ components/table/magazine/magazine-table.tsx | 2 ++ components/table/master-categories/categories-table.tsx | 2 ++ components/table/master-role-table.tsx | 2 ++ components/table/master-user-table.tsx | 2 ++ .../master/master-user-level/master-user-level-table.tsx | 2 ++ components/table/static-page-table.tsx | 2 ++ components/table/suggestions/suggestions-table.tsx | 2 ++ 13 files changed, 28 insertions(+), 3 deletions(-) diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index d96c550..e216131 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -362,6 +362,8 @@ export default function DashboardContainer() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} @@ -492,6 +494,8 @@ export default function DashboardContainer() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={topPagespage} total={topPagesTotalPage} diff --git a/components/main/detail/list-news.tsx b/components/main/detail/list-news.tsx index 9e6fd28..8fd2432 100644 --- a/components/main/detail/list-news.tsx +++ b/components/main/detail/list-news.tsx @@ -361,7 +361,7 @@ export default function ListNews() { onChange={setPage} classNames={{ item: "w-fit px-3", - cursor: "w-fit px-3 text-center", + cursor: "w-fit px-3", }} /> diff --git a/components/page/detail-news.tsx b/components/page/detail-news.tsx index 1408a41..b07365e 100644 --- a/components/page/detail-news.tsx +++ b/components/page/detail-news.tsx @@ -189,7 +189,8 @@ export default function DetailNews(props: { data: any; listArticle: any }) { className="p-2" title={

- {`File ${index + 1}`} + {file.file_alt} + {/* {`File ${index + 1}`} */}

} > @@ -225,7 +226,7 @@ export default function DetailNews(props: { data: any; listArticle: any }) { radius="sm" // onPress={() => doDownload(file?.fileName, file?.title)} > - File + Buka File diff --git a/components/table/article-table.tsx b/components/table/article-table.tsx index adfcf42..62e3c51 100644 --- a/components/table/article-table.tsx +++ b/components/table/article-table.tsx @@ -664,6 +664,8 @@ export default function ArticleTable() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/comment/comment-table.tsx b/components/table/comment/comment-table.tsx index 2305e86..c8126cb 100644 --- a/components/table/comment/comment-table.tsx +++ b/components/table/comment/comment-table.tsx @@ -343,6 +343,8 @@ export default function CommentTable() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/disestages/transcript-draft-table.tsx b/components/table/disestages/transcript-draft-table.tsx index f5f7ee4..a4c90c7 100644 --- a/components/table/disestages/transcript-draft-table.tsx +++ b/components/table/disestages/transcript-draft-table.tsx @@ -179,6 +179,8 @@ export default function TranscriptDraftTable(props: { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/magazine/magazine-table.tsx b/components/table/magazine/magazine-table.tsx index 03a08ea..6fc83c6 100644 --- a/components/table/magazine/magazine-table.tsx +++ b/components/table/magazine/magazine-table.tsx @@ -342,6 +342,8 @@ export default function MagazineTable() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/master-categories/categories-table.tsx b/components/table/master-categories/categories-table.tsx index ab3bbc1..92dded9 100644 --- a/components/table/master-categories/categories-table.tsx +++ b/components/table/master-categories/categories-table.tsx @@ -467,6 +467,8 @@ export default function CategoriesTable(props: { triggerRefresh: boolean }) { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/master-role-table.tsx b/components/table/master-role-table.tsx index a9093ad..9c32b2d 100644 --- a/components/table/master-role-table.tsx +++ b/components/table/master-role-table.tsx @@ -288,6 +288,8 @@ export default function MasterRoleTable() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/master-user-table.tsx b/components/table/master-user-table.tsx index 797bc18..1e2f198 100644 --- a/components/table/master-user-table.tsx +++ b/components/table/master-user-table.tsx @@ -306,6 +306,8 @@ export default function MasterUserTable() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/master/master-user-level/master-user-level-table.tsx b/components/table/master/master-user-level/master-user-level-table.tsx index 6ca8be8..5ab3d58 100644 --- a/components/table/master/master-user-level/master-user-level-table.tsx +++ b/components/table/master/master-user-level/master-user-level-table.tsx @@ -378,6 +378,8 @@ export default function MasterUserLevelTable() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/static-page-table.tsx b/components/table/static-page-table.tsx index daaa7cc..66166c7 100644 --- a/components/table/static-page-table.tsx +++ b/components/table/static-page-table.tsx @@ -290,6 +290,8 @@ export default function StaticPageTable() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} diff --git a/components/table/suggestions/suggestions-table.tsx b/components/table/suggestions/suggestions-table.tsx index 2578e5c..1e9d72d 100644 --- a/components/table/suggestions/suggestions-table.tsx +++ b/components/table/suggestions/suggestions-table.tsx @@ -658,6 +658,8 @@ export default function SuggestionsTable() { classNames={{ base: "bg-transparent", wrapper: "bg-transparent", + item: "w-fit px-3", + cursor: "w-fit px-3", }} page={page} total={totalPage} From 53d291c31df02eedd171eac344f097ce0e44d2f6 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Sat, 31 May 2025 21:55:07 +0700 Subject: [PATCH 4/8] fix:login with otp --- components/form/login.tsx | 162 +++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/components/form/login.tsx b/components/form/login.tsx index ccef5fa..bd1735d 100644 --- a/components/form/login.tsx +++ b/components/form/login.tsx @@ -69,90 +69,90 @@ export default function Login() { error("Username & Password Wajib Diisi !"); } else { // login dengan otp - // const response = await emailValidation(data); - // if (response?.error) { - // error("Username / Password Tidak Sesuai"); - // return false; - // } - - // if (response?.data?.messages[0] === "Continue to setup email") { - // setFirstLogin(true); - // } else { - // setNeedOtp(true); - // } - - // login tanpa otp - loading(); - const response = await postSignIn(data); + const response = await emailValidation(data); if (response?.error) { error("Username / Password Tidak Sesuai"); - } else { - const profile = await getProfile(response?.data?.data?.access_token); - const dateTime: any = new Date(); - - const newTime: any = dateTime.getTime() + 10 * 60 * 1000; - - Cookies.set("access_token", response?.data?.data?.access_token, { - expires: 1, - }); - Cookies.set("refresh_token", response?.data?.data?.refresh_token, { - expires: 1, - }); - Cookies.set("time_refresh", newTime, { - expires: 1, - }); - Cookies.set("is_first_login", "true", { - secure: true, - sameSite: "strict", - }); - const resActivity = await saveActivity( - { - activityTypeId: 1, - url: "https://kontenhumas.com/auth", - userId: profile?.data?.data?.id, - }, - accessData?.id_token - ); - Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { - expires: 1, - }); - Cookies.set("uie", profile?.data?.data?.id, { - expires: 1, - }); - Cookies.set("ufne", profile?.data?.data?.fullname, { - expires: 1, - }); - Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { - expires: 1, - }); - Cookies.set("username", profile?.data?.data?.username, { - expires: 1, - }); - Cookies.set("urie", profile?.data?.data?.roleId, { - expires: 1, - }); - Cookies.set("roleName", profile?.data?.data?.roleName, { - expires: 1, - }); - Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { - expires: 1, - }); - Cookies.set("ulne", profile?.data?.data?.userLevelId, { - expires: 1, - }); - Cookies.set("urce", profile?.data?.data?.roleCode, { - expires: 1, - }); - Cookies.set("email", profile?.data?.data?.email, { - expires: 1, - }); - router.push("/admin/dashboard"); - Cookies.set("status", "login", { - expires: 1, - }); - - close(); + return false; } + + if (response?.data?.messages[0] === "Continue to setup email") { + setFirstLogin(true); + } else { + setNeedOtp(true); + } + + // login tanpa otp + // loading(); + // const response = await postSignIn(data); + // if (response?.error) { + // error("Username / Password Tidak Sesuai"); + // } else { + // const profile = await getProfile(response?.data?.data?.access_token); + // const dateTime: any = new Date(); + + // const newTime: any = dateTime.getTime() + 10 * 60 * 1000; + + // Cookies.set("access_token", response?.data?.data?.access_token, { + // expires: 1, + // }); + // Cookies.set("refresh_token", response?.data?.data?.refresh_token, { + // expires: 1, + // }); + // Cookies.set("time_refresh", newTime, { + // expires: 1, + // }); + // Cookies.set("is_first_login", "true", { + // secure: true, + // sameSite: "strict", + // }); + // const resActivity = await saveActivity( + // { + // activityTypeId: 1, + // url: "https://kontenhumas.com/auth", + // userId: profile?.data?.data?.id, + // }, + // accessData?.id_token + // ); + // Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { + // expires: 1, + // }); + // Cookies.set("uie", profile?.data?.data?.id, { + // expires: 1, + // }); + // Cookies.set("ufne", profile?.data?.data?.fullname, { + // expires: 1, + // }); + // Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { + // expires: 1, + // }); + // Cookies.set("username", profile?.data?.data?.username, { + // expires: 1, + // }); + // Cookies.set("urie", profile?.data?.data?.roleId, { + // expires: 1, + // }); + // Cookies.set("roleName", profile?.data?.data?.roleName, { + // expires: 1, + // }); + // Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { + // expires: 1, + // }); + // Cookies.set("ulne", profile?.data?.data?.userLevelId, { + // expires: 1, + // }); + // Cookies.set("urce", profile?.data?.data?.roleCode, { + // expires: 1, + // }); + // Cookies.set("email", profile?.data?.data?.email, { + // expires: 1, + // }); + // router.push("/admin/dashboard"); + // Cookies.set("status", "login", { + // expires: 1, + // }); + + // close(); + // } } }; From af5b8000cd74c1f14ffb7a0e67741a46af49946b Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Sun, 1 Jun 2025 02:00:00 +0700 Subject: [PATCH 5/8] feat: update list sidebar polda --- components/page/sidebar-detail.tsx | 23 ++++++++++++----------- services/article.ts | 5 +++-- types/globals.tsx | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/components/page/sidebar-detail.tsx b/components/page/sidebar-detail.tsx index 15580c6..6a4ce3a 100644 --- a/components/page/sidebar-detail.tsx +++ b/components/page/sidebar-detail.tsx @@ -14,20 +14,13 @@ import Image from "next/image"; export default function SidebarDetail() { const [articleMabes, setArticleMabes] = useState([]); - const [article, setArticle] = useState([]); + const [articlePolda, setArticlePolda] = useState([]); useEffect(() => { - getArticle(); getArticleMabes(); + getArticlePolda(); }, []); - async function getArticle() { - const req = { page: 1, search: "", limit: "10", isPublish: true }; - - const response = await getListArticle(req); - setArticle(response?.data?.data); - } - async function getArticleMabes() { const req = { page: 1, @@ -40,6 +33,14 @@ export default function SidebarDetail() { const response = await getListArticle(req); setArticleMabes(response?.data?.data); } + + async function getArticlePolda() { + const req = { page: 1, search: "", limit: "10", isPublish: true, isPolda: true }; + + const response = await getListArticle(req); + setArticlePolda(response?.data?.data); + } + return (
@@ -109,7 +110,7 @@ export default function SidebarDetail() {
- {article?.length < 1 ? ( + {articlePolda?.length < 1 ? (
@@ -129,7 +130,7 @@ export default function SidebarDetail() { className="mySwiper" slidesPerView={1} > - {article?.map((newsItem: any) => ( + {articlePolda?.map((newsItem: any) => (
Date: Mon, 2 Jun 2025 12:18:56 +0700 Subject: [PATCH 6/8] fix:category landing --- components/main/detail/list-news.tsx | 323 ++++++++++++++------------- components/page/detail-news.tsx | 31 ++- components/page/related-news.tsx | 4 +- 3 files changed, 191 insertions(+), 167 deletions(-) diff --git a/components/main/detail/list-news.tsx b/components/main/detail/list-news.tsx index 8fd2432..b578d0f 100644 --- a/components/main/detail/list-news.tsx +++ b/components/main/detail/list-news.tsx @@ -29,7 +29,7 @@ import { UserIcon, } from "../../icons"; import Link from "next/link"; -import { useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { getArticleByCategoryLanding, getListArticle, @@ -49,6 +49,7 @@ import { import { close, loading } from "@/config/swal"; import { format } from "date-fns"; import { getCategoryById } from "@/services/master-categories"; +import AsyncSelect from "react-select/async"; const months = [ "Jan", @@ -81,12 +82,7 @@ export default function ListNews() { searchParams.get("search") || "" ); const [categorySearch, setCategorySearch] = useState(""); - const [debouncedValue, setDebouncedValue] = useState(""); - const [selectedCategoryId, setSelectedCategoryId] = useState( - categoryIds ? categoryIds : "" - ); - - const [count, setCount] = useState(0); + const [selectedCategoryId, setSelectedCategoryId] = useState([]); const today = new Date(); const [year, setYear] = useState(today.getFullYear()); @@ -101,42 +97,43 @@ export default function ListNews() { setSelectedDate(new Date(year, monthIndex, 1)); }; - const getCategoryId = async () => { - if (categoryIds) { - const res = await getCategoryById(Number(selectedCategoryId)); - setCategorySearch(res?.data?.data.title); - setCategories([res?.data?.data]); - setCount(1); - } - }; - useEffect(() => { - getCategory(); - if (categoryIds && count == 0) { - getCategoryId(); + const search = searchParams.get("search"); + const category = searchParams.get("category_id"); + if (searchParams.get("search")) { + setSearchValue(String(searchParams.get("search"))); + getArticle({ title: String(search) }); } - }, [debouncedValue]); + + if (category && category !== "") { + getCategoryFromQueries(category.split(",")); + } + }, [searchParams]); + + const getCategoryFromQueries = async (category: string[]) => { + const temp = []; + for (const element of category) { + const res = await getCategoryById(Number(element)); + if (res?.data?.data) { + temp.push(res?.data?.data); + } + } + + const setup = setupCategory(temp); + setSelectedCategoryId(setup); + getArticle({ category: setup }); + }; useEffect(() => { getArticle(); - }, [page]); + }, [page, searchParams]); - const getCategory = async () => { - const res = await getArticleByCategoryLanding({ - limit: debouncedValue === "" ? "5" : "", - title: debouncedValue, - }); - if (res?.data?.data) { - setCategories(res?.data?.data); - } - }; - - async function getArticle() { + async function getArticle(props?: { title?: string; category?: any }) { loading(); // topRef.current?.scrollIntoView({ behavior: "smooth" }); const req = { page: page, - search: searchValue || "", + search: props?.title || searchValue || "", limit: "9", isPublish: true, sort: "desc", @@ -144,9 +141,12 @@ export default function ListNews() { pathname.includes("polda") || pathname.includes("satker") ? String(category) : "", - categoryIds: selectedCategoryId, - // categoryIds: - // selectedCategoryId && categorySearch !== "" ? selectedCategoryId : "", + categoryIds: props?.category + ? props.category.map((val: any) => val.id).join(",") + : selectedCategoryId.length > 0 + ? selectedCategoryId.map((val: any) => val.id).join(",") + : "", + startDate: selectedDate && selectedMonth !== null ? convertDateFormatNoTimeV2(new Date(year, selectedMonth, 1)) @@ -162,21 +162,52 @@ export default function ListNews() { close(); } - useEffect(() => { - const timeout = setTimeout(() => { - setDebouncedValue(categorySearch); - }, 1500); + const debounceTimeout = useRef(null); - return () => clearTimeout(timeout); - }, [categorySearch]); - - const onInputChange = (value: string) => { - setCategorySearch(value); - if (value === "") { - setSelectedCategoryId(""); + const getCategory = async (search?: string) => { + const res = await getArticleByCategoryLanding({ + // limit: debouncedValue === "" ? "5" : "", + // title: debouncedValue, + limit: !search || search === "" ? "5" : "", + title: search ? search : "", + }); + if (res?.data?.data) { + setCategories(res?.data?.data); + return res?.data?.data; } + return []; }; + const setupCategory = (data: any) => { + const temp = []; + for (const element of data) { + temp.push({ + id: element.id, + label: element.title, + value: element.id, + }); + } + return temp; + }; + + const loadOptions = useCallback( + (inputValue: string, callback: (options: any) => void) => { + if (debounceTimeout.current) { + clearTimeout(debounceTimeout.current); + } + + debounceTimeout.current = setTimeout(async () => { + try { + const data = await getCategory(inputValue); + callback(setupCategory(data)); + } catch (error) { + callback([]); + } + }, 1500); + }, + [] + ); + return (
@@ -187,118 +218,104 @@ export default function ListNews() {

Berita

-
- { - // if (event.key === "Enter") { - // router.push(pathname + `?search=${searchValue}`); - // getArticle(); - // } - // }} - labelPlacement="outside" - placeholder="Judul..." - value={searchValue} - onValueChange={setSearchValue} - type="search" - /> -
- +
+ { + // if (event.key === "Enter") { + // router.push(pathname + `?search=${searchValue}`); + // getArticle(); + // } + // }} labelPlacement="outside" - variant="bordered" + placeholder="Judul..." + value={searchValue} + onValueChange={setSearchValue} + type="search" + /> + setSelectedCategoryId(e)} - inputProps={{ classNames: { inputWrapper: "border-1" } }} - defaultItems={categories} - > - {/* {categories.length > 0 && - categories.map((category: any) => ( - - {category.title} - - ))} */} - {(item: any) => ( - {item.title} - )} - -
-
- - - - {" "} - {selectedDate - ? format(selectedDate, "MMMM yyyy") - : "Pilih Bulan"} - - - -
- - {year} - -
- -
- {months.map((month, idx) => ( + className="z-50 min-w-[300px] max-w-[600px]" + classNames={{ + control: () => + "border border-gray-300 border-1 rounded-xl min-w-[300px] max-w-[600px]", + menu: () => "z-50", + }} + value={selectedCategoryId} + onChange={setSelectedCategoryId} + /> +
+ + + + {" "} + {selectedDate + ? format(selectedDate, "MMMM yyyy") + : "Pilih Bulan"} + + + +
- ))} -
-
-
{" "} - {selectedDate && ( - setSelectedDate(null)} - > - - - )} + {year} + +
+ +
+ {months.map((month, idx) => ( + + ))} +
+ + {" "} + {selectedDate && ( + setSelectedDate(null)} + > + + + )} +
+ + {/* */}
- {/* */} - - {/* */}
{article?.length < 1 || !article ? (
Tidak ada Data
diff --git a/components/page/detail-news.tsx b/components/page/detail-news.tsx index b07365e..303b7bb 100644 --- a/components/page/detail-news.tsx +++ b/components/page/detail-news.tsx @@ -260,7 +260,11 @@ export default function DetailNews(props: { data: any; listArticle: any }) {

TAGS

{data?.categories?.map((category: any) => ( - + @@ -268,17 +272,20 @@ export default function DetailNews(props: { data: any; listArticle: any }) { ))}
- {data?.tags?.split(",").map((tag: any) => ( - - - - ))} + {data?.tags?.split(",").map( + (tag: any) => + tag !== "" && ( + + + + ) + )}
diff --git a/components/page/related-news.tsx b/components/page/related-news.tsx index 62c8a62..976485d 100644 --- a/components/page/related-news.tsx +++ b/components/page/related-news.tsx @@ -72,8 +72,8 @@ export default function RelatedNews(props: { categories: any }) { ); }} > - {article?.map((newsItem: any) => ( - + {article?.map((newsItem: any, index: number) => ( + Date: Tue, 3 Jun 2025 14:58:43 +0700 Subject: [PATCH 7/8] feat:filter date top article dashboar, create magazine category --- .../form/magazine/create-magazine-form.tsx | 60 +++++++++ .../main/dashboard/dashboard-container.tsx | 120 ++++++++++++++---- 2 files changed, 154 insertions(+), 26 deletions(-) diff --git a/components/form/magazine/create-magazine-form.tsx b/components/form/magazine/create-magazine-form.tsx index 6575916..9c510e6 100644 --- a/components/form/magazine/create-magazine-form.tsx +++ b/components/form/magazine/create-magazine-form.tsx @@ -81,6 +81,9 @@ const createArticleSchema = z.object({ }), }) ), + category: z.array(categorySchema).nonempty({ + message: "Kategori harus memiliki setidaknya satu item", + }), }); export default function NewCreateMagazineForm() { @@ -90,6 +93,30 @@ export default function NewCreateMagazineForm() { const editor = useRef(null); const [files, setFiles] = useState([]); const [thumbnailImg, setThumbnailImg] = useState([]); + const [listCategory, setListCategory] = useState([]); + + useEffect(() => { + fetchCategory(); + }, []); + + const fetchCategory = async () => { + const res = await getArticleByCategory(); + if (res?.data?.data) { + setupCategory(res?.data?.data); + } + }; + + const setupCategory = (data: any) => { + const temp = []; + for (const element of data) { + temp.push({ + id: element.id, + label: element.title, + value: element.id, + }); + } + setListCategory(temp); + }; const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { @@ -153,6 +180,8 @@ export default function NewCreateMagazineForm() { typeId: 1, slug: values.slug, statusId: 1, + categoryIds: values.category.map((a) => a.id).join(","), + // description: htmlToString(removeImgTags(values.description)), description: values.description, // rows: values.rows, @@ -385,6 +414,37 @@ export default function NewCreateMagazineForm() { {errors?.slug && (

{errors.slug?.message}

)} + +

Kategori

+ ( + + "!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500", + }} + classNamePrefix="select" + onChange={onChange} + closeMenuOnSelect={false} + components={animatedComponents} + isClearable={true} + isSearchable={true} + isMulti={true} + placeholder="Kategori..." + name="sub-module" + options={listCategory} + /> + )} + /> + {errors?.category && ( +

+ {errors.category?.message} +

+ )} +

Thumbnail

{thumbnailImg.length > 0 ? ( diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index e216131..fc027bd 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -89,6 +89,15 @@ export default function DashboardContainer() { endDate: parseDate(convertDateFormatNoTimeV2(new Date())), }); + const [topContentDate, setTopContentDate] = useState({ + startDate: parseDate( + convertDateFormatNoTimeV2( + new Date(new Date().setDate(new Date().getDate() - 7)) + ) + ), + endDate: parseDate(convertDateFormatNoTimeV2(new Date())), + }); + const [typeDate, setTypeDate] = useState("monthly"); const [summary, setSummary] = useState(); @@ -122,7 +131,17 @@ export default function DashboardContainer() { useEffect(() => { fetchTopPages(); - }, [topPagespage]); + }, [topPagespage, topContentDate]); + + const getDate = (data: any) => { + if (data === null) { + return ""; + } else { + return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${ + data.day < 10 ? `0${data.day}` : data.day + }`; + } + }; async function fetchTopPages() { const req = { @@ -130,6 +149,8 @@ export default function DashboardContainer() { page: topPagespage, search: "", sort: "desc", + startDate: getDate(topContentDate.startDate), + endDate: getDate(topContentDate.endDate), }; const res = await getTopArticles(req); setTopPages(getTableNumber(10, res.data?.data)); @@ -139,6 +160,7 @@ export default function DashboardContainer() { useEffect(() => { fetchPostCount(); }, [postContentDate]); + async function fetchPostCount() { const getDate = (data: any) => { return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${ @@ -432,14 +454,6 @@ export default function DashboardContainer() { Mingguan
- {/* setStartDateValue(e)} - inputClassName="z-50 w-full text-xs lg:text-sm bg-transparent border-1 border-gray-200 px-2 py-[6px] rounded-sm lg:rounded-lg h-[30px] lg:h-[40px] text-gray-600 dark:text-gray-300" - /> */}

Top Pages

+
+ + + + {convertDateFormatNoTime(topContentDate.startDate)} + + + + + setTopContentDate({ + startDate: e, + endDate: topContentDate.endDate, + }) + } + maxValue={topContentDate.endDate} + /> + + + - + + + + {convertDateFormatNoTime(topContentDate.endDate)} + + + + + setTopContentDate({ + startDate: topContentDate.startDate, + endDate: e, + }) + } + minValue={topContentDate.startDate} + /> + + +
No
Title
Visits
+ {(!topPages || topPages?.length < 1) && ( +
+ Tidak ada Data +
+ )} {topPages?.map((list) => (
{list?.no}
@@ -485,23 +551,25 @@ export default function DashboardContainer() {
{list?.viewCount}
))} -
- setTopPagesPage(page)} - /> -
+ {topPages?.length > 0 && ( +
+ setTopPagesPage(page)} + /> +
+ )}
From a0ee6421d12a35d1e5d705ca72967380feb0c25c Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Mon, 9 Jun 2025 16:36:24 +0700 Subject: [PATCH 8/8] fix:disable create edit delete --- app/(admin)/admin/article/page.tsx | 4 +++- app/(admin)/admin/master-category/page.tsx | 1 + components/main/dashboard/dashboard-container.tsx | 3 ++- components/table/article-table.tsx | 2 +- components/table/master-categories/categories-table.tsx | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/(admin)/admin/article/page.tsx b/app/(admin)/admin/article/page.tsx index a22e455..bc475e7 100644 --- a/app/(admin)/admin/article/page.tsx +++ b/app/(admin)/admin/article/page.tsx @@ -11,10 +11,12 @@ export default function BasicPage() {
- + + {/* */} diff --git a/components/table/article-table.tsx b/components/table/article-table.tsx index 62e3c51..51cf490 100644 --- a/components/table/article-table.tsx +++ b/components/table/article-table.tsx @@ -321,7 +321,7 @@ export default function ArticleTable() { - + copyUrlArticle(article.id, article.slug)} diff --git a/components/table/master-categories/categories-table.tsx b/components/table/master-categories/categories-table.tsx index 92dded9..0797142 100644 --- a/components/table/master-categories/categories-table.tsx +++ b/components/table/master-categories/categories-table.tsx @@ -284,7 +284,7 @@ export default function CategoriesTable(props: { triggerRefresh: boolean }) { - + openModal(category.id, true)}