-
Notifications
You must be signed in to change notification settings - Fork 42
[정해성] sprint4 #163
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
Open
Sea0Soda
wants to merge
2
commits into
codeit-bootcamp-frontend:Basic-정해성
Choose a base branch
from
Sea0Soda:Basic-정해성-sprint4
base: Basic-정해성
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "Basic-\uC815\uD574\uC131-sprint4"
Open
[정해성] sprint4 #163
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 hidden or 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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>items</title> | ||
</head> | ||
<body> | ||
<h1>item pages</h1> | ||
</body> | ||
</html> |
This file contains hidden or 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,40 @@ | ||
function isValidEmail(email) { | ||
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ | ||
return regex.test(email) | ||
} | ||
|
||
export const validationRules = { | ||
email: [ | ||
{ condition: (v) => !v, message: '이메일을 입력해주세요.' }, | ||
{ | ||
condition: (v) => !isValidEmail(v), | ||
message: '잘못된 이메일 형식입니다.', | ||
}, | ||
], | ||
password: [ | ||
{ condition: (v) => !v, message: '비밀번호를 입력해주세요.' }, | ||
{ | ||
condition: (v) => v.length < 8, | ||
message: '비밀번호를 8자 이상 입력해주세요.', | ||
}, | ||
], | ||
nickname: [{ condition: (v) => !v, message: '닉네임을 입력해주세요.' }], | ||
} | ||
|
||
export function validateInput( | ||
input, | ||
type, | ||
validateErrorMessage, | ||
showError, | ||
clearError | ||
) { | ||
const value = input.value.trim() | ||
const errorEl = validateErrorMessage(input) | ||
const failed = validationRules[type].find(({ condition }) => condition(value)) | ||
|
||
if (failed) { | ||
showError(input, errorEl, failed.message) | ||
} else { | ||
clearError(input, errorEl) | ||
} | ||
} |
This file contains hidden or 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,95 @@ | ||
import { validateInput } from './ValidationRules.js' | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
const emailInput = document.getElementById('email') | ||
const passwordInput = document.getElementById('password') | ||
const loginButton = document.querySelector('.login_button') | ||
|
||
// 이메일 부분 | ||
|
||
emailInput.addEventListener('blur', () => { | ||
validateInput( | ||
emailInput, | ||
'email', | ||
validateErrorMessage, | ||
showError, | ||
clearError | ||
) | ||
updateButtonState() | ||
}) | ||
|
||
// 비밀번호 부분 | ||
|
||
passwordInput.addEventListener('blur', () => { | ||
validateInput( | ||
passwordInput, | ||
'password', | ||
validateErrorMessage, | ||
showError, | ||
clearError | ||
) | ||
updateButtonState() | ||
}) | ||
|
||
function showError(input, errorElement, message) { | ||
const wrapper = input.closest('.login_password_wrap') || input | ||
wrapper.classList.add('error') | ||
errorElement.textContent = message | ||
errorElement.style.display = 'block' | ||
} | ||
|
||
function clearError(input, errorElement) { | ||
const wrapper = input.closest('.login_password_wrap') || input | ||
wrapper.classList.remove('error') | ||
errorElement.textContent = '' | ||
errorElement.style.display = 'none' | ||
} | ||
|
||
function validateErrorMessage(input) { | ||
let wrapper = input.closest('.login_password_wrap') || input | ||
let next = wrapper.nextElementSibling | ||
if (!next || !next.classList.contains('error-message')) { | ||
const error = document.createElement('p') | ||
error.className = 'error-message' | ||
error.style.color = 'red' | ||
error.style.fontSize = '14px' | ||
error.style.marginTop = '4px' | ||
wrapper.parentNode.insertBefore(error, wrapper.nextSibling) | ||
return error | ||
} | ||
return next | ||
} | ||
|
||
function updateButtonState() { | ||
const emailValue = emailInput.value.trim() | ||
const passwordValue = passwordInput.value.trim() | ||
|
||
const hasEmailError = validateErrorMessage(emailInput).textContent !== '' | ||
const hasPasswordError = | ||
validateErrorMessage(passwordInput).textContent !== '' | ||
|
||
const isValid = | ||
emailValue && passwordValue && !hasEmailError && !hasPasswordError | ||
|
||
loginButton.disabled = !isValid | ||
|
||
if (isValid) { | ||
loginButton.classList.add('active') | ||
} else { | ||
loginButton.classList.remove('active') | ||
} | ||
} | ||
|
||
emailInput.addEventListener('input', updateButtonState) | ||
passwordInput.addEventListener('input', updateButtonState) | ||
|
||
const loginForm = document.querySelector('.login_form_container') | ||
|
||
loginForm.addEventListener('submit', function (e) { | ||
e.preventDefault() // 폼 제출 방지 | ||
if (!loginButton.disabled) { | ||
window.location.href = '/items.html' | ||
} | ||
}) | ||
updateButtonState() | ||
}) |
This file contains hidden or 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,142 @@ | ||
import { validateInput } from './ValidationRules.js' | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
const emailInput = document.getElementById('email') | ||
const nicknameInput = document.getElementById('nickname') | ||
const passwordInput = document.getElementById('password') | ||
const passwordCheckInput = document.getElementById('passwordCheck') | ||
const signupButton = document.querySelector('.login_button') | ||
const signupForm = document.querySelector('.signup_form_frame') | ||
|
||
// 이메일 부분 | ||
emailInput.addEventListener('blur', () => { | ||
validateInput( | ||
emailInput, | ||
'email', | ||
validateErrorMessage, | ||
showError, | ||
clearError | ||
) | ||
updateButtonState() | ||
}) | ||
|
||
// 닉네임 부분 | ||
nicknameInput.addEventListener('blur', () => | ||
validateInput( | ||
nicknameInput, | ||
'nickname', | ||
validateErrorMessage, | ||
showError, | ||
clearError | ||
) | ||
) | ||
|
||
// 비밀번호 부분 | ||
passwordInput.addEventListener('blur', () => | ||
validateInput( | ||
passwordInput, | ||
'password', | ||
validateErrorMessage, | ||
showError, | ||
clearError | ||
) | ||
) | ||
|
||
// 비밀번호 확인 부분 | ||
passwordCheckInput.addEventListener('blur', () => { | ||
const pwValue = passwordInput.value.trim() | ||
const checkValue = passwordCheckInput.value.trim() | ||
const errorMsg = validateErrorMessage(passwordCheckInput) | ||
|
||
if (pwValue !== checkValue) { | ||
showError(passwordCheckInput, errorMsg, '비밀번호가 일치하지 않습니다.') | ||
} else { | ||
clearError(passwordCheckInput, errorMsg) | ||
} | ||
|
||
updateButtonState() | ||
}) | ||
|
||
emailInput.addEventListener('input', updateButtonState) | ||
nicknameInput.addEventListener('input', updateButtonState) | ||
passwordInput.addEventListener('input', updateButtonState) | ||
passwordCheckInput.addEventListener('input', updateButtonState) | ||
|
||
function updateButtonState() { | ||
const emailValue = emailInput.value.trim() | ||
const nicknameValue = nicknameInput.value.trim() | ||
const passwordValue = passwordInput.value.trim() | ||
const passwordCheckValue = passwordCheckInput.value.trim() | ||
|
||
const hasEmailError = validateErrorMessage(emailInput).textContent !== '' | ||
const hasNicknameError = | ||
validateErrorMessage(nicknameInput).textContent !== '' | ||
const hasPasswordError = | ||
validateErrorMessage(passwordInput).textContent !== '' | ||
const hasPasswordCheckError = | ||
validateErrorMessage(passwordCheckInput).textContent !== '' | ||
|
||
const isValid = | ||
emailValue && | ||
nicknameValue && | ||
passwordValue && | ||
passwordCheckValue && | ||
!hasEmailError && | ||
!hasNicknameError && | ||
!hasPasswordError && | ||
!hasPasswordCheckError | ||
|
||
signupButton.disabled = !isValid | ||
|
||
if (isValid) { | ||
signupButton.classList.add('active') | ||
} else { | ||
signupButton.classList.remove('active') | ||
} | ||
} | ||
|
||
// 회원가입시 로그인페이지로 | ||
signupForm.addEventListener('submit', function (e) { | ||
e.preventDefault() | ||
if (!signupButton.disabled) { | ||
window.location.href = '/login/index.html' | ||
} | ||
}) | ||
|
||
function isValidEmail(email) { | ||
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ | ||
return regex.test(email) | ||
} | ||
|
||
function showError(input, errorElement, message) { | ||
const wrapper = input.closest('.login_password_wrap') || input | ||
wrapper.classList.add('error') | ||
errorElement.textContent = message | ||
errorElement.style.display = 'block' | ||
} | ||
|
||
function clearError(input, errorElement) { | ||
const wrapper = input.closest('.login_password_wrap') || input | ||
wrapper.classList.remove('error') | ||
errorElement.textContent = '' | ||
errorElement.style.display = 'none' | ||
} | ||
|
||
function validateErrorMessage(input) { | ||
let wrapper = input.closest('.login_password_wrap') || input | ||
let next = wrapper.nextElementSibling | ||
if (!next || !next.classList.contains('error-message')) { | ||
const error = document.createElement('p') | ||
error.className = 'error-message' | ||
error.style.color = 'red' | ||
error.style.fontSize = '14px' | ||
error.style.marginTop = '4px' | ||
wrapper.parentNode.insertBefore(error, wrapper.nextSibling) | ||
return error | ||
} | ||
return next | ||
} | ||
|
||
// 페이지 로드 초기화 | ||
updateButtonState() | ||
}) |
This file contains hidden or 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 |
---|---|---|
|
@@ -79,5 +79,6 @@ | |
</div> | ||
</div> | ||
</div> | ||
<script type="module" src="../js/login.js"></script> | ||
</body> | ||
</html> |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -96,5 +96,6 @@ | |
</div> | ||
</div> | ||
</div> | ||
<script type="module" src="../js/signup.js"></script> | ||
</body> | ||
</html> |
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.
Uh oh!
There was an error while loading. Please reload this page.