-
Notifications
You must be signed in to change notification settings - Fork 24
[심예진] sprint4 #75
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
The head ref may contain hidden characters: "Basic-\uC2EC\uC608\uC9C4-sprint4"
[심예진] sprint4 #75
Changes from all commits
983460c
ada2d15
37ffef9
84d78ba
f5534d4
03e0069
12cf5cf
879d476
3716104
73b1539
081c133
3ca7c4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| const emailInput = document.getElementById("login-email"); | ||
| const passwordInput = document.getElementById("login-password"); | ||
| const emailError = document.getElementById("emailError"); | ||
| const passwordError = document.getElementById("passwordError"); | ||
| const togglePassword = document.getElementById("togglePassword"); | ||
| const loginBtn = document.getElementById("loginBtn"); | ||
|
|
||
| function validateEmail(email) { | ||
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
| return emailRegex.test(email); | ||
| } | ||
|
|
||
| function checkValidity() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로직은 깔끔하게 잘 작성해주셨지만 해당 함수의 책임이 조금 많은 것 같습니다. 유효성 검사와 UI 상태 변경까지 이 함수에서 동시에 처리하고 있어서 함수 역할이 모호해진 것 같아요. 아래와 같은 방식로 '판단로직'과 '결과반영' 을 분리해주시면 가독성과 유지보수성이 좋아질 것 같습니다. |
||
| const emailValid = validateEmail(emailInput.value); | ||
| const passwordValid = passwordInput.value.length >= 8; | ||
| const errors = emailError.textContent || passwordError.textContent; | ||
|
|
||
| if (emailInput.value && passwordInput.value && emailValid && passwordValid && !errors) { | ||
| loginBtn.classList.remove("disabled"); | ||
| } else { | ||
| loginBtn.classList.add("disabled"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재는.disabled 클래스만 변경하고 있는데, 실제로 버튼 클릭을 막고 싶다면 button.disabled = true도 병행해주는 것이 좋습니다. |
||
| } | ||
| } | ||
|
|
||
| //이메일 확인 | ||
| emailInput.addEventListener("blur", () => { | ||
| const value = emailInput.value.trim(); | ||
| if (value === "") { | ||
| emailError.textContent = "이메일을 입력해주세요."; | ||
| emailInput.classList.add("input-error"); | ||
| } else if (!validateEmail(value)) { | ||
| emailError.textContent = "잘못된 이메일 형식입니다."; | ||
| emailInput.classList.add("input-error"); | ||
| } else { | ||
| emailError.textContent = ""; | ||
| emailInput.classList.remove("input-error"); | ||
| } | ||
| checkValidity(); | ||
| }); | ||
|
|
||
| //비밀번호 확인 | ||
| passwordInput.addEventListener("blur", () => { | ||
| const value = passwordInput.value.trim(); | ||
| if (value === "") { | ||
| passwordError.textContent = "비밀번호를 입력해주세요."; | ||
| passwordInput.classList.add("input-error"); | ||
| } else if (value.length < 8) { | ||
| passwordError.textContent = "비밀번호를 8자 이상 입력해주세요."; | ||
| passwordInput.classList.add("input-error"); | ||
| } else { | ||
| passwordError.textContent = ""; | ||
| passwordInput.classList.remove("input-error"); | ||
| } | ||
| checkValidity(); | ||
| }); | ||
|
|
||
| // //비밀번호 눈 가리기 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 비밀번호 토글 로직을 아주 잘 작성해주셨습니다! 코드만 봤을땐 문제없이 동작할거같은데, 잘 안되었나요??🤔 |
||
| // togglePassword.addEventListener("click", () => { | ||
| // const eyePassword = passwordInput.getAttribute.type === "password"; | ||
|
|
||
| // passwordInput.type = eyePassword ? "text" : "password"; | ||
|
|
||
| // togglePassword.src = eyePassword | ||
| // ? "../image/icon/eyeopen_icon.png" | ||
| // : "../image/icon/eyeclosed_icon.png"; | ||
| // }) | ||
|
|
||
| loginBtn.addEventListener("click", (e) => { | ||
| e.preventDefault(); //a 태그의 기본 이동 막음 | ||
| const emailLogin = validateEmail(emailInput.value.trim()); | ||
| const passwordLogin = passwordInput.value.trim().length >= 8; | ||
| const errorLogin = emailError.textContent || passwordError.textContent; | ||
|
|
||
| if (emailInput.value && passwordInput.value && emailLogin && passwordLogin && !errorLogin) { | ||
| window.location.href = "/items"; | ||
| } | ||
| }); | ||
|
|
||
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.
역할별로 함수 분리를 잘 해주셨습니다! 👍
다만 에러 출력과 스타일 조작 로직이 매번 반복되고 있는데요, 아래와 같이 공용 함수로 분리하면 좋을 것 같습니다.