All files / laravel-saas/resources/js/Pages/Billing Index.tsx

0% Statements 0/184
100% Branches 1/1
100% Functions 1/1
0% Lines 0/184

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216                                                                                                                                                                                                                                                                                                                                                                                                                                               
import React from 'react';
import { Head, Link } from '@inertiajs/react';
import AuthenticatedLayout from '@/Components/Layout/AuthenticatedLayout';
import { BillingPageProps } from '@/types';
import { Card, CardContent, CardHeader, CardTitle } from '@/Components/ui/card';
import { Button } from '@/Components/ui/button';
import { Badge } from '@/Components/ui/badge';
import { Calendar, CreditCard, Download, Package, ShoppingBag } from 'lucide-react';
import { format } from 'date-fns';
 
export default function BillingIndex({
    subscriptions,
    paymentMethods,
    defaultPaymentMethod,
    recentPurchases,
    upcomingInvoice,
    hasStripeAccount,
}: BillingPageProps) {
    return (
        <AuthenticatedLayout>
            <Head title="Billing" />
 
            <div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
                <div className="mb-8">
                    <h1 className="text-3xl font-bold">Billing & Subscriptions</h1>
                    <p className="mt-2 text-gray-600">Manage your subscriptions, payment methods, and purchase history.</p>
                </div>
 
                {/* Quick Actions */}
                <div className="mb-8 grid gap-4 md:grid-cols-4">
                    <Link href="/billing/plans">
                        <Button className="h-full w-full justify-start" variant="outline">
                            <Package className="mr-2 h-4 w-4" />
                            View Plans
                        </Button>
                    </Link>
                    <Link href="/billing/shop">
                        <Button className="h-full w-full justify-start" variant="outline">
                            <ShoppingBag className="mr-2 h-4 w-4" />
                            Shop Products
                        </Button>
                    </Link>
                    <Link href="/billing/payment-methods">
                        <Button className="h-full w-full justify-start" variant="outline">
                            <CreditCard className="mr-2 h-4 w-4" />
                            Payment Methods
                        </Button>
                    </Link>
                    <Link href="/billing/invoices">
                        <Button className="h-full w-full justify-start" variant="outline">
                            <Download className="mr-2 h-4 w-4" />
                            Invoices
                        </Button>
                    </Link>
                </div>
 
                <div className="grid gap-6 lg:grid-cols-2">
                    {/* Active Subscriptions */}
                    <Card>
                        <CardHeader>
                            <CardTitle>Active Subscriptions</CardTitle>
                        </CardHeader>
                        <CardContent>
                            {subscriptions.length > 0 ? (
                                <div className="space-y-4">
                                    {subscriptions.map((subscription) => (
                                        <div key={subscription.id} className="flex items-center justify-between rounded-lg border p-4">
                                            <div>
                                                <h4 className="font-semibold">{subscription.name}</h4>
                                                <p className="text-sm text-gray-600">
                                                    Status: <Badge variant={subscription.stripe_status === 'active' ? 'default' : 'secondary'}>
                                                        {subscription.stripe_status}
                                                    </Badge>
                                                </p>
                                                {subscription.trial_ends_at && (
                                                    <p className="text-sm text-gray-600">
                                                        Trial ends: {format(new Date(subscription.trial_ends_at), 'MMM d, yyyy')}
                                                    </p>
                                                )}
                                                {subscription.ends_at && (
                                                    <p className="text-sm text-gray-600">
                                                        Cancels on: {format(new Date(subscription.ends_at), 'MMM d, yyyy')}
                                                    </p>
                                                )}
                                            </div>
                                            <Link href="/billing/plans">
                                                <Button size="sm" variant="outline">
                                                    Manage
                                                </Button>
                                            </Link>
                                        </div>
                                    ))}
                                </div>
                            ) : (
                                <div className="text-center py-8">
                                    <p className="text-gray-600 mb-4">You don't have any active subscriptions.</p>
                                    <Link href="/billing/plans">
                                        <Button>Browse Plans</Button>
                                    </Link>
                                </div>
                            )}
                        </CardContent>
                    </Card>
 
                    {/* Payment Methods */}
                    <Card>
                        <CardHeader>
                            <CardTitle>Payment Methods</CardTitle>
                        </CardHeader>
                        <CardContent>
                            {paymentMethods.length > 0 ? (
                                <div className="space-y-4">
                                    {paymentMethods.slice(0, 3).map((method) => (
                                        <div key={method.id} className="flex items-center justify-between">
                                            <div className="flex items-center">
                                                <CreditCard className="mr-3 h-5 w-5 text-gray-400" />
                                                <div>
                                                    <p className="font-medium">
                                                        {method.card?.brand} •••• {method.card?.last4}
                                                    </p>
                                                    <p className="text-sm text-gray-600">
                                                        Expires {method.card?.exp_month}/{method.card?.exp_year}
                                                    </p>
                                                </div>
                                            </div>
                                            {defaultPaymentMethod?.id === method.id && (
                                                <Badge variant="secondary">Default</Badge>
                                            )}
                                        </div>
                                    ))}
                                    <Link href="/billing/payment-methods" className="block">
                                        <Button variant="link" className="p-0">
                                            Manage payment methods
                                        </Button>
                                    </Link>
                                </div>
                            ) : (
                                <div className="text-center py-8">
                                    <p className="text-gray-600 mb-4">No payment methods on file.</p>
                                    <Link href="/billing/payment-methods">
                                        <Button>Add Payment Method</Button>
                                    </Link>
                                </div>
                            )}
                        </CardContent>
                    </Card>
 
                    {/* Recent Purchases */}
                    <Card className="lg:col-span-2">
                        <CardHeader>
                            <CardTitle>Recent Purchases</CardTitle>
                        </CardHeader>
                        <CardContent>
                            {recentPurchases.length > 0 ? (
                                <div className="space-y-4">
                                    {recentPurchases.map((purchase) => (
                                        <div key={purchase.id} className="flex items-center justify-between rounded-lg border p-4">
                                            <div className="flex items-center">
                                                <ShoppingBag className="mr-3 h-5 w-5 text-gray-400" />
                                                <div>
                                                    <h4 className="font-semibold">{purchase.product?.name}</h4>
                                                    <p className="text-sm text-gray-600">
                                                        {purchase.paid_at && format(new Date(purchase.paid_at), 'MMM d, yyyy')}
                                                    </p>
                                                </div>
                                            </div>
                                            <div className="text-right">
                                                <p className="font-semibold">
                                                    ${(purchase.amount / 100).toFixed(2)}
                                                </p>
                                                <Badge variant={purchase.status === 'succeeded' ? 'default' : 'secondary'}>
                                                    {purchase.status}
                                                </Badge>
                                            </div>
                                        </div>
                                    ))}
                                    <Link href="/billing/invoices" className="block">
                                        <Button variant="link" className="p-0">
                                            View all purchases
                                        </Button>
                                    </Link>
                                </div>
                            ) : (
                                <div className="text-center py-8">
                                    <p className="text-gray-600">No purchases yet.</p>
                                </div>
                            )}
                        </CardContent>
                    </Card>
 
                    {/* Upcoming Invoice */}
                    {upcomingInvoice && (
                        <Card className="lg:col-span-2">
                            <CardHeader>
                                <CardTitle>Upcoming Invoice</CardTitle>
                            </CardHeader>
                            <CardContent>
                                <div className="flex items-center justify-between">
                                    <div>
                                        <p className="font-semibold">
                                            ${(upcomingInvoice.amount_due / 100).toFixed(2)}
                                        </p>
                                        <p className="text-sm text-gray-600">
                                            Due on {format(new Date(upcomingInvoice.created * 1000), 'MMM d, yyyy')}
                                        </p>
                                    </div>
                                    <Calendar className="h-5 w-5 text-gray-400" />
                                </div>
                            </CardContent>
                        </Card>
                    )}
                </div>
            </div>
        </AuthenticatedLayout>
    );
}