import React, { useState } from 'react'; import { X, Mail, Lock, ArrowRight, Loader2 } from 'lucide-react'; interface LoginModalProps { isOpen: boolean; onClose: () => void; onSwitchToSignup?: () => void; onLoginSuccess?: (user: any) => void; } export const LoginModal: React.FC = ({ isOpen, onClose, onSwitchToSignup, onLoginSuccess }) => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); if (!isOpen) return null; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); try { const API_BASE = `http://${window.location.hostname}:3001`; const response = await fetch(`${API_BASE}/api/v1/auth/login`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.message || 'Đăng nhập thất bại'); } // Lưu phiên đăng nhập localStorage.setItem('token', data.access_token); localStorage.setItem('user', JSON.stringify(data.user)); if (onLoginSuccess) { onLoginSuccess(data.user); } onClose(); } catch (err: any) { setError(err.message); } finally { setIsLoading(false); } }; return (
{/* Backdrop */}
{/* Modal Content */}

Đăng nhập

Chào mừng bạn quay trở lại!

{error && (
{error}
)}
setEmail(e.target.value)} required className="w-full pl-12 pr-4 py-4 bg-gray-50 border border-gray-100 rounded-2xl focus:ring-2 focus:ring-blue-500 focus:bg-white outline-none transition-all" />
setPassword(e.target.value)} required className="w-full pl-12 pr-4 py-4 bg-gray-50 border border-gray-100 rounded-2xl focus:ring-2 focus:ring-blue-500 focus:bg-white outline-none transition-all" />

Chưa có tài khoản?{' '}

); };