Added part of PollComponent And Added part of Settings Components
parent
2bb6da03cb
commit
a22a69e6d9
|
|
@ -0,0 +1,7 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function page() {
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function page() {
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ function page({params}: {params : any}) {
|
|||
const id = Number(params.pollsId);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className='h-full'>
|
||||
<PollDetails id={id}/>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function page() {
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
import React from 'react'
|
||||
import Settings from "@/components/Settings/Settings";
|
||||
import React from "react";
|
||||
|
||||
export default function page() {
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
<section className="w-full flex flex-row justify-between">
|
||||
<Settings />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,49 @@
|
|||
"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 { 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<PollsProps> = ({ id }) => {
|
||||
const router = useRouter();
|
||||
const [details, setDetails] = useState<any | null>(null);
|
||||
const [satisfaction, setSatisfaction] = useState<number[]>([]);
|
||||
const { data, isLoading, isError, isSuccess, refetch } = useQuery({
|
||||
queryKey: ["PollssDetails", id],
|
||||
queryKey: ["PollsDetails", id],
|
||||
queryFn: () => getSinglePoll(id),
|
||||
});
|
||||
|
||||
|
|
@ -25,23 +56,65 @@ const PollDetails: React.FC<PollsProps> = ({ id }) => {
|
|||
}
|
||||
}, [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 (
|
||||
<div>
|
||||
<div className="bg-white w-1/2 mx-auto p-5 h-full flex flex-col items-center">
|
||||
<h1
|
||||
className=""
|
||||
className="font-bold mb-4"
|
||||
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 && (
|
||||
<div className=" flex flex-row flex-wrap w-full justify-between">
|
||||
{details?.pollType === 0 &&
|
||||
details?.choices.map((item: any) => (
|
||||
<RadioGroup
|
||||
onValueChange={(value) => setSatisfaction([Number(value)])}
|
||||
className="flex flex-row mt-4 w-[48%] "
|
||||
dir="rtl"
|
||||
>
|
||||
<div className="flex items-center space-x-2 border border-gray-500 rounded-md w-full p-3 gap-4">
|
||||
<RadioGroupItem value={item.id} id={item.id} />
|
||||
<Label htmlFor={item.id}>
|
||||
<p
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: STR.parseHtml(item.text),
|
||||
}}
|
||||
></p>
|
||||
{/* {STR.removeTags(item.text)} */}
|
||||
</Label>
|
||||
</div>
|
||||
</RadioGroup>
|
||||
// <SelectivePoll
|
||||
// {...poll}
|
||||
// multiple={false}
|
||||
// disabled={poll.answer ? true : false}
|
||||
// onChange={(values) => handleChange(values, "selectedChoices")}
|
||||
// selecteds={values.selectedChoices}
|
||||
// />
|
||||
))}
|
||||
</div>
|
||||
{/* {details.pollType === 1 && (
|
||||
<SelectivePoll
|
||||
multiple
|
||||
{...poll}
|
||||
|
|
@ -53,17 +126,17 @@ const PollDetails: React.FC<PollsProps> = ({ id }) => {
|
|||
|
||||
{!details?.answer && (
|
||||
<Button
|
||||
// onClick={makeRequest}
|
||||
// className={styles.pollButton}
|
||||
// loading={submitLoading}
|
||||
className="w-full text-black bg-yellow rounded-md hover:bg-yellow/80 my-5"
|
||||
// onClick={makeRequest}
|
||||
// className={styles.pollButton}
|
||||
// loading={submitLoading}
|
||||
onClick={onPollAnswerSubmit}
|
||||
>
|
||||
ارسال
|
||||
ثبت
|
||||
</Button>
|
||||
)}
|
||||
{details?.answer && (
|
||||
<p className="mt-8 text-red-600">
|
||||
شما قبلا در این نظرسنجی شرکت کرده اید.
|
||||
</p>
|
||||
<p className="mt-8 text-red">شما قبلا در این نظرسنجی شرکت کرده اید.</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
"use client";
|
||||
import React from "react";
|
||||
import { settingItems } from "@/constants";
|
||||
import { FaAngleLeft } from "react-icons/fa";
|
||||
import Link from "next/link";
|
||||
const CardSetting = ({ title = "", icon = "", onClick = (f: any) => f }) => {
|
||||
return (
|
||||
<>
|
||||
{settingItems.map((menuItem) => (
|
||||
<Link
|
||||
href={menuItem.href}
|
||||
className="cursor-pointer flex flex-row justify-between items-center bg-white shadow-[0_0_2px_1px_rgba(0,0,0,0.1)] rounded-md p-5 mb-3"
|
||||
onClick={onClick}
|
||||
key={menuItem.id}
|
||||
>
|
||||
<div className="flex flex-row items-center gap-3 text-gray-500">
|
||||
{/* <Icon name={icon} className="" /> */}
|
||||
{menuItem.icon}
|
||||
<p className="text-black font-medium">{menuItem.title}</p>
|
||||
</div>
|
||||
|
||||
{/* <Icon name={"angle-left"} className="" /> */}
|
||||
<FaAngleLeft className="text-gray-500"/>
|
||||
</Link>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default CardSetting;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import React from "react";
|
||||
import CardSetting from "./CardSetting";
|
||||
import SocialMedia from "./SocialMedia";
|
||||
|
||||
function Settings() {
|
||||
return (
|
||||
<div className="w-full h-full flex flex-col ">
|
||||
<CardSetting />
|
||||
<SocialMedia />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Settings;
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import Link from "next/link";
|
||||
import React from "react";
|
||||
import { SlSocialInstagram } from "react-icons/sl";
|
||||
import { FaWhatsapp } from "react-icons/fa";
|
||||
import { RiTelegramLine } from "react-icons/ri";
|
||||
import { TfiWorld } from "react-icons/tfi";
|
||||
|
||||
const SocialMedia = () => {
|
||||
return (
|
||||
<div className="flex flex-row gap-3 justify-center items-center my-5 mx-auto">
|
||||
<Link
|
||||
href={"https://instagram.com/shahrbin_app?utm_medium=copy_link"}
|
||||
target="blank"
|
||||
className="w-[50px] h-[50px] text-blue"
|
||||
>
|
||||
<SlSocialInstagram className="w-full h-full text-blue" />
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
href={"https://api.whatsapp.com/send?phone=989055685243"}
|
||||
target="blank"
|
||||
className="w-[50px] h-[50px] text-blue"
|
||||
>
|
||||
<FaWhatsapp className="w-full h-full text-blue" />
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
href={"https://t.me/shahrbin"}
|
||||
target="blank"
|
||||
className="w-[50px] h-[50px] text-blue"
|
||||
>
|
||||
<RiTelegramLine className="w-full h-full text-blue" />
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
href={"https://shahrbinapp.com"}
|
||||
target="blank"
|
||||
className="w-[50px] h-[50px] text-blue"
|
||||
>
|
||||
<TfiWorld className="w-full h-full text-blue" />
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SocialMedia;
|
||||
|
|
@ -4,6 +4,12 @@ import { PiSquaresFourFill } from "react-icons/pi";
|
|||
import { FaChartBar } from "react-icons/fa";
|
||||
import { TbWorld } from "react-icons/tb";
|
||||
import { FaCogs } from "react-icons/fa";
|
||||
// ..
|
||||
import { FaUser } from "react-icons/fa";
|
||||
import { FaInfo } from "react-icons/fa";
|
||||
import { FaQuestionCircle } from "react-icons/fa";
|
||||
import { FaLock } from "react-icons/fa";
|
||||
import { LuLogOut } from "react-icons/lu";
|
||||
|
||||
export const menuItems = [
|
||||
{ id: 1, title: "صفحه اصلی", href: "/User/RecentRequest", icon: <FaList/>},
|
||||
|
|
@ -14,3 +20,12 @@ export const menuItems = [
|
|||
{ id: 6, title: "تنظیمات", href: "/User/Settings", icon: <FaCogs /> },
|
||||
];
|
||||
|
||||
|
||||
export const settingItems = [
|
||||
{ id: 1, title: "ویرایش نمایه", href: "/User/Profile", icon: <FaUser/>},
|
||||
{ id: 2, title: "درباره ما", href: "#", icon: <FaInfo /> },
|
||||
{ id: 3, title: "سوالات متداول", href: "/User/FAQ", icon: <FaQuestionCircle /> },
|
||||
{ id: 4, title: "حریم خصوصی", href: "/User/PnpUser", icon: <FaLock /> },
|
||||
{ id: 5, title: "خروج از حساب کاربری", href: "#" , icon: <LuLogOut /> },
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export async function getSinglePoll(id: number) {
|
|||
// Post CitizenPollsAnswer {id}
|
||||
export async function postCitizenPollsAnswer(
|
||||
id: number,
|
||||
payload: { text: string; choicesIds: [number] }
|
||||
payload: { text: string; choicesIds:number[] }
|
||||
) {
|
||||
const data = await axios.post(
|
||||
`/api/CitizenPolls/Polls/Answer/${id}`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue