255 lines
9.5 KiB
TypeScript
255 lines
9.5 KiB
TypeScript
"use client";
|
||
import React, { useEffect, useState } from "react";
|
||
import greenIcon from "../public/img/greenPoint.svg";
|
||
import blueIcon from "../public/img/bluepoint.svg";
|
||
import Image from "next/image";
|
||
import { ComplainDetailsItems } from "@/constants";
|
||
import { useMutation } from "@tanstack/react-query";
|
||
import useData from "@/store/useData";
|
||
import { convertDate } from "@/lib/utils";
|
||
import { Badge } from "./ui/badge";
|
||
import InspectorOperations from "./InspectorOperations";
|
||
import { postComplaintTracking } from "@/utils/citizenApi";
|
||
import { Button } from "@/components/ui/button";
|
||
import {
|
||
Dialog,
|
||
DialogClose,
|
||
DialogContent,
|
||
DialogDescription,
|
||
DialogFooter,
|
||
DialogHeader,
|
||
DialogTitle,
|
||
DialogTrigger,
|
||
} from "@/components/ui/dialog";
|
||
import { Input } from "./ui/input";
|
||
import { toast } from "sonner";
|
||
import { useRouter } from "next/navigation";
|
||
export default function ComplainsDetails({
|
||
id,
|
||
role,
|
||
Data,
|
||
}: {
|
||
id?: number;
|
||
role: string;
|
||
Data?: any;
|
||
}) {
|
||
const [open, setOpen] = useState<boolean>(true);
|
||
const [password, setPassword] = useState<any>(true);
|
||
const router = useRouter();
|
||
const storeData = useData((state) => state.data);
|
||
let data;
|
||
|
||
const getComplaintMutation = useMutation({
|
||
mutationKey: ["Complaint", id],
|
||
mutationFn: postComplaintTracking,
|
||
onSuccess: (res) => {
|
||
setOpen(false);
|
||
},
|
||
onError: (err) => {
|
||
toast("رمز عبور شما صحیح نمیباشد.", {
|
||
className: "!bg-red-500 !text-white",
|
||
});
|
||
},
|
||
});
|
||
|
||
const handelPassword = () => {
|
||
const payload = { ...storeData, password: password };
|
||
getComplaintMutation.mutate({ Data: payload });
|
||
};
|
||
console.log(storeData);
|
||
useEffect(() => {
|
||
useData.persist.rehydrate();
|
||
}, []);
|
||
useEffect(() => {
|
||
// if (storeData && role == "Inspector") {
|
||
// getComplaintMutation.mutate(storeData);
|
||
// }
|
||
}, [storeData]);
|
||
|
||
if (getComplaintMutation.isSuccess) {
|
||
data = getComplaintMutation.data;
|
||
}
|
||
if (open) {
|
||
return (
|
||
<Dialog open={open} onOpenChange={setOpen}>
|
||
<DialogContent dir="rtl" className="sm:max-w-[425px]">
|
||
<DialogHeader dir="rtl">
|
||
<DialogTitle dir="rtl">رمز عبور</DialogTitle>
|
||
<DialogDescription>
|
||
برای مشاهده درخواست پسورد خود را وارد نمایید.
|
||
</DialogDescription>
|
||
</DialogHeader>
|
||
<div className="grid w-full max-w-sm items-center gap-1.5">
|
||
{/* <Label htmlFor="picture">Picture</Label> */}
|
||
<Input
|
||
dir="rtl"
|
||
id="picture"
|
||
onChange={(e) => setPassword(e.target.value)}
|
||
/>
|
||
</div>
|
||
<DialogFooter>
|
||
<Button
|
||
onClick={() => router.push("/Account/Complaints")}
|
||
type="button"
|
||
variant="outline"
|
||
className=" ml-2"
|
||
>
|
||
بازگشت
|
||
</Button>
|
||
{/* <DialogClose asChild> */}
|
||
<Button onClick={handelPassword} type="submit">
|
||
تایید
|
||
</Button>
|
||
{/* </DialogClose> */}
|
||
</DialogFooter>
|
||
</DialogContent>
|
||
</Dialog>
|
||
);
|
||
}
|
||
return (
|
||
<>
|
||
{data ? (
|
||
<div className=" w-[95vw] lg:w-[82vw] xl:w-[70vw] 3xl:w-[65vw] flex max-lg:flex-col gap-3 items-start mt-5">
|
||
<div className="flex flex-col w-full lg:w-1/3 lg:order-2 gap-3 lg:sticky top-40">
|
||
<div className=" bg-[#E9E9E9] rounded-md py-4 px-10 flex flex-col">
|
||
<p className="text-[#464646] text-base font-bold">گزارش شکایت</p>
|
||
<div className="mt-2">
|
||
<p className="text-[#2e2a2a] text-sm font-medium">
|
||
موضوع شکایت:{" "}
|
||
<span className="text-[#7C838A] text-sm font-medium">
|
||
{data.title}
|
||
</span>
|
||
</p>
|
||
<p className="text-[#464646] text-sm font-medium">
|
||
دستگاه مربوطه:{" "}
|
||
<span className="text-[#7C838A] text-sm font-medium">
|
||
{data?.complaintOrganization
|
||
? data?.complaintOrganization.title
|
||
: "-"}
|
||
</span>
|
||
</p>
|
||
<p className="text-[#464646] text-sm font-medium">
|
||
پرسنل مربوطه:{" "}
|
||
<span className="text-[#7C838A] text-sm font-medium">
|
||
{/* {data.title} */}
|
||
</span>
|
||
</p>
|
||
<p className="text-[#464646] text-sm font-medium">
|
||
زمان ثبت:{" "}
|
||
<span className="text-[#7C838A] text-sm font-medium">
|
||
{convertDate(data.registeredAt)}
|
||
</span>
|
||
</p>
|
||
{/* <p className="text-[#464646] text-sm font-medium">
|
||
{" "}
|
||
موضوع شکایت:{" "}
|
||
<span className="text-[#7C838A] text-sm font-medium">
|
||
متن تستی
|
||
</span>
|
||
</p> */}
|
||
</div>
|
||
{/* <p className="text-[#464646] text-sm font-medium text-justify">
|
||
درخواست شما با کد رهگیری {data.trackingNumber} و رمز عبور 12422 در
|
||
دست بررسی و اقدام می باشد. در صورت تمایل می توانید با شماره تلفن
|
||
0353286545 جهت پشتیبانی تماس حاصل کنید.{" "}
|
||
</p> */}
|
||
</div>
|
||
<div className=" max-lg:hidden order-2 bg-[#E9E9E9] rounded-md p-4 px-10 flex flex-col">
|
||
<p className="text-[#464646] text-base font-bold mb-1">
|
||
انجام عملیات
|
||
</p>
|
||
<InspectorOperations
|
||
updateData={() => getComplaintMutation.mutate(storeData)}
|
||
role={role}
|
||
complaintData={data}
|
||
/>
|
||
</div>
|
||
</div>
|
||
<div className="w-full lg:w-2/3 self-stretch bg-[#E9E9E9] p-4 px-10 rounded-lg">
|
||
<p className="text-[#464646] text-base font-bold">روند شکایت</p>
|
||
<div className=" flex flex-col gap-y-4 mt-4">
|
||
{data.contents?.map((item: any) => {
|
||
return (
|
||
<div
|
||
key={item.id}
|
||
className=" bg-white p-4 rounded-lg shadow-md"
|
||
>
|
||
<div className=" flex gap-4 items-center">
|
||
<p className="">
|
||
<Badge>{item.sender == 0 ? "شهروند" : "بازرس"}</Badge>
|
||
</p>
|
||
<p className="">
|
||
تاریخ :
|
||
<span className="text-[#7C838A]">
|
||
{convertDate(item.dateTime)}
|
||
</span>
|
||
</p>
|
||
</div>
|
||
<div className=" text-[#464646] mt-2">
|
||
متن:{" "}
|
||
<span className="text-[#7C838A]">
|
||
{item.text ? item.text : "-"}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</div>
|
||
<div className=" lg:hidden order-2 w-full bg-[#E9E9E9] rounded-md py-4 px-10 flex flex-col">
|
||
<p className="text-[#464646] text-base font-bold mb-1">
|
||
انجام عملیات
|
||
</p>
|
||
<InspectorOperations
|
||
updateData={() => getComplaintMutation.mutate(storeData)}
|
||
role={role}
|
||
complaintData={data}
|
||
/>
|
||
</div>
|
||
{/* Left */}
|
||
{/* <div className="w-full md:w-1/3 bg-white shadow-lg rounded-md pt-3 px-4 flex flex-row md:flex-col max-md:flex-wrap">
|
||
<p className="text-[#464646] text-base font-bold mb-3">
|
||
وضعیت درخواست
|
||
</p>
|
||
|
||
{ComplainDetailsItems.map((item, index, array) => {
|
||
return (
|
||
<div
|
||
className="w-full justify-start items-start gap-4 inline-flex "
|
||
key={item.id}
|
||
>
|
||
<div className="grow shrink basis-0 pb-2 flex-col justify-start items-start gap-1 inline-flex">
|
||
<div className="self-stretch text-right text-lime-800 text-lg font-semibold leading-[30px]">
|
||
{item.title}
|
||
</div>
|
||
<div className="self-stretch text-right text-zinc-700 text-base font-normal uppercase">
|
||
{item.desc}
|
||
</div>
|
||
<div className="self-stretch text-right text-zinc-700 text-base font-normal">
|
||
{item.date} <br /> {item.time}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="w-6 self-stretch flex-col justify-start items-center gap-1 inline-flex">
|
||
<div className="py-0.5 justify-start items-start gap-2.5 inline-flex">
|
||
<Image
|
||
src={greenIcon}
|
||
alt="greenIcon"
|
||
width={100}
|
||
height={100}
|
||
/>
|
||
</div>
|
||
<div className="w-1 grow shrink basis-0 bg-lime-800 rounded-[1px]"></div>
|
||
</div>
|
||
</div>
|
||
);
|
||
})}
|
||
</div> */}
|
||
</div>
|
||
) : (
|
||
""
|
||
)}
|
||
</>
|
||
);
|
||
}
|