diff --git a/actions/payment.ts b/actions/payment.ts
index 030613f..019300a 100644
--- a/actions/payment.ts
+++ b/actions/payment.ts
@@ -8,6 +8,7 @@ import type {
Payment,
} from "@/lib/backend-types";
import type { User } from "@/lib/types/user";
+import { checkSession } from "@/utils/session";
import { tryCatch } from "@/utils/tryCatch";
import { getServerSession } from "next-auth";
import { revalidatePath } from "next/cache";
@@ -200,27 +201,15 @@ type VerifyPaymentType = {
type?: "TRANSFER" | "WALLET";
};
-class InsufficientFundsError extends Error {
- constructor() {
- super("Insufficient funds in wallet");
- this.name = "InsufficientFundsError";
- }
-}
-
export async function processWalletPayment({
payment,
amount,
}: { payment: Payment | undefined; amount: number }) {
+ await checkSession();
const session = await getServerSession(authOptions);
- if (!session?.user || !payment) {
- throw new Error("User or payment not found");
- }
-
- const walletBalance = session.user.wallet_balance ?? 0;
- if (walletBalance < amount) {
- throw new InsufficientFundsError();
- }
-
+ const walletBalance = session?.user?.wallet_balance ?? 0;
+ console.log("processing wallet payment >>>", walletBalance);
+ if (!payment) return;
const [updatePaymentError, _] = await tryCatch(
updatePayment({
id: payment.id,
@@ -235,9 +224,10 @@ export async function processWalletPayment({
}
console.log("Wallet balance before update:", walletBalance);
const updated_balance = walletBalance - amount;
+ if (!session?.user?.id) return;
const [walletUpdateError, response] = await tryCatch(
updateWalletBalance({
- id: session.user.id,
+ id: session?.user?.id,
wallet_balance: Number.parseFloat(updated_balance?.toFixed(2) ?? "0"),
}),
);
diff --git a/app/(dashboard)/devices/device-table-skeleton.tsx b/app/(dashboard)/devices/device-table-skeleton.tsx
new file mode 100644
index 0000000..033426f
--- /dev/null
+++ b/app/(dashboard)/devices/device-table-skeleton.tsx
@@ -0,0 +1,78 @@
+import { Skeleton } from "@/components/ui/skeleton";
+import {
+ Table,
+ TableBody,
+ TableCaption,
+ TableCell,
+ TableFooter,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/components/ui/table";
+import { cn } from "@/lib/utils";
+
+export default function DevicesTableSkeleton() {
+ return (
+ <>
+
+
+ Table of all devices.
+
+
+ Device Name
+ MAC Address
+ #
+
+
+
+ {Array.from({ length: 10 }).map((_, i) => (
+
+
+
+
+
+
+
+
+
+
+
+ ))}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {Array.from({ length: 10 }).map((_, i) => (
+
+ ))}
+
+ >
+ );
+}
+
+function DeviceCardSkeleton() {
+ return (
+
+ );
+}
diff --git a/app/(dashboard)/devices/page.tsx b/app/(dashboard)/devices/page.tsx
index dcdd1d0..7cce623 100644
--- a/app/(dashboard)/devices/page.tsx
+++ b/app/(dashboard)/devices/page.tsx
@@ -4,6 +4,7 @@ import Search from "@/components/search";
import AddDeviceDialogForm from "@/components/user/add-device-dialog";
import { getServerSession } from "next-auth";
import React, { Suspense } from "react";
+import DevicesTableSkeleton from "./device-table-skeleton";
export default async function Devices({
searchParams,
@@ -11,11 +12,10 @@ export default async function Devices({
searchParams: Promise<{
query: string;
page: number;
- sortBy: string;
- status: string;
}>;
}) {
const query = (await searchParams)?.query || "";
+ const page = (await searchParams)?.page || 1;
const session = await getServerSession(authOptions);
return (
@@ -29,7 +29,7 @@ export default async function Devices({
>
-
+ }>
diff --git a/components/clickable-row.tsx b/components/clickable-row.tsx
index 7a32f3e..9b6e8ab 100644
--- a/components/clickable-row.tsx
+++ b/components/clickable-row.tsx
@@ -4,7 +4,7 @@ import { deviceCartAtom } from "@/lib/atoms";
import type { Device } from "@/lib/backend-types";
import { cn } from "@/lib/utils";
import { useAtom } from "jotai";
-import { Hourglass } from "lucide-react";
+import { HandCoins } from "lucide-react";
import Link from "next/link";
import AddDevicesToCartButton from "./add-devices-to-cart-button";
import BlockDeviceDialog from "./block-device-dialog";
@@ -67,7 +67,8 @@ export default function ClickableRow({
{device.has_a_pending_payment && (
- Payment Pending
+ Payment Pending{" "}
+
)}
diff --git a/components/devices-table.tsx b/components/devices-table.tsx
index c210651..2142d84 100644
--- a/components/devices-table.tsx
+++ b/components/devices-table.tsx
@@ -25,7 +25,6 @@ export async function DevicesTable({
searchParams: Promise<{
query: string;
page: number;
- sortBy: string;
}>;
parentalControl?: boolean;
}) {
@@ -89,10 +88,6 @@ export async function DevicesTable({
-
{data?.map((device) => (
@@ -103,6 +98,10 @@ export async function DevicesTable({
/>
))}
+
>
)}