From eb3f3a3f99d54387da89fea034a49f8dcbe58555 Mon Sep 17 00:00:00 2001 From: yasaman Date: Mon, 19 Feb 2024 11:10:45 +0330 Subject: [PATCH 1/2] The Counter and Slider problem has been solved --- app/components/Landing.tsx | 9 +++++---- components/RequestStep2.tsx | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/components/Landing.tsx b/app/components/Landing.tsx index 5b914a1..6c9276b 100644 --- a/app/components/Landing.tsx +++ b/app/components/Landing.tsx @@ -47,7 +47,7 @@ export default function Landing() { queryFn: () => getSliders(), refetchOnWindowFocus: false, }); - + const { data: NewsData, isLoading: NewsIsLoading, @@ -70,7 +70,8 @@ export default function Landing() { delay: 2500, disableOnInteraction: false, }} - loop={false} + // autoplay={ data?.length > 1 ? { delay: 2500, disableOnInteraction: false } : false } + loop={false} pagination={{ clickable: true, }} @@ -94,7 +95,7 @@ export default function Landing() { ); })} - {data?.length == 1 && ( + {/* {data?.length == 1 && ( bg - )} + )} */} ) : ( <> diff --git a/components/RequestStep2.tsx b/components/RequestStep2.tsx index 88c3c92..bae022d 100644 --- a/components/RequestStep2.tsx +++ b/components/RequestStep2.tsx @@ -193,6 +193,14 @@ export default function RequestStep2() { setCharCount(form.watch("description").length); }, [form.watch("description")]); + function handleDescriptionChange(event: React.ChangeEvent) { + const newCharCount = event.target.value.length; + // Update charCount only when the user types or removes characters + if (newCharCount <= 1024) { + setCharCount(newCharCount); + } + } + function onSubmit(data: z.infer) { console.log(data); const formData = new FormData(); @@ -353,6 +361,16 @@ export default function RequestStep2() { placeholder=" توضیحات خود را بنویسید" className="mb-3 resize-none" {...field} + onChange={(e) => { + const currentValue = e.target.value; + if (currentValue.length <= 1024) { + field.onChange(e); + handleDescriptionChange(e); + } else { + // Truncate the value to the allowed limit + field.onChange(currentValue.substring(0, 1024)); + } + }} /> From e90d5c6e72d33c1ea35466871ff5b8a27a79f209 Mon Sep 17 00:00:00 2001 From: yasaman Date: Tue, 20 Feb 2024 11:53:53 +0330 Subject: [PATCH 2/2] Add Counter to InspectorOpration --- app/CitizenLogin/page.tsx | 8 +++++++- app/components/Landing.tsx | 13 ------------ components/InspectorOperations.tsx | 32 ++++++++++++++++++++++++++++-- components/RequestStep2.tsx | 10 +++++----- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/app/CitizenLogin/page.tsx b/app/CitizenLogin/page.tsx index f7d8040..f8de261 100644 --- a/app/CitizenLogin/page.tsx +++ b/app/CitizenLogin/page.tsx @@ -9,5 +9,11 @@ export default function page() { if (token) { redirect("/RequestStep2"); } - return ; + return ( +
+ + +
+
+ ); } diff --git a/app/components/Landing.tsx b/app/components/Landing.tsx index 6c9276b..acf9a55 100644 --- a/app/components/Landing.tsx +++ b/app/components/Landing.tsx @@ -95,19 +95,6 @@ export default function Landing() { ); })} - {/* {data?.length == 1 && ( - - bg - - )} */} ) : ( <> diff --git a/components/InspectorOperations.tsx b/components/InspectorOperations.tsx index 1959a4c..6732555 100644 --- a/components/InspectorOperations.tsx +++ b/components/InspectorOperations.tsx @@ -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([]); + 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) { + 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) { const formData = new FormData(); @@ -162,12 +176,26 @@ export default function InspectorOperations({ name="text" render={({ field, fieldState: { error } }) => ( - متن + + متن({charCount}/{data?.maxTextLength}) +