"use client"; import { getComments } from "@/utils/CitizenReport"; import { useQuery } from "@tanstack/react-query"; import React, { useState } from "react"; import { FaRegComment } from "react-icons/fa"; import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@/components/ui/drawer"; import { Button } from "../ui/button"; import { MdSend } from "react-icons/md"; import { Textarea } from "../ui/textarea"; // Define types for props interface RequestCommentsProps { reportId: string; commentsCount: number; } const RequestComments: React.FC = ({ reportId, commentsCount, }) => { // Component state const [commentsCounts, setCommentsCounts] = useState(commentsCount); const [comment, setComment] = useState(""); const { data, isLoading, isError, isSuccess, refetch } = useQuery({ queryKey: ["Comments"], queryFn: () => getComments(reportId), // refetchOnWindowFocus: false, }); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); const requestBody = { comment: comment, }; try { const response = await fetch(`/api/comments/${reportId}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(requestBody), }); if (!response.ok) { throw new Error("Network response was not ok"); } // Handle success (e.g., clear the input, show a success message, etc.) setComment(""); console.log("Comment submitted successfully!"); } catch (error) { // Handle error console.error("There was an error submitting the comment:", error); } }; return ( <> e.stopPropagation()}>

هنوز نظری برای این درخواست ثبت نشده است.