"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)