'use client' import { ShieldExclamationIcon } from '@assets/icons' import images from '@assets/images' import Button from '@components/atoms/Button' import TextInput from '@components/atoms/TextInput' import Image from 'next/image' import { useState } from 'react' import { useAuth } from '@hooks/useAuth' import { useRouter } from 'next/navigation' import CaptchaInput from '@components/atoms/Captcha' import { encryptAES } from '@utils/helper/CryptoJS' interface IError { message?: string type?: 'login' | 'captcha' } const LoginForm = () => { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState({}) const { login, loginLoading } = useAuth() const router = useRouter() const handleSubmit = async () => { if (!username || !password) { setError({ message: 'Username dan password harus diisi!', type: 'login', }) return } const result = await login({ username, password: encryptAES(password) }) if (result.success) { // Redirect to dashboard router.replace('/') } else { setError({ message: result.message ?? 'Username atau Password Salah!', type: 'login', }) } } return (
{error.message && (
{error.message}
)}
e.preventDefault()} className="flex w-[380px] flex-col gap-8 rounded-lg bg-white p-6 shadow-md sm:w-[420px]" >
logo

Galeri Taksasi Used Car

Masuk

{ setUsername(e.target.value) if (error.type === 'login') setError({}) }} error={error && error.type === 'login' ? error.message : ''} /> { setPassword(e.target.value) if (error.type === 'login') setError({}) }} error={error && error.type === 'login' ? error.message : ''} /> {/* Temporarily hiding captcha as requested */}
) } export default LoginForm