refactor(auth): integrate AuthContext into LoginModal

This commit is contained in:
aryabenade
2026-03-17 11:01:47 +05:30
parent a9c922a898
commit 61c8e1833f

View File

@@ -5,14 +5,15 @@ import { Button } from './ui/button';
import { Input } from './ui/input';
import { Label } from './ui/label';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
interface LoginModalProps {
isOpen: boolean;
onClose: () => void;
onLoginSuccess: (userData: { email: string; name: string }) => void;
// onLoginSuccess: (userData: { email: string; name: string }) => void;
}
export function LoginModal({ isOpen, onClose, onLoginSuccess }: LoginModalProps) {
export function LoginModal({ isOpen, onClose, }: LoginModalProps) {
const [step, setStep] = useState<'email' | 'otp'>('email');
const [email, setEmail] = useState('');
const [otp, setOtp] = useState(['', '', '', '', '', '']);
@@ -20,7 +21,7 @@ export function LoginModal({ isOpen, onClose, onLoginSuccess }: LoginModalProps)
const [isLoading, setIsLoading] = useState(false);
const [helperText, setHelperText] = useState('');
const navigate = useNavigate()
const { login } = useAuth(); // from AuthContext
// Reset modal state when closed
useEffect(() => {
@@ -96,12 +97,10 @@ export function LoginModal({ isOpen, onClose, onLoginSuccess }: LoginModalProps)
const emailParts = email.split('@')[0];
const name = emailParts.charAt(0).toUpperCase() + emailParts.slice(1);
onLoginSuccess({
email,
name: name.length > 8 ? name.substring(0, 8) : name
});
login({ email, name })
setIsLoading(false);
navigate("/melbourne")
// navigate("/melbourne")
onClose();
}, 1500);
};