import { useState, type FormEvent } from 'react'; import { useNavigate } from 'react-router-dom'; import { Container, Paper, Title, Text, TextInput, PasswordInput, Button, Stack, Alert, Center, Box } from '@mantine/core'; import { notifications } from '@mantine/notifications'; import { IconAlertCircle, IconBrandWhatsapp } from '@tabler/icons-react'; import { useAuthStore } from '../stores/authStore'; export default function LoginPage() { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const { login, isLoading, error, clearError } = useAuthStore(); const navigate = useNavigate(); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); clearError(); try { await login(username, password); notifications.show({ title: 'Login successful', message: 'Welcome back!', color: 'green', }); navigate('/dashboard'); } catch (err: any) { const responseData = err?.response?.data; const notificationMessage = responseData?.message || (typeof responseData === 'string' ? responseData.trim() : '') || 'Invalid username or password'; notifications.show({ title: 'Login failed', message: notificationMessage, color: 'red', }); } }; return (
WhatsHooked Sign in to your account
{error && ( } title="Authentication Error" color="red" variant="light" > {error} )}
setUsername(e.target.value)} required disabled={isLoading} size="md" /> setPassword(e.target.value)} required disabled={isLoading} size="md" />
Default credentials: admin / admin123
); }