fixed-issue(50): added invoice download from subscription view, profile drawer and checkout modal #54
30
src/App.tsx
30
src/App.tsx
|
|
@ -952,28 +952,18 @@ export default function App() {
|
|||
const [downloadingModalInvoice, setDownloadingModalInvoice] = useState<boolean>(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 */}
|
||||
|
|
|
|||
|
|
@ -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<ProfileDrawerProps> = ({
|
||||
|
|
@ -69,6 +70,7 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
|
|||
onLogout,
|
||||
onBrowseStorefront,
|
||||
curriculumModules,
|
||||
onDownloadInvoice,
|
||||
}) => {
|
||||
const [showOldPassword, setShowOldPassword] = useState(false);
|
||||
const [showNewPassword, setShowNewPassword] = useState(false);
|
||||
|
|
@ -380,6 +382,23 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
|
|||
</span>
|
||||
)}
|
||||
</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>
|
||||
);
|
||||
})}
|
||||
|
|
|
|||
|
|
@ -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<SubscriptionsViewProps> = ({
|
||||
|
|
@ -15,6 +16,7 @@ export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
|
|||
onOpenAuth,
|
||||
onSwitchTab,
|
||||
curriculumModules,
|
||||
onDownloadInvoice,
|
||||
}) => {
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(6);
|
||||
|
|
@ -147,6 +149,28 @@ export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
|
|||
</span>
|
||||
)}
|
||||
</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>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ export interface UserSubscription {
|
|||
expires_at?: string;
|
||||
is_active: boolean;
|
||||
payment_id?: string;
|
||||
invoice_number?: string;
|
||||
invoice_url?: string;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue