"use client"; // This MUST be the very first line of the file import React, { useState, useEffect } from "react"; import "./LoginModal.scss"; // Adjust path based on your actual structure import { clearAuthMessage } from "@/app/redux/auth/authSlice"; // Define the props interface for LoginModal type LoginModalProps = { onLogin: (email: string, password: string) => Promise; authMessage: string; clearAuthMessage: () => void; }; // LoginModal component export default function LoginModal({ onLogin }: LoginModalProps) { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); console.log("LoginModal rendered"); // Debugging log to check if the component renders // Effect to clear authentication messages when email or password inputs change useEffect(() => { clearAuthMessage(); }, [email, password]); // Dependency array ensures effect runs when these change // Handler for form submission const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // Prevent default form submission behavior setIsLoading(true); // Set loading state to true await onLogin(email, password); // Call the passed onLogin function (now uncommented) setIsLoading(false); // Set loading state back to false after login attempt }; return ( // The content of the login modal, without the modal overlay/wrapper
{/* Email input field */}
setEmail(e.target.value)} required disabled={isLoading} />
{/* Password input field */}
setPassword(e.target.value)} required disabled={isLoading} />
); }