2024-12-26 00:43:39 +05:00
|
|
|
'use client'
|
|
|
|
import {
|
|
|
|
TableCell,
|
|
|
|
TableRow
|
|
|
|
} from "@/components/ui/table";
|
|
|
|
import { deviceCartAtom } from "@/lib/atoms";
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
import type { Device } from "@prisma/client";
|
|
|
|
import { useAtom } from "jotai";
|
|
|
|
import Link from 'next/link';
|
|
|
|
import AddDevicesToCartButton from "./add-devices-to-cart-button";
|
|
|
|
import BlockDeviceDialog from "./block-device-dialog";
|
2025-01-01 23:48:56 +05:00
|
|
|
export default function ClickableRow({ device, parentalControl, admin = false }: { device: Device, parentalControl?: boolean, admin?: boolean }) {
|
2024-12-26 00:43:39 +05:00
|
|
|
const [devices, setDeviceCart] = useAtom(deviceCartAtom)
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TableRow
|
|
|
|
key={device.id}
|
|
|
|
className={cn(parentalControl === false && "cursor-pointer hover:bg-muted",)}
|
|
|
|
onClick={() => {
|
|
|
|
|
|
|
|
if (parentalControl === true) return
|
|
|
|
setDeviceCart((prev) =>
|
|
|
|
devices.some((d) => d.id === device.id)
|
|
|
|
? prev.filter((d) => d.id !== device.id)
|
|
|
|
: [...prev, device]
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<TableCell>
|
|
|
|
<div className="flex flex-col items-start">
|
|
|
|
<Link
|
|
|
|
className="font-medium hover:underline"
|
|
|
|
href={`/devices/${device.id}`}
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
|
|
|
{device.name}
|
|
|
|
</Link>
|
|
|
|
<span className="text-muted-foreground">
|
|
|
|
Active until{" "}
|
2025-01-01 23:48:56 +05:00
|
|
|
{new Date(device.expiryDate || "").toLocaleDateString("en-US", {
|
2024-12-26 00:43:39 +05:00
|
|
|
month: "short",
|
|
|
|
day: "2-digit",
|
|
|
|
year: "numeric",
|
|
|
|
})}
|
|
|
|
</span>
|
2025-01-01 23:48:56 +05:00
|
|
|
{(device.blockedBy === "ADMIN" && device.blocked) && (
|
2024-12-26 00:43:39 +05:00
|
|
|
<div className="p-2 rounded border my-2">
|
|
|
|
<span>Comment: </span>
|
|
|
|
<p className="text-neutral-500">
|
2024-12-26 20:25:38 +05:00
|
|
|
{device?.reasonForBlocking}
|
2024-12-26 00:43:39 +05:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className="font-medium">{device.mac}</TableCell>
|
|
|
|
<TableCell>
|
|
|
|
{!parentalControl ? (
|
|
|
|
<AddDevicesToCartButton device={device} />
|
|
|
|
) : (
|
2025-01-01 23:48:56 +05:00
|
|
|
<BlockDeviceDialog admin={admin} type={device.blocked ? "unblock" : "block"} device={device} />
|
2024-12-26 00:43:39 +05:00
|
|
|
)}
|
|
|
|
</TableCell>
|
|
|
|
</TableRow >
|
|
|
|
)
|
|
|
|
}
|