-
Notifications
You must be signed in to change notification settings - Fork 20
[한동형] Sprint 4 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[한동형] Sprint 4 #43
The head ref may contain hidden characters: "Basic-\uD55C\uB3D9\uD615-sprint4"
Conversation
|
스프리트 미션 하시느라 수고 많으셨어요. |
| const ENTER_EMAIL = "이메일을 입력해주세요."; | ||
| const ENTER_PASSWORD = "비밀번호를 입력해주세요."; | ||
| const WRONG_EMAIL = "잘못된 이메일 형식입니다"; | ||
| const PASSWORD_NEED_EIGHT_WORDS = "비밀번호를 8자 이상 입력해주세요."; | ||
| const NO_ERROR_MESSAGE = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(제안) 에러 메시지를 정의하셨군요? 😊
현재 전역 상수로 정의하셨는데 객체로 만들어서 같은 관심사끼리 묶을 수도 있습니다 !
| const ENTER_EMAIL = "이메일을 입력해주세요."; | |
| const ENTER_PASSWORD = "비밀번호를 입력해주세요."; | |
| const WRONG_EMAIL = "잘못된 이메일 형식입니다"; | |
| const PASSWORD_NEED_EIGHT_WORDS = "비밀번호를 8자 이상 입력해주세요."; | |
| const NO_ERROR_MESSAGE = ""; | |
| const ERROR_MESSAGES = { | |
| email: { | |
| empty: "이메일을 입력해주세요.", | |
| invalid: "잘못된 이메일 형식입니다.", | |
| }, | |
| password: { | |
| empty: "비밀번호를 입력해주세요.", | |
| tooShort: "비밀번호를 8자 이상 입력해주세요.", | |
| }, | |
| noError: "", | |
| }; |
| const isEmailValid = | ||
| emailInput.value && emailError.innerHTML === NO_ERROR_MESSAGE; | ||
| const isPasswordValid = | ||
| passwordInput.value && passwordError.innerHTML === NO_ERROR_MESSAGE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굿굿 ! 복잡한 조건문은 변수로 정의하셨네요 !
이렇게 하신다면 조건문에 별칭을 붙일 수 있고 가독성은 향상될거예요 ! 좋은 패턴입니다 ! 👍👍👍
| } | ||
| }; | ||
|
|
||
| const emailValid = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수는 동사로 시작하는게 일반적입니다 !
| const emailValid = () => { | |
| const validateEmail = () => { |
일반적으로 변수는 명사, 함수는 동사로 지어요.
boolean의 경우 isValidEmail와 같이 is, are, has로 시작하기도 합니다. =)
함수의 경우 다음과 같은 단어들이 접두사가 될 수 있어요:
- get
- fetch
- push
- update
- create
- calculate
- set
- 등등 ...
| if (isEmailValid && isPasswordValid) { | ||
| loginBtn.classList.remove("disabled"); | ||
| loginBtn.disabled = false; | ||
| } else { | ||
| loginBtn.classList.add("disabled"); | ||
| loginBtn.disabled = true; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(팁) 다음과 같이 정의해둔 조건을 그대로 사용하실 수도 있습니다. 😊
| if (isEmailValid && isPasswordValid) { | |
| loginBtn.classList.remove("disabled"); | |
| loginBtn.disabled = false; | |
| } else { | |
| loginBtn.classList.add("disabled"); | |
| loginBtn.disabled = true; | |
| } | |
| loginBtn.disabled = !(isEmailValid && isPasswordValid); | |
| if (isEmailValid && isPasswordValid) { | |
| loginBtn.classList.remove("disabled"); | |
| } else { | |
| loginBtn.classList.add("disabled"); | |
| } |
| if (!emailInput.value) { | ||
| emailError.innerHTML = ENTER_EMAIL; | ||
| emailInputWrapper.style.border = "3px solid #F74747"; | ||
| } | ||
| if (emailInput.value && !emailInput.value.includes("@")) { | ||
| emailError.innerHTML = WRONG_EMAIL; | ||
| emailInputWrapper.style.border = "3px solid #F74747"; | ||
| } | ||
| if (emailInput.value && emailInput.value.includes("@")) { | ||
| emailError.innerHTML = NO_ERROR_MESSAGE; | ||
| emailInputWrapper.style.border = "none"; | ||
| } | ||
| toggleLoginButton(); | ||
| }; | ||
| const passwordValid = () => { | ||
| if (!passwordInput.value) { | ||
| passwordError.innerHTML = ENTER_PASSWORD; | ||
| passwordInputWrapper.style.border = "3px solid #F74747"; | ||
| } | ||
| if (passwordInput.value && passwordInput.value.length < 8) { | ||
| passwordError.innerHTML = PASSWORD_NEED_EIGHT_WORDS; | ||
| passwordInputWrapper.style.border = "3px solid #F74747"; | ||
| } | ||
| if (passwordInput.value && passwordInput.value.length >= 8) { | ||
| passwordError.innerHTML = NO_ERROR_MESSAGE; | ||
| passwordInputWrapper.style.border = "none"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(제안)class를 정의해두고 재사용할 수도 있겠네요 ! 😊
.input-error {
border: 3px solid #F74747;
}| if (!emailInput.value) { | |
| emailError.innerHTML = ENTER_EMAIL; | |
| emailInputWrapper.style.border = "3px solid #F74747"; | |
| } | |
| if (emailInput.value && !emailInput.value.includes("@")) { | |
| emailError.innerHTML = WRONG_EMAIL; | |
| emailInputWrapper.style.border = "3px solid #F74747"; | |
| } | |
| if (emailInput.value && emailInput.value.includes("@")) { | |
| emailError.innerHTML = NO_ERROR_MESSAGE; | |
| emailInputWrapper.style.border = "none"; | |
| } | |
| toggleLoginButton(); | |
| }; | |
| const passwordValid = () => { | |
| if (!passwordInput.value) { | |
| passwordError.innerHTML = ENTER_PASSWORD; | |
| passwordInputWrapper.style.border = "3px solid #F74747"; | |
| } | |
| if (passwordInput.value && passwordInput.value.length < 8) { | |
| passwordError.innerHTML = PASSWORD_NEED_EIGHT_WORDS; | |
| passwordInputWrapper.style.border = "3px solid #F74747"; | |
| } | |
| if (passwordInput.value && passwordInput.value.length >= 8) { | |
| passwordError.innerHTML = NO_ERROR_MESSAGE; | |
| passwordInputWrapper.style.border = "none"; | |
| } | |
| if (!emailInput.value) { | |
| emailError.innerHTML = ENTER_EMAIL; | |
| emailInputWrapper.classList.add("input-error"); | |
| } | |
| if (emailInput.value && !emailInput.value.includes("@")) { | |
| emailError.innerHTML = WRONG_EMAIL; | |
| emailInputWrapper.classList.add("input-error"); | |
| } | |
| if (emailInput.value && emailInput.value.includes("@")) { | |
| emailError.innerHTML = NO_ERROR_MESSAGE; | |
| emailInputWrapper.classList.remove("input-error"); | |
| } | |
| toggleLoginButton(); | |
| }; | |
| const passwordValid = () => { | |
| if (!passwordInput.value) { | |
| passwordError.innerHTML = ENTER_PASSWORD; | |
| passwordInputWrapper.classList.add("input-error"); | |
| } | |
| if (passwordInput.value && passwordInput.value.length < 8) { | |
| passwordError.innerHTML = PASSWORD_NEED_EIGHT_WORDS; | |
| passwordInputWrapper.classList.add("input-error"); | |
| } | |
| if (passwordInput.value && passwordInput.value.length >= 8) { | |
| passwordError.innerHTML = NO_ERROR_MESSAGE; | |
| passwordInputWrapper.classList.remove("input-error"); | |
| } |
|
수고 하셨습니다 동형님 ! |
요구사항
기본
##로그인
##회원가입
심화
주요 변경사항
스크린샷
멘토에게