Skip to content

Commit

Permalink
refactor: 닉네임 min length, max length 상수화
Browse files Browse the repository at this point in the history
  • Loading branch information
ukkodeveloper committed Oct 19, 2023
1 parent 6588a85 commit d7384ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions frontend/src/features/member/constants/nickname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const MIN_LENGTH_NICKNAME = 2;
export const MAX_LENGTH_NICKNAME = 20;
5 changes: 3 additions & 2 deletions frontend/src/features/member/hooks/useNickname.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuthContext } from '@/features/auth/components/AuthProvider';
import { MAX_LENGTH_NICKNAME, MIN_LENGTH_NICKNAME } from '@/features/member/constants/nickname';
import { updateNickname } from '@/features/member/remotes/nickname';
import ROUTE_PATH from '@/shared/constants/path';
import { useMutation } from '@/shared/hooks/useMutation';
Expand All @@ -27,10 +28,10 @@ const useNickname = () => {
const handleChangeNickname: React.ChangeEventHandler<HTMLInputElement> = (event) => {
const currentNickname = event.currentTarget.value;

if (currentNickname.length > 20) {
if (currentNickname.length > MAX_LENGTH_NICKNAME) {
setNicknameErrorMessage('2글자 이상 20글자 이하 문자만 가능합니다.');
return;
} else if (currentNickname.length < 2) {
} else if (currentNickname.length < MIN_LENGTH_NICKNAME) {
setNicknameErrorMessage('2글자 이상 20글자 이하 문자만 가능합니다.');
} else if (currentNickname === user?.nickname) {
setNicknameErrorMessage('이전과 다른 닉네임으로 변경해주세요.');
Expand Down

0 comments on commit d7384ff

Please sign in to comment.