import React, { useState } from 'react'; import { TextField, Button, Typography, Stack, Box, IconButton, InputAdornment } from '@mui/material'; import { useTheme } from '@mui/material/styles'; import VisibilityOffOutlinedIcon from '@mui/icons-material/VisibilityOffOutlined'; import { VisibilityOutlined } from '@mui/icons-material'; import SidePanel from './SidePanel'; import { useNavigate, Link } from 'react-router-dom'; import authService from '../../../services/authService'; const LoginForm = () => { const navigate = useNavigate(); const theme = useTheme(); const [showPassword, setShowPassword] = useState(false); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleTogglePassword = () => { setShowPassword(prev => !prev); }; const handleLogin = async () => { setLoading(true); setError(''); const result = await authService.login(email, password); if (!result.success) { setError(result.message || 'Login failed'); setLoading(false); return; } localStorage.setItem('token', result.data.token); localStorage.setItem('refresh_token', result.data.refresh_token); setLoading(false); // الانتقال للداشبورد مع منع الرجوع navigate('/dashboard', { replace: true }); }; return ( {/* الشعار */} logo {/* عنوان تسجيل الدخول */} Login Enter your username and password to access your account securely. Welcome back to our service! {/* إدخال البريد */} Email setEmail(e.target.value)} sx={{ '& input': { fontWeight: 500, fontSize: '15px' }, '& input::placeholder': { color: '#969BA7' }, '& .MuiOutlinedInput-root': { borderRadius: '10px', transition: '0.3s', '&.Mui-focused fieldset': { borderColor: theme.palette.primary.main, boxShadow: '0 0 0 2px rgba(255, 145, 77, 0.2)' } }, '& .MuiOutlinedInput-root.Mui-focused': { borderColor: '#3f51b5', boxShadow: '0 0 0 2px rgba(63,81,181,0.1)' } }} /> {/* إدخال كلمة السر */} Password setPassword(e.target.value)} sx={{ '& input': { fontWeight: 500, fontSize: '15px' }, '& input::placeholder': { color: '#969BA7' }, '& .MuiOutlinedInput-root': { borderRadius: '10px', transition: '0.3s', '&.Mui-focused fieldset': { borderColor: theme.palette.primary.main, boxShadow: '0 0 0 2px rgba(255, 145, 77, 0.2)' } }, '& .MuiOutlinedInput-root.Mui-focused': { borderColor: '#3f51b5', boxShadow: '0 0 0 2px rgba(63,81,181,0.1)' }, '& input::-ms-reveal, & input::-ms-clear': { display: 'none', }, }} InputProps={{ endAdornment: ( {showPassword ? : } ) }} /> {/* عرض الخطأ */} {error && ( {error} )} {/* زر تسجيل الدخول */} {/* Divider */} Or {/* Google Button */} {/* Facebook Button */} {/* Register Link */} Don’t have an account?{' '} Register {/* ForgetPassword Link */} Did you forget the password?{' '} Forget Password {/* Terms */} By logging in, I agree to the{' '} Terms of Service {' '} and{' '} Privacy Policy . ); }; export default LoginForm;