import React, { useState, useEffect } from 'react'; import { Box, Container, Paper, Typography, Grid, Alert, Tabs, Tab, Card, CardContent, Divider, Avatar, } from '@mui/material'; import { Person, PersonAdd, AccountCircle, } from '@mui/icons-material'; import 'react-phone-number-input/style.css'; import './LoginPage.css'; import { useAuth } from 'hooks/AuthContext'; import { BackstoryLogo } from 'components/ui/BackstoryLogo'; import { BackstoryPageProps } from 'components/BackstoryTab'; import { LoginForm } from "components/EmailVerificationComponents"; import { CandidateRegistrationForm } from "components/RegistrationForms"; import { useNavigate } from 'react-router-dom'; const LoginPage: React.FC = (props: BackstoryPageProps) => { const navigate = useNavigate(); const { setSnack } = props; const [tabValue, setTabValue] = useState(0); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(null); const { guest, user, login, isLoading, error } = useAuth(); const name = (user?.userType === 'candidate') ? user.username : user?.email || ''; const [errorMessage, setErrorMessage] = useState(null); const showGuest: boolean = false; useEffect(() => { if (!loading || !error) { return; } if (loading && error) { /* Remove 'HTTP .*: ' from error string */ const jsonStr = error.replace(/^[^{]*/, ''); const data = JSON.parse(jsonStr); setErrorMessage(data.error.message); setSnack(data.error.message, "error"); setTimeout(() => { setErrorMessage(null); setLoading(false); }, 3000); } }, [error, loading]); const handleTabChange = (event: React.SyntheticEvent, newValue: number) => { setTabValue(newValue); setSuccess(null); }; // If user is logged in, navigate to the profile page if (user) { navigate('/candidate/profile'); return (<>); } return ( {showGuest && guest && ( Guest Session Active Session ID: {guest.sessionId} Created: {guest.createdAt.toLocaleString()} )} } label="Login" /> } label="Register" /> {errorMessage && ( {errorMessage} )} {success && ( {success} )} {tabValue === 0 && ( )} {tabValue === 1 && ( )} ); }; export { LoginPage };