All files / laravel-saas/resources/js/Pages Dashboard.tsx

0% Statements 0/222
0% Branches 0/1
0% Functions 0/1
0% Lines 0/222

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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
import { Head } from '@inertiajs/react';
import AuthenticatedLayout from '@/Components/Layout/AuthenticatedLayout';
import { Card, CardContent, CardHeader } from '@/Components/ui/Card';
import { MetricCard } from '@/Components/dashboard/MetricCard';
import { ActivityTable } from '@/Components/dashboard/ActivityTable';
import { QuickActions } from '@/Components/dashboard/QuickActions';
import { Chart } from '@/Components/ui/Chart';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/Components/ui/Tabs';
import { Progress } from '@/Components/ui/Progress';
import { Alert, AlertDescription } from '@/Components/ui/Alert';
import type { PageProps } from '@/types';
import { 
    DollarSign, 
    Users, 
    CreditCard, 
    Activity,
    Plus,
    FileText,
    Settings,
    Download,
    TrendingUp,
} from 'lucide-react';
 
interface DashboardProps extends PageProps {
    stats: {
        totalUsers: number;
        activeUsersToday: number;
        newUsersThisMonth: number;
    };
    showWelcome: boolean;
    recentActivity: any[];
}
 
export default function Dashboard({ auth, stats, showWelcome }: DashboardProps) {
    // Sample data for the new dashboard
    const chartData = [
        { name: 'Jan', value: 400, users: 240, revenue: 2400 },
        { name: 'Feb', value: 300, users: 139, revenue: 2210 },
        { name: 'Mar', value: 200, users: 980, revenue: 2290 },
        { name: 'Apr', value: 278, users: 390, revenue: 2000 },
        { name: 'May', value: 189, users: 480, revenue: 2181 },
        { name: 'Jun', value: 239, users: 380, revenue: 2500 },
    ];
 
    const activityData = [
        {
            id: '1',
            user: {
                name: auth.user.name,
                email: auth.user.email,
            },
            action: 'Logged in',
            target: 'Dashboard',
            status: 'success' as const,
            timestamp: new Date(Date.now() - 1000 * 60 * 5),
        },
        {
            id: '2',
            user: {
                name: 'Jane Smith',
                email: 'jane@example.com',
            },
            action: 'Updated',
            target: 'Profile settings',
            status: 'success' as const,
            timestamp: new Date(Date.now() - 1000 * 60 * 15),
        },
        {
            id: '3',
            user: {
                name: 'Mike Johnson',
                email: 'mike@example.com',
            },
            action: 'Failed payment',
            target: 'Subscription renewal',
            status: 'failed' as const,
            timestamp: new Date(Date.now() - 1000 * 60 * 30),
        },
    ];
 
    const quickActions = [
        {
            id: '1',
            title: 'Add User',
            description: 'Create a new user account',
            icon: Plus,
            onClick: () => alert('Add User clicked'),
        },
        {
            id: '2',
            title: 'Generate Report',
            description: 'Create monthly analytics report',
            icon: FileText,
            onClick: () => alert('Generate Report clicked'),
        },
        {
            id: '3',
            title: 'System Settings',
            description: 'Configure application settings',
            icon: Settings,
            onClick: () => alert('System Settings clicked'),
        },
        {
            id: '4',
            title: 'Export Data',
            description: 'Download user data as CSV',
            icon: Download,
            onClick: () => alert('Export Data clicked'),
        },
    ];
 
    return (
        <AuthenticatedLayout title="Dashboard">
            <Head title="Dashboard" />
 
            <div className="space-y-6">
                {/* Welcome Message */}
                {showWelcome && (
                    <Alert>
                        <TrendingUp className="h-4 w-4" />
                        <AlertDescription>
                            Welcome to Laravel SaaS! Your account has been created successfully. Let's get started!
                        </AlertDescription>
                    </Alert>
                )}
 
                {/* Metrics Grid */}
                <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
                    <MetricCard
                        title="Total Revenue"
                        value={45231.89}
                        valuePrefix="$"
                        description="Revenue this month"
                        trend={{ value: 20.1, isPositive: true, label: 'from last month' }}
                        icon={<DollarSign className="h-4 w-4" />}
                    />
                    <MetricCard
                        title="Total Users"
                        value={stats.totalUsers}
                        description="Registered users"
                        trend={{ value: 12.5, isPositive: true, label: 'from last month' }}
                        icon={<Users className="h-4 w-4" />}
                    />
                    <MetricCard
                        title="Active Today"
                        value={stats.activeUsersToday}
                        description="Users active today"
                        trend={{ value: 5.4, isPositive: false, label: 'from yesterday' }}
                        icon={<Activity className="h-4 w-4" />}
                    />
                    <MetricCard
                        title="New This Month"
                        value={stats.newUsersThisMonth}
                        description="New sign-ups"
                        trend={{ value: 8.2, isPositive: true, label: 'from last month' }}
                        icon={<CreditCard className="h-4 w-4" />}
                    />
                </div>
 
                {/* Charts and Analytics */}
                <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
                    <Card className="lg:col-span-2">
                        <CardHeader>
                            <h3 className="text-lg font-semibold">Analytics Overview</h3>
                        </CardHeader>
                        <CardContent>
                            <Tabs defaultValue="revenue" className="space-y-4">
                                <TabsList>
                                    <TabsTrigger value="revenue">Revenue</TabsTrigger>
                                    <TabsTrigger value="users">Users</TabsTrigger>
                                    <TabsTrigger value="activity">Activity</TabsTrigger>
                                </TabsList>
                                <TabsContent value="revenue">
                                    <Chart
                                        type="area"
                                        data={chartData}
                                        dataKey="revenue"
                                        height={300}
                                    />
                                </TabsContent>
                                <TabsContent value="users">
                                    <Chart
                                        type="bar"
                                        data={chartData}
                                        dataKey="users"
                                        height={300}
                                    />
                                </TabsContent>
                                <TabsContent value="activity">
                                    <Chart
                                        type="line"
                                        data={chartData}
                                        dataKey="value"
                                        height={300}
                                    />
                                </TabsContent>
                            </Tabs>
                        </CardContent>
                    </Card>
 
                    <div className="space-y-6">
                        {/* Performance Metrics */}
                        <Card>
                            <CardHeader>
                                <h3 className="text-lg font-semibold">Performance</h3>
                            </CardHeader>
                            <CardContent className="space-y-4">
                                <div>
                                    <div className="flex items-center justify-between text-sm">
                                        <span>Server Uptime</span>
                                        <span>99.9%</span>
                                    </div>
                                    <Progress value={99.9} className="mt-2" />
                                </div>
                                <div>
                                    <div className="flex items-center justify-between text-sm">
                                        <span>Response Time</span>
                                        <span>245ms</span>
                                    </div>
                                    <Progress value={75} className="mt-2" />
                                </div>
                                <div>
                                    <div className="flex items-center justify-between text-sm">
                                        <span>Database Load</span>
                                        <span>45%</span>
                                    </div>
                                    <Progress value={45} className="mt-2" />
                                </div>
                            </CardContent>
                        </Card>
 
                        {/* Account Info */}
                        <Card>
                            <CardHeader>
                                <h3 className="text-lg font-semibold">Account Details</h3>
                            </CardHeader>
                            <CardContent className="space-y-3">
                                <div className="flex justify-between">
                                    <span className="text-sm text-muted-foreground">Name</span>
                                    <span className="text-sm font-medium">{auth.user.name}</span>
                                </div>
                                <div className="flex justify-between">
                                    <span className="text-sm text-muted-foreground">Email</span>
                                    <span className="text-sm font-medium">{auth.user.email}</span>
                                </div>
                                <div className="flex justify-between">
                                    <span className="text-sm text-muted-foreground">Role</span>
                                    <span className="text-sm font-medium capitalize">{auth.user.role}</span>
                                </div>
                            </CardContent>
                        </Card>
                    </div>
                </div>
 
                {/* Quick Actions and Recent Activity */}
                <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
                    <QuickActions actions={quickActions} />
                    <ActivityTable data={activityData} />
                </div>
            </div>
        </AuthenticatedLayout>
    );
}