Added part of PollComponent And Added part of Settings Components

master
YasamanKahdooei 2024-07-09 14:58:48 +03:30
parent 2bb6da03cb
commit a22a69e6d9
11 changed files with 232 additions and 30 deletions

7
app/User/FAQ/page.tsx Normal file
View File

@ -0,0 +1,7 @@
import React from 'react'
export default function page() {
return (
<div>page</div>
)
}

View File

@ -0,0 +1,7 @@
import React from 'react'
export default function page() {
return (
<div>page</div>
)
}

View File

@ -5,7 +5,7 @@ function page({params}: {params : any}) {
const id = Number(params.pollsId); const id = Number(params.pollsId);
return ( return (
<div> <div className='h-full'>
<PollDetails id={id}/> <PollDetails id={id}/>
</div> </div>
) )

View File

@ -0,0 +1,7 @@
import React from 'react'
export default function page() {
return (
<div>page</div>
)
}

View File

@ -1,7 +1,10 @@
import React from 'react' import Settings from "@/components/Settings/Settings";
import React from "react";
export default function page() { export default function page() {
return ( return (
<div>page</div> <section className="w-full flex flex-row justify-between">
) <Settings />
</section>
);
} }

View File

@ -1,18 +1,49 @@
"use client"; "use client";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query"; import { useMutation, useQuery } from "@tanstack/react-query";
import { useParams } from "next/navigation"; import { useParams, useRouter } from "next/navigation";
import { getSinglePoll } from "@/utils/CitizenPolls"; import { getSinglePoll, postCitizenPollsAnswer } from "@/utils/CitizenPolls";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { RadioGroup, RadioGroupItem } from "../ui/radio-group";
import { Label } from "../ui/label";
import { toast } from "sonner";
interface PollsProps { interface PollsProps {
id: number; id: number;
} }
export class STR {
static removeTags(str = "") {
return str.replace(/(<([^>])+>)/gi, "").replace(/&nbsp;/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 PollDetails: React.FC<PollsProps> = ({ id }) => {
const router = useRouter();
const [details, setDetails] = useState<any | null>(null); const [details, setDetails] = useState<any | null>(null);
const [satisfaction, setSatisfaction] = useState<number[]>([]);
const { data, isLoading, isError, isSuccess, refetch } = useQuery({ const { data, isLoading, isError, isSuccess, refetch } = useQuery({
queryKey: ["PollssDetails", id], queryKey: ["PollsDetails", id],
queryFn: () => getSinglePoll(id), queryFn: () => getSinglePoll(id),
}); });
@ -25,23 +56,65 @@ const PollDetails: React.FC<PollsProps> = ({ id }) => {
} }
}, [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 ( return (
<div> <div className="bg-white w-1/2 mx-auto p-5 h-full flex flex-col items-center">
<h1 <h1
className="" className="font-bold mb-4"
dangerouslySetInnerHTML={{ __html: details?.question }} dangerouslySetInnerHTML={{ __html: details?.question }}
></h1> ></h1>
<div className=" flex flex-row flex-wrap w-full justify-between">
{/* {details.pollType === 0 && ( {details?.pollType === 0 &&
<SelectivePoll details?.choices.map((item: any) => (
{...poll} <RadioGroup
multiple={false} onValueChange={(value) => setSatisfaction([Number(value)])}
disabled={poll.answer ? true : false} className="flex flex-row mt-4 w-[48%] "
onChange={(values) => handleChange(values, "selectedChoices")} dir="rtl"
selecteds={values.selectedChoices} >
/> <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} />
{details.pollType === 1 && ( <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 <SelectivePoll
multiple multiple
{...poll} {...poll}
@ -53,17 +126,17 @@ const PollDetails: React.FC<PollsProps> = ({ id }) => {
{!details?.answer && ( {!details?.answer && (
<Button <Button
// onClick={makeRequest} className="w-full text-black bg-yellow rounded-md hover:bg-yellow/80 my-5"
// className={styles.pollButton} // onClick={makeRequest}
// loading={submitLoading} // className={styles.pollButton}
// loading={submitLoading}
onClick={onPollAnswerSubmit}
> >
ارسال ثبت
</Button> </Button>
)} )}
{details?.answer && ( {details?.answer && (
<p className="mt-8 text-red-600"> <p className="mt-8 text-red">شما قبلا در این نظرسنجی شرکت کرده اید.</p>
شما قبلا در این نظرسنجی شرکت کرده اید.
</p>
)} )}
</div> </div>
); );

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -4,6 +4,12 @@ import { PiSquaresFourFill } from "react-icons/pi";
import { FaChartBar } from "react-icons/fa"; import { FaChartBar } from "react-icons/fa";
import { TbWorld } from "react-icons/tb"; import { TbWorld } from "react-icons/tb";
import { FaCogs } from "react-icons/fa"; 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 = [ export const menuItems = [
{ id: 1, title: "صفحه اصلی", href: "/User/RecentRequest", icon: <FaList/>}, { id: 1, title: "صفحه اصلی", href: "/User/RecentRequest", icon: <FaList/>},
@ -14,3 +20,12 @@ export const menuItems = [
{ id: 6, title: "تنظیمات", href: "/User/Settings", icon: <FaCogs /> }, { 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 /> },
];

View File

@ -23,7 +23,7 @@ export async function getSinglePoll(id: number) {
// Post CitizenPollsAnswer {id} // Post CitizenPollsAnswer {id}
export async function postCitizenPollsAnswer( export async function postCitizenPollsAnswer(
id: number, id: number,
payload: { text: string; choicesIds: [number] } payload: { text: string; choicesIds:number[] }
) { ) {
const data = await axios.post( const data = await axios.post(
`/api/CitizenPolls/Polls/Answer/${id}`, `/api/CitizenPolls/Polls/Answer/${id}`,