From 7c50c94f3616ff57bab36b714790be6e455679c9 Mon Sep 17 00:00:00 2001 From: Urvish Date: Wed, 14 Oct 2026 12:57:29 +0530 Subject: [PATCH] fixed-issue(50): added invoice download from subscription view, profile drawer and checkout modal --- src/App.tsx | 30 +++++++------------ src/components/auth/ProfileDrawer.tsx | 21 ++++++++++++- .../subscriptions/SubscriptionsView.tsx | 26 +++++++++++++++- src/types/index.ts | 2 ++ 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c812df5..f62f64f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -952,28 +952,18 @@ export default function App() { const [downloadingModalInvoice, setDownloadingModalInvoice] = useState(false); const handleDownloadCheckoutInvoice = async (paymentId: string, directUrl?: string) => { - if (directUrl) { - window.open(directUrl, '_blank'); - switchTab('subscriptions'); - setVerificationResult(null); - return; - } - if (!userToken) return; setDownloadingModalInvoice(true); try { - const headers = { 'Authorization': `Bearer ${userToken}` }; - const res = await axios.get(`${API_BASE}/api/checkout/payment/${paymentId}/invoice`, { headers }); - const { short_url } = res.data; - if (short_url) { - window.open(short_url, '_blank'); - switchTab('subscriptions'); - setVerificationResult(null); - } else { - throw new Error('Invoice download URL is not available.'); + let targetUrl = directUrl; + if (!targetUrl || targetUrl.includes('rzp.io') || targetUrl.includes('razorpay.com')) { + targetUrl = `/api/checkout/payment/${paymentId}/invoice/view`; } - } catch (err: any) { - const errorMsg = err.response?.data?.detail || err.message || String(err); - alert(`Could not download invoice: ${errorMsg}`); + if (!targetUrl.startsWith('http')) { + targetUrl = `${API_BASE}${targetUrl.startsWith('/') ? '' : '/'}${targetUrl}`; + } + window.open(targetUrl, '_blank'); + switchTab('subscriptions'); + setVerificationResult(null); } finally { setDownloadingModalInvoice(false); } @@ -1066,6 +1056,7 @@ export default function App() { }} onSwitchTab={switchTab} curriculumModules={curriculumModules} + onDownloadInvoice={handleDownloadCheckoutInvoice} /> )} @@ -1156,6 +1147,7 @@ export default function App() { switchTab('storefront'); }} curriculumModules={curriculumModules} + onDownloadInvoice={handleDownloadCheckoutInvoice} /> {/* 🔐 Password Updated Success Modal */} diff --git a/src/components/auth/ProfileDrawer.tsx b/src/components/auth/ProfileDrawer.tsx index 39cbd10..4506fb7 100644 --- a/src/components/auth/ProfileDrawer.tsx +++ b/src/components/auth/ProfileDrawer.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { XCircle, Users, ShieldCheck, CheckCircle, AlertCircle, - Eye, EyeOff, RefreshCw, LogOut + Eye, EyeOff, RefreshCw, LogOut, Download } from 'lucide-react'; import type { UserProfile, ModuleItem, Currency } from '../../types'; import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries'; @@ -37,6 +37,7 @@ interface ProfileDrawerProps { onLogout: () => void; onBrowseStorefront: () => void; curriculumModules: ModuleItem[]; + onDownloadInvoice?: (paymentId: string, directUrl?: string) => void; } export const ProfileDrawer: React.FC = ({ @@ -69,6 +70,7 @@ export const ProfileDrawer: React.FC = ({ onLogout, onBrowseStorefront, curriculumModules, + onDownloadInvoice, }) => { const [showOldPassword, setShowOldPassword] = useState(false); const [showNewPassword, setShowNewPassword] = useState(false); @@ -380,6 +382,23 @@ export const ProfileDrawer: React.FC = ({ )} + + {(sub.payment_id || sub.invoice_url) && onDownloadInvoice && ( +
+ + {sub.invoice_number ? `INV: ${sub.invoice_number}` : 'Official Invoice'} + + +
+ )} ); })} diff --git a/src/components/subscriptions/SubscriptionsView.tsx b/src/components/subscriptions/SubscriptionsView.tsx index 2bd906c..ce64f6b 100644 --- a/src/components/subscriptions/SubscriptionsView.tsx +++ b/src/components/subscriptions/SubscriptionsView.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { CheckCircle } from 'lucide-react'; +import { CheckCircle, Download } from 'lucide-react'; import { Pagination } from '../common/Pagination'; import type { UserProfile, ModuleItem } from '../../types'; @@ -8,6 +8,7 @@ interface SubscriptionsViewProps { onOpenAuth: (mode: 'login') => void; onSwitchTab: (tab: 'storefront') => void; curriculumModules: ModuleItem[]; + onDownloadInvoice?: (paymentId: string, directUrl?: string) => void; } export const SubscriptionsView: React.FC = ({ @@ -15,6 +16,7 @@ export const SubscriptionsView: React.FC = ({ onOpenAuth, onSwitchTab, curriculumModules, + onDownloadInvoice, }) => { const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(6); @@ -147,6 +149,28 @@ export const SubscriptionsView: React.FC = ({ )} + + {(sub.payment_id || sub.invoice_url) && onDownloadInvoice && ( +
+ {sub.invoice_number ? ( +
+ Invoice: + {sub.invoice_number} +
+ ) : ( + Tax Invoice + )} + +
+ )} ); diff --git a/src/types/index.ts b/src/types/index.ts index b8a5891..877ee68 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -20,6 +20,8 @@ export interface UserSubscription { expires_at?: string; is_active: boolean; payment_id?: string; + invoice_number?: string; + invoice_url?: string; metadata?: Record; }