interstellar_ai/app/components/Login.tsx

156 lines
4.9 KiB
TypeScript
Raw Normal View History

2024-09-20 10:00:54 +02:00
import React, { useState } from 'react';
import Settings from './Settings'; // Import the Settings component
const Login: React.FC = () => {
// State to handle popup visibility
const [showLoginPopup, setShowLoginPopup] = useState(false);
const [showSignUpPopup, setShowSignUpPopup] = useState(false);
2024-09-20 10:00:54 +02:00
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [showSettingsPopup, setShowSettingsPopup] = useState(false);
// Credentials state
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [accountName, setAccountName] = useState('Pluto'); // Set the account name
const [newAccountEmail, setNewAccountEmail] = useState('');
const [newAccountPassword, setNewAccountPassword] = useState('');
2024-09-20 10:00:54 +02:00
// Fixed credentials
const fixedEmail = 'pluto@imareal.planet';
const fixedPassword = 'fuckTheSun1234';
const fixedAccount = 'Pluto';
2024-09-20 10:00:54 +02:00
// Function to toggle the login popup
const toggleLoginPopup = () => setShowLoginPopup(!showLoginPopup);
// Function to toggle the sign-up popup
const toggleSignUpPopup = () => {
setShowSignUpPopup(!showSignUpPopup);
setShowLoginPopup(false); // Hide login popup when opening the sign-up popup
2024-09-20 10:00:54 +02:00
};
// Function to handle login
const handleLogin = () => {
if ((email === fixedEmail || accountName === fixedAccount) && password === fixedPassword) {
2024-09-20 10:00:54 +02:00
setIsLoggedIn(true); // Successful login
setShowLoginPopup(false); // Close the login popup
2024-09-20 10:00:54 +02:00
} else {
alert('Incorrect credentials');
}
};
// Function to handle account creation
const handleCreateAccount = () => {
console.log('New Account Created:', newAccountEmail, newAccountPassword);
alert('Account created successfully! You can now log in.');
toggleSignUpPopup(); // Close sign-up popup
};
2024-09-20 10:00:54 +02:00
// Function to toggle the settings popup
const toggleSettingsPopup = () => setShowSettingsPopup(!showSettingsPopup);
return (
<div>
{/* Login or Settings Button */}
2024-09-25 11:40:17 +02:00
<button className='header-login-button' onClick={isLoggedIn ? toggleSettingsPopup : toggleLoginPopup}>
2024-09-25 11:22:59 +02:00
{isLoggedIn ? 'Settings' : 'Log In'}
</button>
2024-09-20 10:00:54 +02:00
{/* Conditional rendering of the Login Popup */}
{showLoginPopup && (
2024-09-20 10:00:54 +02:00
<div className="popup-overlay">
<div className="popup-content">
<h2>Log In</h2>
{/* Close Button */}
<button className="close-popup" onClick={toggleLoginPopup} aria-label="Close popup">
Close
</button>
2024-09-20 10:00:54 +02:00
{/* Name or Email Input */}
<div>
<input
type="text"
placeholder="Name or Email"
value={email}
2024-09-20 10:00:54 +02:00
onChange={(e) => setEmail(e.target.value)}
/>
</div>
{/* Password Input */}
2024-09-20 10:00:54 +02:00
<div>
<input
type="password"
placeholder="Password"
value={password}
2024-09-20 10:00:54 +02:00
onChange={(e) => setPassword(e.target.value)}
/>
</div>
{/* Log In Button */}
<div>
<button className="log-into-account" onClick={handleLogin}>Log In</button>
2024-09-20 10:00:54 +02:00
</div>
{/* Text for creating an account */}
<p>
Don't have an account yet? Create one {' '}
<span
style={{ color: 'blue', cursor: 'pointer' }}
onClick={toggleSignUpPopup}
>
here
</span>
</p>
2024-09-20 10:00:54 +02:00
</div>
</div>
)}
{/* Conditional rendering of the Sign-Up Popup */}
{showSignUpPopup && (
2024-09-20 10:00:54 +02:00
<div className="popup-overlay">
<div className="popup-content">
<h2>Create Account</h2>
2024-09-20 10:00:54 +02:00
{/* New Account Email Input */}
2024-09-20 10:00:54 +02:00
<div>
<input
type="text"
placeholder="Email"
value={newAccountEmail}
onChange={(e) => setNewAccountEmail(e.target.value)}
2024-09-20 10:00:54 +02:00
/>
</div>
{/* New Account Password Input */}
2024-09-20 10:00:54 +02:00
<div>
<input
type="password"
placeholder="Password"
value={newAccountPassword}
onChange={(e) => setNewAccountPassword(e.target.value)}
2024-09-20 10:00:54 +02:00
/>
</div>
{/* Create Account Button */}
2024-09-20 10:00:54 +02:00
<div>
<button className="create-account" onClick={handleCreateAccount}>Create Account</button>
2024-09-20 10:00:54 +02:00
</div>
{/* Close Button */}
<button className="close-popup" onClick={toggleSignUpPopup} aria-label="Close popup">
2024-09-20 10:00:54 +02:00
Close
</button>
</div>
2024-09-20 10:00:54 +02:00
</div>
)}
{/* Conditional rendering of the Settings Popup */}
{showSettingsPopup && <Settings closeSettings={toggleSettingsPopup} accountName={accountName} />}
</div>
);
};
export default Login;