Improve the design of the frontend

This commit is contained in:
Urtzi Alfaro
2025-08-08 19:21:23 +02:00
parent 488bb3ef93
commit 62ca49d4b8
53 changed files with 5395 additions and 5387 deletions

View File

@@ -1,360 +1,242 @@
import React, { useState, useEffect } from 'react';
import { TrendingUp, TrendingDown, Package, AlertTriangle, Cloud, Users } from 'lucide-react';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, BarChart, Bar } from 'recharts';
import React from 'react';
import { useDashboard } from '../../hooks/useDashboard';
import { useOrderSuggestions } from '../../hooks/useOrderSuggestions';
import { useRealAlerts } from '../../hooks/useRealAlerts';
// Import simplified components
import TodayRevenue from '../../components/simple/TodayRevenue';
import CriticalAlerts from '../../components/simple/CriticalAlerts';
import TodayProduction from '../../components/simple/TodayProduction';
import QuickActions from '../../components/simple/QuickActions';
import QuickOverview from '../../components/simple/QuickOverview';
import OrderSuggestions from '../../components/simple/OrderSuggestions';
// Helper functions
const getConfidenceColor = (confidence: 'high' | 'medium' | 'low') => {
switch (confidence) {
case 'high':
return 'bg-success-100 text-success-800';
case 'medium':
return 'bg-warning-100 text-warning-800';
case 'low':
return 'bg-danger-100 text-danger-800';
default:
return 'bg-gray-100 text-gray-800';
}
};
interface DashboardPageProps {
onNavigateToOrders?: () => void;
onNavigateToReports?: () => void;
onNavigateToProduction?: () => void;
}
const getConfidenceLabel = (confidence: 'high' | 'medium' | 'low') => {
switch (confidence) {
case 'high':
return 'Alta';
case 'medium':
return 'Media';
case 'low':
return 'Baja';
default:
return 'Media';
}
};
const DashboardPage = () => {
const DashboardPage: React.FC<DashboardPageProps> = ({
onNavigateToOrders,
onNavigateToReports,
onNavigateToProduction
}) => {
const {
weather,
todayForecasts,
metrics,
products,
isLoading,
error,
reload
reload,
todayForecasts,
metrics
} = useDashboard();
if (isLoading) {
return <div>Loading dashboard...</div>;
}
// Use real API data for order suggestions
const {
dailyOrders: realDailyOrders,
weeklyOrders: realWeeklyOrders,
isLoading: ordersLoading
} = useOrderSuggestions();
if (error) {
// Use real API data for alerts
const {
alerts: realAlerts,
onAlertAction
} = useRealAlerts();
// Transform forecast data for production component
const mockProduction = todayForecasts.map((forecast, index) => ({
id: `prod-${index}`,
product: forecast.product,
emoji: forecast.product.toLowerCase().includes('croissant') ? '🥐' :
forecast.product.toLowerCase().includes('pan') ? '🍞' :
forecast.product.toLowerCase().includes('magdalena') ? '🧁' : '🥖',
quantity: forecast.predicted,
status: 'pending' as const,
scheduledTime: index < 3 ? '06:00' : '14:00',
confidence: forecast.confidence === 'high' ? 0.9 :
forecast.confidence === 'medium' ? 0.7 : 0.5
}));
// Helper function for greeting
const getGreeting = () => {
const hour = new Date().getHours();
if (hour < 12) return 'Buenos días';
if (hour < 18) return 'Buenas tardes';
return 'Buenas noches';
};
if (isLoading) {
return (
<div>
<p>Error: {error}</p>
<button onClick={reload}>Retry</button>
<div className="flex items-center justify-center h-64">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"></div>
<p className="mt-4 text-gray-600">Cargando datos de tu panadería...</p>
</div>
</div>
);
}
// Sample historical data for charts (you can move this to the hook later)
const salesHistory = [
{ date: '2024-10-28', ventas: 145, prediccion: 140 },
{ date: '2024-10-29', ventas: 128, prediccion: 135 },
{ date: '2024-10-30', ventas: 167, prediccion: 160 },
{ date: '2024-10-31', ventas: 143, prediccion: 145 },
{ date: '2024-11-01', ventas: 156, prediccion: 150 },
{ date: '2024-11-02', ventas: 189, prediccion: 185 },
{ date: '2024-11-03', ventas: 134, prediccion: 130 },
];
const topProducts = [
{ name: 'Croissants', quantity: 45, trend: 'up' },
{ name: 'Pan de molde', quantity: 32, trend: 'up' },
{ name: 'Baguettes', quantity: 28, trend: 'down' },
{ name: 'Napolitanas', quantity: 23, trend: 'up' },
{ name: 'Café', quantity: 67, trend: 'up' },
];
if (error) {
return (
<div className="bg-red-50 border border-red-200 rounded-lg p-6">
<h3 className="text-red-800 font-medium">Error al cargar datos</h3>
<p className="text-red-700 mt-1">{error}</p>
<button
onClick={() => reload()}
className="mt-4 px-4 py-2 bg-red-100 hover:bg-red-200 text-red-800 rounded-lg transition-colors"
>
Reintentar
</button>
</div>
);
}
return (
<div className="p-6 space-y-6">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between">
<div>
<h1 className="text-2xl font-bold text-gray-900">
{/* ¡Hola, {user.fullName?.split(' ')[0] || 'Usuario'}! 👋 */}
Hola
</h1>
<p className="text-gray-600 mt-1">
Aquí tienes un resumen de tu panadería para hoy
</p>
<div className="p-4 md:p-6 space-y-6 bg-gray-50 min-h-screen">
{/* Welcome Header */}
<div className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between">
<div>
<h1 className="text-2xl font-bold text-gray-900">
{getGreeting()}! 👋
</h1>
<p className="text-gray-600 mt-1">
{new Date().toLocaleDateString('es-ES', {
weekday: 'long',
day: 'numeric',
month: 'long',
year: 'numeric'
})}
</p>
</div>
<div className="mt-4 sm:mt-0 flex items-center space-x-4">
{weather && (
<div className="flex items-center text-sm text-gray-600 bg-gray-50 rounded-lg px-4 py-2">
<span className="text-lg mr-2">
{weather.precipitation > 0 ? '🌧️' : weather.temperature > 20 ? '☀️' : '⛅'}
</span>
<span>{weather.temperature}°C</span>
</div>
)}
<div className="text-right">
<div className="text-sm font-medium text-gray-900">Estado del sistema</div>
<div className="text-xs text-green-600 flex items-center">
<div className="w-2 h-2 bg-green-500 rounded-full mr-1"></div>
Operativo
</div>
</div>
</div>
</div>
</div>
{/* Critical Section - Always Visible */}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Revenue - Most Important */}
<TodayRevenue
currentRevenue={metrics?.totalSales || 287.50}
previousRevenue={256.25}
dailyTarget={350}
/>
{weather && (
<div className="mt-4 sm:mt-0 flex items-center text-sm text-gray-600 bg-white rounded-lg px-4 py-2 shadow-soft">
<Cloud className="h-4 w-4 mr-2" />
<span>{weather.temperature}°C - {weather.description}</span>
</div>
)}
{/* Alerts - Real API Data */}
<CriticalAlerts
alerts={realAlerts}
onAlertClick={onAlertAction}
/>
{/* Quick Actions - Easy Access */}
<QuickActions
onActionClick={(actionId) => {
console.log('Action clicked:', actionId);
// Handle quick actions
switch (actionId) {
case 'view_orders':
onNavigateToOrders?.();
break;
case 'view_sales':
onNavigateToReports?.();
break;
default:
// Handle other actions
break;
}
}}
/>
</div>
{/* Key Metrics */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<div className="bg-white p-6 rounded-xl shadow-soft">
<div className="flex items-center">
<div className="p-2 bg-primary-100 rounded-lg">
<Package className="h-6 w-6 text-primary-600" />
</div>
<div className="ml-4">
<p className="text-sm font-medium text-gray-600">Ventas de Hoy</p>
<p className="text-2xl font-bold text-gray-900">{metrics?.totalSales ?? 0}</p>
<p className="text-xs text-success-600 flex items-center mt-1">
<TrendingUp className="h-3 w-3 mr-1" />
+12% vs ayer
</p>
</div>
</div>
</div>
{/* Order Suggestions - Real AI-Powered Recommendations */}
<OrderSuggestions
dailyOrders={realDailyOrders}
weeklyOrders={realWeeklyOrders}
onUpdateQuantity={(orderId, quantity, type) => {
console.log('Update order quantity:', orderId, quantity, type);
// In real implementation, this would update the backend
}}
onCreateOrder={(items, type) => {
console.log('Create order:', type, items);
// Navigate to orders page to complete the order
onNavigateToOrders?.();
}}
onViewDetails={() => {
onNavigateToOrders?.();
}}
/>
<div className="bg-white p-6 rounded-xl shadow-soft">
<div className="flex items-center">
<div className="p-2 bg-success-100 rounded-lg">
<TrendingUp className="h-6 w-6 text-success-600" />
</div>
<div className="ml-4">
<p className="text-sm font-medium text-gray-600">Reducción Desperdicio</p>
<p className="text-2xl font-bold text-gray-900">{metrics?.wasteReduction ?? 0}%</p>
<p className="text-xs text-success-600 flex items-center mt-1">
<TrendingUp className="h-3 w-3 mr-1" />
Mejorando
</p>
</div>
</div>
</div>
{/* Production Section - Core Operations */}
<TodayProduction
items={mockProduction}
onUpdateQuantity={(itemId: string, quantity: number) => {
console.log('Update quantity:', itemId, quantity);
}}
onUpdateStatus={(itemId: string, status: any) => {
console.log('Update status:', itemId, status);
}}
onViewDetails={() => {
onNavigateToProduction?.();
}}
/>
<div className="bg-white p-6 rounded-xl shadow-soft">
<div className="flex items-center">
<div className="p-2 bg-blue-100 rounded-lg">
<Users className="h-6 w-6 text-blue-600" />
</div>
<div className="ml-4">
<p className="text-sm font-medium text-gray-600">Precisión IA</p>
<p className="text-2xl font-bold text-gray-900">{metrics?.accuracy ?? 0}%</p>
<p className="text-xs text-success-600 flex items-center mt-1">
<TrendingUp className="h-3 w-3 mr-1" />
Excelente
</p>
</div>
</div>
</div>
{/* Quick Overview - Supporting Information */}
<QuickOverview
onNavigateToOrders={onNavigateToOrders}
onNavigateToReports={onNavigateToReports}
/>
<div className="bg-white p-6 rounded-xl shadow-soft">
<div className="flex items-center">
<div className="p-2 bg-warning-100 rounded-lg">
<AlertTriangle className="h-6 w-6 text-warning-600" />
</div>
<div className="ml-4">
<p className="text-sm font-medium text-gray-600">Roturas Stock</p>
<p className="text-2xl font-bold text-gray-900">{metrics?.stockouts ?? 0}</p>
<p className="text-xs text-success-600 flex items-center mt-1">
<TrendingDown className="h-3 w-3 mr-1" />
Reduciendo
</p>
</div>
</div>
</div>
</div>
{/* Main Content Grid */}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* Sales Chart */}
<div className="bg-white p-6 rounded-xl shadow-soft">
<h3 className="text-lg font-semibold text-gray-900 mb-4">
Ventas vs Predicciones (Última Semana)
</h3>
<div className="h-64">
<ResponsiveContainer width="100%" height="100%">
<LineChart data={salesHistory}>
<CartesianGrid strokeDasharray="3 3" stroke="#f0f0f0" />
<XAxis
dataKey="date"
stroke="#666"
fontSize={12}
tickFormatter={(value) => {
const date = new Date(value);
return `${date.getDate()}/${date.getMonth() + 1}`;
}}
/>
<YAxis stroke="#666" fontSize={12} />
<Tooltip
contentStyle={{
backgroundColor: '#fff',
border: '1px solid #e5e7eb',
borderRadius: '8px',
boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1)'
}}
labelFormatter={(value) => {
const date = new Date(value);
return `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`;
}}
/>
<Line
type="monotone"
dataKey="ventas"
stroke="#f97316"
strokeWidth={3}
name="Ventas Reales"
dot={{ fill: '#f97316', strokeWidth: 2, r: 4 }}
/>
<Line
type="monotone"
dataKey="prediccion"
stroke="#64748b"
strokeWidth={2}
strokeDasharray="5 5"
name="Predicción IA"
dot={{ fill: '#64748b', strokeWidth: 2, r: 3 }}
/>
</LineChart>
</ResponsiveContainer>
</div>
</div>
{/* Today's Forecasts */}
<div className="bg-white p-6 rounded-xl shadow-soft">
<h3 className="text-lg font-semibold text-gray-900 mb-4">
Predicciones para Hoy
</h3>
<div className="space-y-4">
{todayForecasts.map((forecast, index) => (
<div key={index} className="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
<div className="flex-1">
<div className="flex items-center justify-between">
<span className="font-medium text-gray-900">{forecast.product}</span>
<span className={`px-2 py-1 rounded text-xs font-medium ${getConfidenceColor(forecast.confidence)}`}>
{getConfidenceLabel(forecast.confidence)}
</span>
</div>
<div className="flex items-center mt-1">
<span className="text-xl font-bold text-gray-900 mr-2">
{forecast.predicted}
</span>
<span className={`text-sm flex items-center ${
forecast.change >= 0 ? 'text-success-600' : 'text-danger-600'
}`}>
{forecast.change >= 0 ? (
<TrendingUp className="h-3 w-3 mr-1" />
) : (
<TrendingDown className="h-3 w-3 mr-1" />
)}
{Math.abs(forecast.change)} vs ayer
</span>
</div>
</div>
</div>
))}
</div>
</div>
</div>
{/* Bottom Section */}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* Top Products */}
<div className="bg-white p-6 rounded-xl shadow-soft">
<h3 className="text-lg font-semibold text-gray-900 mb-4">
Productos Más Vendidos (Esta Semana)
</h3>
<div className="h-64">
<ResponsiveContainer width="100%" height="100%">
<BarChart data={topProducts}>
<CartesianGrid strokeDasharray="3 3" stroke="#f0f0f0" />
<XAxis
dataKey="name"
stroke="#666"
fontSize={12}
angle={-45}
textAnchor="end"
height={80}
/>
<YAxis stroke="#666" fontSize={12} />
<Tooltip
contentStyle={{
backgroundColor: '#fff',
border: '1px solid #e5e7eb',
borderRadius: '8px',
boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1)'
}}
/>
<Bar
dataKey="quantity"
fill="#f97316"
radius={[4, 4, 0, 0]}
name="Cantidad Vendida"
/>
</BarChart>
</ResponsiveContainer>
</div>
</div>
{/* Quick Actions */}
<div className="bg-white p-6 rounded-xl shadow-soft">
<h3 className="text-lg font-semibold text-gray-900 mb-4">
Acciones Rápidas
</h3>
<div className="space-y-3">
<button className="w-full p-4 text-left border border-gray-200 rounded-lg hover:border-primary-300 hover:bg-primary-50 transition-all">
<div className="flex items-center">
<div className="p-2 bg-primary-100 rounded-lg mr-3">
<TrendingUp className="h-5 w-5 text-primary-600" />
</div>
<div>
<div className="font-medium text-gray-900">Ver Predicciones Detalladas</div>
<div className="text-sm text-gray-500">Analiza las predicciones completas</div>
</div>
</div>
</button>
<button className="w-full p-4 text-left border border-gray-200 rounded-lg hover:border-primary-300 hover:bg-primary-50 transition-all">
<div className="flex items-center">
<div className="p-2 bg-success-100 rounded-lg mr-3">
<Package className="h-5 w-5 text-success-600" />
</div>
<div>
<div className="font-medium text-gray-900">Gestionar Pedidos</div>
<div className="text-sm text-gray-500">Revisa y ajusta tus pedidos</div>
</div>
</div>
</button>
<button className="w-full p-4 text-left border border-gray-200 rounded-lg hover:border-primary-300 hover:bg-primary-50 transition-all">
<div className="flex items-center">
<div className="p-2 bg-blue-100 rounded-lg mr-3">
<Users className="h-5 w-5 text-blue-600" />
</div>
<div>
<div className="font-medium text-gray-900">Configurar Alertas</div>
<div className="text-sm text-gray-500">Personaliza tus notificaciones</div>
</div>
</div>
</button>
</div>
</div>
</div>
{/* Weather Impact Alert */}
{/* Weather Impact Alert - Context Aware */}
{weather && weather.precipitation > 0 && (
<div className="bg-blue-50 border border-blue-200 rounded-xl p-4">
<div className="flex items-start">
<Cloud className="h-5 w-5 text-blue-600 mt-0.5 mr-3" />
<span className="text-2xl mr-3">🌧</span>
<div>
<h4 className="font-medium text-blue-900">Impacto del Clima</h4>
<h4 className="font-medium text-blue-900">Impacto del Clima Detectado</h4>
<p className="text-blue-800 text-sm mt-1">
Se esperan precipitaciones hoy. Esto puede reducir el tráfico peatonal en un 20-30%.
Considera ajustar la producción de productos frescos.
Se esperan precipitaciones ({weather.precipitation}mm). Las predicciones se han ajustado
automáticamente considerando una reducción del 15% en el tráfico.
</p>
<div className="mt-2 flex items-center text-xs text-blue-700">
<div className="w-2 h-2 bg-blue-500 rounded-full mr-2"></div>
Producción y pedidos ya optimizados
</div>
</div>
</div>
</div>
)}
{/* Success Message - When Everything is Good */}
{realAlerts.length === 0 && (
<div className="bg-green-50 border border-green-200 rounded-xl p-6 text-center">
<div className="text-4xl mb-2">🎉</div>
<h4 className="font-medium text-green-900">¡Todo bajo control!</h4>
<p className="text-green-700 text-sm mt-1">
No hay alertas activas. Tu panadería está funcionando perfectamente.
</p>
</div>
)}
</div>
);
};

