import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import './LoginAnimation.css'; function ValidatorLogin({ changeRole }) { const [credentials, setCredentials] = useState({ email: 'hod.computer.kjsce@example.com', password: 'securePassword123' }); const [animate, setAnimate] = useState(false); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); // Loading state const handleChangeRole = () => { setAnimate(true); setTimeout(() => { changeRole(); }, 800); // Ensure this matches your CSS animation duration }; // Basic email validation const validateEmail = (email) => { const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; return emailRegex.test(email); }; const handleSubmit = async (e) => { e.preventDefault(); // Basic validation if (!credentials.email || !credentials.password) { setError('Please enter both email and password.'); return; } // Validate email format if (!validateEmail(credentials.email)) { setError('Please enter a valid email address.'); return; } setLoading(true); // Show loading state setError(''); // Reset previous errors try { const response = await fetch(`${import.meta.env.VITE_APP_API_URL}/validator-login`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, credentials: 'include', body: JSON.stringify(credentials), }); const result = await response.json(); if (response.ok) { // Handle successful login (navigate, store tokens, etc.) window.location.href = '/validator/dashboard'; } else { setError(result.message || 'Invalid login credentials.'); } } catch (error) { console.error('Error during login:', error); setError('An error occurred. Please try again later.'); } finally { setLoading(false); // Hide loading state } }; return (
or use email
{/* Display Error Message */} {error &&Our web application simplifies the process of requesting, approving, and managing financial support for research students and associates.
Go to Applicant’s Sign in