"use client"; import React, { useEffect, useState } from "react"; import { useParams, useRouter } from "next/navigation"; import axios from "axios"; import { ApiServerBaseUrl } from "@/utils/baseurl.utils"; const InvoiceDetail: React.FC = () => { const params = useParams(); const router = useRouter(); const invoiceId = params?.id; const [paymentData, setPaymentData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchPaymentData = async () => { try { // Check if it's a trial invoice if (invoiceId === "trial-inv") { setPaymentData({ createdAt: new Date().toISOString(), endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(), status: "active", email: "user@example.com", // You could fetch meaningful user email if stored in localStorage planId: "Free Trial", amount: 0 }); setLoading(false); return; } const sessionId = localStorage.getItem("payment_session"); if (!sessionId) { setError("No payment session found"); setLoading(false); return; } const res: any = await axios.get(`${ApiServerBaseUrl}/payment/details`, { params: { session_id: sessionId }, }); setPaymentData(res.data.data); } catch (err: any) { setError(err.response?.data?.error || "Failed to fetch payment details"); } finally { setLoading(false); } }; fetchPaymentData(); }, [invoiceId]); const invoice = paymentData ? { number: `#${invoiceId}`, issueDate: paymentData.createdAt ? new Date(paymentData.createdAt).toLocaleDateString() : "N/A", validTill: paymentData.endDate ? new Date(paymentData.endDate).toLocaleDateString() : "N/A", status: paymentData.status || "pending", issuedFor: paymentData.email || "", customerId: "", plan: paymentData.planId || "N/A", bankName: "Bank of Canada", accountNo: "1234567890", country: "Canada", items: [ { sno: 1, plan: paymentData.planId || "N/A", qty: 1, price: paymentData.amount, amount: paymentData.amount, }, ], subtotal: paymentData.amount, tax: 0, grandTotal: paymentData.amount, createdAt: paymentData.createdAt, } : null; const handlePrint = () => window.print(); if (loading) { return (
Loading invoice details...
); } if (error || !invoice) { return (

{error || "Invoice not found"}

); } return (
{/* ===================== PRICING-PAGE BACKGROUND GLOWS ===================== */}
{/* ===================== PAGE CONTENT ===================== */}
{/* Back Button */} {/* Invoice Card */}

INVOICE

Invoice No:

{invoice.number}

logo

SOCIAL BUDDY

Social Media Manager

Social Buddy

support@socialbuddy.com

+1-555-SOCIAL-1

{/* Invoice info */}

Issue For:

{invoice.createdAt}

Customer ID: N/A

Plan: {invoice.plan}

Issue Date:

{invoice.issueDate}

Valid Till:

{invoice.validTill}

Status:

{invoice.status}
{/* Table */}
{invoice.items.map((item) => ( ))}
S.NO PLAN QTY PRICE AMOUNT
{item.sno} {item.plan} {item.qty} ${item.price.toFixed(2)} ${item.amount.toFixed(2)}
{/* Totals */}
Subtotal: ${invoice.subtotal.toFixed(2)}
Tax: ${invoice.tax.toFixed(2)}
Grand Total: ${invoice.grandTotal.toFixed(2)}
{/* Print Button */}
{/* Print Styles */}
); }; export default InvoiceDetail;