"use client"; import { BadgeDollarSign, Clipboard, ClipboardCheck, Loader2, Wallet, } from "lucide-react"; import { useActionState, useEffect, useState } from "react"; import { toast } from "sonner"; import { type VerifyDevicePaymentState, verifyDevicePayment } from "@/actions/payment"; import { Table, TableBody, TableCaption, TableCell, TableFooter, TableRow, } from "@/components/ui/table"; import type { Payment } from "@/lib/backend-types"; import type { User } from "@/lib/types/user"; import { Button } from "./ui/button"; const initialState: VerifyDevicePaymentState = { message: "", success: false, fieldErrors: {}, }; export default function DevicesToPay({ payment, user, }: { payment?: Payment; user?: User }) { const [state, formAction, isPending] = useActionState(verifyDevicePayment, initialState); // Handle toast notifications based on state changes useEffect(() => { if (state.success && state.message) { toast.success("Payment successful!", { closeButton: true, description: state.message, }); } else if (!state.success && state.message && state.message !== initialState.message) { toast.error("Payment Verification Failed", { closeButton: true, description: state.message, }); } }, [state]); const devices = payment?.devices; if (devices?.length === 0) { return null; } // 100+(n−1)×75 const walletBalance = user?.wallet_balance ?? 0; const isWalletPayVisible = walletBalance > (payment?.amount ?? 0); return (
Account No
{accountNo}