Compare commits

..

No commits in common. "4b8fc0721e3c518769b4ea37e0565b245f6f04f8" and "e546ebd3ddbefcadc25f5911de06e30c46cdbf98" have entirely different histories.

4 changed files with 56 additions and 76 deletions

View File

@ -1,13 +1,12 @@
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'
@ -26,21 +25,13 @@ 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 { const { id, label, name, rules, type = 'text', ...rest } = properties
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 },
} = useRemixFormContext() } = useFormContext()
const error: FieldError = get(errors, name) const error: FieldError = get(errors, name)
@ -55,8 +46,7 @@ export const Input = <TFormValues extends Record<string, unknown>>(
<input <input
id={id} id={id}
type={inputType} type={inputType}
className="h-[42px] w-full rounded-md border border-[#DFDFDF] p-2" className="w-full rounded-md border border-[#DFDFDF] p-2"
placeholder={inputType === 'password' ? '******' : placeholder}
{...register(name, rules)} {...register(name, rules)}
{...rest} {...rest}
/> />
@ -65,17 +55,22 @@ export const Input = <TFormValues extends Record<string, unknown>>(
type="button" type="button"
variant="icon" variant="icon"
size="fit" size="fit"
className="absolute right-3 h-[42px] text-gray-500" className="absolute top-9 right-3 text-gray-500"
onClick={() => onClick={() =>
setInputType(inputType === 'password' ? 'text' : 'password') setInputType(inputType === 'password' ? 'text' : 'password')
} }
> >
<EyeIcon {inputType === 'password' ? (
className={twMerge( <EyeIcon
'h-4 w-4', width={15}
inputType === 'password' ? 'text-gray-500/50' : 'text-gray-500', height={15}
)} />
/> ) : (
<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, useState } from 'react' import { useEffect } 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,8 +30,6 @@ 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',
@ -41,21 +39,11 @@ 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])
@ -84,10 +72,6 @@ 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>
@ -98,7 +82,6 @@ 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>
@ -106,7 +89,6 @@ 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,47 +11,49 @@ 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]"> <>
<Link <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]">
to="/news" <Link
className="mt-2 h-full py-2" to="/news"
> className="mt-2 h-full py-2"
<img >
src={APP.logo} <img
alt={APP.title} src={APP.logo}
className="h-3/4 w-auto sm:h-full" alt={APP.title}
/> className="h-3/4 w-auto sm:h-full"
</Link> />
<div className="hidden h-full items-center py-1.5 font-light whitespace-pre-line sm:flex"> </Link>
{APP.description} <div className="hidden h-full items-center py-1.5 font-light whitespace-pre-line sm:flex">
</div> {APP.description}
<div className="flex items-center gap-[15px]"> </div>
<Button className="h-8 w-auto rounded-none px-3 text-xs sm:h-[50px] sm:w-[150px] sm:text-lg"> <div className="flex items-center gap-[15px]">
About Us <Button className="h-8 w-auto rounded-none px-3 text-xs sm:h-[50px] sm:w-[150px] sm:text-lg">
</Button> About Us
{loaderData?.userToken ? ( </Button>
<fetcher.Form {loaderData?.userToken ? (
method="POST" <fetcher.Form
action="/actions/news/logout" method="POST"
> 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"
type="submit" onClick={() => setIsLoginOpen(true)}
> >
Logout Masuk
</Button> </Button>
</fetcher.Form> )}
) : ( </div>
<Button
variant="newsSecondary"
className="hidden sm:block"
onClick={() => setIsLoginOpen(true)}
>
Masuk
</Button>
)}
</div> </div>
</div> </>
) )
} }

View File

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