shahrbin-citizen/components/Polls/PollDetails.tsx

73 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"use client";
import React, { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { useParams } from "next/navigation";
import { getSinglePoll } from "@/utils/CitizenPolls";
import { Button } from "../ui/button";
interface PollsProps {
id: number;
}
const PollDetails: React.FC<PollsProps> = ({ id }) => {
const [details, setDetails] = useState<any | null>(null);
const { data, isLoading, isError, isSuccess, refetch } = useQuery({
queryKey: ["PollssDetails", id],
queryFn: () => getSinglePoll(id),
});
useEffect(() => {
if (data) {
console.log(data);
console.log(data.data);
console.log(data.data[0]);
setDetails(data.data);
}
}, [data]);
return (
<div>
<h1
className=""
dangerouslySetInnerHTML={{ __html: details?.question }}
></h1>
{/* {details.pollType === 0 && (
<SelectivePoll
{...poll}
multiple={false}
disabled={poll.answer ? true : false}
onChange={(values) => handleChange(values, "selectedChoices")}
selecteds={values.selectedChoices}
/>
)}
{details.pollType === 1 && (
<SelectivePoll
multiple
{...poll}
disabled={poll.answer ? true : false}
onChange={(values) => handleChange(values, "selectedChoices")}
selecteds={values.selectedChoices}
/>
)} */}
{!details?.answer && (
<Button
// onClick={makeRequest}
// className={styles.pollButton}
// loading={submitLoading}
>
ارسال
</Button>
)}
{details?.answer && (
<p className="mt-8 text-red-600">
شما قبلا در این نظرسنجی شرکت کرده اید.
</p>
)}
</div>
);
};
export default PollDetails;