From a5a3c48a6117d3687281395d615d307a0c2fd437 Mon Sep 17 00:00:00 2001 From: YasamanKahdooei Date: Sat, 13 Jul 2024 14:47:07 +0330 Subject: [PATCH] A bug fixed --- components/FollowUp.tsx | 1 + components/RequestStep0.tsx | 8 +++++-- components/RequestStep2.tsx | 44 ++++++++++++++++++++++++++++--------- constants/index.tsx | 2 +- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/components/FollowUp.tsx b/components/FollowUp.tsx index ca6e8aa..b65374d 100644 --- a/components/FollowUp.tsx +++ b/components/FollowUp.tsx @@ -124,6 +124,7 @@ export default function FollowUp() { diff --git a/components/RequestStep0.tsx b/components/RequestStep0.tsx index 0e82f45..92e5f21 100644 --- a/components/RequestStep0.tsx +++ b/components/RequestStep0.tsx @@ -12,8 +12,9 @@ export default function RequestStep0() { {RequestItems.map((item, index) => { return ( {item.name}

+

+ {item.description} +

icon diff --git a/components/RequestStep2.tsx b/components/RequestStep2.tsx index 00158e0..5110847 100644 --- a/components/RequestStep2.tsx +++ b/components/RequestStep2.tsx @@ -66,6 +66,7 @@ export default function RequestStep2() { const router = useRouter(); const [file, setFile] = useState([]); const [charCount, setCharCount] = useState(0); + const [charCountPerson, setCharCountPerson] = useState(0); // Queries const { data: optionsData, isLoading: isLoadingData } = useQuery({ @@ -81,7 +82,13 @@ export default function RequestStep2() { OrganizationId: z.string({ required_error: "لطفا دستگاه مربوطه را انتخاب نمایید.", }), - person: z.string().optional(), + person: z.string() + .min(1, { + message: "لطفا نام فرد مورد نظر را بنویسید.", + }) + .max(50, { + message: "تعداد کاراکترها بیشتر از حد مجاز میباشد.", + }), description: z .string() .min(1, { @@ -197,19 +204,21 @@ export default function RequestStep2() { setCharCount(newCharCount); } } + + function handlePersonCharCountChange( + event: React.ChangeEvent + ) { + const newCharCount = event.target.value.length; + // Update charCount only when the user types or removes characters + if (newCharCount <= 50) { + setCharCountPerson(newCharCount); + } + } // Add the useEffect hook to monitor changes in the description field useEffect(() => { 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 <= optionsData?.maxTextLength) { - setCharCount(newCharCount); - } - } - function onSubmit(data: z.infer) { console.log(data); const formData = new FormData(); @@ -351,12 +360,27 @@ export default function RequestStep2() { render={({ field }) => ( - فرد مربوطه + فرد مرتبط({charCountPerson}/{50}) { + const currentValue = e.target.value; + if (currentValue.length <= 50) { + field.onChange(e); + handlePersonCharCountChange(e); + } else { + // Truncate the value to the allowed limit + field.onChange( + currentValue.substring( + 0, + 50 + ) + ); + } + }} /> diff --git a/constants/index.tsx b/constants/index.tsx index 3486c7b..5a4920b 100644 --- a/constants/index.tsx +++ b/constants/index.tsx @@ -39,7 +39,7 @@ export const boxItems = [ name: " گزارش فساد", icon: "/img/box1.svg", icon2: "/img/box1-hover.svg", - description: "ارسال گزارش با احراز هویت", + description: "ارسال گزارش ", link: "/RequestStep0", }, {