feat: enhance payment flow with automatic redirection to appointment history after successful payment
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||
import { request } from "@/services/response";
|
||||
import { formatToman } from "@/lib/money";
|
||||
import Cookies from "js-cookie";
|
||||
@@ -10,6 +10,7 @@ import Layout from "@/components/layout";
|
||||
export default function PaymentDetailsPage() {
|
||||
const params = useParams();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const [payment, setPayment] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
@@ -54,6 +55,15 @@ export default function PaymentDetailsPage() {
|
||||
}
|
||||
}, [params.uuid, router]);
|
||||
|
||||
// پس از دیدن جزئیاتِ پرداختِ موفق، خودکار به تاریخچهٔ نوبتها (تب تأییدشده) برو.
|
||||
useEffect(() => {
|
||||
const isSuccess = searchParams.get("status") === "success" || payment?.status === "success";
|
||||
if (isSuccess) {
|
||||
const t = setTimeout(() => router.push("/dashboard?sidebar=1"), 4000);
|
||||
return () => clearTimeout(t);
|
||||
}
|
||||
}, [payment, searchParams, router]);
|
||||
|
||||
const getStatusLabel = (status) => {
|
||||
const statusMap = {
|
||||
pending: "در انتظار پرداخت",
|
||||
@@ -202,7 +212,7 @@ export default function PaymentDetailsPage() {
|
||||
{/* دکمهها */}
|
||||
<div className="mt-8 flex gap-4">
|
||||
{["pending", "failed", "canceled"].includes(payment.status) &&
|
||||
payment.appointment_uuid ? (
|
||||
payment.appointment_uuid ? (
|
||||
<button
|
||||
onClick={handleRetryPayment}
|
||||
disabled={paying}
|
||||
@@ -211,15 +221,15 @@ export default function PaymentDetailsPage() {
|
||||
{paying
|
||||
? "در حال انتقال به درگاه..."
|
||||
: payment.status === "pending"
|
||||
? "پرداخت"
|
||||
: "تلاش مجدد"}
|
||||
? "پرداخت"
|
||||
: "تلاش مجدد"}
|
||||
</button>
|
||||
) : null}
|
||||
<button
|
||||
onClick={() => router.push("/dashboard?sidebar=2")}
|
||||
onClick={() => router.push("/dashboard?sidebar=1")}
|
||||
className="flex-1 bg-[#5559CE] hover:bg-[#4448b3] text-white font-bold py-3 px-6 rounded-lg transition-colors"
|
||||
>
|
||||
بازگشت به تراکنشها
|
||||
بازگشت به نوبت های من
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -15,7 +15,7 @@ function PaymentResultRedirect() {
|
||||
const q = status ? `?status=${status}` : "";
|
||||
router.replace(`/payment/${paymentUuid}${q}`);
|
||||
} else {
|
||||
router.replace("/dashboard?sidebar=2");
|
||||
router.replace("/dashboard?sidebar=1");
|
||||
}
|
||||
}, [searchParams, router]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user