318 lines
16 KiB
TypeScript
318 lines
16 KiB
TypeScript
import React from 'react';
|
|
import { FileText, CheckCircle, AlertCircle, Calendar, Users, Receipt, Ticket, Download, RefreshCw } from 'lucide-react';
|
|
|
|
interface ReportsExportTabProps {
|
|
dateFilter: 'all' | 'this_month' | 'last_30_days' | 'custom';
|
|
startDate: string;
|
|
endDate: string;
|
|
downloadingReport: string | null;
|
|
successMessage: string | null;
|
|
errorMessage: string | null;
|
|
totalUsers: number;
|
|
totalPayments: number;
|
|
totalSubscriptions: number;
|
|
totalCoupons: number;
|
|
onDateFilterChange: (filter: 'all' | 'this_month' | 'last_30_days' | 'custom') => void;
|
|
onStartDateChange: (val: string) => void;
|
|
onEndDateChange: (val: string) => void;
|
|
onDownloadReport: (reportKey: string) => void;
|
|
}
|
|
|
|
export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
|
dateFilter,
|
|
startDate,
|
|
endDate,
|
|
downloadingReport,
|
|
successMessage,
|
|
errorMessage,
|
|
totalUsers,
|
|
totalPayments,
|
|
totalSubscriptions,
|
|
totalCoupons,
|
|
onDateFilterChange,
|
|
onStartDateChange,
|
|
onEndDateChange,
|
|
onDownloadReport,
|
|
}) => {
|
|
return (
|
|
<div className="space-y-6">
|
|
{/* Top Header Card */}
|
|
<div className="bg-gradient-to-r from-slate-900 via-indigo-950 to-slate-900 rounded-3xl p-6 text-white shadow-xl relative overflow-hidden">
|
|
<div className="absolute right-0 top-0 w-96 h-full bg-indigo-500/10 rounded-full blur-3xl pointer-events-none" />
|
|
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 relative z-10">
|
|
<div className="space-y-1">
|
|
<div className="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-indigo-500/20 text-indigo-300 border border-indigo-500/30 text-[11px] font-black uppercase tracking-wider">
|
|
<FileText className="h-3.5 w-3.5 text-indigo-400" /> Export Utilities & Financial Ledgers
|
|
</div>
|
|
<h2 className="text-xl font-black text-white flex items-center gap-2.5 mt-2">
|
|
Reports & Financial Export Hub
|
|
</h2>
|
|
<p className="text-xs text-slate-300 max-w-2xl font-medium leading-relaxed">
|
|
Generate and download audit-compliant CSV spreadsheets for registered customers, Razorpay payment transactions and sales revenue, active subscriber entitlements, and promotional coupon redemptions.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Notifications */}
|
|
{successMessage && (
|
|
<div className="bg-emerald-50 border border-emerald-200 text-emerald-800 px-4 py-3 rounded-2xl text-xs font-semibold flex items-center gap-2 shadow-xs animate-in fade-in">
|
|
<CheckCircle className="h-4 w-4 text-emerald-600 shrink-0" />
|
|
{successMessage}
|
|
</div>
|
|
)}
|
|
{errorMessage && (
|
|
<div className="bg-rose-50 border border-rose-200 text-rose-800 px-4 py-3 rounded-2xl text-xs font-semibold flex items-center gap-2 shadow-xs animate-in fade-in">
|
|
<AlertCircle className="h-4 w-4 text-rose-600 shrink-0" />
|
|
{errorMessage}
|
|
</div>
|
|
)}
|
|
|
|
{/* Filter Bar: Date Range Selector */}
|
|
<div className="bg-slate-50/80 border border-slate-200/80 rounded-2xl p-4 flex flex-col md:flex-row justify-between items-start md:items-center gap-4 shadow-xs">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<span className="text-[11px] font-bold text-slate-500 uppercase tracking-wider mr-1 flex items-center gap-1.5">
|
|
<Calendar className="h-3.5 w-3.5 text-indigo-600" /> Date Window:
|
|
</span>
|
|
{[
|
|
{ id: 'all' as const, label: 'All Time' },
|
|
{ id: 'this_month' as const, label: 'This Month' },
|
|
{ id: 'last_30_days' as const, label: 'Last 30 Days' },
|
|
{ id: 'custom' as const, label: 'Custom Range' },
|
|
].map((f) => (
|
|
<button
|
|
key={f.id}
|
|
type="button"
|
|
onClick={() => onDateFilterChange(f.id)}
|
|
className={`px-3 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer ${
|
|
dateFilter === f.id
|
|
? 'bg-indigo-600 text-white shadow-sm'
|
|
: 'bg-white text-slate-600 border border-slate-200 hover:bg-slate-100 shadow-sm'
|
|
}`}
|
|
>
|
|
{f.label}
|
|
</button>
|
|
))}
|
|
</div>
|
|
|
|
{dateFilter === 'custom' && (
|
|
<div className="flex items-center gap-2 w-full md:w-auto animate-in fade-in">
|
|
<input
|
|
type="date"
|
|
value={startDate}
|
|
onChange={(e) => onStartDateChange(e.target.value)}
|
|
className="bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 shadow-sm cursor-pointer"
|
|
/>
|
|
<span className="text-xs text-slate-400 font-bold">to</span>
|
|
<input
|
|
type="date"
|
|
value={endDate}
|
|
onChange={(e) => onEndDateChange(e.target.value)}
|
|
className="bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 shadow-sm cursor-pointer"
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* 4 Report Cards Grid */}
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
{/* Report 1: Customers Ledger */}
|
|
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-indigo-300 transition-all space-y-4">
|
|
<div className="space-y-3">
|
|
<div className="flex items-center justify-between">
|
|
<div className="h-10 w-10 rounded-2xl bg-indigo-50 border border-indigo-200 flex items-center justify-center text-indigo-600">
|
|
<Users className="h-5 w-5" />
|
|
</div>
|
|
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-indigo-50 text-indigo-700 border border-indigo-100">
|
|
{totalUsers} Total Users
|
|
</span>
|
|
</div>
|
|
<div>
|
|
<h3 className="text-base font-black text-slate-800">Customers & Practitioners Ledger</h3>
|
|
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
|
Export complete customer database with contact details, country, active subscription counts, active plans, total order counts, and cumulative lifetime spend.
|
|
</p>
|
|
</div>
|
|
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1.5">
|
|
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
|
<span className="text-slate-400 font-semibold">Included Columns:</span>
|
|
<span className="font-semibold text-slate-700">User ID, Email, Name, Phone, Role, Spend (INR/USD/EUR)</span>
|
|
</div>
|
|
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
|
<span className="text-slate-400 font-semibold">Target Audience:</span>
|
|
<span className="font-semibold text-indigo-600">CRM & Growth Audits</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="pt-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => onDownloadReport('customers')}
|
|
disabled={downloadingReport !== null}
|
|
className="w-full py-2.5 px-4 rounded-xl text-xs font-black bg-indigo-600 hover:bg-indigo-500 text-white shadow-md shadow-indigo-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
|
>
|
|
{downloadingReport === 'customers' ? (
|
|
<>
|
|
<RefreshCw className="h-3.5 w-3.5 animate-spin" /> Generating CSV...
|
|
</>
|
|
) : (
|
|
<>
|
|
<Download className="h-3.5 w-3.5" /> Export Customers (.csv)
|
|
</>
|
|
)}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Report 2: Financial & Revenue Ledger */}
|
|
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-emerald-300 transition-all space-y-4">
|
|
<div className="space-y-3">
|
|
<div className="flex items-center justify-between">
|
|
<div className="h-10 w-10 rounded-2xl bg-emerald-50 border border-emerald-200 flex items-center justify-center text-emerald-600">
|
|
<Receipt className="h-5 w-5" />
|
|
</div>
|
|
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-emerald-50 text-emerald-700 border border-emerald-100">
|
|
{totalPayments} Total Orders
|
|
</span>
|
|
</div>
|
|
<div>
|
|
<h3 className="text-base font-black text-slate-800">Payments & Revenue Ledger</h3>
|
|
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
|
Accounting & transaction ledger containing Razorpay Payment IDs, invoice numbers, base plan fees, coupon discounts, order currency, and total amounts paid.
|
|
</p>
|
|
</div>
|
|
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1.5">
|
|
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
|
<span className="text-slate-400 font-semibold">Financial Scope:</span>
|
|
<span className="font-semibold text-emerald-600">Collected Revenue & Order Totals</span>
|
|
</div>
|
|
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
|
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
|
<span className="font-semibold text-slate-700">Financial Reconciliation & Revenue Auditing</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="pt-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => onDownloadReport('payments')}
|
|
disabled={downloadingReport !== null}
|
|
className="w-full py-2.5 px-4 rounded-xl text-xs font-black bg-emerald-600 hover:bg-emerald-500 text-white shadow-md shadow-emerald-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
|
>
|
|
{downloadingReport === 'payments' ? (
|
|
<>
|
|
<RefreshCw className="h-3.5 w-3.5 animate-spin" /> Generating CSV...
|
|
</>
|
|
) : (
|
|
<>
|
|
<Download className="h-3.5 w-3.5" /> Export Payments & Revenue Ledger (.csv)
|
|
</>
|
|
)}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Report 3: Subscriptions Ledger */}
|
|
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-blue-300 transition-all space-y-4">
|
|
<div className="space-y-3">
|
|
<div className="flex items-center justify-between">
|
|
<div className="h-10 w-10 rounded-2xl bg-blue-50 border border-blue-200 flex items-center justify-center text-blue-600">
|
|
<CheckCircle className="h-5 w-5" />
|
|
</div>
|
|
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-blue-50 text-blue-700 border border-blue-100">
|
|
{totalSubscriptions} Subscriptions
|
|
</span>
|
|
</div>
|
|
<div>
|
|
<h3 className="text-base font-black text-slate-800">Subscriptions & Entitlements Ledger</h3>
|
|
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
|
Export clinical plan access records, customer identities, subscription status, billing cycle, auto-renewal flag, activation dates, expiration dates, and remaining days.
|
|
</p>
|
|
</div>
|
|
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1.5">
|
|
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
|
<span className="text-slate-400 font-semibold">Metrics Included:</span>
|
|
<span className="font-semibold text-slate-700">Country, Plan Currency, Status, Days Remaining</span>
|
|
</div>
|
|
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
|
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
|
<span className="font-semibold text-blue-600">Churn & Expiration Tracking</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="pt-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => onDownloadReport('subscriptions')}
|
|
disabled={downloadingReport !== null}
|
|
className="w-full py-2.5 px-4 rounded-xl text-xs font-black bg-blue-600 hover:bg-blue-500 text-white shadow-md shadow-blue-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
|
>
|
|
{downloadingReport === 'subscriptions' ? (
|
|
<>
|
|
<RefreshCw className="h-3.5 w-3.5 animate-spin" /> Generating CSV...
|
|
</>
|
|
) : (
|
|
<>
|
|
<Download className="h-3.5 w-3.5" /> Export Subscriptions (.csv)
|
|
</>
|
|
)}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Report 4: Coupon Redemptions */}
|
|
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-purple-300 transition-all space-y-4">
|
|
<div className="space-y-3">
|
|
<div className="flex items-center justify-between">
|
|
<div className="h-10 w-10 rounded-2xl bg-purple-50 border border-purple-200 flex items-center justify-center text-purple-600">
|
|
<Ticket className="h-5 w-5" />
|
|
</div>
|
|
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-purple-50 text-purple-700 border border-purple-100">
|
|
{totalCoupons} Promo Codes
|
|
</span>
|
|
</div>
|
|
<div>
|
|
<h3 className="text-base font-black text-slate-800">Promotions & Coupon Redemptions</h3>
|
|
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
|
Track coupon performance and redemptions across orders, including discount rates, caps, customer emails, associated invoices, and total discount value granted.
|
|
</p>
|
|
</div>
|
|
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1.5">
|
|
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
|
<span className="text-slate-400 font-semibold">Campaign Metrics:</span>
|
|
<span className="font-semibold text-slate-700">Code, Category, Discounts & Caps (INR/USD/EUR)</span>
|
|
</div>
|
|
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
|
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
|
<span className="font-semibold text-purple-600">Marketing & Partner ROI</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="pt-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => onDownloadReport('coupons')}
|
|
disabled={downloadingReport !== null}
|
|
className="w-full py-2.5 px-4 rounded-xl text-xs font-black bg-purple-600 hover:bg-purple-500 text-white shadow-md shadow-purple-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
|
>
|
|
{downloadingReport === 'coupons' ? (
|
|
<>
|
|
<RefreshCw className="h-3.5 w-3.5 animate-spin" /> Generating CSV...
|
|
</>
|
|
) : (
|
|
<>
|
|
<Download className="h-3.5 w-3.5" /> Export Redemptions (.csv)
|
|
</>
|
|
)}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|