many fixes
This commit is contained in:
@@ -11,30 +11,69 @@ import {
|
||||
import { Card } from '../../components/ui/card';
|
||||
import Badge from '../../components/ui/badge/Badge';
|
||||
import Button from '../../components/ui/button/Button';
|
||||
import { useToast } from '../../components/ui/toast/ToastContainer';
|
||||
import {
|
||||
getCreditBalance,
|
||||
getCreditPackages,
|
||||
getInvoices,
|
||||
getAvailablePaymentMethods,
|
||||
purchaseCreditPackage,
|
||||
downloadInvoicePDF,
|
||||
getPayments,
|
||||
submitManualPayment,
|
||||
createPaymentMethod,
|
||||
deletePaymentMethod,
|
||||
setDefaultPaymentMethod,
|
||||
type CreditBalance,
|
||||
type CreditPackage,
|
||||
type Invoice,
|
||||
type PaymentMethod,
|
||||
type Payment,
|
||||
getPlans,
|
||||
getSubscriptions,
|
||||
createSubscription,
|
||||
cancelSubscription,
|
||||
type Plan,
|
||||
type Subscription,
|
||||
} from '../../services/billing.api';
|
||||
|
||||
type TabType = 'plan' | 'upgrade' | 'credits' | 'purchase' | 'invoices' | 'payment-methods';
|
||||
type TabType = 'plan' | 'upgrade' | 'credits' | 'purchase' | 'invoices' | 'payments' | 'payment-methods';
|
||||
|
||||
export default function PlansAndBillingPage() {
|
||||
const [activeTab, setActiveTab] = useState<TabType>('plan');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string>('');
|
||||
const [planLoadingId, setPlanLoadingId] = useState<number | null>(null);
|
||||
const [purchaseLoadingId, setPurchaseLoadingId] = useState<number | null>(null);
|
||||
|
||||
// Data states
|
||||
const [creditBalance, setCreditBalance] = useState<CreditBalance | null>(null);
|
||||
const [packages, setPackages] = useState<CreditPackage[]>([]);
|
||||
const [invoices, setInvoices] = useState<Invoice[]>([]);
|
||||
const [payments, setPayments] = useState<Payment[]>([]);
|
||||
const [paymentMethods, setPaymentMethods] = useState<PaymentMethod[]>([]);
|
||||
const [plans, setPlans] = useState<Plan[]>([]);
|
||||
const [subscriptions, setSubscriptions] = useState<Subscription[]>([]);
|
||||
const [selectedPaymentMethod, setSelectedPaymentMethod] = useState<string | undefined>(undefined);
|
||||
const [manualPayment, setManualPayment] = useState({
|
||||
invoice_id: '',
|
||||
amount: '',
|
||||
payment_method: '',
|
||||
reference: '',
|
||||
notes: '',
|
||||
});
|
||||
const [newPaymentMethod, setNewPaymentMethod] = useState({
|
||||
type: 'bank_transfer',
|
||||
display_name: '',
|
||||
instructions: '',
|
||||
});
|
||||
const handleBillingError = (err: any, fallback: string) => {
|
||||
const message = err?.message || fallback;
|
||||
setError(message);
|
||||
toast?.error?.(message);
|
||||
};
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
@@ -43,17 +82,29 @@ export default function PlansAndBillingPage() {
|
||||
const loadData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const [balanceData, packagesData, invoicesData, methodsData] = await Promise.all([
|
||||
const [balanceData, packagesData, invoicesData, paymentsData, methodsData, plansData, subsData] = await Promise.all([
|
||||
getCreditBalance(),
|
||||
getCreditPackages(),
|
||||
getInvoices({}),
|
||||
getPayments({}),
|
||||
getAvailablePaymentMethods(),
|
||||
getPlans(),
|
||||
getSubscriptions(),
|
||||
]);
|
||||
|
||||
setCreditBalance(balanceData);
|
||||
setPackages(packagesData.results || []);
|
||||
setInvoices(invoicesData.results || []);
|
||||
setPaymentMethods(methodsData.results || []);
|
||||
setPayments(paymentsData.results || []);
|
||||
const methods = methodsData.results || [];
|
||||
setPaymentMethods(methods);
|
||||
if (methods.length > 0) {
|
||||
const defaultMethod = methods.find((m) => m.is_default);
|
||||
const firstMethod = defaultMethod || methods[0];
|
||||
setSelectedPaymentMethod((prev) => prev || firstMethod.type || firstMethod.id);
|
||||
}
|
||||
setPlans((plansData.results || []).filter((p) => p.is_active !== false));
|
||||
setSubscriptions(subsData.results || []);
|
||||
} catch (err: any) {
|
||||
setError(err.message || 'Failed to load billing data');
|
||||
console.error('Billing load error:', err);
|
||||
@@ -62,15 +113,126 @@ export default function PlansAndBillingPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectPlan = async (planId: number) => {
|
||||
try {
|
||||
if (!selectedPaymentMethod && paymentMethods.length > 0) {
|
||||
setError('Select a payment method to continue');
|
||||
return;
|
||||
}
|
||||
setPlanLoadingId(planId);
|
||||
await createSubscription({ plan_id: planId, payment_method: selectedPaymentMethod });
|
||||
toast?.success?.('Subscription updated');
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
handleBillingError(err, 'Failed to update subscription');
|
||||
} finally {
|
||||
setPlanLoadingId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelSubscription = async () => {
|
||||
if (!currentSubscription?.id) {
|
||||
setError('No active subscription to cancel');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setPlanLoadingId(currentSubscription.id);
|
||||
await cancelSubscription(currentSubscription.id);
|
||||
toast?.success?.('Subscription cancellation requested');
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
handleBillingError(err, 'Failed to cancel subscription');
|
||||
} finally {
|
||||
setPlanLoadingId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handlePurchase = async (packageId: number) => {
|
||||
try {
|
||||
if (!selectedPaymentMethod && paymentMethods.length > 0) {
|
||||
setError('Select a payment method to continue');
|
||||
return;
|
||||
}
|
||||
setPurchaseLoadingId(packageId);
|
||||
await purchaseCreditPackage({
|
||||
package_id: packageId,
|
||||
payment_method: 'stripe',
|
||||
payment_method: (selectedPaymentMethod as any) || 'stripe',
|
||||
});
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
setError(err.message || 'Failed to purchase credits');
|
||||
handleBillingError(err, 'Failed to purchase credits');
|
||||
} finally {
|
||||
setPurchaseLoadingId(null);
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownloadInvoice = async (invoiceId: number) => {
|
||||
try {
|
||||
const blob = await downloadInvoicePDF(invoiceId);
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `invoice-${invoiceId}.pdf`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
} catch (err: any) {
|
||||
handleBillingError(err, 'Failed to download invoice');
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmitManualPayment = async () => {
|
||||
try {
|
||||
const payload = {
|
||||
invoice_id: manualPayment.invoice_id ? Number(manualPayment.invoice_id) : undefined,
|
||||
amount: manualPayment.amount,
|
||||
payment_method: manualPayment.payment_method || (selectedPaymentMethod as any) || 'manual',
|
||||
reference: manualPayment.reference,
|
||||
notes: manualPayment.notes,
|
||||
};
|
||||
await submitManualPayment(payload as any);
|
||||
toast?.success?.('Manual payment submitted');
|
||||
setManualPayment({ invoice_id: '', amount: '', payment_method: '', reference: '', notes: '' });
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
handleBillingError(err, 'Failed to submit payment');
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddPaymentMethod = async () => {
|
||||
if (!newPaymentMethod.display_name.trim()) {
|
||||
setError('Payment method name is required');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await createPaymentMethod(newPaymentMethod as any);
|
||||
toast?.success?.('Payment method added');
|
||||
setNewPaymentMethod({ type: 'bank_transfer', display_name: '', instructions: '' });
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
handleBillingError(err, 'Failed to add payment method');
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemovePaymentMethod = async (id: string) => {
|
||||
try {
|
||||
await deletePaymentMethod(id);
|
||||
toast?.success?.('Payment method removed');
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
handleBillingError(err, 'Failed to remove payment method');
|
||||
}
|
||||
};
|
||||
|
||||
const handleSetDefaultPaymentMethod = async (id: string) => {
|
||||
try {
|
||||
await setDefaultPaymentMethod(id);
|
||||
toast?.success?.('Default payment method updated');
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
handleBillingError(err, 'Failed to set default');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -82,12 +244,20 @@ export default function PlansAndBillingPage() {
|
||||
);
|
||||
}
|
||||
|
||||
const currentSubscription = subscriptions.find((sub) => sub.status === 'active') || subscriptions[0];
|
||||
const currentPlanId = typeof currentSubscription?.plan === 'object' ? currentSubscription.plan.id : currentSubscription?.plan;
|
||||
const currentPlan = plans.find((p) => p.id === currentPlanId);
|
||||
const hasActivePlan = Boolean(currentPlanId);
|
||||
const hasPaymentMethods = paymentMethods.length > 0;
|
||||
const subscriptionStatus = currentSubscription?.status || (hasActivePlan ? 'active' : 'none');
|
||||
|
||||
const tabs = [
|
||||
{ id: 'plan' as TabType, label: 'Current Plan', icon: <Package className="w-4 h-4" /> },
|
||||
{ id: 'upgrade' as TabType, label: 'Upgrade/Downgrade', icon: <ArrowUpCircle className="w-4 h-4" /> },
|
||||
{ id: 'credits' as TabType, label: 'Credits Overview', icon: <TrendingUp className="w-4 h-4" /> },
|
||||
{ id: 'purchase' as TabType, label: 'Purchase Credits', icon: <CreditCard className="w-4 h-4" /> },
|
||||
{ id: 'invoices' as TabType, label: 'Billing History', icon: <FileText className="w-4 h-4" /> },
|
||||
{ id: 'payments' as TabType, label: 'Payments', icon: <Wallet className="w-4 h-4" /> },
|
||||
{ id: 'payment-methods' as TabType, label: 'Payment Methods', icon: <Wallet className="w-4 h-4" /> },
|
||||
];
|
||||
|
||||
@@ -137,37 +307,64 @@ export default function PlansAndBillingPage() {
|
||||
<div className="space-y-6">
|
||||
<Card className="p-6">
|
||||
<h2 className="text-lg font-semibold mb-4">Your Current Plan</h2>
|
||||
{!hasActivePlan && (
|
||||
<div className="p-4 mb-4 rounded-lg border border-amber-200 bg-amber-50 text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-200">
|
||||
No active plan found. Please choose a plan to activate your account.
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<div className="text-2xl font-bold text-gray-900 dark:text-white">Free Plan</div>
|
||||
<div className="text-gray-600 dark:text-gray-400">Perfect for getting started</div>
|
||||
<div className="text-2xl font-bold text-gray-900 dark:text-white">
|
||||
{currentPlan?.name || 'No Plan Selected'}
|
||||
</div>
|
||||
<div className="text-gray-600 dark:text-gray-400">
|
||||
{currentPlan?.description || 'Select a plan to unlock full access.'}
|
||||
</div>
|
||||
</div>
|
||||
<Badge variant="light" color="success">Active</Badge>
|
||||
<Badge variant="light" color={hasActivePlan ? 'success' : 'warning'}>
|
||||
{hasActivePlan ? subscriptionStatus : 'plan required'}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mt-6">
|
||||
<div className="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400">Monthly Credits</div>
|
||||
<div className="text-2xl font-bold text-gray-900 dark:text-white">
|
||||
{creditBalance?.plan_credits_per_month.toLocaleString() || 0}
|
||||
{creditBalance?.plan_credits_per_month?.toLocaleString?.() || 0}
|
||||
</div>
|
||||
</div>
|
||||
<div className="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400">Sites Allowed</div>
|
||||
<div className="text-2xl font-bold text-gray-900 dark:text-white">1</div>
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400">Current Balance</div>
|
||||
<div className="text-2xl font-bold text-gray-900 dark:text-white">
|
||||
{creditBalance?.credits?.toLocaleString?.() || 0}
|
||||
</div>
|
||||
</div>
|
||||
<div className="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400">Team Members</div>
|
||||
<div className="text-2xl font-bold text-gray-900 dark:text-white">1</div>
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400">Period Ends</div>
|
||||
<div className="text-2xl font-bold text-gray-900 dark:text-white text-base">
|
||||
{currentSubscription?.current_period_end
|
||||
? new Date(currentSubscription.current_period_end).toLocaleDateString()
|
||||
: '—'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-6 flex gap-3">
|
||||
<Button variant="primary" tone="brand">
|
||||
Upgrade Plan
|
||||
<Button variant="primary" tone="brand" onClick={() => setActiveTab('upgrade')}>
|
||||
{hasActivePlan ? 'Change Plan' : 'Choose a Plan'}
|
||||
</Button>
|
||||
<Button variant="outline" tone="neutral">
|
||||
Compare Plans
|
||||
<Button variant="outline" tone="neutral" onClick={() => setActiveTab('purchase')}>
|
||||
Purchase Credits
|
||||
</Button>
|
||||
{hasActivePlan && (
|
||||
<Button
|
||||
variant="outline"
|
||||
tone="neutral"
|
||||
disabled={planLoadingId === currentSubscription?.id}
|
||||
onClick={handleCancelSubscription}
|
||||
>
|
||||
{planLoadingId === currentSubscription?.id ? 'Cancelling...' : 'Cancel Subscription'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
@@ -175,12 +372,15 @@ export default function PlansAndBillingPage() {
|
||||
<Card className="p-6">
|
||||
<h2 className="text-lg font-semibold mb-4">Plan Features</h2>
|
||||
<ul className="space-y-3">
|
||||
{['Basic AI Tools', 'Content Generation', 'Keyword Research', 'Email Support'].map((feature) => (
|
||||
<li key={feature} className="flex items-center gap-2 text-gray-700 dark:text-gray-300">
|
||||
<CheckCircle className="w-5 h-5 text-green-600" />
|
||||
{feature}
|
||||
</li>
|
||||
))}
|
||||
{(currentPlan?.features && currentPlan.features.length > 0
|
||||
? currentPlan.features
|
||||
: ['Credits included each month', 'Module access per plan limits', 'Email support'])
|
||||
.map((feature) => (
|
||||
<li key={feature} className="flex items-center gap-2 text-gray-700 dark:text-gray-300">
|
||||
<CheckCircle className="w-5 h-5 text-green-600" />
|
||||
{feature}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Card>
|
||||
</div>
|
||||
@@ -193,126 +393,78 @@ export default function PlansAndBillingPage() {
|
||||
<h2 className="text-xl font-semibold mb-2">Available Plans</h2>
|
||||
<p className="text-gray-600 dark:text-gray-400">Choose the plan that best fits your needs</p>
|
||||
</div>
|
||||
|
||||
{hasPaymentMethods ? (
|
||||
<div className="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
|
||||
<div className="text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">Select payment method</div>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{paymentMethods.map((method) => (
|
||||
<label
|
||||
key={method.id}
|
||||
className={`px-3 py-2 rounded-lg border cursor-pointer text-sm ${
|
||||
selectedPaymentMethod === (method.type || method.id)
|
||||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/30'
|
||||
: 'border-gray-200 dark:border-gray-700'
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
className="sr-only"
|
||||
checked={selectedPaymentMethod === (method.type || method.id)}
|
||||
onChange={() => setSelectedPaymentMethod(method.type || method.id)}
|
||||
/>
|
||||
<div className="font-semibold text-gray-900 dark:text-white">{method.display_name}</div>
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400">{method.type}</div>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="p-4 rounded-lg border border-amber-200 bg-amber-50 text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-200">
|
||||
No payment methods available. Please contact support or add one from the Payment Methods tab.
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
{/* Free Plan */}
|
||||
<Card className="p-6 relative">
|
||||
<div className="mb-4">
|
||||
<h3 className="text-lg font-semibold">Free</h3>
|
||||
<div className="text-3xl font-bold text-gray-900 dark:text-white mt-2">$0</div>
|
||||
<div className="text-sm text-gray-500">/month</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{plans.map((plan) => {
|
||||
const isCurrent = plan.id === currentPlanId;
|
||||
const price = plan.price ? `$${plan.price}/${plan.interval || 'month'}` : 'Custom';
|
||||
return (
|
||||
<Card key={plan.id} className="p-6 relative border border-gray-200 dark:border-gray-700">
|
||||
<div className="mb-4">
|
||||
<h3 className="text-lg font-semibold">{plan.name}</h3>
|
||||
<div className="text-3xl font-bold text-gray-900 dark:text-white mt-2">{price}</div>
|
||||
<div className="text-sm text-gray-500">{plan.description || 'Standard plan'}</div>
|
||||
</div>
|
||||
<div className="space-y-3 mb-6">
|
||||
{(plan.features && plan.features.length > 0 ? plan.features : ['Monthly credits included', 'Module access per plan', 'Email support']).map((feature) => (
|
||||
<div key={feature} className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>{feature}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Button
|
||||
variant={isCurrent ? 'outline' : 'primary'}
|
||||
tone="brand"
|
||||
fullWidth
|
||||
disabled={isCurrent || planLoadingId === plan.id}
|
||||
onClick={() => handleSelectPlan(plan.id)}
|
||||
>
|
||||
{planLoadingId === plan.id
|
||||
? 'Updating...'
|
||||
: isCurrent
|
||||
? 'Current Plan'
|
||||
: 'Select Plan'}
|
||||
</Button>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
{plans.length === 0 && (
|
||||
<div className="col-span-3 text-center py-12 text-gray-500">
|
||||
No plans available. Please contact support.
|
||||
</div>
|
||||
<div className="space-y-3 mb-6">
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>100 credits/month</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>1 site</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>1 user</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>Basic features</span>
|
||||
</div>
|
||||
</div>
|
||||
<Badge variant="light" color="success" className="absolute top-4 right-4">Current</Badge>
|
||||
</Card>
|
||||
|
||||
{/* Starter Plan */}
|
||||
<Card className="p-6 border-2 border-blue-500">
|
||||
<Badge variant="light" color="primary" className="absolute top-4 right-4">Popular</Badge>
|
||||
<div className="mb-4">
|
||||
<h3 className="text-lg font-semibold">Starter</h3>
|
||||
<div className="text-3xl font-bold text-gray-900 dark:text-white mt-2">$29</div>
|
||||
<div className="text-sm text-gray-500">/month</div>
|
||||
</div>
|
||||
<div className="space-y-3 mb-6">
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>1,000 credits/month</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>3 sites</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>2 users</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>Full AI suite</span>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="primary" tone="brand" fullWidth>
|
||||
Upgrade to Starter
|
||||
</Button>
|
||||
</Card>
|
||||
|
||||
{/* Professional Plan */}
|
||||
<Card className="p-6">
|
||||
<div className="mb-4">
|
||||
<h3 className="text-lg font-semibold">Professional</h3>
|
||||
<div className="text-3xl font-bold text-gray-900 dark:text-white mt-2">$99</div>
|
||||
<div className="text-sm text-gray-500">/month</div>
|
||||
</div>
|
||||
<div className="space-y-3 mb-6">
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>5,000 credits/month</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>10 sites</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>5 users</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>Priority support</span>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="outline" tone="neutral" fullWidth>
|
||||
Upgrade to Pro
|
||||
</Button>
|
||||
</Card>
|
||||
|
||||
{/* Enterprise Plan */}
|
||||
<Card className="p-6">
|
||||
<div className="mb-4">
|
||||
<h3 className="text-lg font-semibold">Enterprise</h3>
|
||||
<div className="text-3xl font-bold text-gray-900 dark:text-white mt-2">$299</div>
|
||||
<div className="text-sm text-gray-500">/month</div>
|
||||
</div>
|
||||
<div className="space-y-3 mb-6">
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>20,000 credits/month</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>Unlimited sites</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>20 users</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CheckCircle className="w-4 h-4 text-green-600" />
|
||||
<span>Dedicated support</span>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="outline" tone="neutral" fullWidth>
|
||||
Upgrade to Enterprise
|
||||
</Button>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Card className="p-6 bg-blue-50 dark:bg-blue-900/20 border-blue-200 dark:border-blue-800">
|
||||
@@ -379,6 +531,37 @@ export default function PlansAndBillingPage() {
|
||||
{/* Purchase Credits Tab */}
|
||||
{activeTab === 'purchase' && (
|
||||
<div className="space-y-6">
|
||||
{hasPaymentMethods ? (
|
||||
<div className="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
|
||||
<div className="text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">Select payment method</div>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{paymentMethods.map((method) => (
|
||||
<label
|
||||
key={method.id}
|
||||
className={`px-3 py-2 rounded-lg border cursor-pointer text-sm ${
|
||||
selectedPaymentMethod === (method.type || method.id)
|
||||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/30'
|
||||
: 'border-gray-200 dark:border-gray-700'
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
className="sr-only"
|
||||
checked={selectedPaymentMethod === (method.type || method.id)}
|
||||
onChange={() => setSelectedPaymentMethod(method.type || method.id)}
|
||||
/>
|
||||
<div className="font-semibold text-gray-900 dark:text-white">{method.display_name}</div>
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400">{method.type}</div>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="p-4 rounded-lg border border-amber-200 bg-amber-50 text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-200">
|
||||
No payment methods available. Please contact support or add one from the Payment Methods tab.
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card className="p-6">
|
||||
<h2 className="text-lg font-semibold mb-4">Credit Packages</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
@@ -400,8 +583,9 @@ export default function PlansAndBillingPage() {
|
||||
onClick={() => handlePurchase(pkg.id)}
|
||||
fullWidth
|
||||
className="mt-6"
|
||||
disabled={purchaseLoadingId === pkg.id || (!hasPaymentMethods && paymentMethods.length > 0)}
|
||||
>
|
||||
Purchase
|
||||
{purchaseLoadingId === pkg.id ? 'Processing...' : 'Purchase'}
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
@@ -470,6 +654,7 @@ export default function PlansAndBillingPage() {
|
||||
size="sm"
|
||||
startIcon={<Download className="w-4 h-4" />}
|
||||
className="ml-auto"
|
||||
onClick={() => handleDownloadInvoice(invoice.id)}
|
||||
>
|
||||
Download
|
||||
</Button>
|
||||
@@ -483,13 +668,176 @@ export default function PlansAndBillingPage() {
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Payments Tab */}
|
||||
{activeTab === 'payments' && (
|
||||
<div className="space-y-6">
|
||||
<Card className="p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold">Payments</h2>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400">Recent payments and manual submissions</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full">
|
||||
<thead className="bg-gray-50 dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700">
|
||||
<tr>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Invoice</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Amount</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Method</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-200 dark:divide-gray-700">
|
||||
{payments.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={5} className="px-6 py-8 text-center text-gray-500">
|
||||
No payments yet
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
payments.map((payment) => (
|
||||
<tr key={payment.id} className="hover:bg-gray-50 dark:hover:bg-gray-800">
|
||||
<td className="px-6 py-4 text-sm font-medium text-gray-900 dark:text-white">
|
||||
{payment.invoice_number || payment.invoice_id || '-'}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm text-gray-900 dark:text-white">
|
||||
${payment.amount}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm text-gray-600 dark:text-gray-400">
|
||||
{payment.payment_method}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<Badge
|
||||
variant="light"
|
||||
color={
|
||||
payment.status === 'succeeded' || payment.status === 'completed'
|
||||
? 'success'
|
||||
: payment.status === 'pending' || payment.status === 'processing'
|
||||
? 'warning'
|
||||
: 'error'
|
||||
}
|
||||
>
|
||||
{payment.status}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm text-gray-600 dark:text-gray-400">
|
||||
{new Date(payment.created_at).toLocaleDateString()}
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card className="p-6">
|
||||
<h3 className="text-lg font-semibold mb-4">Submit Manual Payment</h3>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Invoice ID (optional)</label>
|
||||
<input
|
||||
type="number"
|
||||
value={manualPayment.invoice_id}
|
||||
onChange={(e) => setManualPayment((p) => ({ ...p, invoice_id: e.target.value }))}
|
||||
className="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
|
||||
placeholder="Invoice ID"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Amount</label>
|
||||
<input
|
||||
type="text"
|
||||
value={manualPayment.amount}
|
||||
onChange={(e) => setManualPayment((p) => ({ ...p, amount: e.target.value }))}
|
||||
className="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
|
||||
placeholder="e.g., 99.00"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Payment Method</label>
|
||||
<input
|
||||
type="text"
|
||||
value={manualPayment.payment_method}
|
||||
onChange={(e) => setManualPayment((p) => ({ ...p, payment_method: e.target.value }))}
|
||||
className="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
|
||||
placeholder="bank_transfer / local_wallet / manual"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Reference</label>
|
||||
<input
|
||||
type="text"
|
||||
value={manualPayment.reference}
|
||||
onChange={(e) => setManualPayment((p) => ({ ...p, reference: e.target.value }))}
|
||||
className="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
|
||||
placeholder="Reference or transaction id"
|
||||
/>
|
||||
</div>
|
||||
<div className="md:col-span-2">
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Notes</label>
|
||||
<textarea
|
||||
value={manualPayment.notes}
|
||||
onChange={(e) => setManualPayment((p) => ({ ...p, notes: e.target.value }))}
|
||||
className="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
|
||||
placeholder="Optional notes"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-4 flex justify-end">
|
||||
<Button variant="primary" tone="brand" onClick={handleSubmitManualPayment}>
|
||||
Submit Manual Payment
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Payment Methods Tab */}
|
||||
{activeTab === 'payment-methods' && (
|
||||
<div className="space-y-6">
|
||||
<Card className="p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h2 className="text-lg font-semibold">Payment Methods</h2>
|
||||
<Button variant="primary" tone="brand">
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Type</label>
|
||||
<select
|
||||
value={newPaymentMethod.type}
|
||||
onChange={(e) => setNewPaymentMethod((p) => ({ ...p, type: e.target.value }))}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
|
||||
>
|
||||
<option value="bank_transfer">Bank Transfer</option>
|
||||
<option value="local_wallet">Local Wallet</option>
|
||||
<option value="manual">Manual</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Display Name</label>
|
||||
<input
|
||||
type="text"
|
||||
value={newPaymentMethod.display_name}
|
||||
onChange={(e) => setNewPaymentMethod((p) => ({ ...p, display_name: e.target.value }))}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
|
||||
placeholder="e.g., Bank Transfer (USD)"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Instructions (optional)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={newPaymentMethod.instructions}
|
||||
onChange={(e) => setNewPaymentMethod((p) => ({ ...p, instructions: e.target.value }))}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
|
||||
placeholder="Where to send payment"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<Button variant="primary" tone="brand" onClick={handleAddPaymentMethod}>
|
||||
Add Payment Method
|
||||
</Button>
|
||||
</div>
|
||||
@@ -501,11 +849,26 @@ export default function PlansAndBillingPage() {
|
||||
<div>
|
||||
<div className="font-medium text-gray-900 dark:text-white">{method.display_name}</div>
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400">{method.type}</div>
|
||||
{method.instructions && (
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400 mt-1">{method.instructions}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{method.is_enabled && (
|
||||
<Badge variant="light" color="success">Active</Badge>
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
{method.is_enabled && (
|
||||
<Badge variant="light" color="success">Active</Badge>
|
||||
)}
|
||||
{method.is_default ? (
|
||||
<Badge variant="light" color="info">Default</Badge>
|
||||
) : (
|
||||
<Button variant="outline" size="sm" onClick={() => handleSetDefaultPaymentMethod(method.id)}>
|
||||
Make Default
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="outline" size="sm" tone="neutral" onClick={() => handleRemovePaymentMethod(method.id)}>
|
||||
Remove
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{paymentMethods.length === 0 && (
|
||||
|
||||
Reference in New Issue
Block a user