From e8296ae3f695abff5f2c3d10b070f6e28b872703 Mon Sep 17 00:00:00 2001 From: i701 Date: Thu, 10 Apr 2025 22:39:38 +0500 Subject: [PATCH] temporary fix for build and remove previous auth related code --- .vscode/settings.json | 3 + app/(dashboard)/user-payments/page.tsx | 6 +- .../users/[userId]/verify/page.tsx | 251 ++++++---- app/(dashboard)/users/page.tsx | 8 +- app/api/check-devices/route.ts | 262 +++++------ components/admin/admin-devices-table.tsx | 342 +++++++------- components/admin/user-payments-table.tsx | 432 +++++++++--------- components/user-table.tsx | 328 +++++++------ hooks/use-formula.ts | 8 - lib/auth-guard.ts | 14 - 10 files changed, 854 insertions(+), 800 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 hooks/use-formula.ts delete mode 100644 lib/auth-guard.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3662b37 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib" +} \ No newline at end of file diff --git a/app/(dashboard)/user-payments/page.tsx b/app/(dashboard)/user-payments/page.tsx index e689978..1a8605a 100644 --- a/app/(dashboard)/user-payments/page.tsx +++ b/app/(dashboard)/user-payments/page.tsx @@ -1,5 +1,4 @@ import { UsersPaymentsTable } from "@/components/admin/user-payments-table"; -import { AdminAuthGuard } from "@/lib/auth-guard"; import React, { Suspense } from "react"; export default async function UserPayments({ @@ -12,15 +11,12 @@ export default async function UserPayments({ status: string; }>; }) { - await AdminAuthGuard(); const query = (await searchParams)?.query || ""; return (
-

- User Payments -

+

User Payments

