-
Notifications
You must be signed in to change notification settings - Fork 20
Basic 박재현 Sprint 4 #37
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
Basic 박재현 Sprint 4 #37
The head ref may contain hidden characters: "Basic-\uBC15\uC7AC\uD604"
Conversation
…the Login and Signup pages
|
스프리트 미션 하시느라 수고 많으셨어요. |
|
크으 ~ 여전히 커밋 단위와 커밋 메시지 매우 명확하네요 👍 |
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.
크으 global.css가 정말 유용하겠군요 !
훌륭합니다 ! 이제 서비스 전반적으로 사용되는 스타일은 global.css에 적용하면 되겠군요 ! 👍
| function checkEmail() { | ||
| const emailInput = document.getElementsByClassName("sign-email")[0]; | ||
| const emailError = document.getElementsByClassName("sign-email-error")[0]; | ||
|
|
||
| emailInput.classList.remove("error"); | ||
|
|
||
| if (!emailInput.value) { | ||
| emailInput.style.border = "1px solid red"; | ||
| emailError.textContent = "이메일을 입력해주세요."; | ||
| } else if (!emailInput.checkValidity()) { | ||
| emailInput.style.border = "1px solid red"; | ||
| emailError.textContent = "잘못된 이메일 형식입니다."; | ||
| } else { | ||
| emailInput.style.border = ""; | ||
| emailError.textContent = ""; | ||
| } | ||
| toggleLoginBtn(); | ||
| toggleSignupBtn(); | ||
| } |
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.
굿굿 ! 하나의 이메일 유효성 검사와 관련된 함수를 작성하셨군요 👍
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.
(심화/생각해보기/제안/선택) 단일 책임 원칙 적용하기
단일 책임 원칙?: 하나의 클래스(함수)는 하나의 기능 담당하여 하나의 책임을 수행하는데 집중되어야 있어야 한다는 의미이다.
현재 checkEmail 함수는:
- document를 통해
element를 받아오고 있습니다 - 엘리먼트를 변경하고 있습니다.
- 유효성 검사를 하고 있습니다.
하나의 함수에 여러 목적을 달성하고 있어요 !
다음과 같이 책임을 분리할 수 있습니다:
| function checkEmail() { | |
| const emailInput = document.getElementsByClassName("sign-email")[0]; | |
| const emailError = document.getElementsByClassName("sign-email-error")[0]; | |
| emailInput.classList.remove("error"); | |
| if (!emailInput.value) { | |
| emailInput.style.border = "1px solid red"; | |
| emailError.textContent = "이메일을 입력해주세요."; | |
| } else if (!emailInput.checkValidity()) { | |
| emailInput.style.border = "1px solid red"; | |
| emailError.textContent = "잘못된 이메일 형식입니다."; | |
| } else { | |
| emailInput.style.border = ""; | |
| emailError.textContent = ""; | |
| } | |
| toggleLoginBtn(); | |
| toggleSignupBtn(); | |
| } | |
| function validateEmail(emailInput) { | |
| if (!emailInput.value) { | |
| return { isValid: false, error: "이메일을 입력해주세요." }; | |
| } | |
| if (!emailInput.checkValidity()) { | |
| return { isValid: false, error: "잘못된 이메일 형식입니다." }; | |
| } | |
| return { isValid: true, error: "" }; | |
| } | |
| function applyEmailFeedback(emailInput, emailError, validationResult) { | |
| if (validationResult.isValid) { | |
| emailInput.style.border = ""; | |
| emailError.textContent = ""; | |
| emailInput.classList.remove("error"); | |
| } else { | |
| emailInput.style.border = "1px solid red"; | |
| emailError.textContent = validationResult.error; | |
| emailInput.classList.add("error"); | |
| } | |
| } | |
| function toggleButtons() { | |
| toggleLoginBtn(); | |
| toggleSignupBtn(); | |
| } | |
| function checkEmail() { | |
| const emailInput = document.getElementsByClassName("sign-email")[0]; | |
| const emailError = document.getElementsByClassName("sign-email-error")[0]; | |
| const validationResult = validateEmail(emailInput); | |
| applyEmailFeedback(emailInput, emailError, validationResult); | |
| toggleButtons(); | |
| } |
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.
(더 더 더 나아가서/심화/선택) 추가로 email 리소스에만 국한하지 않고 여러 필드도 적용해볼 수 있어요.
다음과 같이 스키마를 작성하여 관심사를 분리할 수 있습니다:
const schema = {
email: {
target: document.getElementsByClassName("sign-email")[0],
validators: [
{ check: (v) => v.trim() !== "", error: "이메일을 입력해주세요." },
{ check: (v) => /\S+@\S+\.\S+/.test(v), error: "잘못된 이메일 형식입니다." },
],
},
password: {
target: document.getElementsByClassName("sign-password")[0],
validators: [
{ check: (v) => v.trim() !== "", error: "비밀번호를 입력해주세요." },
{ check: (v) => v.length >= 8, error: "비밀번호는 최소 8자 이상이어야 합니다." },
],
},
};스키마를 활용하여 각 리소스에 따라 유효성 검사를 하면 확장에 용이한 패턴이 됩니다 😊
| if ( | ||
| emailInput.checkValidity() && | ||
| nicknameInput.value.length >= 3 && | ||
| pwInput.value.length >= 8 && | ||
| pwcheckInput.value === pwInput.value | ||
| ) { | ||
| submitBtn.disabled = false; | ||
| } else { | ||
| submitBtn.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 ( | |
| emailInput.checkValidity() && | |
| nicknameInput.value.length >= 3 && | |
| pwInput.value.length >= 8 && | |
| pwcheckInput.value === pwInput.value | |
| ) { | |
| submitBtn.disabled = false; | |
| } else { | |
| submitBtn.disabled = true; | |
| } | |
| const isValid = emailInput.checkValidity() && | |
| nicknameInput.value.length >= 3 && | |
| pwInput.value.length >= 8 && | |
| pwcheckInput.value === pwInput.value | |
| submitBtn.disabled = !isValid; |
이렇게 하면 조건문이 어떤 의미를 가지는지 알 수 있기에 가독성이 좋아질 수 있습니다 😊
|
수고하셨습니다 재현님 ! 미션 수행하시느라 수고 많으셨어요 재현님 ! |
요구사항
기본
로그인
회원가입
심화
주요 변경사항
스크린샷
멘토에게