-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] FormInput 수정 & 로그인, 회원가입 폼 컴포넌트 제작 #85
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70810bf
chore: install tanstack form, zod
yoorli b433b99
fix: FormInput 비밀번호 토글 접근성 및 안정성 개선
yoorli 01cfc42
feat: SearchBar 제어/비제어 패턴 지원 및 코드 정리
yoorli b9a23d8
feat: 로그인/회원가입 폼 컴포넌트 및 검증 스키마 추가
yoorli 7017107
Merge remote-tracking branch 'origin/main' into yoolri-feat/input
yoorli 7e5c73a
fix: package.json에 빠진 zod 재설치
yoorli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 { LoginForm } from './login-form'; |
This file contains hidden or 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,111 @@ | ||||||||||||
| 'use client'; | ||||||||||||
|
|
||||||||||||
| import { useForm } from '@tanstack/react-form'; | ||||||||||||
|
|
||||||||||||
| import { FormInput } from '@/components/shared'; | ||||||||||||
| import { Button } from '@/components/ui'; | ||||||||||||
| import { loginSchema } from '@/lib/schema/auth'; | ||||||||||||
|
|
||||||||||||
| const getHintMessage = (errors: unknown[], isTouched: boolean, submissionAttempts: number) => { | ||||||||||||
| const firstError = errors[0] as { message?: string } | undefined; | ||||||||||||
| const showError = isTouched || submissionAttempts > 0; | ||||||||||||
|
|
||||||||||||
| return showError ? firstError?.message : undefined; | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| export const LoginForm = () => { | ||||||||||||
| const form = useForm({ | ||||||||||||
| defaultValues: { | ||||||||||||
| email: '', | ||||||||||||
| password: '', | ||||||||||||
| }, | ||||||||||||
| validators: { | ||||||||||||
| onSubmit: loginSchema, | ||||||||||||
| onChange: loginSchema, | ||||||||||||
| }, | ||||||||||||
| onSubmit: async ({ value }) => { | ||||||||||||
| // API 호출 | ||||||||||||
| alert('login:' + value.email); | ||||||||||||
| }, | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| return ( | ||||||||||||
| <form | ||||||||||||
| className='flex-col-center w-full gap-8' | ||||||||||||
| onSubmit={(e) => { | ||||||||||||
| e.preventDefault(); | ||||||||||||
| void form.handleSubmit(); | ||||||||||||
| }} | ||||||||||||
| > | ||||||||||||
| <div className='flex-col-center w-full gap-4'> | ||||||||||||
| <form.Field name='email'> | ||||||||||||
| {(field) => { | ||||||||||||
| const { | ||||||||||||
| meta: { errors, isTouched }, | ||||||||||||
| } = field.state; | ||||||||||||
| const hintMessage = getHintMessage(errors, isTouched, form.state.submissionAttempts); | ||||||||||||
|
Comment on lines
+43
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getHintMessage가 에러메시지를 처리하는 유틸함수니까, 더 간단하게 이렇게 처리할 수 있을 것 같아요
Suggested change
그러면 아래처럼 isTouched랑 errors를 전부 field에서 뽑을 수 있어서 JSX 리턴문을 좀 더 간소화 시킬 수 있게 돼요! const getHintMessage = (field: AnyFieldAPI) => {
const errors = field.state.meta.errors
...
}; |
||||||||||||
|
|
||||||||||||
| return ( | ||||||||||||
| <FormInput | ||||||||||||
| hintMessage={hintMessage} | ||||||||||||
| inputProps={{ | ||||||||||||
| type: 'email', | ||||||||||||
| autoComplete: 'email', | ||||||||||||
| placeholder: '이메일을 입력해주세요', | ||||||||||||
| value: field.state.value, | ||||||||||||
| onChange: (e) => field.handleChange(e.target.value), | ||||||||||||
| }} | ||||||||||||
| labelName='이메일' | ||||||||||||
| /> | ||||||||||||
| ); | ||||||||||||
| }} | ||||||||||||
| </form.Field> | ||||||||||||
|
|
||||||||||||
| <form.Field name='password'> | ||||||||||||
| {(field) => { | ||||||||||||
| const { | ||||||||||||
| meta: { errors, isTouched }, | ||||||||||||
| } = field.state; | ||||||||||||
| const hintMessage = getHintMessage(errors, isTouched, form.state.submissionAttempts); | ||||||||||||
|
|
||||||||||||
| return ( | ||||||||||||
| <FormInput | ||||||||||||
| hintMessage={hintMessage} | ||||||||||||
| inputProps={{ | ||||||||||||
| type: 'password', | ||||||||||||
| placeholder: '비밀번호를 입력해주세요', | ||||||||||||
| value: field.state.value, | ||||||||||||
| onChange: (e) => field.handleChange(e.target.value), | ||||||||||||
| }} | ||||||||||||
| labelName='비밀번호' | ||||||||||||
| /> | ||||||||||||
| ); | ||||||||||||
| }} | ||||||||||||
| </form.Field> | ||||||||||||
| </div> | ||||||||||||
|
|
||||||||||||
| <form.Subscribe | ||||||||||||
| selector={(state) => ({ | ||||||||||||
| canSubmit: state.canSubmit, | ||||||||||||
| isSubmitting: state.isSubmitting, | ||||||||||||
| })} | ||||||||||||
| > | ||||||||||||
| {({ canSubmit, isSubmitting }) => { | ||||||||||||
| const disabled = !canSubmit || isSubmitting; | ||||||||||||
|
|
||||||||||||
| return ( | ||||||||||||
| <Button | ||||||||||||
| className='border-none' | ||||||||||||
| disabled={disabled} | ||||||||||||
| size='md' | ||||||||||||
| type='submit' | ||||||||||||
| variant='primary' | ||||||||||||
| > | ||||||||||||
| 로그인하기 | ||||||||||||
| </Button> | ||||||||||||
| ); | ||||||||||||
| }} | ||||||||||||
| </form.Subscribe> | ||||||||||||
| </form> | ||||||||||||
| ); | ||||||||||||
| }; | ||||||||||||
This file contains hidden or 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 { SignupForm } from './signup-form'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 void라는게 있는지 몰랐네요 좋은 것 같습니다