From a22a69e6d9538a8ffd6ad0e8f8143125aa2bcd1c Mon Sep 17 00:00:00 2001 From: YasamanKahdooei Date: Tue, 9 Jul 2024 14:58:48 +0330 Subject: [PATCH] Added part of PollComponent And Added part of Settings Components --- app/User/FAQ/page.tsx | 7 ++ app/User/PnpUser/page.tsx | 7 ++ app/User/Polls/[pollsId]/page.tsx | 2 +- app/User/Profile/page.tsx | 7 ++ app/User/Settings/page.tsx | 9 ++- components/Polls/PollDetails.tsx | 121 ++++++++++++++++++++++------ components/Settings/CardSetting.tsx | 30 +++++++ components/Settings/Settings.tsx | 14 ++++ components/Settings/SocialMedia.tsx | 46 +++++++++++ constants/index.tsx | 17 +++- utils/CitizenPolls.ts | 2 +- 11 files changed, 232 insertions(+), 30 deletions(-) create mode 100644 app/User/FAQ/page.tsx create mode 100644 app/User/PnpUser/page.tsx create mode 100644 app/User/Profile/page.tsx create mode 100644 components/Settings/CardSetting.tsx create mode 100644 components/Settings/Settings.tsx create mode 100644 components/Settings/SocialMedia.tsx diff --git a/app/User/FAQ/page.tsx b/app/User/FAQ/page.tsx new file mode 100644 index 0000000..cb2be10 --- /dev/null +++ b/app/User/FAQ/page.tsx @@ -0,0 +1,7 @@ +import React from 'react' + +export default function page() { + return ( +
page
+ ) +} diff --git a/app/User/PnpUser/page.tsx b/app/User/PnpUser/page.tsx new file mode 100644 index 0000000..cb2be10 --- /dev/null +++ b/app/User/PnpUser/page.tsx @@ -0,0 +1,7 @@ +import React from 'react' + +export default function page() { + return ( +
page
+ ) +} diff --git a/app/User/Polls/[pollsId]/page.tsx b/app/User/Polls/[pollsId]/page.tsx index 1ffc4f4..8755473 100644 --- a/app/User/Polls/[pollsId]/page.tsx +++ b/app/User/Polls/[pollsId]/page.tsx @@ -5,7 +5,7 @@ function page({params}: {params : any}) { const id = Number(params.pollsId); return ( -
+
) diff --git a/app/User/Profile/page.tsx b/app/User/Profile/page.tsx new file mode 100644 index 0000000..cb2be10 --- /dev/null +++ b/app/User/Profile/page.tsx @@ -0,0 +1,7 @@ +import React from 'react' + +export default function page() { + return ( +
page
+ ) +} diff --git a/app/User/Settings/page.tsx b/app/User/Settings/page.tsx index cb2be10..bae71f9 100644 --- a/app/User/Settings/page.tsx +++ b/app/User/Settings/page.tsx @@ -1,7 +1,10 @@ -import React from 'react' +import Settings from "@/components/Settings/Settings"; +import React from "react"; export default function page() { return ( -
page
- ) +
+ +
+ ); } diff --git a/components/Polls/PollDetails.tsx b/components/Polls/PollDetails.tsx index 5cfa15a..bdc1496 100644 --- a/components/Polls/PollDetails.tsx +++ b/components/Polls/PollDetails.tsx @@ -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 = ({ id }) => { + const router = useRouter(); const [details, setDetails] = useState(null); + const [satisfaction, setSatisfaction] = useState([]); const { data, isLoading, isError, isSuccess, refetch } = useQuery({ - queryKey: ["PollssDetails", id], + queryKey: ["PollsDetails", id], queryFn: () => getSinglePoll(id), }); @@ -25,23 +56,65 @@ const PollDetails: React.FC = ({ 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 ( -
+

- - {/* {details.pollType === 0 && ( - handleChange(values, "selectedChoices")} - selecteds={values.selectedChoices} - /> - )} - {details.pollType === 1 && ( +
+ {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 && ( = ({ id }) => { {!details?.answer && ( )} {details?.answer && ( -

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

+

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

)}
); diff --git a/components/Settings/CardSetting.tsx b/components/Settings/CardSetting.tsx new file mode 100644 index 0000000..f6070ca --- /dev/null +++ b/components/Settings/CardSetting.tsx @@ -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) => ( + +
+ {/* */} + {menuItem.icon} +

{menuItem.title}

+
+ + {/* */} + + + ))} + + ); +}; + +export default CardSetting; diff --git a/components/Settings/Settings.tsx b/components/Settings/Settings.tsx new file mode 100644 index 0000000..cf368f3 --- /dev/null +++ b/components/Settings/Settings.tsx @@ -0,0 +1,14 @@ +import React from "react"; +import CardSetting from "./CardSetting"; +import SocialMedia from "./SocialMedia"; + +function Settings() { + return ( +
+ + +
+ ); +} + +export default Settings; diff --git a/components/Settings/SocialMedia.tsx b/components/Settings/SocialMedia.tsx new file mode 100644 index 0000000..bbfcfc7 --- /dev/null +++ b/components/Settings/SocialMedia.tsx @@ -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 ( +
+ + + + + + + + + + + + + + + +
+ ); +}; + +export default SocialMedia; diff --git a/constants/index.tsx b/constants/index.tsx index 13f94df..c68569b 100644 --- a/constants/index.tsx +++ b/constants/index.tsx @@ -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: }, @@ -13,4 +19,13 @@ export const menuItems = [ { id: 5, title: "اخبار", href: "/User/News" , icon: }, { id: 6, title: "تنظیمات", href: "/User/Settings", icon: }, ]; - \ No newline at end of file + + + export const settingItems = [ + { id: 1, title: "ویرایش نمایه", href: "/User/Profile", icon: }, + { id: 2, title: "درباره ما", href: "#", icon: }, + { id: 3, title: "سوالات متداول", href: "/User/FAQ", icon: }, + { id: 4, title: "حریم خصوصی", href: "/User/PnpUser", icon: }, + { id: 5, title: "خروج از حساب کاربری", href: "#" , icon: }, + ]; + diff --git a/utils/CitizenPolls.ts b/utils/CitizenPolls.ts index cf5c7aa..7138f29 100644 --- a/utils/CitizenPolls.ts +++ b/utils/CitizenPolls.ts @@ -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}`,