Skip to content

Commit 96c35ca

Browse files
committed
feat: Improve validation for RegisterForm inputs
1 parent fe9e941 commit 96c35ca

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/containers/register/RegisterFormContainer.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { withRouter, RouteComponentProps } from 'react-router-dom';
1616
import qs from 'qs';
1717
import { useApolloClient } from '@apollo/react-hooks';
1818
import { GET_CURRENT_USER } from '../../lib/graphql/user';
19+
import { isEmpty, trim } from 'ramda';
1920

2021
interface RegisterFormContainerProps extends RouteComponentProps<{}> {}
2122

@@ -65,16 +66,28 @@ const RegisterFormContainer: React.FC<RegisterFormContainerProps> = ({
6566
const onSubmit = async (form: RegisterFormType) => {
6667
setError(null);
6768
// validate
69+
70+
const isCustomEmpty = (str: string) => {
71+
if (typeof str !== 'string') {
72+
return isEmpty(str);
73+
}
74+
return isEmpty(trim(str.replace(/\s/g, '')));
75+
};
76+
6877
const validation = {
6978
displayName: (text: string) => {
70-
if (text.trim() === '') {
71-
return '이름을 입력해주세요.';
79+
if (isCustomEmpty(text)) {
80+
return '프로필 이름을 입력해주세요.';
7281
}
7382
if (text.trim().length > 45) {
7483
return '이름은 최대 45자까지 입력 할 수 있습니다.';
7584
}
7685
},
7786
username: (text: string) => {
87+
if (isCustomEmpty(text)) {
88+
return '사용자 ID를 입력해주세요.';
89+
}
90+
7891
if (!/^[a-z0-9-_]{3,16}$/.test(text)) {
7992
return '사용자 ID는 3~16자의 알파벳 소문자,숫자,혹은 - _ 으로 이루어져야 합니다.';
8093
}

0 commit comments

Comments
 (0)