From f2e3d7f73175f5d6b9317bc7d9375ece8bd88b75 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Wed, 12 Feb 2025 12:07:28 +0700 Subject: [PATCH] feat:scheduled create article --- app/auth/page.tsx | 21 +++-- .../form/article/create-article-form.tsx | 91 ++++++++++++++++--- components/layout/navbar/NavbarHumas.tsx | 10 +- .../main/dashboard/dashboard-container.tsx | 23 +++-- 4 files changed, 111 insertions(+), 34 deletions(-) diff --git a/app/auth/page.tsx b/app/auth/page.tsx index 7687f9e..932d056 100644 --- a/app/auth/page.tsx +++ b/app/auth/page.tsx @@ -6,18 +6,21 @@ import Cookies from "js-cookie"; import React, { useEffect, useState } from "react"; export default function AuthPage() { - const isAuthenticated = Cookies.get("is_authenticated") || "false"; + // const isAuthenticated = Cookies.get("is_authenticated") || "false"; - console.log("isAuthenticated : ", isAuthenticated); + // console.log("isAuthenticated : ", isAuthenticated); - const [hasMounted, setHasMounted] = useState(false); + // const [hasMounted, setHasMounted] = useState(false); - useEffect(() => { - setHasMounted(true); - }, []); + // useEffect(() => { + // setHasMounted(true); + // }, []); - // Render - if (!hasMounted) return null; + // // Render + // if (!hasMounted) return null; - return isAuthenticated == "true" ? : ; + return ; + + // isAuthenticated == "true" ? + // : ; } diff --git a/components/form/article/create-article-form.tsx b/components/form/article/create-article-form.tsx index c68e068..43fc9d0 100644 --- a/components/form/article/create-article-form.tsx +++ b/components/form/article/create-article-form.tsx @@ -1,5 +1,12 @@ "use client"; -import { FormEvent, Fragment, useEffect, useRef, useState } from "react"; +import { + FormEvent, + Fragment, + useCallback, + useEffect, + useRef, + useState, +} from "react"; import { Controller, useForm } from "react-hook-form"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -24,9 +31,15 @@ import makeAnimated from "react-select/animated"; import { Checkbox, Chip, + Modal, + ModalBody, + ModalContent, + ModalFooter, + ModalHeader, Select, SelectItem, SelectSection, + useDisclosure, } from "@nextui-org/react"; import GenerateSingleArticleForm from "./generate-ai-single-form"; import { htmlToString } from "@/utils/global"; @@ -39,6 +52,7 @@ import { updateManualArticle, } from "@/service/generate-article"; import GenerateContentRewriteForm from "./generate-ai-content-rewrite-form"; +import Datepicker from "react-tailwindcss-datepicker"; const CustomEditor = dynamic( () => { @@ -92,6 +106,8 @@ const createArticleSchema = z.object({ }); export default function CreateArticleForm() { + const { isOpen, onOpen, onOpenChange } = useDisclosure(); + const animatedComponents = makeAnimated(); const MySwal = withReactContent(Swal); const router = useRouter(); @@ -108,7 +124,16 @@ export default function CreateArticleForm() { const [filesValidation, setFileValidation] = useState(""); const [diseData, setDiseData] = useState(); const [selectedWritingType, setSelectedWritingType] = useState("single"); - const [status, setStatus] = useState<"publish" | "draft">("publish"); + const [status, setStatus] = useState<"publish" | "draft" | "scheduled">( + "publish" + ); + const [isScheduled, setIsScheduled] = useState(false); + const [timeValue, setTimeValue] = useState(""); + + const [startDateValue, setStartDateValue] = useState({ + startDate: null, + endDate: null, + }); const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { @@ -132,7 +157,7 @@ export default function CreateArticleForm() { register, control, handleSubmit, - formState: { errors }, + formState: { errors, isValid }, setValue, getValues, watch, @@ -177,8 +202,7 @@ export default function CreateArticleForm() { } } else { setThumbnailValidation(""); - setFileValidation("Required"); - + setFileValidation(""); MySwal.fire({ title: "Simpan Data", text: "", @@ -426,14 +450,6 @@ export default function CreateArticleForm() { setValue("tags", uniqueArray as [string, ...string[]]); }; - useEffect(() => { - console.log("seklec", selectedMainImage); - console.log("seklssssec", files); - if (selectedMainImage) { - console.log("filll", files[selectedMainImage]); - } - }, [selectedMainImage]); - return (
{errors.tags?.message}

)} +
+ + Publish dengan Jadwal + + {isScheduled && ( +
+
+

Tanggal

+ setStartDateValue(e)} + inputClassName="z-50 w-full text-xs lg:text-sm bg-white dark bg-black 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" + /> +
+
+

Waktu

+ +
+
+ )} +
+
diff --git a/components/layout/navbar/NavbarHumas.tsx b/components/layout/navbar/NavbarHumas.tsx index f8226b2..8a8371c 100644 --- a/components/layout/navbar/NavbarHumas.tsx +++ b/components/layout/navbar/NavbarHumas.tsx @@ -68,11 +68,11 @@ export default function NavbarHumas(props: { size: string }) { const language = storedLanguage((state) => state.locale); const setLanguage = storedLanguage((state) => state.setLocale); - useEffect(() => { - if (!isAuthenticated) { - onLogout(); - } - }, [token]); + // useEffect(() => { + // if (!isAuthenticated) { + // onLogout(); + // } + // }, [token]); const onLogout = () => { Object.keys(Cookies.get()).forEach((cookieName) => { diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index 513908c..2b796ad 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -68,6 +68,15 @@ const dummyTopPages = [ }, ]; +const dummyViz = { + todayPost: 10, + weeklyPost: 56, + totalPost: 223, + totalView: 422, + totalShare: 126, + totalComment: 67, +}; + const dummyPostCount = [ { id: 1, name: "Polda Sumatera Utara", count: 132 }, { id: 2, name: "Polda Metro Jaya", count: 128 }, @@ -210,10 +219,12 @@ export default function DashboardContainer() {

- 4 Post Hari ini + {dummyViz.todayPost} Post{" "} + Hari ini

- 12 Post Minggu ini + {dummyViz.weeklyPost} Post{" "} + Minggu ini

@@ -223,28 +234,28 @@ export default function DashboardContainer() {
Total post
-
121
+
{dummyViz.totalPost}
Total views
-
154
+
{dummyViz.totalView}
Total share
-
154
+
{dummyViz.totalShare}
Total comment
-
530
+
{dummyViz.totalComment}