diff --git a/app/(dashboard)/users/[userId]/verify/page.tsx b/app/(dashboard)/users/[userId]/verify/page.tsx index 9c87191..52c60ae 100644 --- a/app/(dashboard)/users/[userId]/verify/page.tsx +++ b/app/(dashboard)/users/[userId]/verify/page.tsx @@ -1,95 +1,176 @@ -import InputReadOnly from '@/components/input-read-only'; -import { Badge } from '@/components/ui/badge'; -import UserRejectDialog from '@/components/user/user-reject-dialog'; -import { UserVerifyDialog } from '@/components/user/user-verify-dialog'; -import { getNationalPerson } from '@/lib/person'; +import InputReadOnly from "@/components/input-read-only"; +import { Badge } from "@/components/ui/badge"; +import UserRejectDialog from "@/components/user/user-reject-dialog"; +import { UserVerifyDialog } from "@/components/user/user-verify-dialog"; +import { getNationalPerson } from "@/lib/person"; -import prisma from '@/lib/db'; -import Image from 'next/image'; +import Image from "next/image"; export default async function VerifyUserPage({ - params, + params, }: { - params: Promise<{ - userId: string; - }>; + params: Promise<{ + userId: string; + }>; }) { - const userId = (await params).userId - const dbUser = await prisma.user.findUnique({ - where: { - id: userId, - }, - include: { - island: { - include: { - atoll: true - } - } - } - }) + const userId = (await params).userId; + // const dbUser = await prisma.user.findUnique({ + // where: { + // id: userId, + // }, + // include: { + // island: { + // include: { + // atoll: true + // } + // } + // } + // }) - const nationalData = await getNationalPerson({ idCard: dbUser?.id_card ?? "" }) + // const nationalData = await getNationalPerson({ idCard: dbUser?.id_card ?? "" }) + return null; + // return ( + //
+ //
+ //

Verify user

- return ( -
-
-

- Verify user -

+ //
+ // {dbUser && !dbUser?.verified && } + // {dbUser && !dbUser?.verified && } + // {dbUser?.verified && ( + // + // Verified + // + // )} + //
+ //
+ //
+ //
+ //

Database Information

+ //
+ // + // + // + // + // -
- {dbUser && !dbUser?.verified && } - {dbUser && !dbUser?.verified && } - {dbUser?.verified && Verified} -
- -
-
-
-

Database Information

-
- - - - - - - - -
-
-
-

National Information

-
- - - - - - - -
- id photo -
-
-
-
- -
- ) + // + // + //
+ //
+ //
+ //

National Information

+ //
+ // + // + // + // + // + // + // + //
+ // id photo + //
+ //
+ //
+ //
+ //
+ // ); } diff --git a/app/(dashboard)/users/page.tsx b/app/(dashboard)/users/page.tsx index fa3a250..2660b16 100644 --- a/app/(dashboard)/users/page.tsx +++ b/app/(dashboard)/users/page.tsx @@ -2,7 +2,6 @@ import { Rejectuser } from "@/actions/user-actions"; import Filter from "@/components/filter"; import Search from "@/components/search"; import { UsersTable } from "@/components/user-table"; -import { AdminAuthGuard } from "@/lib/auth-guard"; import { AArrowDown, AArrowUp, @@ -36,15 +35,10 @@ export default async function AdminUsers({ status: string; }>; }) { - await AdminAuthGuard(); - - return (
-

- Users -

+

Users

", device.name); - console.log("paid date -> ", device.payments[0]?.paidAt); - console.log("no of months paid -> ", device.payments[0]?.numberOfMonths); - console.log("calculated expire date -> ", expiryDate); - console.log("notification threshold -> ", notificationThreshold); - console.log("current date -> ", currentDate); + // console.log("device name -> ", device.name); + // console.log("paid date -> ", device.payments[0]?.paidAt); + // console.log("no of months paid -> ", device.payments[0]?.numberOfMonths); + // console.log("calculated expire date -> ", expiryDate); + // console.log("notification threshold -> ", notificationThreshold); + // console.log("current date -> ", currentDate); - // Check if device is within notification period - if ( - isWithinInterval(currentDate, { - start: notificationThreshold, - end: expiryDate, - }) - ) { - // Device is within 5 days of expiring - if (device.User?.phoneNumber) { - await sendNotifySms( - new Date(expiryDate), - device.User?.phoneNumber ?? "", - device.name, - ); - devicesNeedingNotification++; - } - } + // // Check if device is within notification period + // if ( + // isWithinInterval(currentDate, { + // start: notificationThreshold, + // end: expiryDate, + // }) + // ) { + // // Device is within 5 days of expiring + // if (device.User?.phoneNumber) { + // await sendNotifySms( + // new Date(expiryDate), + // device.User?.phoneNumber ?? "", + // device.name, + // ); + // devicesNeedingNotification++; + // } + // } - // Check if device has expired - if (isAfter(currentDate, expiryDate)) { - // Device has expired, block it - // TODO: add a reason for blocking - await blockDevice({ - macAddress: device.mac, - type: "block", - }); - await prisma.device.update({ - where: { id: device.id }, - data: { - isActive: false, - blocked: true, - }, - }); - devicesBlocked++; - } - } + // // Check if device has expired + // if (isAfter(currentDate, expiryDate)) { + // // Device has expired, block it + // // TODO: add a reason for blocking + // await blockDevice({ + // macAddress: device.mac, + // type: "block", + // }); + // await prisma.device.update({ + // where: { id: device.id }, + // data: { + // isActive: false, + // blocked: true, + // }, + // }); + // devicesBlocked++; + // } + // } - if (hoursSinceLastRun < 24) { - return Response.json({ - totalActiveDevices: devices.length, - devicesChecked: { - notified: devicesNeedingNotification, - blocked: devicesBlocked, - }, - message: "Check was run recently", - nextCheckIn: `${Math.round(24 - hoursSinceLastRun)} hours`, - }); - } + // if (hoursSinceLastRun < 24) { + // return Response.json({ + // totalActiveDevices: devices.length, + // devicesChecked: { + // notified: devicesNeedingNotification, + // blocked: devicesBlocked, + // }, + // message: "Check was run recently", + // nextCheckIn: `${Math.round(24 - hoursSinceLastRun)} hours`, + // }); + // } - return Response.json({ - success: true, - totalActiveDevices: devices.length, - devicesChecked: { - notified: devicesNeedingNotification, - blocked: devicesBlocked, - }, - runAt: currentTime, - }); - } catch (error) { - if (error instanceof Error) { - if (error.message === "API key is missing") { - return Response.json({ error: "API key is required" }, { status: 401 }); - } - if (error.message === "Invalid API key") { - return Response.json({ error: "Invalid API key" }, { status: 403 }); - } - } + // return Response.json({ + // success: true, + // totalActiveDevices: devices.length, + // devicesChecked: { + // notified: devicesNeedingNotification, + // blocked: devicesBlocked, + // }, + // runAt: currentTime, + // }); + // } catch (error) { + // if (error instanceof Error) { + // if (error.message === "API key is missing") { + // return Response.json({ error: "API key is required" }, { status: 401 }); + // } + // if (error.message === "Invalid API key") { + // return Response.json({ error: "Invalid API key" }, { status: 403 }); + // } + // } - console.error("Error in device check:", error); - return Response.json({ error: "Failed to check devices" }, { status: 500 }); - } -} - -// Mock function - replace with your actual SMS implementation -async function sendNotifySms( - expireDate: Date, - phoneNumber: string, - deviceName?: string, -) { - const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${process.env.SMS_API_KEY}`, - }, - body: JSON.stringify({ - check_delivery: false, - number: phoneNumber, - message: `REMINDER! Your device [${deviceName}] will expire on ${new Date(expireDate)}.`, - }), - }); - const data = await respose.json(); - console.log(data); - return data; - // Implement your SMS logic here + // console.error("Error in device check:", error); + // return Response.json({ error: "Failed to check devices" }, { status: 500 }); + // } + // } + + // // Mock function - replace with your actual SMS implementation + // async function sendNotifySms( + // expireDate: Date, + // phoneNumber: string, + // deviceName?: string, + // ) { + // const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, { + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: `Bearer ${process.env.SMS_API_KEY}`, + // }, + // body: JSON.stringify({ + // check_delivery: false, + // number: phoneNumber, + // message: `REMINDER! Your device [${deviceName}] will expire on ${new Date(expireDate)}.`, + // }), + // }); + // const data = await respose.json(); + // console.log(data); + // return data; + // } diff --git a/components/admin/admin-devices-table.tsx b/components/admin/admin-devices-table.tsx index ea6b3f1..7dcd06b 100644 --- a/components/admin/admin-devices-table.tsx +++ b/components/admin/admin-devices-table.tsx @@ -8,8 +8,6 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import { auth } from "@/app/auth"; -import prisma from "@/lib/db"; import { headers } from "next/headers"; import Link from "next/link"; import BlockDeviceDialog from "../block-device-dialog"; @@ -27,178 +25,178 @@ export async function AdminDevicesTable({ }>; parentalControl?: boolean; }) { - const session = await auth.api.getSession({ - headers: await headers(), - }); - const isAdmin = session?.user.role === "ADMIN"; - const query = (await searchParams)?.query || ""; - const page = (await searchParams)?.page; - const sortBy = (await searchParams)?.sortBy || "asc"; - const totalDevices = await prisma.device.count({ - where: { - OR: [ - { - name: { - contains: query || "", - mode: "insensitive", - }, - }, - { - mac: { - contains: query || "", - mode: "insensitive", - }, - }, - ], - }, - }); + // const session = await auth.api.getSession({ + // headers: await headers(), + // }); + // const isAdmin = session?.user.role === "ADMIN"; + // const query = (await searchParams)?.query || ""; + // const page = (await searchParams)?.page; + // const sortBy = (await searchParams)?.sortBy || "asc"; + // const totalDevices = await prisma.device.count({ + // where: { + // OR: [ + // { + // name: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // { + // mac: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // ], + // }, + // }); - const totalPages = Math.ceil(totalDevices / 10); - const limit = 10; - const offset = (Number(page) - 1) * limit || 0; + // const totalPages = Math.ceil(totalDevices / 10); + // const limit = 10; + // const offset = (Number(page) - 1) * limit || 0; - const devices = await prisma.device.findMany({ - where: { - OR: [ - { - name: { - contains: query || "", - mode: "insensitive", - }, - }, - { - mac: { - contains: query || "", - mode: "insensitive", - }, - }, - ], - }, - include: { - User: true, - payments: true, - }, - skip: offset, - take: limit, - orderBy: { - name: `${sortBy}` as "asc" | "desc", - }, - }); + // const devices = await prisma.device.findMany({ + // where: { + // OR: [ + // { + // name: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // { + // mac: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // ], + // }, + // include: { + // User: true, + // payments: true, + // }, + // skip: offset, + // take: limit, + // orderBy: { + // name: `${sortBy}` as "asc" | "desc", + // }, + // }); + return null; + // return ( + //
+ // {devices.length === 0 ? ( + //
+ //

No devices yet.

+ //
+ // ) : ( + // <> + //
+ // + // Table of all devices. + // + // + // Device Name + // User + // MAC Address + // isActive + // blocked + // blockedBy + // expiryDate + // + // + // + // {devices.map((device) => ( + // + // + //
+ // + // {device.name} + // + // {device.isActive && ( + // + // Active until{" "} + // {new Date().toLocaleDateString("en-US", { + // month: "short", + // day: "2-digit", + // year: "numeric", + // })} + // + // )} - return ( -
- {devices.length === 0 ? ( -
-

No devices yet.

-
- ) : ( - <> -
-
- Table of all devices. - - - Device Name - User - MAC Address - isActive - blocked - blockedBy - expiryDate - - - - {devices.map((device) => ( - - -
- - {device.name} - - {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 + //

+ //
+ // )} + //
+ //
+ // + // {device.User?.name} + // - {device.blocked && ( -
- Comment: -

- blocked because he was watching youtube -

-
- )} - - - - {device.User?.name} - - - {device.mac} - - {device.isActive ? "Active" : "Inactive"} - - - {device.blocked ? "Blocked" : "Not Blocked"} - - - {device.blocked ? device.blockedBy : ""} - - - {new Date().toLocaleDateString("en-US", { - month: "short", - day: "2-digit", - year: "numeric", - })} - - - - -
- ))} -
- - - - {query.length > 0 && ( -

- Showing {devices.length} locations for "{query} - " -

- )} -
- - {totalDevices} devices - -
-
-
- -
-
- {devices.map((device) => ( - - ))} -
- - )} -
- ); + // {device.mac} + // + // {device.isActive ? "Active" : "Inactive"} + // + // + // {device.blocked ? "Blocked" : "Not Blocked"} + // + // + // {device.blocked ? device.blockedBy : ""} + // + // + // {new Date().toLocaleDateString("en-US", { + // month: "short", + // day: "2-digit", + // year: "numeric", + // })} + // + // + // + // + // + // ))} + // + // + // + // + // {query.length > 0 && ( + //

