"use client"; import { close, error, loading } from "@/config/swal"; import { FormEvent, Fragment, useEffect, useRef, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { Input, Textarea } from "@heroui/input"; import { Button } from "@heroui/button"; import { useParams, useRouter } from "next/navigation"; import { getCommentById, saveCommentStatus } from "@/services/comment"; import { Modal, ModalBody, ModalContent, ModalFooter, ModalHeader, useDisclosure, } from "@heroui/react"; import { getArticleById } from "@/services/article"; import Link from "next/link"; import { postArticleComment } from "@/services/master-user"; import Cookies from "js-cookie"; interface DetailComments { id: number; message: string; articleId: number; commentFromName: string; } export default function ReviewComment() { const MySwal = withReactContent(Swal); const { isOpen, onOpen, onOpenChange } = useDisclosure(); const params = useParams(); const id = Number(params?.id); const router = useRouter(); const [replyValue, setReplyValue] = useState(""); const [detailData, setDetailData] = useState(); const [detailArticle, setDetailArticle] = useState<{ id: number; slug: string; title: string; }>(); useEffect(() => { initFetch(); }, []); const initFetch = async () => { loading(); const res = await getCommentById(id); setDetailData(res?.data?.data); const resArticle = await getArticleById(res?.data?.data?.articleId); setDetailArticle(resArticle?.data?.data); close(); }; const handleCommentStatus = async (statusId: number) => { MySwal.fire({ title: "Submit Data", text: "", icon: "warning", showCancelButton: true, cancelButtonColor: "#d33", confirmButtonColor: "#3085d6", confirmButtonText: "Simpan", }).then((result) => { if (result.isConfirmed) { saveStatus(statusId); } }); }; const saveStatus = async (statusId: number) => { const req = { id: id, statusId: statusId }; const res = await saveCommentStatus(req); if (res?.error) { error(res.message); return false; } successSubmit("/admin/comment"); }; function successSubmit(redirect: string) { MySwal.fire({ title: "Sukses", icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: "OK", }).then((result) => { if (result.isConfirmed) { router.push(redirect); } }); } const sendComment = async () => { const data = { commentFromEmail: "ppid@polri.go.id", commentFromName: "Mabes Polri", articleId: detailData?.articleId, isPublic: true, message: replyValue, parentId: id, }; const res = await postArticleComment(data); if (res?.error) { error(res?.message); return false; } saveStatus(2); }; return (

Artikel

{detailArticle?.title}

Nama

Komentar