-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from Team-Lecue/refactor/Register
dev로 들어가라 !!!!!
- Loading branch information
Showing
7 changed files
with
122 additions
and
79 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 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,31 @@ | ||
export type isValidState = 'valid' | 'special' | 'duplicate' | 'space'; | ||
|
||
export interface NicknameInputProps { | ||
nickname: string; | ||
isValid: string; | ||
handleSetNickname: (nickname: string) => void; | ||
handleSetIsActive: (isActive: boolean) => void; | ||
handleSetIsValid: (isValid: isValidState) => void; | ||
} | ||
|
||
export interface SubmitButtonProps extends NicknameInputProps { | ||
token: string; | ||
isActive: boolean; | ||
} | ||
|
||
export interface CheckNicknameProps { | ||
handleSetNickname: (nickname: string) => void; | ||
handleSetWordCnt: (wordCnt: number) => void; | ||
handleSetIsValid: (isValid: isValidState) => void; | ||
e: React.ChangeEvent<HTMLInputElement>; | ||
} | ||
|
||
export interface patchNicknameProps { | ||
token: string; | ||
nickname: string; | ||
} | ||
|
||
export interface usePatchNicknameProps extends patchNicknameProps { | ||
handleSetIsActive: (isActive: boolean) => void; | ||
handleSetIsValid: (isValid: isValidState) => void; | ||
} |
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,7 @@ | ||
/** 영어, 숫자, 문자, 공백인지 체크하는 정규식 함수 */ | ||
const checkInputRange = (str: string) => { | ||
const regExp = /[ㄱ-ㅎㅏ-ㅣ가-힣0-9a-zA-Z\s]/g; | ||
return regExp.test(str) || str.length === 0; | ||
}; | ||
|
||
export default checkInputRange; |
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,26 @@ | ||
import { CheckNicknameProps } from '../types/registerTypes'; | ||
import checkInputRange from './checkInputRange'; | ||
|
||
/** 8자 이하 & 한글, 영어, 숫자만 입력 가능하도록 & 첫번째 글자는 공백 불가능 체크 함수*/ | ||
const handleChangeInput = (props: CheckNicknameProps) => { | ||
const { handleSetNickname, handleSetWordCnt, handleSetIsValid, e } = props; | ||
|
||
const input = e.target.value; | ||
|
||
if (e.target.value.length <= 8 && checkInputRange(input[input.length - 1])) { | ||
if (e.target.value === ' ') { | ||
handleSetNickname(''); | ||
handleSetWordCnt(0); | ||
} else { | ||
handleSetNickname(e.target.value); | ||
handleSetWordCnt(e.target.value.length); | ||
} | ||
handleSetIsValid('valid'); | ||
} else { | ||
e.target.value.length > 8 | ||
? handleSetIsValid('valid') | ||
: handleSetIsValid('special'); | ||
} | ||
}; | ||
|
||
export default handleChangeInput; |