-
Notifications
You must be signed in to change notification settings - Fork 5
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] Input 검증 에러 메시지 타입 구조 변경 #376
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1d9c607
refactor: errorMessage 타입을 string | undefined에서 string | null로 변경
jinhokim98 a7afaa1
refactor: 에러가 아닐 때 errorMessage를 null로 리턴
jinhokim98 18e1a65
fix: 에러 import 되지 않던 현상 해결
jinhokim98 fea31e0
refactor: 에러 메시지 validate 함수 리턴하는 대로 그대로 set
jinhokim98 01e0a15
feat: 에러메시지 보여지도록 추가
jinhokim98 e9b5876
refactor: 에러메시지 타입 string | null로 변경
jinhokim98 7fe787c
Merge branch 'fe-dev' into feature/#371
jinhokim98 f7be3cb
Merge branch 'fe-dev' of https://github.com/woowacourse-teams/2024-ha…
jinhokim98 8333ac5
Merge branch 'feature/#371' of https://github.com/woowacourse-teams/2…
jinhokim98 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 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
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
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
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
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
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,48 @@ | ||
import {useState} from 'react'; | ||
|
||
import validateEventPassword from '@utils/validate/validateEventPassword'; | ||
|
||
import {useFetch} from '@apis/useFetch'; | ||
|
||
import RULE from '@constants/rule'; | ||
|
||
import useEvent from './useEvent'; | ||
|
||
const useSetPassword = (eventName: string) => { | ||
const {fetch} = useFetch(); | ||
const [password, setPassword] = useState(''); | ||
const [errorMessage, setErrorMessage] = useState<string | null>(null); | ||
const [canSubmit, setCanSubmit] = useState(false); | ||
const {createNewEvent} = useEvent(); | ||
|
||
const submitPassword = async (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
const {eventId} = await fetch({queryFunction: () => createNewEvent({eventName, password: parseInt(password)})}); | ||
return eventId; | ||
}; | ||
|
||
const handlePasswordChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const newValue = event.target.value; | ||
const {isValid, errorMessage} = validateEventPassword(newValue); | ||
|
||
setCanSubmit(newValue.length === RULE.maxEventPasswordLength); | ||
setErrorMessage(errorMessage); | ||
|
||
if (isValid) { | ||
setPassword(newValue); | ||
} else { | ||
event.target.value = password; | ||
} | ||
}; | ||
|
||
return { | ||
password, | ||
errorMessage, | ||
canSubmit, | ||
submitPassword, | ||
handlePasswordChange, | ||
}; | ||
}; | ||
|
||
export default useSetPassword; |
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,5 +1,5 @@ | ||
export interface ValidateResult { | ||
isValid: boolean; | ||
errorMessage?: string; | ||
errorMessage: string | null; | ||
errorInfo?: Record<string, boolean>; | ||
} |
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
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
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.
undefined보다 확실히 nul이 더 좋은 것 같아요!