'use client'; import React, { useEffect, useState } from 'react'; import axios from 'axios'; import Link from 'next/link'; import IconDownload from '@/components/icon/icon-download'; import IconEdit from '@/components/icon/icon-edit'; import IconPlus from '@/components/icon/icon-plus'; import IconPrinter from '@/components/icon/icon-printer'; import IconSend from '@/components/icon/icon-send'; import { formatCreatedAtWithEnd } from '@/utils/commonFunction.utils'; import { useRouter } from 'next/navigation'; const ComponentsAppsInvoicePreview = () => { const [payment, setPayment] = useState(null); const router = useRouter(); // 🧩 Print invoice const exportTable = () => { window.print(); }; // 🧩 Fetch payment data useEffect(() => { const sessionId = localStorage.getItem('payment_session'); if (!sessionId) { router.push('/pricing'); return; } const fetchPayment = async () => { try { const res: any = await axios.get( 'https://ebay.backend.data4autos.com/api/payment/details', { params: { session_id: sessionId } } ); setPayment(res.data.payment); } catch (error) { console.error('Error fetching payment details:', error); } }; fetchPayment(); }, [router]); // 🧩 Invoice line items (example if your backend doesn't send itemized data) const items = [ { id: 1, title: payment?.plan || 'Subscription Plan', quantity: 1, price: payment?.amount || '0', amount: payment?.amount || '0', }, ]; const columns = [ { key: 'id', label: 'S.NO' }, { key: 'title', label: 'PLAN' }, { key: 'quantity', label: 'QTY' }, { key: 'price', label: 'PRICE', class: 'ltr:text-right rtl:text-left' }, { key: 'amount', label: 'AMOUNT', class: 'ltr:text-right rtl:text-left' }, ]; return (
{/* ========= INVOICE CARD ========= */}
{/* Header */}
Invoice
logo
Data4Autos
sales@data4autos.com
+1-647-679-7651

{/* ========= INVOICE DETAILS ========= */}
Issue For:
{payment?.email || '—'}
Customer ID: {payment?.userid || '—'}
Plan: {payment?.plan || '—'}
Invoice : #{payment?.id || '—'}
Issue Date : {payment?.createdAt ? new Date(payment.createdAt).toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric', }) : '—'}
Valid Till : {formatCreatedAtWithEnd(payment?.createdAt)?.split(' - ')[1]}
Status : {payment?.status === 'succeeded' ? 'Paid' : payment?.status || '—'}
Bank Name: Bank of Canada
Account No: 1234567890
{/*
SWIFT Code: S58K796
*/}
Country: Canada
{/* ========= ITEMS TABLE ========= */}
{columns.map((column) => ( ))} {items.map((item) => ( ))}
{column.label}
{item.id} {item.title} {item.quantity} ${item.price} ${item.amount}
{/* ========= TOTAL ========= */}
Subtotal ${payment?.amount || '0'}
Tax $0
Grand Total ${payment?.amount || '0'}
{/* ========= ACTION BUTTONS ========= */}
{/* */} {/* Create Edit */}
); }; export default ComponentsAppsInvoicePreview;