View File

@@ -1,5 +1,9 @@
import React, { useState, useEffect } from 'react';
import { Package, Plus, Edit, Trash2, Calendar, CheckCircle, AlertCircle, Clock } from 'lucide-react';
import { Package, Plus, Edit, Trash2, Calendar, CheckCircle, AlertCircle, Clock, BarChart3, TrendingUp, Euro, Settings } from 'lucide-react';
// Import complex components
import WhatIfPlanner from '../../components/ui/WhatIfPlanner';
import DemandHeatmap from '../../components/ui/DemandHeatmap';
interface Order {
id: string;
@@ -24,7 +28,7 @@ const OrdersPage: React.FC = () => {
const [orders, setOrders] = useState<Order[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [showNewOrder, setShowNewOrder] = useState(false);
const [activeTab, setActiveTab] = useState<'all' | 'pending' | 'delivered'>('all');
const [activeTab, setActiveTab] = useState<'orders' | 'analytics' | 'forecasting' | 'suppliers'>('orders');
// Sample orders data
const sampleOrders: Order[] = [
@@ -135,11 +139,47 @@ const OrdersPage: React.FC = () => {
}
};
// Sample data for complex components
const orderDemandHeatmapData = [
{
weekStart: '2024-11-04',
days: [
{
date: '2024-11-04',
demand: 180,
isToday: true,
products: [
{ name: 'Harina de trigo', demand: 50, confidence: 'high' as const },
{ name: 'Levadura fresca', demand: 2, confidence: 'high' as const },
{ name: 'Mantequilla', demand: 5, confidence: 'medium' as const },
{ name: 'Vasos café', demand: 1000, confidence: 'medium' as const },
]
},
{ date: '2024-11-05', demand: 165, isForecast: true },
{ date: '2024-11-06', demand: 195, isForecast: true },
{ date: '2024-11-07', demand: 220, isForecast: true },
{ date: '2024-11-08', demand: 185, isForecast: true },
{ date: '2024-11-09', demand: 250, isForecast: true },
{ date: '2024-11-10', demand: 160, isForecast: true }
]
}
];
const baselineSupplyData = {
totalDemand: 180,
totalRevenue: 420,
products: [
{ name: 'Harina de trigo', demand: 50, price: 0.85 },
{ name: 'Levadura fresca', demand: 2, price: 3.20 },
{ name: 'Mantequilla', demand: 5, price: 4.20 },
{ name: 'Leche entera', demand: 20, price: 0.95 },
{ name: 'Vasos café', demand: 1000, price: 0.08 },
]
};
const filteredOrders = orders.filter(order => {
if (activeTab === 'all') return true;
if (activeTab === 'pending') return order.status === 'pending' || order.status === 'confirmed';
if (activeTab === 'delivered') return order.status === 'delivered';
return true;
if (activeTab === 'orders') return true;
return false;
});
const handleDeleteOrder = (orderId: string) => {
@@ -181,24 +221,31 @@ const OrdersPage: React.FC = () => {
</button>
</div>
{/* Tabs */}
{/* Enhanced Tabs */}
<div className="bg-white rounded-xl shadow-soft p-1">
<div className="flex space-x-1">
{[
{ id: 'all', label: 'Todos', count: orders.length },
{ id: 'pending', label: 'Pendientes', count: orders.filter(o => o.status === 'pending' || o.status === 'confirmed').length },
{ id: 'delivered', label: 'Entregados', count: orders.filter(o => o.status === 'delivered').length }
{ id: 'orders', label: 'Gestión de Pedidos', icon: Package, count: orders.length },
{ id: 'analytics', label: 'Análisis', icon: BarChart3 },
{ id: 'forecasting', label: 'Simulaciones', icon: TrendingUp },
{ id: 'suppliers', label: 'Proveedores', icon: Settings }
].map((tab) => (
<button
key={tab.id}
onClick={() => setActiveTab(tab.id as any)}
className={`flex-1 py-2 px-4 text-sm font-medium rounded-lg transition-all ${
className={`flex-1 py-3 px-4 text-sm font-medium rounded-lg transition-all flex items-center justify-center ${
activeTab === tab.id
? 'bg-primary-100 text-primary-700'
: 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'
}`}
>
{tab.label} ({tab.count})
<tab.icon className="h-4 w-4 mr-2" />
{tab.label}
{tab.count && (
<span className="ml-2 px-2 py-1 bg-gray-200 text-gray-700 rounded-full text-xs">
{tab.count}
</span>
)}
</button>
))}
</div>
@@ -224,8 +271,11 @@ const OrdersPage: React.FC = () => {
</div>
</div>
{/* Orders Grid */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{/* Tab Content */}
{activeTab === 'orders' && (
<>
{/* Orders Grid */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{filteredOrders.map((order) => (
<div key={order.id} className="bg-white rounded-xl shadow-soft hover:shadow-medium transition-shadow">
{/* Order Header */}
@@ -390,6 +440,148 @@ const OrdersPage: React.FC = () => {
</button>
</div>
</div>
</>
)}
{/* Analytics Tab */}
{activeTab === 'analytics' && (
<div className="space-y-6">
<DemandHeatmap
data={orderDemandHeatmapData}
selectedProduct="Ingredientes"
onDateClick={(date) => {
console.log('Selected date:', date);
}}
/>
{/* Cost Analysis Chart */}
<div className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<h3 className="text-lg font-semibold text-gray-900 mb-4 flex items-center">
<Euro className="h-5 w-5 mr-2 text-primary-600" />
Análisis de Costos
</h3>
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<div className="bg-green-50 border border-green-200 rounded-lg p-4">
<div className="text-green-800 font-semibold">Ahorro Mensual</div>
<div className="text-2xl font-bold text-green-900">124.50</div>
<div className="text-sm text-green-700">vs mes anterior</div>
</div>
<div className="bg-blue-50 border border-blue-200 rounded-lg p-4">
<div className="text-blue-800 font-semibold">Gasto Promedio</div>
<div className="text-2xl font-bold text-blue-900">289.95</div>
<div className="text-sm text-blue-700">por pedido</div>
</div>
<div className="bg-purple-50 border border-purple-200 rounded-lg p-4">
<div className="text-purple-800 font-semibold">Eficiencia</div>
<div className="text-2xl font-bold text-purple-900">94.2%</div>
<div className="text-sm text-purple-700">predicción IA</div>
</div>
</div>
<div className="mt-6 h-64 bg-gray-50 rounded-lg flex items-center justify-center">
<div className="text-center text-gray-500">
<BarChart3 className="h-12 w-12 mx-auto mb-2 text-gray-400" />
<p>Gráfico de tendencias de costos</p>
<p className="text-sm">Próximamente disponible</p>
</div>
</div>
</div>
</div>
)}
{/* Forecasting/Simulations Tab */}
{activeTab === 'forecasting' && (
<div className="space-y-6">
<WhatIfPlanner
baselineData={baselineSupplyData}
onScenarioRun={(scenario, result) => {
console.log('Scenario run:', scenario, result);
}}
/>
</div>
)}
{/* Suppliers Tab */}
{activeTab === 'suppliers' && (
<div className="space-y-6">
{/* Suppliers Management */}
<div className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<h3 className="text-lg font-semibold text-gray-900 mb-4 flex items-center">
<Settings className="h-5 w-5 mr-2 text-primary-600" />
Gestión de Proveedores
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{[
{
name: 'Harinas Castellana',
category: 'Ingredientes',
rating: 4.8,
reliability: 98,
nextDelivery: '2024-11-05',
status: 'active'
},
{
name: 'Distribuciones Madrid',
category: 'Consumibles',
rating: 4.5,
reliability: 95,
nextDelivery: '2024-11-04',
status: 'active'
},
{
name: 'Lácteos Frescos SA',
category: 'Ingredientes',
rating: 4.9,
reliability: 99,
nextDelivery: '2024-11-03',
status: 'active'
}
].map((supplier, index) => (
<div key={index} className="border border-gray-200 rounded-lg p-4">
<div className="flex items-center justify-between mb-3">
<h4 className="font-medium text-gray-900">{supplier.name}</h4>
<span className="px-2 py-1 bg-green-100 text-green-800 text-xs rounded-full">
{supplier.status === 'active' ? 'Activo' : 'Inactivo'}
</span>
</div>
<div className="space-y-2">
<div className="text-sm text-gray-600">
<span className="font-medium">Categoría:</span> {supplier.category}
</div>
<div className="text-sm text-gray-600">
<span className="font-medium">Calificación:</span> {supplier.rating}/5
</div>
<div className="text-sm text-gray-600">
<span className="font-medium">Confiabilidad:</span> {supplier.reliability}%
</div>
<div className="text-sm text-gray-600">
<span className="font-medium">Próxima entrega:</span> {new Date(supplier.nextDelivery).toLocaleDateString('es-ES')}
</div>
</div>
<div className="mt-4 flex space-x-2">
<button className="flex-1 px-3 py-2 text-sm bg-primary-100 text-primary-700 rounded-lg hover:bg-primary-200 transition-colors">
Editar
</button>
<button className="px-3 py-2 text-sm bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors">
Contactar
</button>
</div>
</div>
))}
</div>
<div className="mt-6 text-center">
<button className="inline-flex items-center px-4 py-2 bg-primary-500 text-white rounded-lg hover:bg-primary-600 transition-colors">
<Plus className="h-4 w-4 mr-2" />
Añadir Proveedor
</button>
</div>
</div>
</div>
)}
{/* New Order Modal Placeholder */}
{showNewOrder && (

View File

@@ -0,0 +1,671 @@
import React, { useState, useEffect } from 'react';
import {
Clock, Calendar, ChefHat, TrendingUp, AlertTriangle,
CheckCircle, Settings, Plus, BarChart3, Users,
Timer, Target, Activity, Zap
} from 'lucide-react';
// Import existing complex components
import ProductionSchedule from '../../components/ui/ProductionSchedule';
import DemandHeatmap from '../../components/ui/DemandHeatmap';
import { useDashboard } from '../../hooks/useDashboard';
// Types for production management
interface ProductionMetrics {
efficiency: number;
onTimeCompletion: number;
wastePercentage: number;
energyUsage: number;
staffUtilization: number;
}
interface ProductionBatch {
id: string;
product: string;
batchSize: number;
startTime: string;
endTime: string;
status: 'planned' | 'in_progress' | 'completed' | 'delayed';
assignedStaff: string[];
actualYield: number;
expectedYield: number;
notes?: string;
temperature?: number;
humidity?: number;
}
interface StaffMember {
id: string;
name: string;
role: 'baker' | 'assistant' | 'decorator';
currentTask?: string;
status: 'available' | 'busy' | 'break';
efficiency: number;
}
interface Equipment {
id: string;
name: string;
type: 'oven' | 'mixer' | 'proofer' | 'cooling_rack';
status: 'idle' | 'in_use' | 'maintenance' | 'error';
currentBatch?: string;
temperature?: number;
maintenanceDue?: string;
}
const ProductionPage: React.FC = () => {
const { todayForecasts, metrics, weather, isLoading } = useDashboard();
const [activeTab, setActiveTab] = useState<'schedule' | 'batches' | 'analytics' | 'staff' | 'equipment'>('schedule');
const [productionMetrics, setProductionMetrics] = useState<ProductionMetrics>({
efficiency: 87.5,
onTimeCompletion: 94.2,
wastePercentage: 3.8,
energyUsage: 156.7,
staffUtilization: 78.3
});
// Sample production schedule data
const [productionSchedule, setProductionSchedule] = useState([
{
time: '05:00 AM',
items: [
{
id: 'prod-1',
product: 'Croissants',
quantity: 48,
priority: 'high' as const,
estimatedTime: 180,
status: 'in_progress' as const,
confidence: 0.92,
notes: 'Alta demanda prevista - lote doble'
},
{
id: 'prod-2',
product: 'Pan de molde',
quantity: 35,
priority: 'high' as const,
estimatedTime: 240,
status: 'pending' as const,
confidence: 0.88
}
],
totalTime: 420
},
{
time: '08:00 AM',
items: [
{
id: 'prod-3',
product: 'Baguettes',
quantity: 25,
priority: 'medium' as const,
estimatedTime: 200,
status: 'pending' as const,
confidence: 0.75
},
{
id: 'prod-4',
product: 'Magdalenas',
quantity: 60,
priority: 'medium' as const,
estimatedTime: 120,
status: 'pending' as const,
confidence: 0.82
}
],
totalTime: 320
}
]);
const [productionBatches, setProductionBatches] = useState<ProductionBatch[]>([
{
id: 'batch-1',
product: 'Croissants',
batchSize: 48,
startTime: '05:00',
endTime: '08:00',
status: 'in_progress',
assignedStaff: ['maria-lopez', 'carlos-ruiz'],
actualYield: 45,
expectedYield: 48,
temperature: 180,
humidity: 65,
notes: 'Masa fermentando correctamente'
},
{
id: 'batch-2',
product: 'Pan de molde',
batchSize: 35,
startTime: '06:30',
endTime: '10:30',
status: 'planned',
assignedStaff: ['ana-garcia'],
actualYield: 0,
expectedYield: 35,
notes: 'Esperando finalización de croissants'
}
]);
const [staff, setStaff] = useState<StaffMember[]>([
{
id: 'maria-lopez',
name: 'María López',
role: 'baker',
currentTask: 'Preparando croissants',
status: 'busy',
efficiency: 94.2
},
{
id: 'carlos-ruiz',
name: 'Carlos Ruiz',
role: 'assistant',
currentTask: 'Horneando croissants',
status: 'busy',
efficiency: 87.8
},
{
id: 'ana-garcia',
name: 'Ana García',
role: 'baker',
status: 'available',
efficiency: 91.5
}
]);
const [equipment, setEquipment] = useState<Equipment[]>([
{
id: 'oven-1',
name: 'Horno Principal',
type: 'oven',
status: 'in_use',
currentBatch: 'batch-1',
temperature: 180,
maintenanceDue: '2024-11-15'
},
{
id: 'mixer-1',
name: 'Amasadora Industrial',
type: 'mixer',
status: 'idle',
maintenanceDue: '2024-11-20'
},
{
id: 'proofer-1',
name: 'Fermentadora',
type: 'proofer',
status: 'in_use',
currentBatch: 'batch-2',
temperature: 28,
maintenanceDue: '2024-12-01'
}
]);
// Demand heatmap sample data
const heatmapData = [
{
weekStart: '2024-11-04',
days: [
{
date: '2024-11-04',
demand: 180,
isToday: true,
products: [
{ name: 'Croissants', demand: 48, confidence: 'high' as const },
{ name: 'Pan de molde', demand: 35, confidence: 'high' as const },
{ name: 'Baguettes', demand: 25, confidence: 'medium' as const },
{ name: 'Magdalenas', demand: 32, confidence: 'medium' as const },
]
},
{
date: '2024-11-05',
demand: 165,
isForecast: true,
products: [
{ name: 'Croissants', demand: 42, confidence: 'high' as const },
{ name: 'Pan de molde', demand: 38, confidence: 'medium' as const },
{ name: 'Baguettes', demand: 28, confidence: 'medium' as const },
{ name: 'Magdalenas', demand: 28, confidence: 'low' as const },
]
},
{
date: '2024-11-06',
demand: 195,
isForecast: true,
products: [
{ name: 'Croissants', demand: 55, confidence: 'high' as const },
{ name: 'Pan de molde', demand: 40, confidence: 'high' as const },
{ name: 'Baguettes', demand: 32, confidence: 'medium' as const },
{ name: 'Magdalenas', demand: 35, confidence: 'medium' as const },
]
},
{ date: '2024-11-07', demand: 220, isForecast: true },
{ date: '2024-11-08', demand: 185, isForecast: true },
{ date: '2024-11-09', demand: 250, isForecast: true },
{ date: '2024-11-10', demand: 160, isForecast: true }
]
}
];
const getStatusColor = (status: string) => {
switch (status) {
case 'planned':
return 'bg-blue-100 text-blue-800';
case 'in_progress':
return 'bg-yellow-100 text-yellow-800';
case 'completed':
return 'bg-green-100 text-green-800';
case 'delayed':
return 'bg-red-100 text-red-800';
default:
return 'bg-gray-100 text-gray-800';
}
};
const getEquipmentStatusColor = (status: Equipment['status']) => {
switch (status) {
case 'idle':
return 'bg-gray-100 text-gray-800';
case 'in_use':
return 'bg-green-100 text-green-800';
case 'maintenance':
return 'bg-yellow-100 text-yellow-800';
case 'error':
return 'bg-red-100 text-red-800';
default:
return 'bg-gray-100 text-gray-800';
}
};
if (isLoading) {
return (
<div className="p-6">
<div className="animate-pulse space-y-6">
<div className="h-8 bg-gray-200 rounded w-1/3"></div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
{[...Array(4)].map((_, i) => (
<div key={i} className="h-32 bg-gray-200 rounded-xl"></div>
))}
</div>
</div>
</div>
);
}
return (
<div className="p-6 space-y-6 bg-gray-50 min-h-screen">
{/* Header */}
<div className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<div className="flex flex-col lg:flex-row lg:items-center lg:justify-between">
<div>
<h1 className="text-2xl font-bold text-gray-900 flex items-center">
<ChefHat className="h-8 w-8 mr-3 text-primary-600" />
Centro de Producción
</h1>
<p className="text-gray-600 mt-1">
Gestión completa de la producción diaria y planificación inteligente
</p>
</div>
<div className="mt-4 lg:mt-0 flex items-center space-x-4">
<div className="bg-gray-50 rounded-lg px-4 py-2">
<div className="text-sm font-medium text-gray-900">Eficiencia Hoy</div>
<div className="text-2xl font-bold text-primary-600">{productionMetrics.efficiency}%</div>
</div>
<button className="inline-flex items-center px-4 py-2 bg-primary-500 text-white rounded-xl hover:bg-primary-600 transition-colors">
<Plus className="h-5 w-5 mr-2" />
Nuevo Lote
</button>
</div>
</div>
</div>
{/* Key Metrics Cards */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4">
<div className="bg-white p-6 rounded-xl shadow-sm border border-gray-200">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-gray-600">Eficiencia</p>
<p className="text-2xl font-bold text-green-600">{productionMetrics.efficiency}%</p>
</div>
<div className="p-3 bg-green-100 rounded-lg">
<Target className="h-6 w-6 text-green-600" />
</div>
</div>
<div className="mt-2 flex items-center text-xs text-green-600">
<TrendingUp className="h-3 w-3 mr-1" />
+2.3% vs ayer
</div>
</div>
<div className="bg-white p-6 rounded-xl shadow-sm border border-gray-200">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-gray-600">A Tiempo</p>
<p className="text-2xl font-bold text-blue-600">{productionMetrics.onTimeCompletion}%</p>
</div>
<div className="p-3 bg-blue-100 rounded-lg">
<Clock className="h-6 w-6 text-blue-600" />
</div>
</div>
<div className="mt-2 flex items-center text-xs text-blue-600">
<CheckCircle className="h-3 w-3 mr-1" />
Muy bueno
</div>
</div>
<div className="bg-white p-6 rounded-xl shadow-sm border border-gray-200">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-gray-600">Desperdicio</p>
<p className="text-2xl font-bold text-orange-600">{productionMetrics.wastePercentage}%</p>
</div>
<div className="p-3 bg-orange-100 rounded-lg">
<AlertTriangle className="h-6 w-6 text-orange-600" />
</div>
</div>
<div className="mt-2 flex items-center text-xs text-orange-600">
<TrendingUp className="h-3 w-3 mr-1" />
-0.5% vs ayer
</div>
</div>
<div className="bg-white p-6 rounded-xl shadow-sm border border-gray-200">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-gray-600">Energía</p>
<p className="text-2xl font-bold text-purple-600">{productionMetrics.energyUsage} kW</p>
</div>
<div className="p-3 bg-purple-100 rounded-lg">
<Zap className="h-6 w-6 text-purple-600" />
</div>
</div>
<div className="mt-2 flex items-center text-xs text-purple-600">
<Activity className="h-3 w-3 mr-1" />
Normal
</div>
</div>
<div className="bg-white p-6 rounded-xl shadow-sm border border-gray-200">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-gray-600">Personal</p>
<p className="text-2xl font-bold text-indigo-600">{productionMetrics.staffUtilization}%</p>
</div>
<div className="p-3 bg-indigo-100 rounded-lg">
<Users className="h-6 w-6 text-indigo-600" />
</div>
</div>
<div className="mt-2 flex items-center text-xs text-indigo-600">
<Users className="h-3 w-3 mr-1" />
3/4 activos
</div>
</div>
</div>
{/* Tabs Navigation */}
<div className="bg-white rounded-xl shadow-sm p-1">
<div className="flex space-x-1">
{[
{ id: 'schedule', label: 'Programa', icon: Calendar },
{ id: 'batches', label: 'Lotes Activos', icon: Timer },
{ id: 'analytics', label: 'Análisis', icon: BarChart3 },
{ id: 'staff', label: 'Personal', icon: Users },
{ id: 'equipment', label: 'Equipos', icon: Settings }
].map((tab) => (
<button
key={tab.id}
onClick={() => setActiveTab(tab.id as any)}
className={`flex-1 py-3 px-4 text-sm font-medium rounded-lg transition-all flex items-center justify-center ${
activeTab === tab.id
? 'bg-primary-100 text-primary-700'
: 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'
}`}
>
<tab.icon className="h-4 w-4 mr-2" />
{tab.label}
</button>
))}
</div>
</div>
{/* Tab Content */}
<div className="space-y-6">
{activeTab === 'schedule' && (
<>
<ProductionSchedule
schedule={productionSchedule}
onUpdateQuantity={(itemId, quantity) => {
setProductionSchedule(prev =>
prev.map(slot => ({
...slot,
items: slot.items.map(item =>
item.id === itemId ? { ...item, quantity } : item
)
}))
);
}}
onUpdateStatus={(itemId, status) => {
setProductionSchedule(prev =>
prev.map(slot => ({
...slot,
items: slot.items.map(item =>
item.id === itemId ? { ...item, status } : item
)
}))
);
}}
/>
</>
)}
{activeTab === 'batches' && (
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{productionBatches.map((batch) => (
<div key={batch.id} className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<div className="flex items-center justify-between mb-4">
<h3 className="font-semibold text-gray-900">{batch.product}</h3>
<span className={`px-3 py-1 rounded-full text-sm font-medium ${getStatusColor(batch.status)}`}>
{batch.status === 'planned' ? 'Planificado' :
batch.status === 'in_progress' ? 'En Progreso' :
batch.status === 'completed' ? 'Completado' : 'Retrasado'}
</span>
</div>
<div className="space-y-3">
<div className="grid grid-cols-2 gap-4">
<div>
<p className="text-sm text-gray-600">Tamaño del Lote</p>
<p className="font-semibold text-gray-900">{batch.batchSize} unidades</p>
</div>
<div>
<p className="text-sm text-gray-600">Rendimiento</p>
<p className="font-semibold text-gray-900">
{batch.actualYield || 0}/{batch.expectedYield}
</p>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<p className="text-sm text-gray-600">Inicio</p>
<p className="font-semibold text-gray-900">{batch.startTime}</p>
</div>
<div>
<p className="text-sm text-gray-600">Fin Estimado</p>
<p className="font-semibold text-gray-900">{batch.endTime}</p>
</div>
</div>
{(batch.temperature || batch.humidity) && (
<div className="grid grid-cols-2 gap-4">
{batch.temperature && (
<div>
<p className="text-sm text-gray-600">Temperatura</p>
<p className="font-semibold text-gray-900">{batch.temperature}°C</p>
</div>
)}
{batch.humidity && (
<div>
<p className="text-sm text-gray-600">Humedad</p>
<p className="font-semibold text-gray-900">{batch.humidity}%</p>
</div>
)}
</div>
)}
<div>
<p className="text-sm text-gray-600 mb-2">Personal Asignado</p>
<div className="flex space-x-2">
{batch.assignedStaff.map((staffId) => {
const staffMember = staff.find(s => s.id === staffId);
return (
<span
key={staffId}
className="px-2 py-1 bg-gray-100 text-gray-700 text-sm rounded"
>
{staffMember?.name || staffId}
</span>
);
})}
</div>
</div>
{batch.notes && (
<div className="bg-gray-50 rounded-lg p-3">
<p className="text-sm text-gray-700">{batch.notes}</p>
</div>
)}
</div>
</div>
))}
</div>
)}
{activeTab === 'analytics' && (
<div className="space-y-6">
<DemandHeatmap
data={heatmapData}
onDateClick={(date) => {
console.log('Selected date:', date);
}}
/>
{/* Production Trends Chart Placeholder */}
<div className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<h3 className="text-lg font-semibold text-gray-900 mb-4 flex items-center">
<BarChart3 className="h-5 w-5 mr-2 text-primary-600" />
Tendencias de Producción
</h3>
<div className="h-64 bg-gray-50 rounded-lg flex items-center justify-center">
<div className="text-center text-gray-500">
<BarChart3 className="h-12 w-12 mx-auto mb-2 text-gray-400" />
<p>Gráfico de tendencias de producción</p>
<p className="text-sm">Próximamente disponible</p>
</div>
</div>
</div>
</div>
)}
{activeTab === 'staff' && (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{staff.map((member) => (
<div key={member.id} className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<div className="flex items-center justify-between mb-4">
<h3 className="font-semibold text-gray-900">{member.name}</h3>
<span className={`px-2 py-1 rounded-full text-xs font-medium ${
member.status === 'available' ? 'bg-green-100 text-green-800' :
member.status === 'busy' ? 'bg-yellow-100 text-yellow-800' :
'bg-gray-100 text-gray-800'
}`}>
{member.status === 'available' ? 'Disponible' :
member.status === 'busy' ? 'Ocupado' : 'Descanso'}
</span>
</div>
<div className="space-y-3">
<div>
<p className="text-sm text-gray-600">Rol</p>
<p className="font-medium text-gray-900 capitalize">{member.role}</p>
</div>
{member.currentTask && (
<div>
<p className="text-sm text-gray-600">Tarea Actual</p>
<p className="font-medium text-gray-900">{member.currentTask}</p>
</div>
)}
<div>
<p className="text-sm text-gray-600">Eficiencia</p>
<div className="flex items-center space-x-2">
<div className="flex-1 bg-gray-200 rounded-full h-2">
<div
className="bg-primary-600 h-2 rounded-full"
style={{ width: `${member.efficiency}%` }}
></div>
</div>
<span className="text-sm font-medium text-gray-900">{member.efficiency}%</span>
</div>
</div>
</div>
</div>
))}
</div>
)}
{activeTab === 'equipment' && (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{equipment.map((item) => (
<div key={item.id} className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<div className="flex items-center justify-between mb-4">
<h3 className="font-semibold text-gray-900">{item.name}</h3>
<span className={`px-2 py-1 rounded-full text-xs font-medium ${getEquipmentStatusColor(item.status)}`}>
{item.status === 'idle' ? 'Inactivo' :
item.status === 'in_use' ? 'En Uso' :
item.status === 'maintenance' ? 'Mantenimiento' : 'Error'}
</span>
</div>
<div className="space-y-3">
<div>
<p className="text-sm text-gray-600">Tipo</p>
<p className="font-medium text-gray-900 capitalize">{item.type}</p>
</div>
{item.currentBatch && (
<div>
<p className="text-sm text-gray-600">Lote Actual</p>
<p className="font-medium text-gray-900">
{productionBatches.find(b => b.id === item.currentBatch)?.product || item.currentBatch}
</p>
</div>
)}
{item.temperature && (
<div>
<p className="text-sm text-gray-600">Temperatura</p>
<p className="font-medium text-gray-900">{item.temperature}°C</p>
</div>
)}
{item.maintenanceDue && (
<div>
<p className="text-sm text-gray-600">Próximo Mantenimiento</p>
<p className="font-medium text-orange-600">
{new Date(item.maintenanceDue).toLocaleDateString('es-ES')}
</p>
</div>
)}
</div>
</div>
))}
</div>
)}
</div>
</div>
);
};
export default ProductionPage;