diff --git a/app/components/ui/input.tsx b/app/components/ui/input.tsx new file mode 100644 index 0000000..5945534 --- /dev/null +++ b/app/components/ui/input.tsx @@ -0,0 +1,78 @@ +import { useState, type ComponentProps, type ReactNode } from 'react' +import { + get, + useFormContext, + type FieldError, + type FieldValues, + type Path, + type RegisterOptions, +} from 'react-hook-form' + +import { EyeIcon } from '~/components/icons/eye' + +import { Button } from './button' + +type TInputProperties = Omit< + ComponentProps<'input'>, + 'size' +> & { + id: string + label?: ReactNode + name: Path + rules?: RegisterOptions +} + +export const Input = >( + properties: TInputProperties, +) => { + const { id, label, name, rules, type = 'text', ...rest } = properties + const [inputType, setInputType] = useState(type) + + const { + register, + formState: { errors }, + } = useFormContext() + + const error: FieldError = get(errors, name) + + return ( +
+ + + {type === 'password' && ( + + )} +
+ ) +} diff --git a/app/layouts/news/default.tsx b/app/layouts/news/default.tsx index d231cd5..ed5dd4d 100644 --- a/app/layouts/news/default.tsx +++ b/app/layouts/news/default.tsx @@ -50,6 +50,7 @@ export const NewsDefaultLayout = (properties: PropsWithChildren) => { setIsRegisterOpen={setIsRegisterOpen} setIsLoginOpen={setIsLoginOpen} setIsForgetOpen={setForgetOpen} + setIsSuccessModalOpen={setIsSuccessModalOpen} /> diff --git a/app/layouts/news/form-login.tsx b/app/layouts/news/form-login.tsx index 680201b..003b530 100644 --- a/app/layouts/news/form-login.tsx +++ b/app/layouts/news/form-login.tsx @@ -1,90 +1,93 @@ // import { EyeIcon, EyeOffIcon } from 'lucide-react' -import { useState, type Dispatch, type SetStateAction } from 'react' +import { zodResolver } from '@hookform/resolvers/zod' +import { type Dispatch, type SetStateAction } from 'react' +import { FormProvider, useForm } from 'react-hook-form' +import { z } from 'zod' -import { EyeIcon } from '~/components/icons/eye' import { Button } from '~/components/ui/button' +import { Input } from '~/components/ui/input' + +const loginSchema = z.object({ + email: z.string().email('Email tidak valid'), + password: z.string().min(6, 'Kata sandi minimal 6 karakter'), +}) + +export type TLoginSchema = z.infer type TProperties = { setIsRegisterOpen: Dispatch> setIsLoginOpen: Dispatch> setIsForgetOpen: Dispatch> + setIsSuccessModalOpen: Dispatch> } export const FormLogin = (properties: TProperties) => { - const { setIsRegisterOpen, setIsLoginOpen, setIsForgetOpen } = properties - const [showPassword, setShowPassword] = useState(false) + const { + setIsRegisterOpen, + setIsLoginOpen, + setIsForgetOpen, + setIsSuccessModalOpen, + } = properties + + const formMethods = useForm({ + resolver: zodResolver(loginSchema), + }) + + const { handleSubmit } = formMethods + + const onSubmit = handleSubmit((data) => { + console.log('data', data) // eslint-disable-line no-console + setIsSuccessModalOpen(true) + setIsLoginOpen(false) + }) return (
-
- {/* Input Email / No Telepon */} -
- - + + -
- {/* Input Password */} -
- - - -
- {/* Lupa Kata Sandi */} -
- Lupa Kata Sandi? + {/* Lupa Kata Sandi */} +
+ Lupa Kata Sandi? + +
+ + {/* Tombol Masuk */} -
- - {/* Tombol Masuk */} - -
+ + {/* Link Daftar */}