diff --git a/app/User/Feedback/[feedbackId]/page.tsx b/app/User/Feedback/[feedbackId]/page.tsx new file mode 100644 index 0000000..043c5c2 --- /dev/null +++ b/app/User/Feedback/[feedbackId]/page.tsx @@ -0,0 +1,10 @@ +import React from 'react' +import Feedback from "@/components/Feedback/Feedback"; + +function page({ params }: { params: any }) { + const id = params.feedbackId; + + return ; +} + +export default page; diff --git a/app/User/Feedback/page.tsx b/app/User/Feedback/page.tsx new file mode 100644 index 0000000..459d4e4 --- /dev/null +++ b/app/User/Feedback/page.tsx @@ -0,0 +1,9 @@ +import React from 'react' + +function page() { + return ( +
Feedback Page
+ ) +} + +export default page \ No newline at end of file diff --git a/components/Feedback/Feedback.tsx b/components/Feedback/Feedback.tsx new file mode 100644 index 0000000..4fd3195 --- /dev/null +++ b/components/Feedback/Feedback.tsx @@ -0,0 +1,282 @@ +// Feedback.tsx +"use client"; +import React, { useEffect, useState, MouseEvent } from "react"; +import { useForm } from "react-hook-form"; +import { number, z } from "zod"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useMutation, useQuery } from "@tanstack/react-query"; +import { useRouter } from "next/navigation"; +import { toast } from "sonner"; +import Rating from "@/components/Rating/Rating"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; +import { Label } from "@/components/ui/label"; +import { + getSingleCitizenReportMine, + postFeedback, + postObjection, +} from "@/utils/CitizenReport"; +import { convertFullTime } from "@/lib/utils"; +import { ThreeDots } from "react-loader-spinner"; +import { Value } from "@radix-ui/react-select"; + +// Define the post Feedback function type +type PostFeedbackArgs = { + id: string; + rating: number; +}; + +// Define the post Objection function type +type PostObjectionArgs = { + id: string; + payload: { + comments: string; + attachments: string[]; + }; +}; + +const FormSchema = z.object({ + comments: z.string().min(1, { + message: "لطفا توضیحات خود را وارد نمایید.", + }), + fileInput: z.string().optional(), + type: z.enum(["1", "0"], { + required_error: "لطفا یکی از دو گزینه زیر را انتخاب کنید.", + }), +}); + +interface FeedbackProps { + id: string; +} + +interface ReportData { + trackingNumber: string; + categoryTitle: string; + sent: string; +} + +const Feedback: React.FC = ({ id }) => { + const router = useRouter(); + const [satisfaction, setSatisfaction] = useState(2); + const [reportData, setReportData] = useState(null); + const [rating, setRating] = useState(0); // State to hold rating value + + const { data, isLoading, isSuccess } = useQuery({ + queryKey: ["ReportMineId", id], + queryFn: () => getSingleCitizenReportMine(id), + }); + + useEffect(() => { + if (data) { + setReportData(data.data); + } + }, [data, isSuccess]); + + const form = useForm>({ + resolver: zodResolver(FormSchema), + defaultValues: { + comments: "", + fileInput: "", + type: "0", + }, + }); + + const postFeedbackMutation = useMutation({ + mutationKey: ["postFeedback"], + mutationFn: ({ id, rating }: PostFeedbackArgs) => postFeedback(id, rating), + onSuccess: () => { + // setValues((prev) => ({ ...prev, rating: 0 })); + // N + form.reset(); + router.push("/User/MyRequest"); + toast.success("بازخورد شما با موفقیت ثبت شد"); + }, + onError: (error: any) => { + toast.error(`خطا در ارسال بازخورد: ${error.message}`); + }, + }); + + const postObjectionMutation = useMutation({ + mutationKey: ["postObjection"], + mutationFn: ({ id, payload }: PostObjectionArgs) => + postObjection(id, payload), + onSuccess: () => { + // N + form.reset(); + toast.success("اعتراض شما با موفقیت ثبت شد"); + router.push("/User/MyRequest"); + }, + onError: (error: any) => { + toast.error(`خطا در ارسال اعتراض: ${error.message}`); + }, + }); + + // N + const onRatingSubmit = () => { + postFeedbackMutation.mutate({ id, rating }); + }; + + const onObjectionSubmit = (data: z.infer) => { + const formData = new FormData(); + formData.append("comments", data.comments); + if (data.fileInput) { + formData.append("attachments", data.fileInput); + } + postObjectionMutation.mutate({ + id, + payload: { + comments: data.comments, + attachments: data.fileInput ? [data.fileInput as string] : [], + }, + }); + }; + + return ( +
+ {isLoading ? ( +
+ {/* Loading Spinner */} + +
در حال بارگذاری...
+
+ ) : ( + <> +

+ شهروند گرامی، درخواست شما با کد رهگیری{" "} + + {reportData?.trackingNumber} + {" "} + و مربوط به گروه موضوعی{" "} + + {reportData?.categoryTitle} + {" "} + ثبت شده در تاریخ{" "} + + {convertFullTime(reportData?.sent)} + {" "} + پیگیری و رسیدگی شد. +

+

+ لطفا میزان رضایتمندی خود را از فرآیند رسیدگی اعلام نمایید. +

+

+ نظرات شما باعث ارتقای سطح خدمت‌رسانی ما خواهد شد. +

+ +

+ آیا از نحوه ی پاسخگویی راضی بودید؟ +

+ + setSatisfaction(Number(value))} + className="flex flex-row justify-end mt-4 w-full" + > +
+ + +
+
+ + +
+
+ +
+ {satisfaction === 1 && ( +
+ form.setValue("fileInput", value)} + /> + + +
+ )} + + {satisfaction === 0 && ( + <> +

+ باتوجه به عدم رضایت شما از نحوه رسیدگی، درخواست برای بررسی + مجدد به واحد بازرسی ارجاع داده می‌شود. +

+
+ +
+ ( + + + توضیحات + + + + + + + )} + /> + ( + + + پیوست‌ها + + + + + + + )} + /> +
+ +
+ + + )} +
+ + )} +
+ ); +}; + +export default Feedback; diff --git a/components/Rating/Rating.tsx b/components/Rating/Rating.tsx new file mode 100644 index 0000000..5f9d7b1 --- /dev/null +++ b/components/Rating/Rating.tsx @@ -0,0 +1,75 @@ +import React, { useEffect, useState } from "react"; +import { FaStar } from "react-icons/fa"; + +interface Star { + id: number; + hover: boolean; + active: boolean; +} + +const defaultStars: Star[] = [ + { id: 1, hover: false, active: true }, + { id: 2, hover: false, active: true }, + { id: 3, hover: false, active: true }, + { id: 4, hover: false, active: false }, + { id: 5, hover: false, active: false }, +]; + +interface RatingProps { + onChange?: (value: number, name: string) => void; + name?: string; +} + +const Rating: React.FC = ({ onChange = () => {}, name = "" }) => { + const [stars, setStars] = useState(defaultStars); + const [rating, setRating] = useState(3); + + const onMouseEnter = (star: Star) => { + const index = stars.indexOf(star); + const modifiedStars = stars.map((s, i) => ({ ...s, hover: i <= index })); + setStars(modifiedStars); + }; + + const onMouseLeave = () => { + setStars((prev) => prev.map((s) => ({ ...s, hover: false }))); + }; + + const onClick = (star: Star) => { + const index = stars.indexOf(star); + setRating(index + 1); + onChange(index + 1, name); + const modifiedStars = stars.map((s, i) => ({ ...s, active: i <= index })); + setStars(modifiedStars); + }; + + console.log("stars2", stars); + console.log("rating2", rating); + + useEffect(() => { + setStars(defaultStars); + }, []); + + return ( +
+ {stars.map((star) => ( + onMouseEnter(star)} + onClick={() => onClick(star)} + > + + + ))} +
+ ); +}; + +export default Rating; diff --git a/components/RecentRequest/RecentRequests.tsx b/components/RecentRequest/RecentRequests.tsx index 15942c4..931aaaa 100644 --- a/components/RecentRequest/RecentRequests.tsx +++ b/components/RecentRequest/RecentRequests.tsx @@ -43,7 +43,7 @@ function RecentRequests() { return (
{/* Right */} -
+
{/* */} {/* */} diff --git a/components/RecentRequest/TabRequests.tsx b/components/RecentRequest/TabRequests.tsx index 48f717f..a4c6cb1 100644 --- a/components/RecentRequest/TabRequests.tsx +++ b/components/RecentRequest/TabRequests.tsx @@ -6,9 +6,12 @@ import NearestRequests from "./NearestRequests"; export function TabRequests() { return ( - + نزدیک ترین ها همه + + نقشه + @@ -16,6 +19,10 @@ export function TabRequests() { + + {/* */} +

Mapppp

+
); } diff --git a/components/Requests/RequestCard.tsx b/components/Requests/RequestCard.tsx index 365562d..9524257 100644 --- a/components/Requests/RequestCard.tsx +++ b/components/Requests/RequestCard.tsx @@ -13,6 +13,8 @@ import { getCitizenReport } from "@/utils/CitizenReport"; import { convertFullTime } from "@/lib/utils"; import { useRouter } from "next/navigation"; import RequestViolations from "./RequestViolations"; +import { usePathname } from "next/navigation"; +import { FaRegComment } from "react-icons/fa"; import { postReportViolation } from "@/utils/CitizenReport"; import RequestProcess from "./RequestProcess"; @@ -37,6 +39,8 @@ interface RequestItem { isLiked: boolean; likes: number; commentsCount: number; + isFeedbacked: boolean; + reportState: number; } interface RequestCardProps { @@ -56,10 +60,14 @@ type PostViolationArgs = { const RequestCard: React.FC = ({ item, isSelfRequest }) => { const router = useRouter(); + const pathname = usePathname(); - const handleClick = () => { + const handleClick = (e:any) => { if (isSelfRequest) { router.push(`/User/MyRequest/${item.id}`); + + e.stopPropagation(); + console.log("clickkkk"); } }; @@ -72,7 +80,7 @@ const RequestCard: React.FC = ({ item, isSelfRequest }) => { }; return ( - <> + <>
= ({ item, isSelfRequest }) => { = ({ item, isSelfRequest }) => { />
+ + {item.reportState == 1 && + !item?.isFeedbacked && + pathname == "/User/MyRequest" && ( +
{ + e.stopPropagation(); + // navigate(`/user/feedback/${item.id}`); + router.push(`/User/Feedback/${item.id}`); + }} + className=" flex gap-2 justify-center items-center bg-blue3 bg-opacity-40 transition delay-75 rounded-md py-1 " + > + +

+ ثبت بازخورد +

+
+ )}
diff --git a/components/ui/form.tsx b/components/ui/form.tsx index b6d044c..aa20c1f 100644 --- a/components/ui/form.tsx +++ b/components/ui/form.tsx @@ -93,7 +93,7 @@ const FormLabel = React.forwardRef< return (