"use client"; import { useState } from "react"; import { useAuth } from "@/hooks/use-auth"; import { FolderKanban, Loader2, Eye, EyeOff } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Alert, AlertDescription } from "@/components/ui/alert"; export default function LoginPage() { const { login, isLoading: authLoading } = useAuth(); const [formData, setFormData] = useState({ login: "", password: "", }); const [showPassword, setShowPassword] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(null); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setFormData((prev) => ({ ...prev, [name]: value })); // Limpiar error al escribir if (error) setError(null); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); setIsSubmitting(true); // Validación básica if (!formData.login.trim()) { setError("El usuario es requerido"); setIsSubmitting(false); return; } if (!formData.password) { setError("La contraseña es requerida"); setIsSubmitting(false); return; } try { const result = await login({ login: formData.login.trim(), password: formData.password, }); if (!result.success) { setError(result.error || "Error al iniciar sesión"); } // Si success, el AuthProvider redirigirá automáticamente } catch { setError("Error inesperado. Por favor, intenta de nuevo."); } finally { setIsSubmitting(false); } }; const isLoading = isSubmitting || authLoading; return (
{/* Header */}
Dolibarr Proyectos Inicia sesión para acceder al panel de gestión
{/* Form */}
{/* Error Alert */} {error && ( {error} )} {/* Usuario */}
{/* Contraseña */}

Usa tus credenciales de Dolibarr para acceder

); }