diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-20 14:33:21 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-20 14:33:21 +0700 |
| commit | 833488811b4164d7fbdce9bd70e171f06d62bf8d (patch) | |
| tree | c781a3ced1f27b8f1c81ed5401fd758d79c1de1c /src/lib/auth/components/Login.jsx | |
| parent | 87e7292941a251f09b5af39d9020896a3bfb0f97 (diff) | |
login and register
Diffstat (limited to 'src/lib/auth/components/Login.jsx')
| -rw-r--r-- | src/lib/auth/components/Login.jsx | 124 |
1 files changed, 6 insertions, 118 deletions
diff --git a/src/lib/auth/components/Login.jsx b/src/lib/auth/components/Login.jsx index 6fbc1475..171ff4c8 100644 --- a/src/lib/auth/components/Login.jsx +++ b/src/lib/auth/components/Login.jsx @@ -1,124 +1,12 @@ -import Image from 'next/image' -import IndoteknikLogo from '@/images/logo.png' -import Link from '@/core/components/elements/Link/Link' -import { useState } from 'react' -import loginApi from '../api/loginApi' -import { useRouter } from 'next/router' -import Alert from '@/core/components/elements/Alert/Alert' -import { setAuth } from '@/core/utils/auth' +import LoginDesktop from "./LoginDesktop" +import LoginMobile from "./LoginMobile" const Login = () => { - const router = useRouter() - const [email, setEmail] = useState('') - const [password, setPassword] = useState('') - const [isLoading, setIsLoading] = useState(false) - const [alert, setAlert] = useState(null) - - const handleSubmit = async (e) => { - e.preventDefault() - setAlert(null) - setIsLoading(true) - const login = await loginApi({ email, password }) - setIsLoading(false) - - if (login.isAuth) { - setAuth(login.user) - router.push('/') - return - } - switch (login.reason) { - case 'NOT_FOUND': - setAlert({ - children: 'Email atau password tidak cocok', - type: 'info' - }) - break - case 'NOT_ACTIVE': - setAlert({ - children: ( - <> - Email belum diaktivasi, - <Link - className='text-gray-900' - href={`/activate?email=${email}`} - > - aktivasi sekarang - </Link> - </> - ), - type: 'info' - }) - break - } - } - return ( - <div className='p-6 pt-10 flex flex-col items-center min-h-screen'> - <Link href='/'> - <Image - src={IndoteknikLogo} - alt='Logo Indoteknik' - width={150} - height={50} - /> - </Link> - <h1 className='text-2xl mt-4 font-semibold'>Mulai Belanja Sekarang</h1> - <h2 className='text-gray_r-11 font-normal mt-1 mb-4'>Masuk ke akun kamu untuk belanja</h2> - - {alert && ( - <Alert - className='text-center' - type={alert.type} - > - {alert.children} - </Alert> - )} - - <form - className='w-full mt-6 flex flex-col gap-y-4' - onSubmit={handleSubmit} - > - <div> - <label htmlFor='email'>Alamat Email</label> - <input - type='email' - id='email' - className='form-input w-full mt-3' - value={email} - onChange={(e) => setEmail(e.target.value)} - placeholder='contoh@email.com' - /> - </div> - <div> - <label htmlFor='password'>Kata Sandi</label> - <input - type='password' - id='password' - className='form-input w-full mt-3' - value={password} - onChange={(e) => setPassword(e.target.value)} - placeholder='••••••••••••' - /> - </div> - <button - type='submit' - className='btn-yellow w-full mt-2' - disabled={!email || !password || isLoading} - > - {!isLoading ? 'Masuk' : 'Loading...'} - </button> - </form> - - <div className='text-gray_r-11 mt-4'> - Belum punya akun Indoteknik?{' '} - <Link - href='/register' - className='inline' - > - Daftar - </Link> - </div> - </div> + <> + <LoginMobile /> + <LoginDesktop /> + </> ) } |
