-
Notifications
You must be signed in to change notification settings - Fork 39
[이태식] sprint4 #164
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-\uC774\uD0DC\uC2DD-sprint4"
[이태식] sprint4 #164
Changes from all commits
b7a00e9
912c5d2
4eff2e6
798548c
1b0fc3d
4096a89
bcc5eaa
abca9e0
48e027d
36f03c4
91972a9
48a9717
df02d92
aaeb50d
973dc71
722efb8
80a490d
eadc1ba
8d84d0f
e955c5a
5e9e5d9
1f39a24
c7c098f
9592767
c97bd5f
7e1f93e
26a13b2
9c67c37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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,174 @@ | ||||||||||
| const loginForm = document.querySelector(".login-form"); | ||||||||||
| const signupForm = document.querySelector(".signup-form"); | ||||||||||
|
|
||||||||||
| const setInputError = (event) => { | ||||||||||
|
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. ❗️ 수정요청 const setInputError = (event) => {
if (event.target.closest("button")) return;
const { id, value, validationMessage, nextElementSibling } = event.target;
nextElementSibling?.remove();
if (id === "useremail") {
handleUserEmailError(event.target, validationMessage);
return;
}
if (id === "password") {
handlePasswordError(event.target, value);
return;
}
if (id === "passwordCheck") {
handlePasswordCheckError(event.target, value);
return;
}
handleDefaultError(event.target, value);
}; |
||||||||||
| if (event.target.closest("button")) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| if (event.target.value === "") { | ||||||||||
| event.target.nextElementSibling?.remove(); | ||||||||||
|
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. 💊 제안 |
||||||||||
| event.target.classList.add("input-error"); | ||||||||||
| setErrorMessage(event.target, "empty"); | ||||||||||
| } else if (event.target.id === "useremail") { | ||||||||||
| event.target.nextElementSibling?.remove(); | ||||||||||
| if (event.target.validationMessage) { | ||||||||||
| event.target.classList.add("input-error"); | ||||||||||
| setErrorMessage(event.target, "email"); | ||||||||||
| } else { | ||||||||||
| event.target.classList.remove("input-error"); | ||||||||||
| } | ||||||||||
| } else if ( | ||||||||||
| event.target.id === "password" || | ||||||||||
| event.target.id === "passwordCheck" | ||||||||||
| ) { | ||||||||||
| event.target.nextElementSibling?.remove(); | ||||||||||
| if (event.target.value.length < 8) { | ||||||||||
| event.target.classList.add("input-error"); | ||||||||||
| setErrorMessage(event.target, "password"); | ||||||||||
| } else { | ||||||||||
| event.target.classList.remove("input-error"); | ||||||||||
| checkPassword(); | ||||||||||
| } | ||||||||||
| } else { | ||||||||||
| event.target.classList.remove("input-error"); | ||||||||||
| event.target.nextElementSibling?.remove(); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const checkPassword = () => { | ||||||||||
| const password = document.querySelector("#password"); | ||||||||||
| const passwordCheck = document.querySelector("#passwordCheck"); | ||||||||||
| if ( | ||||||||||
| password.value !== passwordCheck?.value && | ||||||||||
| passwordCheck?.value.length >= 8 | ||||||||||
| ) { | ||||||||||
| passwordCheck.nextElementSibling?.remove(); | ||||||||||
| passwordCheck.classList.add("input-error"); | ||||||||||
| passwordCheck.classList.remove("input-valid"); | ||||||||||
| setErrorMessage(passwordCheck, "passwordCheck"); | ||||||||||
| } else if (password.value === passwordCheck?.value) { | ||||||||||
| passwordCheck.nextElementSibling?.remove(); | ||||||||||
| passwordCheck.classList.remove("input-error"); | ||||||||||
| passwordCheck.classList.add("input-valid"); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const setErrorMessage = (element, type) => { | ||||||||||
| const errorMessage = document.createElement("p"); | ||||||||||
| errorMessage.classList.add("error-message", "text-lg", "semibold"); | ||||||||||
| if (type === "empty") { | ||||||||||
| if (!element.nextElementSibling) { | ||||||||||
|
Comment on lines
+59
to
+60
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. 💊 제안
Suggested change
|
||||||||||
| switch (element.id) { | ||||||||||
| case "useremail": | ||||||||||
| errorMessage.textContent = "이메일을 입력해주세요."; | ||||||||||
| break; | ||||||||||
| case "password": | ||||||||||
| errorMessage.textContent = "비밀번호를 입력해주세요."; | ||||||||||
| break; | ||||||||||
| case "nickname": | ||||||||||
| errorMessage.textContent = "닉네임을 입력해주세요."; | ||||||||||
| break; | ||||||||||
| case "passwordCheck": | ||||||||||
| errorMessage.textContent = "비밀번호 확인을 입력해주세요."; | ||||||||||
| break; | ||||||||||
| } | ||||||||||
| element.after(errorMessage); | ||||||||||
| } | ||||||||||
| } else if (type === "email") { | ||||||||||
| errorMessage.textContent = "잘못된 이메일 형식입니다."; | ||||||||||
| element.after(errorMessage); | ||||||||||
| } else if (type === "password") { | ||||||||||
| errorMessage.textContent = "비밀번호를 8자 이상 입력해주세요."; | ||||||||||
| element.after(errorMessage); | ||||||||||
| } else if (type === "passwordCheck") { | ||||||||||
| errorMessage.textContent = "비밀번호가 일치하지 않습니다."; | ||||||||||
| element.after(errorMessage); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const setInputValid = (event) => { | ||||||||||
| if (event.target.closest("button")) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| if (!event.target.classList.contains("input-error")) { | ||||||||||
| event.target.classList.add("input-valid"); | ||||||||||
| } else { | ||||||||||
| event.target.classList.remove("input-valid"); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const isValidForm = (event) => { | ||||||||||
| for (let e of event.currentTarget) { | ||||||||||
|
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. 💊 제안
Suggested change
|
||||||||||
| if (e.tagName === "INPUT" && !e.classList.contains("input-valid")) { | ||||||||||
| return false; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| return true; | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const loginButton = document.querySelector(".login-button"); | ||||||||||
| const signupButton = document.querySelector(".signup-button"); | ||||||||||
|
|
||||||||||
| const toItems = (e) => { | ||||||||||
| e.preventDefault(); | ||||||||||
| location.href = "./items.html"; | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const toLogin = (e) => { | ||||||||||
| e.preventDefault(); | ||||||||||
| location.href = "./login.html"; | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const setLoginButton = (event) => { | ||||||||||
| if (isValidForm(event)) { | ||||||||||
| loginButton.disabled = false; | ||||||||||
| loginButton.classList.remove("button-disabled"); | ||||||||||
| loginButton.addEventListener("click", toItems); | ||||||||||
| } else { | ||||||||||
| loginButton.disabled = true; | ||||||||||
| loginButton.classList.add("button-disabled"); | ||||||||||
| loginButton.removeEventListener("click", toItems); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const setSignupButton = (event) => { | ||||||||||
| if (isValidForm(event)) { | ||||||||||
| signupButton.disabled = false; | ||||||||||
| signupButton.classList.remove("button-disabled"); | ||||||||||
| signupButton.addEventListener("click", toLogin); | ||||||||||
| } else { | ||||||||||
| signupButton.disabled = true; | ||||||||||
| signupButton.classList.add("button-disabled"); | ||||||||||
| signupButton.removeEventListener("click", toLogin); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const visibilityBtn = document.querySelectorAll(".visibility-btn"); | ||||||||||
| let isVisible = false; | ||||||||||
| const toggleVisibility = (event) => { | ||||||||||
| if (isVisible) { | ||||||||||
| event.target.alt = "눈감음"; | ||||||||||
| event.target.src = "images/ic_visibility_off.png"; | ||||||||||
| event.target.parentElement.nextElementSibling.nextElementSibling.type = | ||||||||||
| "password"; | ||||||||||
| } else { | ||||||||||
| event.target.alt = "눈 뜸"; | ||||||||||
| event.target.src = "images/ic_visibility_on.png"; | ||||||||||
| event.target.parentElement.nextElementSibling.nextElementSibling.type = | ||||||||||
| "text"; | ||||||||||
| } | ||||||||||
| isVisible = !isVisible; | ||||||||||
| }; | ||||||||||
| console.log(visibilityBtn); | ||||||||||
| for (let ele of visibilityBtn) { | ||||||||||
| console.log(ele); | ||||||||||
| ele.addEventListener("click", toggleVisibility); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| loginForm?.addEventListener("focusout", setInputError); | ||||||||||
| loginForm?.addEventListener("focusout", setInputValid); | ||||||||||
| loginForm?.addEventListener("focusout", setLoginButton); | ||||||||||
|
|
||||||||||
| signupForm?.addEventListener("focusout", setInputError); | ||||||||||
| signupForm?.addEventListener("focusout", setInputValid); | ||||||||||
| signupForm?.addEventListener("focusout", setSignupButton); | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| html { | ||
| font-family: Pretendard, sans-serif; | ||
| font-size: 16px; | ||
| } | ||
|
|
||
| :root { | ||
| --gray900: #111827; | ||
| --gray800: #1F2937; | ||
| --gray700: #374151; | ||
| --gray600: #4B5563; | ||
| --gray500: #6B7280; | ||
| --gray400: #9CA3AF; | ||
| --gray200: #E5E7EB; | ||
| --gray100: #F3F4F6; | ||
| --gray50: #F9FAFB; | ||
| --blue: #3692FF; | ||
| --error: #F74747; | ||
| } |
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.
💊 제안
한 파일에서 로그인, 회원가입 공용으로 JS를 작성해주셨네요~
둘이 공통되는 부분이 많이 이렇게 해주신 것 같아요.
다만 그렇게 되면 코드가 복잡해져서 유지보수성이 떨어지고 로그인 페이지의 경우 불필요한 코드까지 알아야합니다~
가능하면 공통 로직들은 분리해주시고 각 페이지별 JS를 따로 만드시는 것을 추천드려요!