diff --git a/components/form/article/edit-article-form.tsx b/components/form/article/edit-article-form.tsx index 5893a30..f238e33 100644 --- a/components/form/article/edit-article-form.tsx +++ b/components/form/article/edit-article-form.tsx @@ -18,13 +18,22 @@ import { deleteArticleFiles, getArticleByCategory, getArticleById, + submitApproval, updateArticle, uploadArticleFile, uploadArticleThumbnail, } from "@/service/article"; import ReactSelect from "react-select"; import makeAnimated from "react-select/animated"; -import { Chip } from "@heroui/react"; +import { + Chip, + Modal, + ModalBody, + ModalContent, + ModalFooter, + ModalHeader, + useDisclosure, +} from "@heroui/react"; import GenerateSingleArticleForm from "./generate-ai-single-form"; import { htmlToString } from "@/utils/global"; import { close, error, loading } from "@/config/swal"; @@ -112,6 +121,10 @@ export default function EditArticleForm(props: { isDetail: boolean }) { null ); const [thumbnailValidation, setThumbnailValidation] = useState(""); + const { isOpen, onOpen, onOpenChange } = useDisclosure(); + const [approvalStatus, setApprovalStatus] = useState(2); + const [approvalMessage, setApprovalMessage] = useState(""); + const [detailData, setDetailData] = useState(); const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { @@ -151,6 +164,7 @@ export default function EditArticleForm(props: { isDetail: boolean }) { loading(); const res = await getArticleById(id); const data = res.data?.data; + setDetailData(data); setValue("title", data?.title); setValue("slug", data?.slug); setValue("description", data?.htmlDescription); @@ -161,15 +175,14 @@ export default function EditArticleForm(props: { isDetail: boolean }) { setupInitCategory(data?.categories); close(); - console.log("Data Aritcle", data?.files); } const setupInitCategory = (data: any) => { const temp: CategoryType[] = []; - for (let i = 0; i < data.length; i++) { + for (let i = 0; i < data?.length; i++) { const datas = listCategory.filter((a) => a.id == data[i].id); if (datas[0]) { - temp.push(datas[0]); // Hanya tambahkan jika datas[0] ada + temp.push(datas[0]); } } setValue("category", temp as [CategoryType, ...CategoryType[]]); @@ -373,6 +386,49 @@ export default function EditArticleForm(props: { isDetail: boolean }) { } }; + const approval = async () => { + loading(); + const req = { + articleId: Number(id), + message: approvalMessage, + statusId: approvalStatus, + }; + const res = await submitApproval(req); + + if (res?.error) { + error(res.message); + return false; + } + close(); + initState(); + + MySwal.fire({ + title: "Sukses", + icon: "success", + confirmButtonColor: "#3085d6", + confirmButtonText: "OK", + }).then((result) => { + if (result.isConfirmed) { + } + }); + }; + + const doApproval = () => { + MySwal.fire({ + title: "Submit Data?", + text: "", + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#d33", + confirmButtonColor: "#3085d6", + confirmButtonText: "Submit", + }).then((result) => { + if (result.isConfirmed) { + approval(); + } + }); + }; + return (
+ {isDetail && detailData?.statusId === 1 && ( + + )} + {isDetail && detailData?.statusId === 1 && ( + + )} {!isDetail && (
+ + + {(onClose) => ( + <> + Approval + +

+ Status : + + {" "} + {approvalStatus === 3 ? "Disetujui" : "Ditolak"} + +

+