feat(dashboard): add dashboard with statistics
- Add dashboard stats API endpoint with key metrics - Add stat-card component for displaying metrics - Add occupancy-chart component for court occupancy visualization - Add recent-bookings component for today's bookings list - Add quick-actions component for common admin actions - Update dashboard page with full implementation Stats include: today's bookings, revenue, occupancy rate, active members, pending bookings, and upcoming tournaments. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
4
apps/web/components/dashboard/index.ts
Normal file
4
apps/web/components/dashboard/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export { StatCard, StatCardSkeleton } from './stat-card';
|
||||
export { OccupancyChart, OccupancyChartSkeleton } from './occupancy-chart';
|
||||
export { RecentBookings, RecentBookingsSkeleton } from './recent-bookings';
|
||||
export { QuickActions } from './quick-actions';
|
||||
201
apps/web/components/dashboard/occupancy-chart.tsx
Normal file
201
apps/web/components/dashboard/occupancy-chart.tsx
Normal file
@@ -0,0 +1,201 @@
|
||||
"use client";
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface CourtOccupancy {
|
||||
courtId: string;
|
||||
courtName: string;
|
||||
availableHours: number;
|
||||
bookedHours: number;
|
||||
occupancyPercent: number;
|
||||
}
|
||||
|
||||
interface OccupancyChartProps {
|
||||
data: CourtOccupancy[];
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export function OccupancyChart({ data, isLoading = false }: OccupancyChartProps) {
|
||||
if (isLoading) {
|
||||
return <OccupancyChartSkeleton />;
|
||||
}
|
||||
|
||||
if (data.length === 0) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<svg
|
||||
className="w-5 h-5 text-primary-500"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"
|
||||
/>
|
||||
</svg>
|
||||
Ocupacion de Canchas
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-col items-center justify-center py-8 text-primary-500">
|
||||
<svg
|
||||
className="w-12 h-12 mb-2 opacity-50"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M20 12H4M12 20V4"
|
||||
/>
|
||||
</svg>
|
||||
<p className="text-sm">No hay canchas configuradas</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// Calculate overall occupancy
|
||||
const totalAvailable = data.reduce((sum, c) => sum + c.availableHours, 0);
|
||||
const totalBooked = data.reduce((sum, c) => sum + c.bookedHours, 0);
|
||||
const overallOccupancy = totalAvailable > 0
|
||||
? Math.round((totalBooked / totalAvailable) * 100)
|
||||
: 0;
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<svg
|
||||
className="w-5 h-5 text-primary-500"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"
|
||||
/>
|
||||
</svg>
|
||||
Ocupacion de Canchas
|
||||
</CardTitle>
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className={cn(
|
||||
"text-2xl font-bold",
|
||||
overallOccupancy >= 80
|
||||
? "text-green-600"
|
||||
: overallOccupancy >= 50
|
||||
? "text-blue-600"
|
||||
: "text-primary-600"
|
||||
)}
|
||||
>
|
||||
{overallOccupancy}%
|
||||
</span>
|
||||
<span className="text-sm text-primary-500">total</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
{data.map((court) => (
|
||||
<div key={court.courtId}>
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<span className="text-sm font-medium text-primary-700">
|
||||
{court.courtName}
|
||||
</span>
|
||||
<span className="text-sm text-primary-500">
|
||||
{court.bookedHours}h / {court.availableHours}h
|
||||
</span>
|
||||
</div>
|
||||
<div className="relative h-4 bg-gray-100 rounded-full overflow-hidden">
|
||||
{/* Available bar (background) */}
|
||||
<div className="absolute inset-0 bg-green-100"></div>
|
||||
{/* Booked bar */}
|
||||
<div
|
||||
className={cn(
|
||||
"absolute inset-y-0 left-0 rounded-full transition-all duration-500",
|
||||
court.occupancyPercent >= 80
|
||||
? "bg-blue-500"
|
||||
: court.occupancyPercent >= 50
|
||||
? "bg-blue-400"
|
||||
: "bg-blue-300"
|
||||
)}
|
||||
style={{ width: `${court.occupancyPercent}%` }}
|
||||
></div>
|
||||
</div>
|
||||
<div className="flex items-center justify-between mt-1">
|
||||
<span
|
||||
className={cn(
|
||||
"text-xs font-medium",
|
||||
court.occupancyPercent >= 80
|
||||
? "text-blue-600"
|
||||
: court.occupancyPercent >= 50
|
||||
? "text-blue-500"
|
||||
: "text-primary-500"
|
||||
)}
|
||||
>
|
||||
{court.occupancyPercent}% ocupado
|
||||
</span>
|
||||
<span className="text-xs text-green-600">
|
||||
{court.availableHours - court.bookedHours}h disponible
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Legend */}
|
||||
<div className="flex items-center justify-center gap-6 mt-6 pt-4 border-t border-primary-100">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-3 h-3 rounded-full bg-blue-400"></div>
|
||||
<span className="text-xs text-primary-500">Ocupado</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-3 h-3 rounded-full bg-green-100"></div>
|
||||
<span className="text-xs text-primary-500">Disponible</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// Loading skeleton
|
||||
export function OccupancyChartSkeleton() {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="h-6 bg-primary-100 rounded w-40 animate-pulse"></div>
|
||||
<div className="h-8 bg-primary-100 rounded w-16 animate-pulse"></div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
{[1, 2, 3].map((i) => (
|
||||
<div key={i} className="animate-pulse">
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<div className="h-4 bg-primary-100 rounded w-24"></div>
|
||||
<div className="h-4 bg-primary-100 rounded w-16"></div>
|
||||
</div>
|
||||
<div className="h-4 bg-primary-100 rounded-full"></div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
151
apps/web/components/dashboard/quick-actions.tsx
Normal file
151
apps/web/components/dashboard/quick-actions.tsx
Normal file
@@ -0,0 +1,151 @@
|
||||
"use client";
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Link from "next/link";
|
||||
|
||||
interface QuickAction {
|
||||
label: string;
|
||||
href: string;
|
||||
icon: React.ReactNode;
|
||||
color: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
const quickActions: QuickAction[] = [
|
||||
{
|
||||
label: "Nueva Reserva",
|
||||
href: "/bookings",
|
||||
icon: (
|
||||
<svg
|
||||
className="w-6 h-6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
color: "bg-blue-500 hover:bg-blue-600",
|
||||
description: "Crear una nueva reserva de cancha",
|
||||
},
|
||||
{
|
||||
label: "Abrir Caja",
|
||||
href: "/pos",
|
||||
icon: (
|
||||
<svg
|
||||
className="w-6 h-6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M17 9V7a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2m2 4h10a2 2 0 002-2v-6a2 2 0 00-2-2H9a2 2 0 00-2 2v6a2 2 0 002 2zm7-5a2 2 0 11-4 0 2 2 0 014 0z"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
color: "bg-green-500 hover:bg-green-600",
|
||||
description: "Iniciar turno de caja registradora",
|
||||
},
|
||||
{
|
||||
label: "Nueva Venta",
|
||||
href: "/pos",
|
||||
icon: (
|
||||
<svg
|
||||
className="w-6 h-6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
color: "bg-purple-500 hover:bg-purple-600",
|
||||
description: "Registrar venta en el punto de venta",
|
||||
},
|
||||
{
|
||||
label: "Registrar Cliente",
|
||||
href: "/clients",
|
||||
icon: (
|
||||
<svg
|
||||
className="w-6 h-6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M18 9v3m0 0v3m0-3h3m-3 0h-3m-2-5a4 4 0 11-8 0 4 4 0 018 0zM3 20a6 6 0 0112 0v1H3v-1z"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
color: "bg-orange-500 hover:bg-orange-600",
|
||||
description: "Agregar un nuevo cliente al sistema",
|
||||
},
|
||||
];
|
||||
|
||||
export function QuickActions() {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<svg
|
||||
className="w-5 h-5 text-primary-500"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M13 10V3L4 14h7v7l9-11h-7z"
|
||||
/>
|
||||
</svg>
|
||||
Acciones Rapidas
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
{quickActions.map((action) => (
|
||||
<Link key={action.label} href={action.href}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="w-full h-auto flex flex-col items-center gap-3 p-4 hover:bg-primary-50 border border-primary-100 rounded-lg transition-all hover:shadow-md group"
|
||||
>
|
||||
<div
|
||||
className={`w-12 h-12 rounded-full flex items-center justify-center text-white transition-transform group-hover:scale-110 ${action.color}`}
|
||||
>
|
||||
{action.icon}
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<p className="font-medium text-primary-800 text-sm">
|
||||
{action.label}
|
||||
</p>
|
||||
<p className="text-xs text-primary-500 mt-1 line-clamp-2">
|
||||
{action.description}
|
||||
</p>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
201
apps/web/components/dashboard/recent-bookings.tsx
Normal file
201
apps/web/components/dashboard/recent-bookings.tsx
Normal file
@@ -0,0 +1,201 @@
|
||||
"use client";
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn, formatTime } from "@/lib/utils";
|
||||
import Link from "next/link";
|
||||
|
||||
interface Booking {
|
||||
id: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
status: string;
|
||||
court: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
client: {
|
||||
id: string;
|
||||
name: string;
|
||||
} | null;
|
||||
}
|
||||
|
||||
interface RecentBookingsProps {
|
||||
bookings: Booking[];
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
const statusConfig: Record<string, { label: string; className: string }> = {
|
||||
PENDING: {
|
||||
label: "Pendiente",
|
||||
className: "bg-yellow-100 text-yellow-700",
|
||||
},
|
||||
CONFIRMED: {
|
||||
label: "Confirmada",
|
||||
className: "bg-blue-100 text-blue-700",
|
||||
},
|
||||
COMPLETED: {
|
||||
label: "Completada",
|
||||
className: "bg-green-100 text-green-700",
|
||||
},
|
||||
CANCELLED: {
|
||||
label: "Cancelada",
|
||||
className: "bg-red-100 text-red-700",
|
||||
},
|
||||
NO_SHOW: {
|
||||
label: "No asistio",
|
||||
className: "bg-gray-100 text-gray-700",
|
||||
},
|
||||
};
|
||||
|
||||
export function RecentBookings({ bookings, isLoading = false }: RecentBookingsProps) {
|
||||
if (isLoading) {
|
||||
return <RecentBookingsSkeleton />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<svg
|
||||
className="w-5 h-5 text-primary-500"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
|
||||
/>
|
||||
</svg>
|
||||
Reservas de Hoy
|
||||
</CardTitle>
|
||||
<Link href="/bookings">
|
||||
<Button variant="ghost" size="sm" className="text-sm">
|
||||
Ver todas
|
||||
<svg
|
||||
className="w-4 h-4 ml-1"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M9 5l7 7-7 7"
|
||||
/>
|
||||
</svg>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{bookings.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-8 text-primary-500">
|
||||
<svg
|
||||
className="w-12 h-12 mb-2 opacity-50"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
|
||||
/>
|
||||
</svg>
|
||||
<p className="text-sm">No hay reservas para hoy</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{bookings.map((booking) => {
|
||||
const status = statusConfig[booking.status] || statusConfig.PENDING;
|
||||
const startTime = new Date(booking.startTime);
|
||||
const endTime = new Date(booking.endTime);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={booking.id}
|
||||
className="flex items-center gap-4 p-3 rounded-lg bg-primary-50 hover:bg-primary-100 transition-colors"
|
||||
>
|
||||
{/* Time */}
|
||||
<div className="flex-shrink-0 text-center min-w-[70px]">
|
||||
<p className="text-sm font-semibold text-primary-800">
|
||||
{formatTime(startTime)}
|
||||
</p>
|
||||
<p className="text-xs text-primary-500">
|
||||
- {formatTime(endTime)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Divider */}
|
||||
<div className="w-px h-10 bg-primary-200"></div>
|
||||
|
||||
{/* Details */}
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium text-primary-800 truncate">
|
||||
{booking.client?.name || "Sin cliente"}
|
||||
</p>
|
||||
<p className="text-xs text-primary-500 truncate">
|
||||
{booking.court.name}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Status badge */}
|
||||
<span
|
||||
className={cn(
|
||||
"flex-shrink-0 px-2 py-1 text-xs font-medium rounded-full",
|
||||
status.className
|
||||
)}
|
||||
>
|
||||
{status.label}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// Loading skeleton
|
||||
export function RecentBookingsSkeleton() {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="h-6 bg-primary-100 rounded w-36 animate-pulse"></div>
|
||||
<div className="h-8 bg-primary-100 rounded w-20 animate-pulse"></div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="flex items-center gap-4 p-3 rounded-lg bg-primary-50 animate-pulse"
|
||||
>
|
||||
<div className="flex-shrink-0 text-center min-w-[70px]">
|
||||
<div className="h-4 bg-primary-100 rounded w-16 mb-1"></div>
|
||||
<div className="h-3 bg-primary-100 rounded w-12 mx-auto"></div>
|
||||
</div>
|
||||
<div className="w-px h-10 bg-primary-200"></div>
|
||||
<div className="flex-1">
|
||||
<div className="h-4 bg-primary-100 rounded w-32 mb-1"></div>
|
||||
<div className="h-3 bg-primary-100 rounded w-20"></div>
|
||||
</div>
|
||||
<div className="h-6 bg-primary-100 rounded-full w-20"></div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
134
apps/web/components/dashboard/stat-card.tsx
Normal file
134
apps/web/components/dashboard/stat-card.tsx
Normal file
@@ -0,0 +1,134 @@
|
||||
"use client";
|
||||
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
interface StatCardProps {
|
||||
title: string;
|
||||
value: string | number;
|
||||
icon: ReactNode;
|
||||
trend?: {
|
||||
value: number;
|
||||
isPositive: boolean;
|
||||
};
|
||||
color?: "primary" | "accent" | "green" | "blue" | "purple" | "orange";
|
||||
}
|
||||
|
||||
const colorVariants = {
|
||||
primary: {
|
||||
bg: "bg-primary-50",
|
||||
icon: "bg-primary-100 text-primary-600",
|
||||
text: "text-primary-700",
|
||||
},
|
||||
accent: {
|
||||
bg: "bg-accent-50",
|
||||
icon: "bg-accent-100 text-accent-600",
|
||||
text: "text-accent-700",
|
||||
},
|
||||
green: {
|
||||
bg: "bg-green-50",
|
||||
icon: "bg-green-100 text-green-600",
|
||||
text: "text-green-700",
|
||||
},
|
||||
blue: {
|
||||
bg: "bg-blue-50",
|
||||
icon: "bg-blue-100 text-blue-600",
|
||||
text: "text-blue-700",
|
||||
},
|
||||
purple: {
|
||||
bg: "bg-purple-50",
|
||||
icon: "bg-purple-100 text-purple-600",
|
||||
text: "text-purple-700",
|
||||
},
|
||||
orange: {
|
||||
bg: "bg-orange-50",
|
||||
icon: "bg-orange-100 text-orange-600",
|
||||
text: "text-orange-700",
|
||||
},
|
||||
};
|
||||
|
||||
export function StatCard({ title, value, icon, trend, color = "primary" }: StatCardProps) {
|
||||
const colors = colorVariants[color];
|
||||
|
||||
return (
|
||||
<Card className="hover:shadow-md transition-shadow">
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1">
|
||||
<p className="text-sm font-medium text-primary-500 mb-1">{title}</p>
|
||||
<p className="text-3xl font-bold text-primary-800">{value}</p>
|
||||
{trend && (
|
||||
<div className="flex items-center mt-2">
|
||||
<span
|
||||
className={cn(
|
||||
"text-sm font-medium flex items-center gap-1",
|
||||
trend.isPositive ? "text-green-600" : "text-red-600"
|
||||
)}
|
||||
>
|
||||
{trend.isPositive ? (
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M5 10l7-7m0 0l7 7m-7-7v18"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M19 14l-7 7m0 0l-7-7m7 7V3"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
{trend.isPositive ? "+" : ""}
|
||||
{trend.value}%
|
||||
</span>
|
||||
<span className="text-xs text-primary-400 ml-1">vs ayer</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
"flex-shrink-0 w-12 h-12 rounded-lg flex items-center justify-center",
|
||||
colors.icon
|
||||
)}
|
||||
>
|
||||
{icon}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// Loading skeleton for stat card
|
||||
export function StatCardSkeleton() {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-start justify-between animate-pulse">
|
||||
<div className="flex-1">
|
||||
<div className="h-4 bg-primary-100 rounded w-24 mb-2"></div>
|
||||
<div className="h-8 bg-primary-100 rounded w-16"></div>
|
||||
</div>
|
||||
<div className="w-12 h-12 bg-primary-100 rounded-lg"></div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user