-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 참여한 사람 입력 시 자음이 분리되는 버그와 리펙터링 (#889)
* feat: 닉네임 길이 8자로 늘림 * feat: 반복되는 닉네임 상태와 유효성 검증을 수행하는 useMemberName 훅 구현 * feat: 이름 입력 관리를 훅 사용으로 대체하여 같은 로직 반복 제거 * feat: 상수를 사용하도록 수정 * chore: 임시로 props 매칭하여 넘기도록 함 * chore: 불필요해진 파일 제거 * chore: 철자 수정 * chore: 사용하지 않는 import 제거 * feat: 중복 이름이면 에러 메세지 띄우도록 함 * feat: 이름 중복 시 출력할 에러 메세지 선언 * feat: 중복 요소 확인 유틸 분리 * fix: props로 받는 타입 정의 * rename: nickname -> memberName으로 변경 * rename: isDuplicate -> isDuplicated로 변경
- Loading branch information
Showing
10 changed files
with
74 additions
and
60 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
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 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {useState} from 'react'; | ||
|
||
import validateMemberName from '@utils/validate/validateMemberName'; | ||
import {Nickname} from 'types/serviceType'; | ||
|
||
const useMemberName = (defaultMemberName?: string) => { | ||
const [name, setName] = useState<Nickname>(defaultMemberName ?? ''); | ||
const [errorMessage, setErrorMessage] = useState<string | null>(null); | ||
const [canSubmit, setCanSubmit] = useState(false); | ||
|
||
const handleNameChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const name = event.target.value; | ||
const {memberName: memberNameResult, isValid, errorMessage: errorMessageResult} = validateMemberName(name); | ||
setErrorMessage(errorMessageResult); | ||
|
||
if (isValid || name.length === 0) { | ||
setName(memberNameResult); | ||
setCanSubmit(isValid); | ||
} | ||
}; | ||
|
||
const clearMemberName = () => { | ||
setName(''); | ||
setErrorMessage(null); | ||
setCanSubmit(false); | ||
}; | ||
|
||
return {errorMessage, canSubmit, name, handleNameChange, clearMemberName}; | ||
}; | ||
|
||
export default useMemberName; |
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,5 @@ | ||
const isDuplicated = (arr: string[], target: string) => { | ||
return arr.includes(target); | ||
}; | ||
|
||
export default isDuplicated; |
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