Compare commits

..

3 Commits

4 changed files with 76 additions and 56 deletions

View File

@ -1,12 +1,13 @@
import { useState, type ComponentProps, type ReactNode } from 'react' import { useState, type ComponentProps, type ReactNode } from 'react'
import { import {
get, get,
useFormContext,
type FieldError, type FieldError,
type FieldValues, type FieldValues,
type Path, type Path,
type RegisterOptions, type RegisterOptions,
} from 'react-hook-form' } from 'react-hook-form'
import { useRemixFormContext } from 'remix-hook-form'
import { twMerge } from 'tailwind-merge'
import { EyeIcon } from '~/components/icons/eye' import { EyeIcon } from '~/components/icons/eye'
@ -25,13 +26,21 @@ type TInputProperties<T extends FieldValues> = Omit<
export const Input = <TFormValues extends Record<string, unknown>>( export const Input = <TFormValues extends Record<string, unknown>>(
properties: TInputProperties<TFormValues>, properties: TInputProperties<TFormValues>,
) => { ) => {
const { id, label, name, rules, type = 'text', ...rest } = properties const {
id,
label,
name,
rules,
type = 'text',
placeholder,
...rest
} = properties
const [inputType, setInputType] = useState(type) const [inputType, setInputType] = useState(type)
const { const {
register, register,
formState: { errors }, formState: { errors },
} = useFormContext() } = useRemixFormContext()
const error: FieldError = get(errors, name) const error: FieldError = get(errors, name)
@ -46,7 +55,8 @@ export const Input = <TFormValues extends Record<string, unknown>>(
<input <input
id={id} id={id}
type={inputType} type={inputType}
className="w-full rounded-md border border-[#DFDFDF] p-2" className="h-[42px] w-full rounded-md border border-[#DFDFDF] p-2"
placeholder={inputType === 'password' ? '******' : placeholder}
{...register(name, rules)} {...register(name, rules)}
{...rest} {...rest}
/> />
@ -55,22 +65,17 @@ export const Input = <TFormValues extends Record<string, unknown>>(
type="button" type="button"
variant="icon" variant="icon"
size="fit" size="fit"
className="absolute top-9 right-3 text-gray-500" className="absolute right-3 h-[42px] text-gray-500"
onClick={() => onClick={() =>
setInputType(inputType === 'password' ? 'text' : 'password') setInputType(inputType === 'password' ? 'text' : 'password')
} }
> >
{inputType === 'password' ? ( <EyeIcon
<EyeIcon className={twMerge(
width={15} 'h-4 w-4',
height={15} inputType === 'password' ? 'text-gray-500/50' : 'text-gray-500',
/> )}
) : ( />
<EyeIcon
width={15}
height={15}
/>
)}
</Button> </Button>
)} )}
</div> </div>

View File

