-
Notifications
You must be signed in to change notification settings - Fork 39
[김영현] Sprint4 #91
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-\uAE40\uC601\uD604-sprint4"
[김영현] Sprint4 #91
Changes from all commits
7bdaf43
bf151e2
c4c4758
7068044
f61e76f
f38233c
04cd035
69896ca
aad8299
e371fa5
3af9d05
4bf098e
e6508d5
8b61b84
8d71afc
a0c7796
9854b69
028512e
2a2a0eb
c49f3c2
6bd545e
963dc4f
31aec70
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,68 @@ | ||
| import { emailInput, passwordInput, emailPattern, emailError, passwordError, loginBtn, isEmailValid, isPasswordValid } from "./validation-common.js"; | ||
|
|
||
| // 이메일 유효성 검사 함수 | ||
| const emailCheck = () => { | ||
| // 이메일 값 공백 제거 후 가져오기. | ||
| const emailValue = emailInput.value.trim(); | ||
| isEmailValid.value = false; | ||
|
|
||
| if (emailValue === "") { | ||
| emailError.textContent = "이메일을 입력해주세요."; | ||
| emailError.style.display = "block"; | ||
| emailInput.classList.add("input-error"); | ||
| } else if (!emailPattern.test(emailValue)) { | ||
| emailError.textContent = "잘못된 이메일 형식입니다."; | ||
| emailError.style.display = "block"; | ||
| emailInput.classList.add("input-error"); | ||
| } else { | ||
| emailError.style.display = "none"; | ||
| emailInput.classList.remove("input-error"); | ||
| isEmailValid.value = true; | ||
| } | ||
|
|
||
| loginBtnToggle(); | ||
| }; | ||
|
|
||
| // 패스워드 유효성 검사 함수 | ||
| const passwordCheck = () => { | ||
| const passwordValue = passwordInput.value.trim(); | ||
| isPasswordValid.value = false; | ||
|
|
||
| if (passwordValue === "") { | ||
| passwordError.textContent = "비밀번호를 입력해주세요."; | ||
| passwordError.style.display = "block"; | ||
| passwordInput.classList.add("input-error"); | ||
| } else if (passwordValue.length < 8) { | ||
| passwordError.textContent = "비밀번호를 8자 이상 입력해주세요."; | ||
| passwordError.style.display = "block"; | ||
| passwordInput.classList.add("input-error"); | ||
| } else { | ||
| passwordError.style.display = "none"; | ||
| passwordInput.classList.remove("input-error"); | ||
| isPasswordValid.value = true; | ||
| } | ||
|
|
||
| loginBtnToggle(); | ||
| }; | ||
|
|
||
| // 이메일, 패스워드 유효성 검사에 따른 로그인 버튼 활성화 함수 | ||
| const loginBtnToggle = () => { | ||
| if (isEmailValid.value && isPasswordValid.value) { | ||
| loginBtn.style.backgroundColor = "#3578e5"; | ||
| loginBtn.style.cursor = "pointer"; | ||
| loginBtn.disabled = false; | ||
| } else { | ||
| loginBtn.style.backgroundColor = "#9ca3af"; | ||
| loginBtn.style.color = "#f3f4f6"; | ||
| loginBtn.style.cursor = "not-allowed"; | ||
| loginBtn.disabled = true; | ||
| } | ||
|
Comment on lines
+49
to
+59
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. 💊 제안 이는 다른 로직들도 동일합니다~ 같은 로직의 경우 하나를 재사용하는 것이 유지보수 측면에서도 좋으니 account.css를 만드셨던 것처럼 두 파일의 중복을 줄이는 법도 고민해보세요~
Collaborator
Author
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. 네 피드백 감사합니다. 저도 구현하면서 두 파일의 동일한 함수가 사용 되고 있어 이를 한번만 정의 해서 import하는 방식을 고민했는데 알려주셔서 감사합니다!!! 🔥🔥 |
||
| }; | ||
|
|
||
| // focusout 이벤트 | ||
| emailInput.addEventListener("focusout", emailCheck); | ||
| passwordInput.addEventListener("focusout", passwordCheck); | ||
|
|
||
| // 초기 로그인 버튼 비활성화 | ||
| loginBtn.disabled = true; | ||
| loginBtn.style.cursor = "not-allowed"; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { | ||
| emailInput, | ||
| nameInput, | ||
| passwordInput, | ||
| passwordCheckInput, | ||
| emailPattern, | ||
| emailError, | ||
| passwordError, | ||
| passwordCheckError, | ||
| signupBtn, | ||
| isEmailValid, | ||
| isPasswordValid, | ||
| isPasswordCheckValid, | ||
| } from "./validation-common.js"; | ||
|
|
||
| // 이메일 유효성 검사 함수 | ||
| const emailCheck = () => { | ||
| // 이메일 값 공백 제거 후 가져오기. | ||
| const emailValue = emailInput.value.trim(); | ||
| isEmailValid.value = false; | ||
|
|
||
| if (emailValue === "") { | ||
| emailError.textContent = "이메일을 입력해주세요."; | ||
| emailError.style.display = "block"; | ||
| emailInput.classList.add("input-error"); | ||
| } else if (!emailPattern.test(emailValue)) { | ||
| emailError.textContent = "잘못된 이메일 형식입니다."; | ||
| emailError.style.display = "block"; | ||
| emailInput.classList.add("input-error"); | ||
| } else { | ||
| emailError.style.display = "none"; | ||
| emailInput.classList.remove("input-error"); | ||
| isEmailValid.value = true; | ||
| } | ||
|
|
||
| signupBtnToggle(); | ||
| }; | ||
|
|
||
| // 패스워드 유효성 검사 함수 | ||
| const passwordCheck = () => { | ||
| const passwordValue = passwordInput.value.trim(); | ||
| isPasswordValid.value = false; | ||
|
|
||
| if (passwordValue === "") { | ||
| passwordError.textContent = "비밀번호를 입력해주세요."; | ||
| passwordError.style.display = "block"; | ||
| passwordInput.classList.add("input-error"); | ||
| } else if (passwordValue.length < 8) { | ||
| passwordError.textContent = "비밀번호를 8자 이상 입력해주세요."; | ||
| passwordError.style.display = "block"; | ||
| passwordInput.classList.add("input-error"); | ||
| } else { | ||
| passwordError.style.display = "none"; | ||
| passwordInput.classList.remove("input-error"); | ||
| isPasswordValid.value = true; | ||
| } | ||
|
|
||
| passwordDblCheck(); // 비밀번호 확인 후, 비밀번호 수정 시 이를 감지 하지 못해서 추가. (즉시 검사하는 함수) | ||
| signupBtnToggle(); | ||
| }; | ||
|
|
||
| const passwordDblCheck = () => { | ||
| const passwordCheckValue = passwordCheckInput.value.trim(); | ||
| const passwordValue = passwordInput.value.trim(); | ||
| isPasswordCheckValid.value = false; | ||
|
|
||
| if (passwordCheckValue !== passwordValue) { | ||
| passwordCheckError.textContent = "비밀번호가 일치하지 않습니다."; | ||
| passwordCheckInput.classList.add("input-error"); | ||
| passwordCheckError.style.display = "block"; | ||
| } else { | ||
| passwordCheckError.style.display = "none"; | ||
| passwordCheckInput.classList.remove("input-error"); | ||
| isPasswordCheckValid.value = true; | ||
| } | ||
|
|
||
| signupBtnToggle(); | ||
| }; | ||
|
|
||
| const signupBtnToggle = () => { | ||
| if (isEmailValid.value && isPasswordValid.value && isPasswordCheckValid.value) { | ||
| signupBtn.style.backgroundColor = "#3578e5"; | ||
| signupBtn.style.cursor = "pointer"; | ||
| signupBtn.disabled = false; | ||
| } else { | ||
| signupBtn.style.backgroundColor = "#9ca3af"; | ||
| signupBtn.style.color = "#f3f4f6"; | ||
| signupBtn.style.cursor = "not-allowed"; | ||
| signupBtn.disabled = true; | ||
| } | ||
| }; | ||
|
|
||
| // focusout 이벤트 | ||
| emailInput.addEventListener("focusout", emailCheck); | ||
| passwordInput.addEventListener("focusout", passwordCheck); | ||
| passwordCheckInput.addEventListener("focusout", passwordDblCheck); | ||
|
|
||
| // 회원가입 버튼 요소 초기 상태 설정 | ||
| signupBtn.style.cursor = "not-allowed"; | ||
| signupBtn.disabled = true; |
|
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. 👍 칭찬 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // 공통 입력 요소 ( 이메일, 비밀번호) | ||
| export const emailInput = document.querySelector("#form-email"); | ||
| export const passwordInput = document.querySelector("#form-password"); | ||
|
|
||
| // 회원가입 전용 입력 요소 (닉네임, 비밀번호 확인) | ||
| export const nameInput = document.querySelector("#form-name"); | ||
| export const passwordCheckInput = document.querySelector("#form-password-check"); | ||
|
|
||
| // 에러 메시지 요소 (이메일, 패스워드, 패스워드 확인) | ||
| export const emailError = document.querySelector("#email-error"); | ||
| export const passwordError = document.querySelector("#password-error"); | ||
| export const passwordCheckError = document.querySelector("#password-check-error"); | ||
|
|
||
| // 로그인 및 회원가입 버튼 | ||
| export const loginBtn = document.querySelector("#btn-login"); | ||
| export const signupBtn = document.querySelector("#btn-signup"); | ||
|
|
||
| // 유효성 검사 패턴 | ||
| export const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; | ||
|
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. 💊 제안 |
||
|
|
||
| // 유효성 검사 상태 변수 | ||
| // 원시타입으로 내보내면 에러가 났음.. 객체로 관리 | ||
| export let isEmailValid = { value: false }; | ||
| export let isPasswordValid = { value: false }; | ||
| export let isPasswordCheckValid = { value: false }; | ||
|
Comment on lines
+23
to
+25
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. ❗️ 수정요청 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| --white: #ffffff; | ||
| --background: #cfe5ff; | ||
| --skyblue: #e6f2ff; | ||
| --error-red: #f74747; | ||
|
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. 💊 제안 |
||
| } | ||
|
|
||
| html { | ||
|
|
||
This file was deleted.
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.
💊 제안
주석을 다는 것은 좋은 습관입니다. 다만 주석 또한 읽어야 하는 정보라 중복되지 않는 내용을 입력해주시는 것이 가독성면에서 더 좋아요.
지금 주석은 아래 trim 메소드를 통해 파악할 수 있는 내용이라 없어도 될 것 같습니다~