"use client"; import React, { useEffect, useState } from "react"; import { useMutation, useQuery } from "@tanstack/react-query"; import { useParams, useRouter } from "next/navigation"; import { getSinglePoll, postCitizenPollsAnswer } from "@/utils/CitizenPolls"; import { Button } from "../ui/button"; import { RadioGroup, RadioGroupItem } from "../ui/radio-group"; import { Label } from "../ui/label"; import { toast } from "sonner"; interface PollsProps { id: number; } export class STR { static removeTags(str = "") { return str.replace(/(<([^>])+>)/gi, "").replace(/ /gi, ""); } static parseHtml(str: any) { const div = document.createElement("div"); div.innerHTML = str; const images = div.getElementsByTagName("img"); // if (images.length > 0) { // Array.from(images).forEach((image) => { // let imageSrc = image.getAttribute("src"); // image.src = URI.createMediaUri(imageSrc); // }); // } return div.innerHTML; } } type PostAnswerArgs = { id: number; payload: { text: string; choicesIds: number[]; }; }; const PollDetails: React.FC = ({ id }) => { const router = useRouter(); const [details, setDetails] = useState(null); const [satisfaction, setSatisfaction] = useState([]); const { data, isLoading, isError, isSuccess, refetch } = useQuery({ queryKey: ["PollsDetails", id], queryFn: () => getSinglePoll(id), }); useEffect(() => { if (data) { console.log(data); console.log(data.data); console.log(data.data[0]); setDetails(data.data); } }, [data]); const postPollAnswerMutation = useMutation({ mutationKey: ["postAnswer"], mutationFn: ({ id, payload }: PostAnswerArgs) => postCitizenPollsAnswer(id, payload), onSuccess: () => { toast.success("پاسخ شما با موفقیت ثبت شد"); router.push("/User/Polls"); }, onError: (error: any) => { toast.error(`خطا در ارسال پاسخ: ${error.message}`); }, }); const onPollAnswerSubmit = () => { postPollAnswerMutation.mutate({ id, payload: { text: "", choicesIds: satisfaction, }, }); }; return (

{details?.pollType === 0 && details?.choices.map((item: any) => ( setSatisfaction([Number(value)])} className="flex flex-row mt-4 w-[48%] " dir="rtl" >
// handleChange(values, "selectedChoices")} // selecteds={values.selectedChoices} // /> ))}
{/* {details.pollType === 1 && ( handleChange(values, "selectedChoices")} selecteds={values.selectedChoices} /> )} */} {!details?.answer && ( )} {details?.answer && (

شما قبلا در این نظرسنجی شرکت کرده اید.

)}
); }; export default PollDetails;