-
+
+
انجام عملیات
@@ -436,10 +436,10 @@ export default function ComplainsDetails({
>
-
- {item.operationWithDescription.description} توسط
- {" "}{item.sender == 0 ? "شهروند" : "بازرس"}
-
+
+ {item.operationWithDescription.description} توسط{" "}
+ {item.sender == 0 ? "شهروند" : "بازرس"}
+
@@ -499,19 +499,6 @@ export default function ComplainsDetails({
- {/* 3 */}
-
-
- انجام عملیات
-
-
getComplaintMutation.mutate(data)}
- role={role}
- complaintData={data}
- id={id}
- key2={key}
- />
-
>
) : (
diff --git a/components/InspectorOperations.tsx b/components/InspectorOperations.tsx
index 358309f..9fe4432 100644
--- a/components/InspectorOperations.tsx
+++ b/components/InspectorOperations.tsx
@@ -29,10 +29,15 @@ import {
} from "@/components/ui/select";
import { Operations } from "@/constants";
import useData from "@/store/useData";
-import { useMutation, useQueryClient } from "@tanstack/react-query";
+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { OperateByInspector } from "@/utils/inspectorApi";
import { toast } from "sonner";
-import { Decrypt } from "@/lib/utils";
+import { Decrypt, formatBytes } from "@/lib/utils";
+import { useState } from "react";
+import { getOptions } from "@/utils/commonApi";
+import AttachmentsDialog from "./AttachmentsDialog";
+import { DialogTrigger } from "./ui/dialog";
+import { Eye, Upload } from "lucide-react";
export default function InspectorOperations({
complaintData,
@@ -47,35 +52,13 @@ export default function InspectorOperations({
id: any;
key2: any;
}) {
- const FormSchema = z.object({
- text: z.string({ required_error: "لطفا متن خود را وارد نمایید." }),
- ...(role == "Inspector" && {
- type: z.enum(["private", "public"], {
- required_error: "لطفا وضعیت عملیات را انتخاب نمایید.",
- }),
- }),
- operation: z.string({
- required_error: "لطفا نوع عملیات را انتخاب نمایید.",
- }),
- media: z
- .custom
((val) => val instanceof FileList, "Required")
- // .refine((files) => files.length > 0, `Required`)
- .refine((files) => files.length <= 5, `Maximum of 5 File are allowed.`)
- .nullish(),
- });
+ const [file, setFile] = useState([]);
- const password = useData((state) => state.data.password);
- const possibleOperations = complaintData?.possibleOperationsWithDescription;
- const queryClient = useQueryClient();
-
- const form = useForm>({
- resolver: zodResolver(FormSchema),
- defaultValues: {
- operation:
- possibleOperations.length == 1
- ? String(possibleOperations[0].value)
- : undefined,
- },
+ // Queries
+ const { data, isLoading, refetch } = useQuery({
+ queryKey: ["Options"],
+ queryFn: () => getOptions(),
+ refetchOnWindowFocus: false,
});
const OperationMutation = useMutation({
@@ -105,6 +88,48 @@ export default function InspectorOperations({
},
});
+ const FormSchema = z.object({
+ text: z
+ .string({ required_error: "لطفا متن خود را وارد نمایید." })
+ .max(
+ data?.maxTextLength,
+ `حداکثر ${data?.maxTextLength} کاراکتر می توانید وارد کنید.`
+ ),
+ ...(role == "Inspector" && {
+ type: z.enum(["private", "public"], {
+ required_error: "لطفا وضعیت عملیات را انتخاب نمایید.",
+ }),
+ }),
+ operation: z.string({
+ required_error: "لطفا نوع عملیات را انتخاب نمایید.",
+ }),
+ media: z
+ .custom()
+ // .refine((files) => files.length > 0, `Required`)
+ .refine(
+ (files) => files.length <= data?.maxFileCount,
+ `تعداد فایل های پیوست شده می بایست حداکثر ${data?.maxFileCount} عدد باشد.`
+ )
+ .refine(
+ (files) => files.every((item) => item.size < data?.maxFileSize),
+ `حجم هر فایل حداکثر می بایست ${data?.maxFileSize} باشد.`
+ )
+ .nullish(),
+ });
+
+ const password = useData((state) => state.data.password);
+ const possibleOperations = complaintData?.possibleOperationsWithDescription;
+
+ const form = useForm>({
+ resolver: zodResolver(FormSchema),
+ defaultValues: {
+ operation:
+ possibleOperations.length == 1
+ ? String(possibleOperations[0].value)
+ : undefined,
+ },
+ });
+
function onSubmit(data: z.infer) {
const storedData = JSON.parse(
localStorage.getItem("CompliantData") as string
@@ -129,13 +154,32 @@ export default function InspectorOperations({
OperationMutation.mutate(formData);
}
+ const deleteFileFromAttachments = (File: any) => {
+ const filtered = file?.filter((item) => item.name !== File);
+ setFile(filtered);
+ form.setValue("media", filtered);
+ };
+
+ const allowedExtensions = data?.allowedExtensions;
+ const split = allowedExtensions?.split(",");
+ const withDot = split?.map((item: string) => "." + item);
+ const newAllowedExtensions = withDot?.join(",");
+ const formatSize = (size: number) => {
+ const string = formatBytes(size);
+ return (
+
+ {string}
+
+ );
+ };
+
return (