Add Counter to InspectorOpration
parent
eb3f3a3f99
commit
e90d5c6e72
|
|
@ -9,5 +9,11 @@ export default function page() {
|
|||
if (token) {
|
||||
redirect("/RequestStep2");
|
||||
}
|
||||
return <CitizenLogin />;
|
||||
return (
|
||||
<div className="flex justify-center items-center w-full h-[calc(100vh-4rem)] ">
|
||||
<CitizenLogin />
|
||||
|
||||
<div className="w-full h-full bg-left-top bg-repeat bg-[url('/img/login-pattern.png')] absolute top-0 left-0 "></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,19 +95,6 @@ export default function Landing() {
|
|||
</SwiperSlide>
|
||||
);
|
||||
})}
|
||||
{/* {data?.length == 1 && (
|
||||
<SwiperSlide>
|
||||
<Image
|
||||
alt="bg"
|
||||
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${data[0]?.image?.url}`}
|
||||
// width={20}
|
||||
// height={20}
|
||||
layout="fill"
|
||||
quality={100}
|
||||
className=" w-full h-full object-cover max-sm:object-[70%]"
|
||||
/>
|
||||
</SwiperSlide>
|
||||
)} */}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
|||
import { OperateByInspector } from "@/utils/inspectorApi";
|
||||
import { toast } from "sonner";
|
||||
import { postComplaintsDetails } from "@/utils/citizenApi";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { DialogTrigger } from "./ui/dialog";
|
||||
import AttachmentsDialog from "./AttachmentsDialog";
|
||||
import { Eye, Upload } from "lucide-react";
|
||||
|
|
@ -52,6 +52,7 @@ export default function InspectorOperations({
|
|||
password?: string;
|
||||
}) {
|
||||
const [first, setfirst] = useState<File[]>([]);
|
||||
const [charCount, setCharCount] = useState(0);
|
||||
|
||||
// Queries
|
||||
const { data, isLoading, refetch } = useQuery({
|
||||
|
|
@ -118,6 +119,19 @@ export default function InspectorOperations({
|
|||
},
|
||||
});
|
||||
|
||||
// Add the useEffect hook to monitor changes in the description field
|
||||
useEffect(() => {
|
||||
setCharCount(form.watch("text")?.length);
|
||||
}, [form.watch("text")]);
|
||||
|
||||
function handleTextChange(event: React.ChangeEvent<HTMLTextAreaElement>) {
|
||||
const newCharCount = event.target.value.length;
|
||||
// Update charCount only when the user types or removes characters
|
||||
if (newCharCount <= data?.maxTextLength) {
|
||||
setCharCount(newCharCount);
|
||||
}
|
||||
}
|
||||
|
||||
//Functions
|
||||
function onSubmit(data: z.infer<typeof FormSchema>) {
|
||||
const formData = new FormData();
|
||||
|
|
@ -162,12 +176,26 @@ export default function InspectorOperations({
|
|||
name="text"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="">متن</FormLabel>
|
||||
<FormLabel className="">
|
||||
متن({charCount}/{data?.maxTextLength})
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
className="resize-none bg-white lg:min-h-[20em]"
|
||||
{...field}
|
||||
readOnly={possibleOperations.length == 0}
|
||||
|
||||
onChange={(e) => {
|
||||
const currentValue = e.target.value;
|
||||
if (currentValue.length <= data?.maxTextLength) {
|
||||
field.onChange(e);
|
||||
handleTextChange(e);
|
||||
} else {
|
||||
// Truncate the value to the allowed limit
|
||||
field.onChange(currentValue.substring(0, data?.maxTextLength));
|
||||
}
|
||||
}}
|
||||
|
||||
/>
|
||||
</FormControl>
|
||||
{!error ? (
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ export default function RequestStep2() {
|
|||
.min(1, {
|
||||
message: "لطفا توضیحات خود را بنویسید.",
|
||||
})
|
||||
.max(1024, {
|
||||
.max(optionsData?.maxTextLength, {
|
||||
message: "تعداد کاراکترها بیشتر از حد مجاز میباشد.",
|
||||
}),
|
||||
uploadFile: z
|
||||
|
|
@ -196,7 +196,7 @@ export default function RequestStep2() {
|
|||
function handleDescriptionChange(event: React.ChangeEvent<HTMLTextAreaElement>) {
|
||||
const newCharCount = event.target.value.length;
|
||||
// Update charCount only when the user types or removes characters
|
||||
if (newCharCount <= 1024) {
|
||||
if (newCharCount <= optionsData?.maxTextLength) {
|
||||
setCharCount(newCharCount);
|
||||
}
|
||||
}
|
||||
|
|
@ -354,7 +354,7 @@ export default function RequestStep2() {
|
|||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||||
توضیحات ({charCount}/1024)
|
||||
توضیحات ({charCount}/{optionsData?.maxTextLength})
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
|
|
@ -363,12 +363,12 @@ export default function RequestStep2() {
|
|||
{...field}
|
||||
onChange={(e) => {
|
||||
const currentValue = e.target.value;
|
||||
if (currentValue.length <= 1024) {
|
||||
if (currentValue.length <= optionsData?.maxTextLength) {
|
||||
field.onChange(e);
|
||||
handleDescriptionChange(e);
|
||||
} else {
|
||||
// Truncate the value to the allowed limit
|
||||
field.onChange(currentValue.substring(0, 1024));
|
||||
field.onChange(currentValue.substring(0, optionsData?.maxTextLength));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue