diff --git a/app/(dashboard)/top-ups/[topupId]/page.tsx b/app/(dashboard)/top-ups/[topupId]/page.tsx index 8bc9827..a36e23f 100644 --- a/app/(dashboard)/top-ups/[topupId]/page.tsx +++ b/app/(dashboard)/top-ups/[topupId]/page.tsx @@ -9,72 +9,72 @@ import { TextShimmer } from "@/components/ui/text-shimmer"; import { cn } from "@/lib/utils"; import { tryCatch } from "@/utils/tryCatch"; export default async function TopupPage({ - params, + params, }: { - params: Promise<{ topupId: string }>; + params: Promise<{ topupId: string }>; }) { - const topupId = (await params).topupId; - const [error, topup] = await tryCatch(getTopup({ id: topupId })); - if (error) { - if (error.message === "Invalid token.") redirect("/auth/signin"); - return ; - } + const topupId = (await params).topupId; + const [error, topup] = await tryCatch(getTopup({ id: topupId })); + if (error) { + if (error.message === "Invalid token.") redirect("/auth/signin"); + return ; + } - return ( -
-
-

Topup

-
- {!topup.is_expired && topup.paid && topup.status !== "PENDING" && ( - - )} - {topup.status === "PENDING" && !topup.is_expired && ( - - )} + return ( +
+
+

Topup

+
+ {!topup.is_expired && topup.paid && topup.status !== "PENDING" && ( + + )} + {topup.status === "PENDING" && !topup.is_expired && ( + + )} - {!topup.paid && - (topup.is_expired ? ( - - ) : topup.status === "PENDING" ? ( - - ) : topup.status === "CANCELLED" ? ( - - ) : ( - "" - ))} -
-
- {!topup.paid && topup.status === "PENDING" && !topup.is_expired && ( - - )} -
- -
-
- ); + {!topup.paid && + (topup.is_expired ? ( + + ) : topup.status === "PENDING" ? ( + + ) : topup.status === "CANCELLED" ? ( + + ) : ( + "" + ))} +
+
+ {!topup.paid && topup.status === "PENDING" && !topup.is_expired && ( + + )} +
+ +
+
+ ); } diff --git a/components/topup-to-pay.tsx b/components/topup-to-pay.tsx index 02f69af..9c8ba25 100644 --- a/components/topup-to-pay.tsx +++ b/components/topup-to-pay.tsx @@ -3,151 +3,155 @@ import { BadgeDollarSign, Loader2 } from "lucide-react"; import { useActionState, useEffect } from "react"; import { toast } from "sonner"; import { - type VerifyTopupPaymentState, - verifyTopupPayment, + type VerifyTopupPaymentState, + verifyTopupPayment, } from "@/actions/payment"; import { - Table, - TableBody, - TableCaption, - TableCell, - TableFooter, - TableRow, + Table, + TableBody, + TableCaption, + TableCell, + TableFooter, + TableRow, } from "@/components/ui/table"; import type { Topup } from "@/lib/backend-types"; import { AccountInfomation } from "./account-information"; import { Button } from "./ui/button"; const initialState: VerifyTopupPaymentState = { - message: "", - success: false, - fieldErrors: {}, + message: "", + success: false, + fieldErrors: {}, }; export default function TopupToPay({ - topup, - disabled, + topup, + disabled, }: { - topup?: Topup; - disabled?: boolean; + topup?: Topup; + disabled?: boolean; }) { - const [state, formAction, isPending] = useActionState( - verifyTopupPayment, - initialState, - ); + const [state, formAction, isPending] = useActionState( + verifyTopupPayment, + initialState, + ); - // Handle toast notifications based on state changes - useEffect(() => { - if (state.success && state.message) { - toast.success("Topup successful!", { - closeButton: true, - description: state.transaction - ? `Your topup payment has been verified successfully using ${state.transaction.sourceBank} bank transfer on ${state.transaction.trxDate}.` - : state.message, - }); - } else if ( - !state.success && - state.message && - state.message !== initialState.message - ) { - toast.error("Topup Payment Verification Failed", { - closeButton: true, - description: state.message, - }); - } - }, [state]); + // Handle toast notifications based on state changes + useEffect(() => { + if (state.success && state.message) { + toast.success("Topup successful!", { + closeButton: true, + description: state.transaction + ? `Your topup payment has been verified successfully using ${state.transaction.sourceBank} bank transfer on ${state.transaction.trxDate}.` + : state.message, + }); + } else if ( + !state.success && + state.message && + state.message !== initialState.message + ) { + toast.error("Topup Payment Verification Failed", { + closeButton: true, + description: state.message, + }); + } + }, [state]); - return ( -
-
- - -
-

Please send the following amount to the payment address

- - {topup?.paid ? ( - - ) : ( -
-
- - - -
- )} -
-
- - - Topup created - - {new Date(topup?.created_at ?? "").toLocaleDateString("en-US", { - month: "short", - day: "2-digit", - year: "numeric", - minute: "2-digit", - hour: "2-digit", - second: "2-digit", - })} - - - - Payment received - - {topup?.paid_at - ? new Date(topup.paid_at).toLocaleDateString("en-US", { - month: "short", - day: "2-digit", - year: "numeric", - minute: "2-digit", - hour: "2-digit", - second: "2-digit", - }) - : "-"} - - - - MIB Reference - - {topup?.mib_reference ? topup.mib_reference : "-"} - - - - - - Total Due - - {topup?.amount?.toFixed(2)} - - - -
-
-
- ); + return ( +
+
+ + + {!topup?.paid || + topup?.is_expired || + (topup?.status !== "CANCELLED" && ( +
+

Please send the following amount to the payment address

+ + {topup?.paid ? ( + + ) : ( +
+
+ + + +
+ )} +
+ ))} +
+ + + Topup created + + {new Date(topup?.created_at ?? "").toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + year: "numeric", + minute: "2-digit", + hour: "2-digit", + second: "2-digit", + })} + + + + Payment received + + {topup?.paid_at + ? new Date(topup.paid_at).toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + year: "numeric", + minute: "2-digit", + hour: "2-digit", + second: "2-digit", + }) + : "-"} + + + + MIB Reference + + {topup?.mib_reference ? topup.mib_reference : "-"} + + + + + + Total Due + + {topup?.amount?.toFixed(2)} + + + +
+
+
+ ); }