-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
250 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { useSignInForm } from './use-sign-in-form' | ||
export { useSignUpForm } from './use-sign-up-form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use client' | ||
|
||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { SubmitHandler, useForm } from 'react-hook-form' | ||
import { z } from 'zod' | ||
|
||
import { signInFormSchema } from '@/features/auth/schema' | ||
|
||
type SignInFormSchema = z.infer<typeof signInFormSchema> | ||
|
||
export function useSignInForm() { | ||
const onSubmit: SubmitHandler<SignInFormSchema> = data => { | ||
console.info('로그인을 시도합니다', data) | ||
} | ||
|
||
const { | ||
handleSubmit, | ||
formState: { errors, isSubmitting }, | ||
register, | ||
} = useForm<SignInFormSchema>({ | ||
resolver: zodResolver(signInFormSchema), | ||
mode: 'onSubmit', | ||
defaultValues: { | ||
email: '', | ||
password: '', | ||
}, | ||
}) | ||
|
||
return { handleSubmit: handleSubmit(onSubmit), errors, register, isSubmitting } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use client' | ||
|
||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { SubmitHandler, useForm } from 'react-hook-form' | ||
import { z } from 'zod' | ||
|
||
import { signUpFormSchema } from '@/features/auth/schema' | ||
|
||
type SignUpFormSchema = z.infer<typeof signUpFormSchema> | ||
|
||
export function useSignUpForm() { | ||
const onSubmit: SubmitHandler<SignUpFormSchema> = data => { | ||
console.info('회원가입을 시도합니다.', data) | ||
} | ||
|
||
const { | ||
handleSubmit, | ||
formState: { errors }, | ||
register, | ||
} = useForm<z.infer<typeof signUpFormSchema>>({ | ||
resolver: zodResolver(signUpFormSchema), | ||
defaultValues: { | ||
email: '', | ||
password: '', | ||
confirmPassword: '', | ||
nickname: '', | ||
}, | ||
}) | ||
|
||
return { handleSubmit: handleSubmit(onSubmit), errors, register } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { signInFormSchema } from './sign-in-form-schema' | ||
export { signUpFormSchema } from './sign-up-form-schema' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from 'zod' | ||
|
||
import { email, password } from './user-schema' | ||
|
||
export const signInFormSchema = z.object({ | ||
email, | ||
password, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { z } from 'zod' | ||
|
||
import { email, nickname, password } from './user-schema' | ||
|
||
export const signUpFormSchema = z | ||
.object({ | ||
nickname, | ||
email, | ||
password, | ||
confirmPassword: password, | ||
}) | ||
.refine(data => data.password === data.confirmPassword, { | ||
message: '비밀번호가 일치하지 않습니다.', | ||
path: ['confirmPassword'], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { z } from 'zod' | ||
|
||
export const email = z.string().email({ message: '이메일 형식에 맞춰 작성해주세요' }) | ||
|
||
export const nickname = z | ||
.string() | ||
.min(2, { message: '최소 2글자 이상의 닉네임을 작성해주세요' }) | ||
.max(6, { message: '최소 6글자 미만의 닉네임을 작성해주세요' }) | ||
|
||
export const password = z | ||
.string() | ||
.min(6, { message: '최소 6글자 이상의 비밀번호를 작성해주세요' }) | ||
.max(20, { message: '최대 20글자 이하의 비밀번호를 작성해주세요' }) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,33 @@ | ||
'use client' | ||
|
||
import { KeyRound, Mail } from 'lucide-react' | ||
import { ChangeEventHandler, useState } from 'react' | ||
|
||
import { TextFiled } from '@/shared/ui/TextFiled' | ||
import { useSignInForm } from '@/features/auth/hook' | ||
import { TextFiled } from '@/shared/ui' | ||
|
||
import styles from './SignForm.module.scss' | ||
import { SubmitButton } from './SubmitButton' | ||
|
||
export function SignInForm() { | ||
const [id, setId] = useState(() => '') | ||
const [pw, setPw] = useState(() => '') | ||
const { handleSubmit, register, errors, isSubmitting } = useSignInForm() | ||
|
||
const onIdChange: ChangeEventHandler<HTMLInputElement> = e => { | ||
setId(e.target.value) | ||
} | ||
|
||
const onPasswordChange: ChangeEventHandler<HTMLInputElement> = e => { | ||
setPw(e.target.value) | ||
} | ||
return ( | ||
<form className={styles.form}> | ||
<TextFiled name={'email'} placeholder="Email" value={id} onChange={onIdChange} icon={<Mail color="#475069" />} /> | ||
<form onSubmit={handleSubmit} className={styles.form}> | ||
<TextFiled | ||
type="email" | ||
placeholder="Email" | ||
error={errors['email']} | ||
icon={<Mail color="#475069" />} | ||
{...register('email')} | ||
/> | ||
<TextFiled | ||
name={'pw'} | ||
placeholder="password" | ||
value={pw} | ||
onChange={onPasswordChange} | ||
type="password" | ||
placeholder="Password" | ||
{...register('password')} | ||
error={errors['password']} | ||
icon={<KeyRound color="#475069" />} | ||
/> | ||
<SubmitButton>Login</SubmitButton> | ||
<SubmitButton disabled={isSubmitting}>Login</SubmitButton> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { searchKeywordSchema } from './search-keyword-schema' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { z } from 'zod' | ||
|
||
export const searchKeywordSchema = z.string().min(2, '검색의 최소 길이 (2글자)를 넘지 않습니다.') |
Oops, something went wrong.