133 lines
3.9 KiB
TypeScript
133 lines
3.9 KiB
TypeScript
import React, { useState } from "react";
|
||
import {
|
||
Table,
|
||
TableBody,
|
||
TableCaption,
|
||
TableCell,
|
||
TableHead,
|
||
TableHeader,
|
||
TableRow,
|
||
} from "@/components/ui/table";
|
||
import { Button } from "@/components/ui/button";
|
||
import {
|
||
Dialog,
|
||
DialogClose,
|
||
DialogContent,
|
||
DialogDescription,
|
||
DialogFooter,
|
||
DialogHeader,
|
||
DialogTitle,
|
||
DialogTrigger,
|
||
} from "@/components/ui/dialog";
|
||
import { ControllerTableItems } from "@/constants";
|
||
import Link from "next/link";
|
||
import { Decrypt, convertDate } from "@/lib/utils";
|
||
import useData from "@/store/useData";
|
||
import { Label } from "./ui/label";
|
||
import { Input } from "./ui/input";
|
||
import { useRouter } from "next/navigation";
|
||
import { toast } from "sonner";
|
||
interface Complaint {
|
||
id: string;
|
||
trackingNumber: string;
|
||
title: string;
|
||
category: {
|
||
id: string;
|
||
title: string;
|
||
description: string;
|
||
};
|
||
complaintOrganization: {
|
||
id: string;
|
||
title: string;
|
||
description: string;
|
||
};
|
||
statusWithDescription: {
|
||
value: number;
|
||
description: string;
|
||
};
|
||
status: number;
|
||
registeredAt: string;
|
||
lastChanged: string;
|
||
lastActor: number;
|
||
cipherKeyInspector: string;
|
||
}
|
||
export default function TableController({ data }: { data: Complaint[] }) {
|
||
|
||
const saveData = useData((state) => state.saveData);
|
||
const [selectedFile, setSelectedFile] = useState<any>(null);
|
||
const [open, setOpen] = useState<boolean>(false);
|
||
const router = useRouter();
|
||
const handleFileChange = (event: any) => {
|
||
const file = event.target.files[0];
|
||
const reader = new FileReader();
|
||
reader.onload = (e) => {
|
||
const contents = e?.target?.result;
|
||
// Process the contents of the file here
|
||
setSelectedFile(contents);
|
||
};
|
||
|
||
reader.readAsText(file);
|
||
};
|
||
|
||
return (
|
||
<div>
|
||
<Table className="border-[1px] border-solid border-muted rounded-md mb-20">
|
||
{/* <TableCaption>A list of your recent invoices.</TableCaption> */}
|
||
<TableHeader>
|
||
<TableRow>
|
||
<TableHead>ردیف</TableHead>
|
||
<TableHead>تاریخ</TableHead>
|
||
<TableHead>کد پیگیری</TableHead>
|
||
<TableHead>موضوع</TableHead>
|
||
<TableHead>وضعیت</TableHead>
|
||
<TableHead>دستگاه مربوطه</TableHead>
|
||
</TableRow>
|
||
</TableHeader>
|
||
<TableBody className="bg-[#F5F5F5]">
|
||
{data?.map((item: Complaint, index: number) => {
|
||
return (
|
||
<TableRow
|
||
className=" hover:bg-gray-200 cursor-pointer"
|
||
key={item.id}
|
||
onClick={() => {
|
||
router.push(`/Account/Complaints/${item.id}`);
|
||
// setOpen(true);
|
||
saveData({
|
||
trackingNumber: item.trackingNumber,
|
||
});
|
||
}}
|
||
>
|
||
{/* <Link
|
||
href={`/UserPanel/ControllerDashboard/Complaints/${item.id}`}
|
||
className="contents"
|
||
> */}
|
||
<TableCell className="w-1/12 font-medium ">
|
||
{index + 1}
|
||
</TableCell>
|
||
<TableCell className="w-2/12">
|
||
{convertDate(item.registeredAt)}
|
||
</TableCell>
|
||
<TableCell className="w-2/12">{item.trackingNumber}</TableCell>
|
||
<TableCell className="w-2/12">
|
||
{item?.title ? item.title : "-"}
|
||
</TableCell>
|
||
<TableCell className="w-2/12">
|
||
{item?.statusWithDescription
|
||
? item.statusWithDescription.description
|
||
: "-"}
|
||
</TableCell>
|
||
<TableCell className="w-3/12">
|
||
{item?.complaintOrganization
|
||
? item?.complaintOrganization.title
|
||
: "-"}
|
||
</TableCell>
|
||
{/* </Link> */}
|
||
</TableRow>
|
||
);
|
||
})}
|
||
</TableBody>
|
||
</Table>
|
||
</div>
|
||
);
|
||
}
|