fixed-issue(50): added invoice download from subscription view, profile drawer and checkout modal

This commit is contained in:
Urvish Prajapati 2026-10-14 12:57:29 +05:30
parent 75acd1de92
commit 7c50c94f36
4 changed files with 58 additions and 21 deletions

View File

@ -952,28 +952,18 @@ export default function App() {
const [downloadingModalInvoice, setDownloadingModalInvoice] = useState<boolean>(false); const [downloadingModalInvoice, setDownloadingModalInvoice] = useState<boolean>(false);
const handleDownloadCheckoutInvoice = async (paymentId: string, directUrl?: string) => { const handleDownloadCheckoutInvoice = async (paymentId: string, directUrl?: string) => {
if (directUrl) {
window.open(directUrl, '_blank');
switchTab('subscriptions');
setVerificationResult(null);
return;
}
if (!userToken) return;
setDownloadingModalInvoice(true); setDownloadingModalInvoice(true);
try { try {
const headers = { 'Authorization': `Bearer ${userToken}` }; let targetUrl = directUrl;
const res = await axios.get(`${API_BASE}/api/checkout/payment/${paymentId}/invoice`, { headers }); if (!targetUrl || targetUrl.includes('rzp.io') || targetUrl.includes('razorpay.com')) {
const { short_url } = res.data; targetUrl = `/api/checkout/payment/${paymentId}/invoice/view`;
if (short_url) {
window.open(short_url, '_blank');
switchTab('subscriptions');
setVerificationResult(null);
} else {
throw new Error('Invoice download URL is not available.');
} }
} catch (err: any) { if (!targetUrl.startsWith('http')) {
const errorMsg = err.response?.data?.detail || err.message || String(err); targetUrl = `${API_BASE}${targetUrl.startsWith('/') ? '' : '/'}${targetUrl}`;
alert(`Could not download invoice: ${errorMsg}`); }
window.open(targetUrl, '_blank');
switchTab('subscriptions');
setVerificationResult(null);
} finally { } finally {
setDownloadingModalInvoice(false); setDownloadingModalInvoice(false);
} }
@ -1066,6 +1056,7 @@ export default function App() {
}} }}
onSwitchTab={switchTab} onSwitchTab={switchTab}
curriculumModules={curriculumModules} curriculumModules={curriculumModules}
onDownloadInvoice={handleDownloadCheckoutInvoice}
/> />
)} )}
@ -1156,6 +1147,7 @@ export default function App() {
switchTab('storefront'); switchTab('storefront');
}} }}
curriculumModules={curriculumModules} curriculumModules={curriculumModules}
onDownloadInvoice={handleDownloadCheckoutInvoice}
/> />
{/* 🔐 Password Updated Success Modal */} {/* 🔐 Password Updated Success Modal */}

View File

@ -1,7 +1,7 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { import {
XCircle, Users, ShieldCheck, CheckCircle, AlertCircle, XCircle, Users, ShieldCheck, CheckCircle, AlertCircle,
Eye, EyeOff, RefreshCw, LogOut Eye, EyeOff, RefreshCw, LogOut, Download
} from 'lucide-react'; } from 'lucide-react';
import type { UserProfile, ModuleItem, Currency } from '../../types'; import type { UserProfile, ModuleItem, Currency } from '../../types';
import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries'; import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries';
@ -37,6 +37,7 @@ interface ProfileDrawerProps {
onLogout: () => void; onLogout: () => void;
onBrowseStorefront: () => void; onBrowseStorefront: () => void;
curriculumModules: ModuleItem[]; curriculumModules: ModuleItem[];
onDownloadInvoice?: (paymentId: string, directUrl?: string) => void;
} }
export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
@ -69,6 +70,7 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
onLogout, onLogout,
onBrowseStorefront, onBrowseStorefront,
curriculumModules, curriculumModules,
onDownloadInvoice,
}) => { }) => {
const [showOldPassword, setShowOldPassword] = useState(false); const [showOldPassword, setShowOldPassword] = useState(false);
const [showNewPassword, setShowNewPassword] = useState(false); const [showNewPassword, setShowNewPassword] = useState(false);
@ -380,6 +382,23 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
</span> </span>
)} )}
</div> </div>
{(sub.payment_id || sub.invoice_url) && onDownloadInvoice && (
<div className="pt-2 border-t border-slate-200/60 flex items-center justify-between">
<span className="text-[9px] font-mono text-slate-500 font-semibold truncate">
{sub.invoice_number ? `INV: ${sub.invoice_number}` : 'Official Invoice'}
</span>
<button
type="button"
onClick={() => onDownloadInvoice(sub.payment_id || '', sub.invoice_url)}
className="inline-flex items-center gap-1 text-[10px] font-bold text-indigo-600 hover:text-indigo-700 bg-indigo-50 hover:bg-indigo-100 px-2 py-1 rounded-md border border-indigo-200 transition-colors cursor-pointer"
title="Download Tax Invoice"
>
<Download className="h-2.5 w-2.5" />
<span>Invoice</span>
</button>
</div>
)}
</div> </div>
); );
})} })}

View File

@ -1,5 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { CheckCircle } from 'lucide-react'; import { CheckCircle, Download } from 'lucide-react';
import { Pagination } from '../common/Pagination'; import { Pagination } from '../common/Pagination';
import type { UserProfile, ModuleItem } from '../../types'; import type { UserProfile, ModuleItem } from '../../types';
@ -8,6 +8,7 @@ interface SubscriptionsViewProps {
onOpenAuth: (mode: 'login') => void; onOpenAuth: (mode: 'login') => void;
onSwitchTab: (tab: 'storefront') => void; onSwitchTab: (tab: 'storefront') => void;
curriculumModules: ModuleItem[]; curriculumModules: ModuleItem[];
onDownloadInvoice?: (paymentId: string, directUrl?: string) => void;
} }
export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({ export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
@ -15,6 +16,7 @@ export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
onOpenAuth, onOpenAuth,
onSwitchTab, onSwitchTab,
curriculumModules, curriculumModules,
onDownloadInvoice,
}) => { }) => {
const [currentPage, setCurrentPage] = useState(1); const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(6); const [pageSize, setPageSize] = useState(6);
@ -147,6 +149,28 @@ export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
</span> </span>
)} )}
</div> </div>
{(sub.payment_id || sub.invoice_url) && onDownloadInvoice && (
<div className="mt-1 pt-3 border-t border-slate-100 flex items-center justify-between gap-2">
{sub.invoice_number ? (
<div className="text-[11px] font-mono text-slate-500 font-medium truncate">
<span className="text-slate-400 mr-1">Invoice:</span>
<span className="text-slate-800 font-bold">{sub.invoice_number}</span>
</div>
) : (
<span className="text-[11px] text-slate-400 font-medium">Tax Invoice</span>
)}
<button
type="button"
onClick={() => onDownloadInvoice(sub.payment_id || '', sub.invoice_url)}
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-indigo-50 hover:bg-indigo-100 border border-indigo-200 text-indigo-700 font-bold text-xs rounded-xl transition-colors duration-200 shadow-sm flex-shrink-0 cursor-pointer"
title="Download Tax Invoice PDF"
>
<Download className="h-3.5 w-3.5" />
<span>Download Invoice</span>
</button>
</div>
)}
</div> </div>
</div> </div>
); );

View File

@ -20,6 +20,8 @@ export interface UserSubscription {
expires_at?: string; expires_at?: string;
is_active: boolean; is_active: boolean;
payment_id?: string; payment_id?: string;
invoice_number?: string;
invoice_url?: string;
metadata?: Record<string, any>; metadata?: Record<string, any>;
} }