+ // Showing {devices.length} locations for "{query} + // " + //

+ // )} + //
+ // + // {totalDevices} devices + // + //
+ //
+ // + // + //
+ //
+ // {devices.map((device) => ( + // + // ))} + //
+ // + // )} + //
+ // ); } diff --git a/components/admin/user-payments-table.tsx b/components/admin/user-payments-table.tsx index 7d0ae08..d6d9e42 100644 --- a/components/admin/user-payments-table.tsx +++ b/components/admin/user-payments-table.tsx @@ -2,228 +2,234 @@ import Pagination from "@/components/pagination"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { - Table, - TableBody, - TableCaption, - TableCell, - TableFooter, - TableHead, - TableHeader, - TableRow, + Table, + TableBody, + TableCaption, + TableCell, + TableFooter, + TableHead, + TableHeader, + TableRow, } from "@/components/ui/table"; -import prisma from "@/lib/db"; import Link from "next/link"; export async function UsersPaymentsTable({ - searchParams, + searchParams, }: { - searchParams: Promise<{ - query: string; - page: number; - sortBy: string; - status: string; - }>; + searchParams: Promise<{ + query: string; + page: number; + sortBy: string; + status: string; + }>; }) { - const query = (await searchParams)?.query || ""; - const page = (await searchParams)?.page; - const sortBy = (await searchParams)?.sortBy || "asc"; - const totalPayments = await prisma.payment.count({ - where: { - OR: [ - { - user: { - name: { - contains: query || "", - mode: "insensitive", - } - }, - }, - { - user: { - phoneNumber: { - contains: query || "", - mode: "insensitive", - } - }, - }, - { - user: { - address: { - contains: query || "", - mode: "insensitive", - } - }, - }, - { - user: { - id_card: { - contains: query || "", - mode: "insensitive", - } - }, - }, - ], - }, - }); + const query = (await searchParams)?.query || ""; + const page = (await searchParams)?.page; + const sortBy = (await searchParams)?.sortBy || "asc"; + // const totalPayments = await prisma.payment.count({ + // where: { + // OR: [ + // { + // user: { + // name: { + // contains: query || "", + // mode: "insensitive", + // } + // }, + // }, + // { + // user: { + // phoneNumber: { + // contains: query || "", + // mode: "insensitive", + // } + // }, + // }, + // { + // user: { + // address: { + // contains: query || "", + // mode: "insensitive", + // } + // }, + // }, + // { + // user: { + // id_card: { + // contains: query || "", + // mode: "insensitive", + // } + // }, + // }, + // ], + // }, + // }); - const totalPages = Math.ceil(totalPayments / 10); - const limit = 10; - const offset = (Number(page) - 1) * limit || 0; + // const totalPages = Math.ceil(totalPayments / 10); + // const limit = 10; + // const offset = (Number(page) - 1) * limit || 0; - const payments = await prisma.payment.findMany({ - where: { - OR: [ - { - user: { - name: { - contains: query || "", - mode: "insensitive", - } - }, - }, - { - user: { - phoneNumber: { - contains: query || "", - mode: "insensitive", - } - }, - }, - { - user: { - address: { - contains: query || "", - mode: "insensitive", - } - }, - }, - { - user: { - id_card: { - contains: query || "", - mode: "insensitive", - } - }, - }, - ], - }, - include: { - user: true, - devices: true, - }, - skip: offset, - take: limit, - orderBy: { - id: `${sortBy}` as "asc" | "desc", - }, - }); + // const payments = await prisma.payment.findMany({ + // where: { + // OR: [ + // { + // user: { + // name: { + // contains: query || "", + // mode: "insensitive", + // } + // }, + // }, + // { + // user: { + // phoneNumber: { + // contains: query || "", + // mode: "insensitive", + // } + // }, + // }, + // { + // user: { + // address: { + // contains: query || "", + // mode: "insensitive", + // } + // }, + // }, + // { + // user: { + // id_card: { + // contains: query || "", + // mode: "insensitive", + // } + // }, + // }, + // ], + // }, + // include: { + // user: true, + // devices: true, + // }, + // skip: offset, + // take: limit, + // orderBy: { + // id: `${sortBy}` as "asc" | "desc", + // }, + // }); - // const users = await prisma.user.findMany({ - // where: { - // role: "USER", - // }, - // include: { - // atoll: true, - // island: true, - // }, - // }); - return ( -
- {payments.length === 0 ? ( -
-

No user payments yet.

-
- ) : ( - <> - - Table of all users. - - - Devices paid - User - Amount - Duration - Payment Status - Payment Method - Paid At - Action - - - - {payments.map((payment) => ( - - -
    - {payment.devices.map((device) => ( -
  1. - {device.name} -
  2. - ))} -
-
- {payment.user.id_card} - {payment.user?.name} - {payment.user?.name} - {payment.id} + // const users = await prisma.user.findMany({ + // where: { + // role: "USER", + // }, + // include: { + // atoll: true, + // island: true, + // }, + // }); + return null; + // return ( + //
+ // {payments.length === 0 ? ( + //
+ //

No user payments yet.

+ //
+ // ) : ( + // <> + //
+ // Table of all users. + // + // + // Devices paid + // User + // Amount + // Duration + // Payment Status + // Payment Method + // Paid At + // Action + // + // + // + // {payments.map((payment) => ( + // + // + //
    + // {payment.devices.map((device) => ( + //
  1. + // {device.name} + //
  2. + // ))} + //
+ //
+ // + // {payment.user.id_card} + // + // {payment.user?.name} + // {payment.user?.name} + // {payment.id} - - {payment.paid ? ( - - Verified - - ) : ( - - Unverified - - )} - - - {new Date(payment.paidAt ?? "").toLocaleDateString("en-US", { - month: "short", - day: "2-digit", - year: "numeric", - })} - + // + // {payment.paid ? ( + // + // Verified + // + // ) : ( + // + // Unverified + // + // )} + // + // + // {new Date(payment.paidAt ?? "").toLocaleDateString( + // "en-US", + // { + // month: "short", + // day: "2-digit", + // year: "numeric", + // }, + // )} + // - {payment.id} - - - - - -
- ))} -
- - - - {query.length > 0 && ( -

- Showing {payments.length} locations for "{query} - " -

- )} -
- - {totalPayments} payments - -
-
-
- - - )} -
- ); + // {payment.id} + // + // + // + // + // + // + // ))} + // + // + // + // + // {query.length > 0 && ( + //

+ // Showing {payments.length} locations for "{query} + // " + //

+ // )} + //
+ // + // {totalPayments} payments + // + //
+ //
+ // + // + // + // )} + //
+ // ); } diff --git a/components/user-table.tsx b/components/user-table.tsx index 2ec9f72..1e54966 100644 --- a/components/user-table.tsx +++ b/components/user-table.tsx @@ -8,7 +8,6 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import prisma from "@/lib/db"; import Link from "next/link"; import Pagination from "./pagination"; import { Badge } from "./ui/badge"; @@ -28,84 +27,84 @@ export async function UsersTable({ const page = (await searchParams)?.page; const sortBy = (await searchParams)?.sortBy || "asc"; const verified = (await searchParams)?.status || "all"; - const totalUsers = await prisma.user.count({ - where: { - OR: [ - { - name: { - contains: query || "", - mode: "insensitive", - }, - }, - { - phoneNumber: { - contains: query || "", - mode: "insensitive", - }, - }, - { - address: { - contains: query || "", - mode: "insensitive", - }, - }, - { - id_card: { - contains: query || "", - mode: "insensitive", - }, - }, - ], - verified: verified === "all" ? undefined : verified === "verified", - }, + // const totalUsers = await prisma.user.count({ + // where: { + // OR: [ + // { + // name: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // { + // phoneNumber: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // { + // address: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // { + // id_card: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // ], + // verified: verified === "all" ? undefined : verified === "verified", + // }, - }); + // }); - const totalPages = Math.ceil(totalUsers / 10); - const limit = 10; - const offset = (Number(page) - 1) * limit || 0; + // const totalPages = Math.ceil(totalUsers / 10); + // const limit = 10; + // const offset = (Number(page) - 1) * limit || 0; - const users = await prisma.user.findMany({ - where: { - OR: [ - { - name: { - contains: query || "", - mode: "insensitive", - }, - }, - { - phoneNumber: { - contains: query || "", - mode: "insensitive", - }, - }, - { - address: { - contains: query || "", - mode: "insensitive", - }, - }, - { - id_card: { - contains: query || "", - mode: "insensitive", - }, - }, - ], - verified: verified === "all" ? undefined : verified === "verified", + // const users = await prisma.user.findMany({ + // where: { + // OR: [ + // { + // name: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // { + // phoneNumber: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // { + // address: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // { + // id_card: { + // contains: query || "", + // mode: "insensitive", + // }, + // }, + // ], + // verified: verified === "all" ? undefined : verified === "verified", - }, - include: { - island: true, - atoll: true, - }, - skip: offset, - take: limit, - orderBy: { - id: `${sortBy}` as "asc" | "desc", - }, - }); + // }, + // include: { + // island: true, + // atoll: true, + // }, + // skip: offset, + // take: limit, + // orderBy: { + // id: `${sortBy}` as "asc" | "desc", + // }, + // }); // const users = await prisma.user.findMany({ // where: { @@ -116,96 +115,95 @@ export async function UsersTable({ // island: true, // }, // }); - return ( -
- {users.length === 0 ? ( -
-

No Users yet.

-
- ) : ( - <> - - Table of all users. - - - Name - ID Card - Atoll - Island - House Name - Status - Dob - Phone Number - Action - - - - {users.map((user) => ( - - {user.name} - {user.id_card} - {user.atoll?.name} - {user.island?.name} - {user.address} + return null; + // return ( + //
+ // {users.length === 0 ? ( + //
+ //

No Users yet.

+ //
+ // ) : ( + // <> + //
+ // Table of all users. + // + // + // Name + // ID Card + // Atoll + // Island + // House Name + // Status + // Dob + // Phone Number + // Action + // + // + // + // {users.map((user) => ( + // + // {user.name} + // {user.id_card} + // {user.atoll?.name} + // {user.island?.name} + // {user.address} - - {user.verified ? ( - - Verified - - ) : ( - - Unverified - - )} - - - {new Date(user.dob ?? "").toLocaleDateString("en-US", { - month: "short", - day: "2-digit", - year: "numeric", - })} - + // + // {user.verified ? ( + // + // Verified + // + // ) : ( + // + // Unverified + // + // )} + // + // + // {new Date(user.dob ?? "").toLocaleDateString("en-US", { + // month: "short", + // day: "2-digit", + // year: "numeric", + // })} + // - {user.phoneNumber} - - - - - - - ))} - - - - - {query.length > 0 && ( -

- Showing {users.length} locations for "{query} - " -

- )} -
- - {totalUsers} users - -
-
-
- - - )} -
- ); + // {user.phoneNumber} + // + // + // + // + // + // + // ))} + // + // + // + // + // {query.length > 0 && ( + //

+ // Showing {users.length} locations for "{query} + // " + //

+ // )} + //
+ // + // {totalUsers} users + // + //
+ //
+ // + // + // + // )} + // + // ); } diff --git a/hooks/use-formula.ts b/hooks/use-formula.ts deleted file mode 100644 index 10b2f7e..0000000 --- a/hooks/use-formula.ts +++ /dev/null @@ -1,8 +0,0 @@ -"use server"; - -import prisma from "@/lib/db"; - -export async function useFormula() { - const formula = await prisma.billFormula.findFirst(); - return formula; -} diff --git a/lib/auth-guard.ts b/lib/auth-guard.ts deleted file mode 100644 index 8c9416e..0000000 --- a/lib/auth-guard.ts +++ /dev/null @@ -1,14 +0,0 @@ -"use server"; -import { auth } from "@/app/auth"; -import { headers } from "next/headers"; -import { redirect } from "next/navigation"; - -export async function AdminAuthGuard() { - const session = await auth.api.getSession({ - headers: await headers(), - }); - if (session?.user.role !== "ADMIN") { - return redirect("/login"); - } - return true; -}