From d82592c189e54eaa200850dd0458a13c6e5dbdaa Mon Sep 17 00:00:00 2001 From: YasamanKahdooei Date: Mon, 27 May 2024 15:52:19 +0330 Subject: [PATCH] Added part of RequestViolation Component --- components/Requests/RequestCard.tsx | 3 +- components/Requests/RequestComment.tsx | 8 +- components/Requests/RequestComments.tsx | 10 +- components/Requests/RequestViolations.tsx | 166 ++++++++++++++++++ components/ui/select.tsx | 22 +-- package-lock.json | 202 ++++++++++++++++++++++ package.json | 1 + utils/CitizenCommon.ts | 18 +- utils/CitizenReport.ts | 37 +++- 9 files changed, 428 insertions(+), 39 deletions(-) create mode 100644 components/Requests/RequestViolations.tsx diff --git a/components/Requests/RequestCard.tsx b/components/Requests/RequestCard.tsx index 89302b9..d744eb5 100644 --- a/components/Requests/RequestCard.tsx +++ b/components/Requests/RequestCard.tsx @@ -13,6 +13,7 @@ import { useQuery } from "@tanstack/react-query"; import { getCitizenReport } from "@/utils/CitizenReport"; import { convertFullTime } from "@/lib/utils"; import { useRouter } from "next/navigation"; +import RequestViolations from "./RequestViolations"; // interface RequestCardProps { // isSelfRequest?: boolean; @@ -104,7 +105,7 @@ const RequestCard: React.FC = ({ item, isSelfRequest }) => {
- + { @@ -30,7 +31,9 @@ const RequestComment: React.FC = ({ dateTime, user, canDelete, + onDeleteCommentSuccess, }) => { + const DeleteComment = useMutation({ mutationKey: ["deleteComment"], mutationFn: deleteComment, @@ -43,6 +46,7 @@ const RequestComment: React.FC = ({ toast(<>{error.message}, { className: "!bg-red-500 !text-white", }); + onDeleteCommentSuccess(); }, }); @@ -84,9 +88,9 @@ const RequestComment: React.FC = ({ {comment}

{canDelete && ( - + )} - +
diff --git a/components/Requests/RequestComments.tsx b/components/Requests/RequestComments.tsx index 29bacf8..ebf34d2 100644 --- a/components/Requests/RequestComments.tsx +++ b/components/Requests/RequestComments.tsx @@ -33,6 +33,7 @@ interface Comment { dateTime: string; user:any; canDelete:boolean; + onDeleteCommentSuccess:any } // Define the post comment function type @@ -127,6 +128,7 @@ const RequestComments: React.FC = ({ dateTime={comment.dateTime} user={comment.user} canDelete={comment.canDelete} + onDeleteCommentSuccess={refetch()} /> ))} @@ -159,14 +161,6 @@ const RequestComments: React.FC = ({ id="comment" value={commentText} /> - {/* setComment(e.target.value)} - /> */} {/* diff --git a/components/Requests/RequestViolations.tsx b/components/Requests/RequestViolations.tsx new file mode 100644 index 0000000..c7dff24 --- /dev/null +++ b/components/Requests/RequestViolations.tsx @@ -0,0 +1,166 @@ +"use client"; +import React, { MouseEventHandler, useEffect, useState } from "react"; +import { useMutation, useQuery } from "@tanstack/react-query"; +import { getViolationTypes } from "@/utils/CitizenCommon"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "../ui/textarea"; +import { Oval } from "react-loader-spinner"; +import { FaRegFlag } from "react-icons/fa"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "../ui/form"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "../ui/select"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; + +const formSchema = z.object({ + violationTypeId: z.string({ + required_error: "لطفا دسته بندی را انتخاب نمایید.", + }), + description: z.string(), +}); + +const RequestViolations = ({ request = {}, comment = {}, type = "" }) => { + // states + const [currentStep, setCurrentStep] = useState(1); + const [violationType, setViolationType] = useState(""); + const [violationDescription, setViolationDescription] = useState(""); + const [charCount, setCharCount] = useState(0); + + const { + data: violationTypes, + isLoading, + isError, + isSuccess, + refetch, + } = useQuery({ + queryKey: ["Violation"], + queryFn: () => getViolationTypes(), + // refetchOnWindowFocus: false, + }); + + // functions + const onSelectType = (vT: string) => (e: any) => { + e.stopPropagation(); + setViolationType(vT); + setCurrentStep((prev) => prev + 1); + }; + + // 1. Define your form. + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + violationTypeId: "", + description: "", + }, + }); + + useEffect(() => { + setCharCount(form.watch("description").length); + }, [form.watch("description")]); + + // 2. Define a submit handler. + function onSubmit(values: z.infer) { + // Do something with the form values. + // ✅ This will be type-safe and validated. + console.log(values); + } + + const handleSubmit = () => {}; + return ( + + + {/* */} + + + + +
+
+ + ( + + {/* + عنوان تخلف + */} + + + + )} + /> + + ( + + + توضیحات ({charCount}/1024) + + +