diff --git a/app/(dashboard)/devices/[deviceId]/page.tsx b/app/(dashboard)/devices/[deviceId]/page.tsx index f3584d6..3a8a904 100644 --- a/app/(dashboard)/devices/[deviceId]/page.tsx +++ b/app/(dashboard)/devices/[deviceId]/page.tsx @@ -13,7 +13,7 @@ export default async function DeviceDetails({ params }: { }) return (
-
+

{device?.name}

@@ -22,7 +22,7 @@ export default async function DeviceDetails({ params }: {
{/* */} {/* -
+

My Devices

@@ -30,13 +30,13 @@ export default async function Devices({
- +
); diff --git a/app/(dashboard)/parental-control/page.tsx b/app/(dashboard)/parental-control/page.tsx index fa6ad43..6922bdc 100644 --- a/app/(dashboard)/parental-control/page.tsx +++ b/app/(dashboard)/parental-control/page.tsx @@ -18,7 +18,7 @@ export default async function ParentalControl({ const query = (await searchParams)?.query || ""; return (
-
+

Parental Control

@@ -26,7 +26,7 @@ export default async function ParentalControl({
diff --git a/app/(dashboard)/payments/[paymentId]/page.tsx b/app/(dashboard)/payments/[paymentId]/page.tsx index 27cd24e..889e0ab 100644 --- a/app/(dashboard)/payments/[paymentId]/page.tsx +++ b/app/(dashboard)/payments/[paymentId]/page.tsx @@ -29,7 +29,7 @@ export default async function PaymentPage({ const formula = await prisma.billFormula.findFirst(); return (
-
+

Payment

{payment?.paid ? "Paid" : "Pending"} diff --git a/app/(dashboard)/payments/page.tsx b/app/(dashboard)/payments/page.tsx index ec73203..6e5dab5 100644 --- a/app/(dashboard)/payments/page.tsx +++ b/app/(dashboard)/payments/page.tsx @@ -15,13 +15,13 @@ export default async function Devices({ const query = (await searchParams)?.query || ""; return (
-
+

My Payments

diff --git a/app/(dashboard)/user-devices/page.tsx b/app/(dashboard)/user-devices/page.tsx index ab2aaf6..5ea7906 100644 --- a/app/(dashboard)/user-devices/page.tsx +++ b/app/(dashboard)/user-devices/page.tsx @@ -1,7 +1,7 @@ export default async function UserDevcies() { return (
-

+

User Devices

diff --git a/app/(dashboard)/users/[userId]/verify/page.tsx b/app/(dashboard)/users/[userId]/verify/page.tsx index 06a39cc..c3deb72 100644 --- a/app/(dashboard)/users/[userId]/verify/page.tsx +++ b/app/(dashboard)/users/[userId]/verify/page.tsx @@ -21,7 +21,7 @@ export default async function VerifyUserPage({ }) return (
-
+

Verify user

diff --git a/app/(dashboard)/users/page.tsx b/app/(dashboard)/users/page.tsx index 360c380..6f40f61 100644 --- a/app/(dashboard)/users/page.tsx +++ b/app/(dashboard)/users/page.tsx @@ -38,7 +38,7 @@ export default async function AdminUsers({ return (
-

+

Users

diff --git a/components/add-devices-to-cart-button.tsx b/components/add-devices-to-cart-button.tsx index db5fdd5..895c356 100644 --- a/components/add-devices-to-cart-button.tsx +++ b/components/add-devices-to-cart-button.tsx @@ -2,32 +2,24 @@ import { deviceCartAtom } from '@/lib/atoms' import type { Device } from '@prisma/client' import { useAtomValue, useSetAtom } from 'jotai' -import { BadgePlus, CheckCheck } from 'lucide-react' import React from 'react' -import { Button } from './ui/button' export default function AddDevicesToCartButton({ device }: { device: Device }) { const setDeviceCart = useSetAtom(deviceCartAtom) const devices = useAtomValue(deviceCartAtom) + + const isChecked = devices.some((d) => d.id === device.id); + return ( - + /> ) } diff --git a/components/clickable-row.tsx b/components/clickable-row.tsx new file mode 100644 index 0000000..89e176a --- /dev/null +++ b/components/clickable-row.tsx @@ -0,0 +1,68 @@ +'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"; +export default function ClickableRow({ device, parentalControl }: { device: Device, parentalControl?: boolean }) { + const [devices, setDeviceCart] = useAtom(deviceCartAtom) + + + return ( + { + + if (parentalControl === true) return + setDeviceCart((prev) => + devices.some((d) => d.id === device.id) + ? prev.filter((d) => d.id !== device.id) + : [...prev, device] + ) + }} + > + +
+ e.stopPropagation()} + > + {device.name} + + + Active until{" "} + {new Date().toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + year: "numeric", + })} + + {parentalControl && ( +
+ Comment: +

+ blocked because he was watching youtube +

+
+ )} +
+
+ {device.mac} + + {!parentalControl ? ( + + ) : ( + + )} + +
+ ) +} diff --git a/components/device-card.tsx b/components/device-card.tsx index 1f5fba8..ebc1ae3 100644 --- a/components/device-card.tsx +++ b/components/device-card.tsx @@ -1,48 +1,75 @@ +'use client' +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' import { Badge } from './ui/badge' export default function DeviceCard({ device, parentalControl }: { device: Device, parentalControl?: boolean }) { - return ( -
-
-
- - {device.name} - - - - {device.mac} - - -
+ const [devices, setDeviceCart] = useAtom(deviceCartAtom) - - Active until{" "} - {new Date().toLocaleDateString("en-US", { - month: "short", - day: "2-digit", - year: "numeric", - })} - - {device.blocked && ( -
- Comment: -

- blocked because he was watching youtube -

+ const isChecked = devices.some((d) => d.id === device.id); + + return ( +
{ }} + onClick={() => { + if (parentalControl === true) return + setDeviceCart((prev) => + devices.some((d) => d.id === device.id) + ? prev.filter((d) => d.id !== device.id) + : [...prev, device] + ) + } + } + className="w-full"> +
+
+
+ + {device.name} + + + + {device.mac} + +
- )} - {!parentalControl ? ( - - ) : ( - - )} + + {device.isActive && ( + + Active until{" "} + {new Date().toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + year: "numeric", + })} + + )} + + {device.blocked && ( +
+ Comment: +

+ blocked because he was watching youtube +

+
+ )} + +
+
+ {!parentalControl ? ( + + ) : ( + + )} +
) diff --git a/components/devices-table.tsx b/components/devices-table.tsx index 65c2a73..c9258d7 100644 --- a/components/devices-table.tsx +++ b/components/devices-table.tsx @@ -11,9 +11,7 @@ import { import { auth } from "@/lib/auth"; import prisma from "@/lib/db"; import { headers } from "next/headers"; -import Link from "next/link"; -import AddDevicesToCartButton from "./add-devices-to-cart-button"; -import BlockDeviceButton from "./block-device-dialog"; +import ClickableRow from "./clickable-row"; import DeviceCard from "./device-card"; import Pagination from "./pagination"; @@ -56,7 +54,7 @@ export async function DevicesTable({ paid: false } }, - isActive: parentalControl ? parentalControl : undefined, + isActive: parentalControl, blocked: parentalControl !== undefined ? undefined : false, }, }); @@ -89,7 +87,6 @@ export async function DevicesTable({ }, isActive: parentalControl, blocked: parentalControl !== undefined ? undefined : false, - }, skip: offset, @@ -114,48 +111,49 @@ export async function DevicesTable({ Device Name MAC Address - Actions + # {devices.map((device) => ( - - -
- - {device.name} - - - Active until{" "} - {new Date().toLocaleDateString("en-US", { - month: "short", - day: "2-digit", - year: "numeric", - })} - - {parentalControl && ( -
- Comment: -

- blocked because he was watching youtube -

-
- )} + // + // + //
+ // + // {device.name} + // + // + // Active until{" "} + // {new Date().toLocaleDateString("en-US", { + // month: "short", + // day: "2-digit", + // year: "numeric", + // })} + // + // {parentalControl && ( + //
+ // Comment: + //

+ // blocked because he was watching youtube + //

+ //
+ // )} -
-
- {device.mac} - - {!parentalControl ? ( - - ) : ( - - )} - -
+ //
+ //
+ // {device.mac} + // + // {!parentalControl ? ( + // + // ) : ( + // + // )} + // + //
+ ))}