Skip to content

Commit

Permalink
닉네임 변경 3자 이상으로 바꾸기 (#603)
Browse files Browse the repository at this point in the history
* chore: vscode update

* feature: 닉네임 제한 변경
  • Loading branch information
hyesungoh authored Feb 3, 2024
1 parent 626b820 commit 043e31c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"prettier.prettierPath": ".yarn/sdks/prettier/index.js",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"typescript.enablePromptUseWorkspaceTsdk": true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@
"typescript": "4.9.5"
},
"packageManager": "[email protected]"
}
}
11 changes: 9 additions & 2 deletions src/pages/my/account/change-nickname.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function MyAccountChangeNickame() {
const { userInformation } = useUserInformation();
const nickname = useInput({ useDebounce: true, initialValue: userInformation.nickName });
const [nicknameError, setNicknameError] = useState('변경될 이름을 입력해주세요.');

const { callMuation, onFormReturn, isValidateNickname } = useChangeNickname({
nickname,
nicknameError,
Expand Down Expand Up @@ -70,6 +71,9 @@ interface UseChangeNicknameProps {
userInformation: UserInformationType;
}

const NICKNAME_MIN_LENGTH = 3;
const NICKNAME_MAX_LENGTH = 20;

function useChangeNickname({
nickname,
nicknameError,
Expand All @@ -86,15 +90,18 @@ function useChangeNickname({
}, [userInformation.nickName]);

const isNicknameNotValidateForLength =
nickname.debouncedValue.trim().length < 4 || 20 < nickname.debouncedValue.trim().length;
nickname.debouncedValue.trim().length < NICKNAME_MIN_LENGTH ||
NICKNAME_MAX_LENGTH < nickname.debouncedValue.trim().length;

const isNicknameSameWithPrev = userInformation.nickName === nickname.debouncedValue.trim();

const isValidateNickname = !isNicknameNotValidateForLength && !isNicknameSameWithPrev;

useDidUpdate(() => {
if (isNicknameNotValidateForLength) {
setNicknameError('닉네임은 4자 이상 20자 이하여야 합니다.');
setNicknameError(
`닉네임은 ${NICKNAME_MIN_LENGTH}자 이상 ${NICKNAME_MAX_LENGTH}자 이하여야 합니다.`
);
return;
}

Expand Down

0 comments on commit 043e31c

Please sign in to comment.