diff --git a/app/(dashboard)/payments/page.tsx b/app/(dashboard)/payments/page.tsx index 768850e..1b8e60d 100644 --- a/app/(dashboard)/payments/page.tsx +++ b/app/(dashboard)/payments/page.tsx @@ -1,9 +1,9 @@ +import { redirect } from "next/navigation"; +import { getServerSession } from "next-auth"; +import { Suspense } from "react"; import { authOptions } from "@/app/auth"; import { PaymentsTable } from "@/components/payments-table"; import Search from "@/components/search"; -import { getServerSession } from "next-auth"; -import { redirect } from "next/navigation"; -import { Suspense } from "react"; export default async function Payments({ searchParams, diff --git a/app/(dashboard)/user-devices/page.tsx b/app/(dashboard)/user-devices/page.tsx index e5654d6..a214eb6 100644 --- a/app/(dashboard)/user-devices/page.tsx +++ b/app/(dashboard)/user-devices/page.tsx @@ -1,4 +1,7 @@ +import { redirect } from "next/navigation"; +import { getServerSession } from "next-auth"; import { Suspense } from "react"; +import { authOptions } from "@/app/auth"; import { AdminDevicesTable } from "@/components/admin/admin-devices-table"; import DynamicFilter from "@/components/generic-filter"; @@ -13,6 +16,8 @@ export default async function UserDevices({ }>; }) { const query = (await searchParams)?.query || ""; + const session = await getServerSession(authOptions); + if (session?.user?.is_admin !== true) redirect("/devices?page=1"); return (
{JSON.stringify(session, null, 2)}
A MAC (Media Access Control) address is a unique identifier assigned to a device`'`s network. It is used to identify the device on a diff --git a/components/payments-table.tsx b/components/payments-table.tsx index 7834a79..5e6bbbd 100644 --- a/components/payments-table.tsx +++ b/components/payments-table.tsx @@ -1,3 +1,7 @@ +import { Calendar } from "lucide-react"; +import Link from "next/link"; +import { redirect } from "next/navigation"; +import { getPayments } from "@/actions/payment"; import { Table, TableBody, @@ -8,14 +12,9 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import Link from "next/link"; - -import { getPayments } from "@/actions/payment"; import type { Payment } from "@/lib/backend-types"; import { cn } from "@/lib/utils"; import { tryCatch } from "@/utils/tryCatch"; -import { Calendar } from "lucide-react"; -import { redirect } from "next/navigation"; import Pagination from "./pagination"; import { Badge } from "./ui/badge"; import { Button } from "./ui/button"; @@ -31,59 +30,6 @@ export async function PaymentsTable({ }>; }) { const query = (await searchParams)?.query || ""; - // const session = await auth.api.getSession({ - // headers: await headers(), - // }); - // const query = (await searchParams)?.query || ""; - // const page = (await searchParams)?.page; - // const totalPayments = await prisma.payment.count({ - // where: { - // userId: session?.session.userId, - // OR: [ - // { - // devices: { - // every: { - // name: { - // contains: query || "", - // mode: "insensitive", - // }, - // }, - // }, - // }, - // ], - // }, - // }); - - // const totalPages = Math.ceil(totalPayments / 10); - // const limit = 10; - // const offset = (Number(page) - 1) * limit || 0; - - // const payments = await prisma.payment.findMany({ - // where: { - // userId: session?.session.userId, - // OR: [ - // { - // devices: { - // every: { - // name: { - // contains: query || "", - // mode: "insensitive", - // }, - // }, - // }, - // }, - // ], - // }, - // include: { - // devices: true, - // }, - - // skip: offset, - // take: limit, - // orderBy: { - // createdAt: "desc", - // }, - // }); const [error, payments] = await tryCatch(getPayments()); if (error) { @@ -223,7 +169,7 @@ function MobilePaymentDetails({ payment }: { payment: Payment }) { return (
) diff --git a/components/user/add-device-dialog.tsx b/components/user/add-device-dialog.tsx index 49a105a..4f98afe 100644 --- a/components/user/add-device-dialog.tsx +++ b/components/user/add-device-dialog.tsx @@ -1,15 +1,14 @@ "use client"; +import { Loader2, Plus } from "lucide-react"; +import { useActionState, useEffect, useState } from "react"; // Import useActionState +import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; -import { Loader2, Plus } from "lucide-react"; -import { useActionState, useEffect, useState } from "react"; // Import useActionState -import { toast } from "sonner"; -import { GetMacAccordion } from "../how-to-get-mac"; - import { addDeviceAction } from "@/queries/devices"; +import { GetMacAccordion } from "../how-to-get-mac"; export type AddDeviceFormState = { message: string; @@ -72,7 +71,7 @@ export default function AddDeviceDialogForm({ user_id }: { user_id?: string }) {