Kahdooei
Hossein Rahmani 2024-07-13 13:13:15 +03:30
commit 1f932149d9
3 changed files with 41 additions and 17 deletions

View File

@ -47,7 +47,7 @@ export default function Landing() {
queryFn: () => getSliders(), queryFn: () => getSliders(),
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
}); });
const { const {
data: NewsData, data: NewsData,
isLoading: NewsIsLoading, isLoading: NewsIsLoading,
@ -70,7 +70,8 @@ export default function Landing() {
delay: 2500, delay: 2500,
disableOnInteraction: false, disableOnInteraction: false,
}} }}
loop={false} // autoplay={ data?.length > 1 ? { delay: 2500, disableOnInteraction: false } : false }
loop={false}
pagination={{ pagination={{
clickable: true, clickable: true,
}} }}
@ -94,19 +95,6 @@ export default function Landing() {
</SwiperSlide> </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>
)}
</> </>
) : ( ) : (
<> <>

View File

@ -33,7 +33,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
import { OperateByInspector } from "@/utils/inspectorApi"; import { OperateByInspector } from "@/utils/inspectorApi";
import { toast } from "sonner"; import { toast } from "sonner";
import { postComplaintsDetails } from "@/utils/citizenApi"; import { postComplaintsDetails } from "@/utils/citizenApi";
import { useState } from "react"; import { useEffect, useState } from "react";
import { DialogTrigger } from "./ui/dialog"; import { DialogTrigger } from "./ui/dialog";
import AttachmentsDialog from "./AttachmentsDialog"; import AttachmentsDialog from "./AttachmentsDialog";
import { Eye, Upload } from "lucide-react"; import { Eye, Upload } from "lucide-react";
@ -52,6 +52,7 @@ export default function InspectorOperations({
password?: string; password?: string;
}) { }) {
const [first, setfirst] = useState<File[]>([]); const [first, setfirst] = useState<File[]>([]);
const [charCount, setCharCount] = useState(0);
// Queries // Queries
const { data, isLoading, refetch } = useQuery({ 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 //Functions
function onSubmit(data: z.infer<typeof FormSchema>) { function onSubmit(data: z.infer<typeof FormSchema>) {
const formData = new FormData(); const formData = new FormData();
@ -162,12 +176,26 @@ export default function InspectorOperations({
name="text" name="text"
render={({ field, fieldState: { error } }) => ( render={({ field, fieldState: { error } }) => (
<FormItem> <FormItem>
<FormLabel className="">متن</FormLabel> <FormLabel className="">
متن({charCount}/{data?.maxTextLength})
</FormLabel>
<FormControl> <FormControl>
<Textarea <Textarea
className="resize-none bg-white lg:min-h-[20em]" className="resize-none bg-white lg:min-h-[20em]"
{...field} {...field}
readOnly={possibleOperations.length == 0} 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> </FormControl>
{!error ? ( {!error ? (

View File

@ -202,6 +202,14 @@ export default function RequestStep2() {
setCharCount(form.watch("description").length); setCharCount(form.watch("description").length);
}, [form.watch("description")]); }, [form.watch("description")]);
function handleDescriptionChange(event: React.ChangeEvent<HTMLTextAreaElement>) {
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<typeof FormSchema>) { function onSubmit(data: z.infer<typeof FormSchema>) {
console.log(data); console.log(data);
const formData = new FormData(); const formData = new FormData();