2025-02-21 16:44:51 +07:00
|
|
|
// import { EyeIcon, EyeOffIcon } from 'lucide-react'
|
2025-02-23 22:08:47 +08:00
|
|
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
|
|
|
import { FormProvider, useForm } from 'react-hook-form'
|
|
|
|
|
import { z } from 'zod'
|
2025-02-21 16:44:51 +07:00
|
|
|
|
2025-02-23 19:43:45 +08:00
|
|
|
import { Button } from '~/components/ui/button'
|
2025-02-23 22:08:47 +08:00
|
|
|
import { Input } from '~/components/ui/input'
|
2025-02-25 05:18:40 +08:00
|
|
|
import type { NewsContextProperties } from '~/contexts/news'
|
2025-02-23 22:08:47 +08:00
|
|
|
|
|
|
|
|
const loginSchema = z.object({
|
|
|
|
|
email: z.string().email('Email tidak valid'),
|
|
|
|
|
password: z.string().min(6, 'Kata sandi minimal 6 karakter'),
|
|
|
|
|
})
|
|
|
|
|
|
2025-02-24 08:04:09 +08:00
|
|
|
type TLoginSchema = z.infer<typeof loginSchema>
|
2025-02-22 17:14:33 +08:00
|
|
|
|
|
|
|
|
type TProperties = {
|
2025-02-25 05:18:40 +08:00
|
|
|
setIsRegisterOpen: NewsContextProperties['setIsRegisterOpen']
|
|
|
|
|
setIsLoginOpen: NewsContextProperties['setIsLoginOpen']
|
|
|
|
|
setIsForgetOpen: NewsContextProperties['setForgetOpen']
|
|
|
|
|
setIsInitSubscribeOpen: NewsContextProperties['setIsInitSubscribeOpen']
|
2025-02-22 17:14:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const FormLogin = (properties: TProperties) => {
|
2025-02-23 22:08:47 +08:00
|
|
|
const {
|
|
|
|
|
setIsRegisterOpen,
|
|
|
|
|
setIsLoginOpen,
|
|
|
|
|
setIsForgetOpen,
|
2025-02-25 05:18:40 +08:00
|
|
|
setIsInitSubscribeOpen,
|
2025-02-23 22:08:47 +08:00
|
|
|
} = properties
|
|
|
|
|
|
|
|
|
|
const formMethods = useForm<TLoginSchema>({
|
|
|
|
|
resolver: zodResolver(loginSchema),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const { handleSubmit } = formMethods
|
|
|
|
|
|
|
|
|
|
const onSubmit = handleSubmit((data) => {
|
|
|
|
|
console.log('data', data) // eslint-disable-line no-console
|
2025-02-25 05:18:40 +08:00
|
|
|
setIsInitSubscribeOpen(true)
|
2025-02-23 22:08:47 +08:00
|
|
|
setIsLoginOpen(false)
|
|
|
|
|
})
|
2025-02-21 16:44:51 +07:00
|
|
|
|
|
|
|
|
return (
|
2025-02-22 15:17:46 +08:00
|
|
|
<div className="flex items-center justify-center">
|
2025-02-22 15:15:04 +07:00
|
|
|
<div className="w-full max-w-md">
|
2025-02-23 22:08:47 +08:00
|
|
|
<FormProvider {...formMethods}>
|
|
|
|
|
<form
|
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
|
className="space-y-4"
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
id="email"
|
|
|
|
|
label="Email / No Telepon"
|
2025-02-21 16:44:51 +07:00
|
|
|
placeholder="Contoh: legal@legalgo.id"
|
2025-02-23 22:08:47 +08:00
|
|
|
name="email"
|
2025-02-21 16:44:51 +07:00
|
|
|
/>
|
|
|
|
|
|
2025-02-23 22:08:47 +08:00
|
|
|
<Input
|
|
|
|
|
id="password"
|
|
|
|
|
label="Kata Sandi"
|
2025-02-21 16:44:51 +07:00
|
|
|
placeholder="Masukkan Kata Sandi"
|
2025-02-23 22:08:47 +08:00
|
|
|
name="password"
|
|
|
|
|
type="password"
|
2025-02-21 16:44:51 +07:00
|
|
|
/>
|
|
|
|
|
|
2025-02-23 22:08:47 +08:00
|
|
|
{/* Lupa Kata Sandi */}
|
|
|
|
|
<div className="flex items-center justify-between text-sm">
|
|
|
|
|
<span className="text-gray-600">Lupa Kata Sandi?</span>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setIsLoginOpen(false)
|
|
|
|
|
setIsForgetOpen(true)
|
|
|
|
|
}}
|
|
|
|
|
className="font-semibold text-[#2E2F7C]"
|
|
|
|
|
variant="link"
|
|
|
|
|
>
|
|
|
|
|
Reset Kata Sandi
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Tombol Masuk */}
|
2025-02-22 21:17:56 +07:00
|
|
|
<Button
|
2025-02-23 22:08:47 +08:00
|
|
|
type="submit"
|
|
|
|
|
className="w-full rounded-md bg-[#2E2F7C] py-2 text-white transition hover:bg-blue-800"
|
2025-02-21 16:44:51 +07:00
|
|
|
>
|
2025-02-23 22:08:47 +08:00
|
|
|
Masuk
|
2025-02-22 21:17:56 +07:00
|
|
|
</Button>
|
2025-02-23 22:08:47 +08:00
|
|
|
</form>
|
|
|
|
|
</FormProvider>
|
2025-02-21 16:44:51 +07:00
|
|
|
|
|
|
|
|
{/* Link Daftar */}
|
|
|
|
|
<div className="mt-4 text-center text-sm">
|
|
|
|
|
Belum punya akun?{' '}
|
2025-02-22 17:14:33 +08:00
|
|
|
<Button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setIsLoginOpen(false)
|
|
|
|
|
setIsRegisterOpen(true)
|
|
|
|
|
}}
|
2025-02-21 16:44:51 +07:00
|
|
|
className="font-semibold text-[#2E2F7C]"
|
2025-02-22 17:14:33 +08:00
|
|
|
variant="link"
|
|
|
|
|
size="fit"
|
2025-02-21 16:44:51 +07:00
|
|
|
>
|
|
|
|
|
Daftar Disini
|
2025-02-22 17:14:33 +08:00
|
|
|
</Button>
|
2025-02-21 16:44:51 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|