Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE-60 ✨ 로그인 페이지 유효성 검사 #20

Merged
merged 3 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 71 additions & 16 deletions src/pages/auth/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,29 @@ import Link from 'next/link';
import AuthLayout from '@/pageLayout/AuthLayout/AuthLayout';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { Form, FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form';
import { PostSigninRequest, PostSigninRequestType } from '@/schema/auth';

export default function SignIn() {
// 폼 정의
const form = useForm<PostSigninRequestType>({
resolver: zodResolver(PostSigninRequest),
mode: 'onBlur',
defaultValues: {
email: '',
password: '',
},
});

function onSubmit(values: PostSigninRequestType) {
// NOTE : 테스트를 위해서 콘솔 넣음
/* eslint-disable no-console */
console.log(values);
}

// TODO: 나중에 컴포넌트 분리하기
return (
<AuthLayout>
<header className='mb-[50px] md:mb-[60px]'>
Expand All @@ -13,18 +34,53 @@ export default function SignIn() {
</Link>
</header>

<form className='flex flex-col items-center w-full px-6'>
<Input type='text' placeholder='이메일' className='lg:max-w-[640px] md:max-w-[384px] lg:h-16 px-4 lg:mb-4 mb-[10px] lg:text-xl md:text-base placeholder-blue-400 rounded-xl bg-blue-200' />
<Input
type='password'
placeholder='비밀번호'
className='lg:max-w-[640px] md:max-w-[384px] lg:h-16 px-4 lg:mb-6 mb-[20px] lg:text-xl md:text-base placeholder-blue-400 rounded-xl bg-blue-200'
/>
<Button type='submit' className='w-full lg:max-w-[640px] md:max-w-[384px] lg:h-16 bg-black-500 text-white lg:text-xl md:text-base rounded-xl md:mb-[10px] mb-[11px]'>
로그인
</Button>
</form>

<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className='flex flex-col items-center lg:gap-6 gap-5 w-full px-6'>
<div className='flex flex-col items-center lg:gap-4 gap-[10px] w-full lg:max-w-[640px] md:max-w-[384px]'>
<FormField
control={form.control}
name='email'
render={({ field, fieldState }) => (
<FormItem className='w-full space-y-0'>
<FormControl>
<Input
type='text'
placeholder='이메일'
className={`lg:h-16 h-11 px-4 lg:text-xl md:text-base placeholder-blue-400 rounded-xl bg-blue-200 ${fieldState.invalid ? 'border-2 border-state-error' : ''}`}
{...field}
/>
</FormControl>
<FormMessage className='flex justify-end text-[13px] text-state-error' />
</FormItem>
)}
/>
<FormField
control={form.control}
name='password'
render={({ field, fieldState }) => (
<FormItem className='w-full space-y-0'>
<FormControl>
<Input
type='password'
placeholder='비밀번호'
className={`lg:h-16 h-11 px-4 lg:text-xl md:text-base placeholder-blue-400 rounded-xl bg-blue-200 ${fieldState.invalid ? 'border-2 border-state-error' : ''}`}
{...field}
/>
</FormControl>
<FormMessage className='flex justify-end font-pretendard text-[13px] text-state-error' />
</FormItem>
)}
/>
</div>
<Button
type='submit'
disabled={!form.formState.isValid}
className={`w-full lg:max-w-[640px] md:max-w-[384px] lg:h-16 h-11 bg-black-500 text-white lg:text-xl md:text-base rounded-xl md:mb-[10px] mb-[11px] ${!form.formState.isValid ? 'bg-blue-300' : 'bg-black-500'}`}
>
로그인
</Button>
</form>
</Form>
<div className=' flex justify-end items-center gap-2 w-full lg:max-w-[640px] md:max-w-[384px] md:px-0 px-6 md:mb-[60px] mb-[50px]'>
<h2 className=' text-blue-400 lg:text-xl md:text-base sm:text-sm'>회원이 아니신가요?</h2>
<Link href='/'>
Expand All @@ -33,16 +89,15 @@ export default function SignIn() {
</Button>
</Link>
</div>

<div className='flex gap-4'>
<Button type='button' className='md:size-[60px] p-0'>
<Image src='/logo-naver.svg' alt='naver' width={60} height={60} className='md:size-[60px] size-10' />
<Image src='/logo-naver.svg' alt='logo-naver' width={60} height={60} className='md:size-[60px] size-10' />
</Button>
<Button type='button' className='md:size-[60px] p-0'>
<Image src='/logo-google.svg' alt='naver' width={60} height={60} className='md:size-[60px] size-10' />
<Image src='/logo-google.svg' alt='logo-google' width={60} height={60} className='md:size-[60px] size-10' />
</Button>
<Button type='button' className='md:size-[60px] p-0'>
<Image src='/logo-kakao.svg' alt='naver' width={60} height={60} className='md:size-[60px] size-10' />
<Image src='/logo-kakao.svg' alt='logo-kakao' width={60} height={60} className='md:size-[60px] size-10' />
</Button>
</div>
</AuthLayout>
Expand Down
8 changes: 8 additions & 0 deletions src/schema/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as z from 'zod';

export const PostSigninRequest = z.object({
email: z.string().min(1, { message: '이메일은 필수 입력입니다.' }).email({ message: '올바른 이메일 주소가 아닙니다.' }),
password: z.string().min(1, { message: '비밀번호는 필수 입력입니다.' }),
});

export type PostSigninRequestType = z.infer<typeof PostSigninRequest>;
Loading