@ -1,5 +1,5 @@
import { zodResolver } from '@hookform/resolvers/zod' import { zodResolver } from '@hookform/resolvers/zod'
import { useEffect } from 'react' import { useEffect, useState } from 'react'
import { useFetcher } from 'react-router' import { useFetcher } from 'react-router'
import { RemixFormProvider, useRemixForm } from 'remix-hook-form' import { RemixFormProvider, useRemixForm } from 'remix-hook-form'
import { z } from 'zod' import { z } from 'zod'
@ -30,6 +30,8 @@ export const FormLogin = (properties: TProperties) => {
setIsInitSubscribeOpen, setIsInitSubscribeOpen,
} = properties } = properties
const fetcher = useFetcher() const fetcher = useFetcher()
const [error, setError] = useState<string>()
const [disabled, setDisabled] = useState(false)
const formMethods = useRemixForm<TLoginSchema>({ const formMethods = useRemixForm<TLoginSchema>({
mode: 'onSubmit', mode: 'onSubmit',
@ -39,11 +41,21 @@ export const FormLogin = (properties: TProperties) => {
const { handleSubmit } = formMethods const { handleSubmit } = formMethods
useEffect(() => {
if (fetcher.state !== 'idle' || fetcher.data?.success) {
setDisabled(true)
return
}
setDisabled(false)
}, [fetcher])
useEffect(() => { useEffect(() => {
if (fetcher.data?.success) { if (fetcher.data?.success) {
setIsInitSubscribeOpen(true) setIsInitSubscribeOpen(true)
setIsLoginOpen(false) setIsLoginOpen(false)
return
} }
setError(fetcher.data?.message)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetcher]) }, [fetcher])
@ -72,6 +84,10 @@ export const FormLogin = (properties: TProperties) => {
type="password" type="password"
/> />
{error && (
<div className="text-sm text-red-500 capitalize">{error}</div>
)}
{/* Lupa Kata Sandi */} {/* Lupa Kata Sandi */}
<div className="flex items-center justify-between text-sm"> <div className="flex items-center justify-between text-sm">
<span className="text-gray-600">Lupa Kata Sandi?</span> <span className="text-gray-600">Lupa Kata Sandi?</span>
@ -82,6 +98,7 @@ export const FormLogin = (properties: TProperties) => {
}} }}
className="font-semibold text-[#2E2F7C]" className="font-semibold text-[#2E2F7C]"
variant="link" variant="link"
size="fit"
> >
Reset Kata Sandi Reset Kata Sandi
</Button> </Button>
@ -89,6 +106,7 @@ export const FormLogin = (properties: TProperties) => {
{/* Tombol Masuk */} {/* Tombol Masuk */}
<Button <Button
disabled={disabled}
type="submit" type="submit"
className="w-full rounded-md bg-[#2E2F7C] py-2 text-white transition hover:bg-blue-800" className="w-full rounded-md bg-[#2E2F7C] py-2 text-white transition hover:bg-blue-800"
> >

View File

@ -11,49 +11,47 @@ export const HeaderTop = () => {
const fetcher = useFetcher() const fetcher = useFetcher()
return ( return (
<> <div className="flex h-[60px] items-center justify-between bg-white px-5 align-middle sm:h-[100px] sm:gap-[15px] sm:px-[50px] sm:py-[20px]">
<div className="flex h-[60px] items-center justify-between bg-white px-5 align-middle sm:h-[100px] sm:gap-[15px] sm:px-[50px] sm:py-[20px]"> <Link
<Link to="/news"
to="/news" className="mt-2 h-full py-2"
className="mt-2 h-full py-2" >
> <img
<img src={APP.logo}
src={APP.logo} alt={APP.title}
alt={APP.title} className="h-3/4 w-auto sm:h-full"
className="h-3/4 w-auto sm:h-full" />
/> </Link>
</Link> <div className="hidden h-full items-center py-1.5 font-light whitespace-pre-line sm:flex">
<div className="hidden h-full items-center py-1.5 font-light whitespace-pre-line sm:flex"> {APP.description}
{APP.description} </div>
</div> <div className="flex items-center gap-[15px]">
<div className="flex items-center gap-[15px]"> <Button className="h-8 w-auto rounded-none px-3 text-xs sm:h-[50px] sm:w-[150px] sm:text-lg">
<Button className="h-8 w-auto rounded-none px-3 text-xs sm:h-[50px] sm:w-[150px] sm:text-lg"> About Us
About Us </Button>
</Button> {loaderData?.userToken ? (
{loaderData?.userToken ? ( <fetcher.Form
<fetcher.Form method="POST"
method="POST" action="/actions/news/logout"
action="/actions/news/logout" >
>
<Button
variant="newsSecondary"
className="hidden sm:block"
type="submit"
>
Logout
</Button>
</fetcher.Form>
) : (
<Button <Button
variant="newsSecondary" variant="newsSecondary"
className="hidden sm:block" className="hidden sm:block"
onClick={() => setIsLoginOpen(true)} type="submit"
> >
Masuk Logout
</Button> </Button>
)} </fetcher.Form>
</div> ) : (
<Button
variant="newsSecondary"
className="hidden sm:block"
onClick={() => setIsLoginOpen(true)}
>
Masuk
</Button>
)}
</div> </div>
</> </div>
) )
} }

View File

@ -37,7 +37,6 @@ export const action = async ({ request }: Route.ActionArgs) => {
return data( return data(
{ {
success: true, success: true,
accessToken: token,
}, },
{ {
headers, headers,