From 1b81639e928703210e28528574cdc8dc0d7b6129 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 27 Aug 2025 23:16:42 +0800 Subject: [PATCH] redirect to credit when success topup --- src/app/credits/success/page.tsx | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/app/credits/success/page.tsx b/src/app/credits/success/page.tsx index 2a6938c..e4b8c81 100644 --- a/src/app/credits/success/page.tsx +++ b/src/app/credits/success/page.tsx @@ -1,7 +1,7 @@ 'use client' import { useEffect, useState } from 'react' -import { useSearchParams } from 'next/navigation' +import { useSearchParams, useRouter } from 'next/navigation' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { CheckCircle, Loader2 } from 'lucide-react' @@ -9,10 +9,12 @@ import Link from 'next/link' export default function CreditTopupSuccess() { const searchParams = useSearchParams() + const router = useRouter() const sessionId = searchParams.get('session_id') const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [amount, setAmount] = useState(null) + const [countdown, setCountdown] = useState(3) useEffect(() => { if (sessionId) { @@ -38,6 +40,24 @@ export default function CreditTopupSuccess() { } }, [sessionId]) + // 倒计时和自动跳转 + useEffect(() => { + if (!loading && !error && amount !== null) { + const timer = setInterval(() => { + setCountdown((prev) => { + if (prev <= 1) { + clearInterval(timer) + router.push('/credits') + return 0 + } + return prev - 1 + }) + }, 1000) + + return () => clearInterval(timer) + } + }, [loading, error, amount, router]) + if (loading) { return (
@@ -87,6 +107,13 @@ export default function CreditTopupSuccess() {

Your credit top-up has been processed successfully. The credits have been added to your account.

+ {countdown > 0 && ( +
+

+ Redirecting to credits page in {countdown} seconds... +

+
+ )}