Sootzani/components/TableController.tsx

175 lines
5.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
};
status: number;
registeredAt: string;
lastChanged: string;
lastActor: number;
cipherKeyInspector: string;
}
export default function TableController({
data,
checkKey,
}: {
data: Complaint[];
checkKey: (item:any) => any;
}) {
console.log(data);
const saveData = useData((state) => state.saveData);
const [selectedFile, setSelectedFile] = useState<any>(null);
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);
console.log(contents);
};
reader.readAsText(file);
};
// const checkKey = (item: any) => {
// const dcKey = Decrypt(item.cipherKeyInspector, selectedFile);
// if (dcKey != false && dcKey != null) {
// saveData({
// trackingNumber: item.trackingNumber,
// password: Decrypt(item.cipherKeyInspector, selectedFile),
// });
// router.push(`/UserPanel/ControllerDashboard/Complaints/${item.id}`);
// } else {
// }
// };
return (
<div>
<Dialog>
{/* <DialogTrigger className=" appearance-none" asChild>
<Button
// onClick={handelVerify}
type="submit"
className="bg-blue hover:bg-blue/90 text-white w-36 p-2 rounded-xl"
>
بارگذاری کلید جدید
</Button>
</DialogTrigger> */}
<Table className="border-[1px] border-solid border-muted rounded-md ">
{/* <TableCaption>A list of your recent invoices.</TableCaption> */}
<TableHeader>
<TableRow>
<TableHead>ردیف</TableHead>
<TableHead>تاریخ</TableHead>
<TableHead>موضوع</TableHead>
<TableHead>دستگاه مربوطه</TableHead>
</TableRow>
</TableHeader>
<TableBody className="bg-[#F5F5F5]">
{data?.map((item: Complaint, index: number) => {
return (
<TableRow
onClick={
() => checkKey(item)
// saveData({
// trackingNumber: item.trackingNumber,
// password: Decrypt(item.cipherKeyInspector),
// })
}
className=" hover:bg-gray-200 cursor-pointer"
key={item.id}
>
{/* <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?.category ? item.category.title : "-"}
</TableCell>
<TableCell className="w-7/12">-</TableCell>
{/* </Link> */}
</TableRow>
);
})}
</TableBody>
</Table>
{/* <DialogTrigger asChild>
<Button variant="outline">Edit Profile</Button>
</DialogTrigger> */}
<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={handleFileChange}
type="file"
accept=".txt"
/>
</div>
<DialogFooter>
<DialogClose asChild>
<Button
onClick={() => {
if (selectedFile) {
toast("کلید شما با موفقیت بارگذاری شد.");
}
}}
type="submit"
>
ذخیره
</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}