-
Notifications
You must be signed in to change notification settings - Fork 35
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
[오정민] Sprint4 #141
Merged
Taero-Kim
merged 2 commits into
codeit-bootcamp-frontend:Basic-오정민
from
ojm51:Basic-오정민-sprint5
Jun 20, 2024
The head ref may contain hidden characters: "Basic-\uC624\uC815\uBBFC-sprint5"
Merged
[오정민] Sprint4 #141
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const showErrorMessage = (target, errorMessageDiv) => { | ||
target.classList.add("error"); | ||
errorMessageDiv.style.display = "block"; | ||
target.setAttribute("data-valid", "false"); | ||
}; | ||
|
||
const hideErrorMessage = (target, errorMessageDiv) => { | ||
target.classList.remove("error"); | ||
errorMessageDiv.style.display = "none"; | ||
target.setAttribute("data-valid", "true"); | ||
}; | ||
|
||
const activeButton = (button) => { | ||
button.disabled = false; | ||
button.classList.add("enabled"); | ||
}; | ||
const disableButton = (button) => { | ||
button.disabled = true; | ||
button.classList.remove("enabled"); | ||
}; | ||
|
||
export { showErrorMessage, hideErrorMessage, activeButton, disableButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,82 @@ | ||
const inputEmail = document.getElementById("input-email"); | ||
const errorMsgEmail = document.querySelector(".error-message.email"); | ||
let flagEmail = 0; | ||
inputEmail.addEventListener("focusout", ({ target }) => { | ||
const pattern = /^[A-Za-z0-9_\.\-]+@[A-Za-z0-9\-]+\.[A-za-z0-9\-]+/; | ||
const VALID_EMAIL_PATTERN = /^[A-Za-z0-9_\.\-]+@[A-Za-z0-9\-]+\.[A-za-z0-9\-]+/; | ||
|
||
const emailInput = document.getElementById("input-email"); | ||
const passwordInput = document.getElementById("input-password"); | ||
|
||
const emailErrorMessage = document.querySelector(".error-message.email"); | ||
const passwordErrorMessage = document.querySelector(".error-message.password"); | ||
|
||
const passwordVisibilityButton = document.querySelector(".password-show-btn"); | ||
const passwordVisibilityIcon = document.querySelector(".password-show-icon"); | ||
const loginButton = document.querySelector(".form-login-btn"); | ||
|
||
const handleFocusOutEmailInput = ({ target }) => { | ||
if (target.value === "") { | ||
target.classList.add("error"); | ||
errorMsgEmail.style.display = "block"; | ||
flagEmail = 0; | ||
} else if (!pattern.test(target.value)) { | ||
target.classList.add("error"); | ||
errorMsgEmail.style.display = "block"; | ||
errorMsgEmail.textContent = "잘못된 이메일 형식입니다."; | ||
flagEmail = 0; | ||
} else { | ||
target.classList.remove("error"); | ||
errorMsgEmail.style.display = "none"; | ||
flagEmail = 1; | ||
showErrorMessage(target, emailErrorMessage); | ||
emailErrorMessage.textContent = "이메일을 입력해주세요."; | ||
disableButton(loginButton); | ||
return; | ||
} | ||
if (!VALID_EMAIL_PATTERN.test(target.value)) { | ||
showErrorMessage(target, emailErrorMessage); | ||
emailErrorMessage.textContent = "잘못된 이메일 형식입니다."; | ||
disableButton(loginButton); | ||
return; | ||
} | ||
hideErrorMessage(target, emailErrorMessage); | ||
checkInputs(); | ||
}); | ||
}; | ||
emailInput.addEventListener("focusout", handleFocusOutEmailInput); | ||
|
||
const inputPassword = document.getElementById("input-password"); | ||
const errorMsgPassword = document.querySelector(".error-message.password"); | ||
let flagPassword = 0; | ||
inputPassword.addEventListener("focusout", ({ target }) => { | ||
const handleFocusOutPasswordInput = ({ target }) => { | ||
if (target.value === "") { | ||
target.classList.add("error"); | ||
errorMsgPassword.style.display = "block"; | ||
flagPassword = 0; | ||
} else if (target.value.length < 8) { | ||
target.classList.add("error"); | ||
errorMsgPassword.style.display = "block"; | ||
errorMsgPassword.textContent = "비밀번호를 8자 이상 입력해주세요."; | ||
flagPassword = 0; | ||
} else { | ||
target.classList.remove("error"); | ||
errorMsgPassword.style.display = "none"; | ||
flagPassword = 1; | ||
showErrorMessage(target, passwordErrorMessage); | ||
passwordErrorMessage.textContent = "비밀번호를 입력해주세요."; | ||
disableButton(loginButton); | ||
return; | ||
} | ||
if (target.value.length < 8) { | ||
showErrorMessage(target, passwordErrorMessage); | ||
passwordErrorMessage.textContent = "비밀번호를 8자 이상 입력해주세요."; | ||
disableButton(loginButton); | ||
return; | ||
} | ||
hideErrorMessage(target, passwordErrorMessage); | ||
checkInputs(); | ||
}); | ||
}; | ||
passwordInput.addEventListener("focusout", handleFocusOutPasswordInput); | ||
|
||
// 버튼 활성화를 위한 input 유효성 검사 | ||
const loginBtn = document.querySelector(".form-login-btn"); | ||
function checkInputs() { | ||
if (flagEmail && flagPassword) { | ||
loginBtn.disabled = false; | ||
loginBtn.classList.add("enabled"); | ||
loginBtn.addEventListener("click", () => { | ||
window.location.href = "../items/index.html"; | ||
}); | ||
} else { | ||
loginBtn.disabled = true; | ||
loginBtn.classList.remove("enabled"); | ||
const checkInputs = () => { | ||
const isValid = | ||
emailInput.getAttribute("data-valid") === "true" && | ||
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. p5; |
||
passwordInput.getAttribute("data-valid") === "true"; | ||
if (isValid) { | ||
activeButton(loginButton); | ||
return; | ||
} | ||
} | ||
disableButton(loginButton); | ||
}; | ||
|
||
// 비밀번호 문자열 보이거나 가리기 | ||
let flagVisibility = 0; // 0 = 비밀번호 가리기, 1 = 비밀번호 보이기 | ||
const pwVisibilityIcon = document.querySelector(".password-show-btn"); | ||
pwVisibilityIcon.addEventListener("click", () => { | ||
if (!flagVisibility) { | ||
inputPassword.type = "text"; | ||
document.querySelector(".password-show-icon").src = | ||
"../asset/icon/btn_visibility_on.png"; | ||
flagVisibility = 1; | ||
} else { | ||
inputPassword.type = "password"; | ||
document.querySelector(".password-show-icon").src = | ||
"../asset/icon/btn_visibility_off.png"; | ||
flagVisibility = 0; | ||
} | ||
}); | ||
const handleTogglePasswordVisibilityButton = ({ target }) => { | ||
const isPasswordVisible = | ||
passwordVisibilityIcon.getAttribute("data-valid") === "true"; | ||
const inputType = isPasswordVisible ? "password" : "text"; | ||
const iconType = isPasswordVisible ? "off" : "on"; | ||
|
||
passwordInput.type = inputType; | ||
passwordVisibilityIcon.src = `../asset/icon/btn_visibility_${iconType}.png`; | ||
target.setAttribute("data-valid", `${!isPasswordVisible}`); | ||
}; | ||
passwordVisibilityButton.addEventListener( | ||
"click", | ||
handleTogglePasswordVisibilityButton | ||
); | ||
|
||
import { | ||
showErrorMessage, | ||
hideErrorMessage, | ||
activeButton, | ||
disableButton, | ||
} from "../auth.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
p5;
active -> activate 동사로 바꿔도 좋을 것 같아요!