-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
44 deletions.
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 setError = (element, message, type) => { | ||
const inputControl = element.parentElement; | ||
const errorDisplay = inputControl.querySelector('.error'); | ||
|
||
errorDisplay.innerText = message; | ||
inputControl.classList.add('error'); | ||
inputControl.classList.remove('success'); | ||
}; | ||
|
||
const setSuccess = (element) => { | ||
const inputControl = element.parentElement; | ||
const errorDisplay = inputControl.querySelector('.error'); | ||
|
||
errorDisplay.innerText = ''; | ||
inputControl.classList.remove('error'); | ||
inputControl.classList.add('success'); | ||
}; | ||
|
||
export const common = { | ||
setError, | ||
setSuccess, | ||
}; |
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,27 @@ | ||
const modal = document.getElementById('error-message-modal'); | ||
const closeModalButton = document.querySelector('.close-modal-button'); | ||
|
||
export const closeModal = () => { | ||
modal.close(); | ||
}; | ||
const handleCloseModal = (e) => { | ||
if (isModalOutSideClicked(e)) { | ||
closeModal(); | ||
} | ||
}; | ||
// 모달 외부 클릭 했는지 확인 | ||
const isModalOutSideClicked = (e) => { | ||
const dialogDimensions = modal.getBoundingClientRect(); | ||
return ( | ||
e.clientX < dialogDimensions.left || | ||
e.clientX > dialogDimensions.right || | ||
e.clientY < dialogDimensions.top || | ||
e.clientY > dialogDimensions.bottom | ||
); | ||
}; | ||
|
||
export const showModal = () => { | ||
modal.showModal(); | ||
}; | ||
|
||
// controller -> evenService -> commonService들의 조합 |
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,57 @@ | ||
import { USER_DATA } from '../../data/users.js'; | ||
import { EMAIL_REGEX } from './regex.js'; | ||
import { showModal } from './modal.js'; | ||
|
||
const checkFormButtonDisabled = () => !formButton; | ||
// 유효성 검사 함수 | ||
const isValidInput = (input) => input.value.trim() !== ''; | ||
const isValidPassword = (password) => password.value.trim().length >= 8; | ||
const isEmailRegistered = (email) => { | ||
return USER_DATA.find((user) => user.email === email.value.trim()); | ||
}; | ||
const validateEmail = () => { | ||
const emailValue = email.value.trim(); | ||
if (emailValue === '') { | ||
setError(email, '이메일을 입력해주세요.', 'email'); | ||
} else if (!isValidEmail(emailValue)) { | ||
setError(email, '잘못된 이메일 형식입니다.', 'email'); | ||
} else { | ||
setSuccess(email); | ||
} | ||
}; | ||
const isValidEmail = (email) => { | ||
return EMAIL_REGEX.test(String(email).toLowerCase()); | ||
}; | ||
const validateNickname = () => { | ||
const nicknameValue = nickname.value.trim(); | ||
if (nicknameValue === '') { | ||
setError(nickname, '닉네임을 입력해주세요.', 'nickname'); | ||
} else { | ||
setSuccess(nickname); | ||
} | ||
}; | ||
const validatePassword = () => { | ||
const passwordValue = password.value.trim(); | ||
if (passwordValue === '') { | ||
setError(password, '비밀번호를 입력해주세요.', 'password'); | ||
} else if (passwordValue.length < 8) { | ||
setError(password, '비밀번호를 8자 이상 입력해주세요', 'password'); | ||
} else { | ||
setSuccess(password); | ||
} | ||
}; | ||
const validatePasswordConfirmation = () => { | ||
const passwordValue = password.value.trim(); | ||
const passwordConfirmValue = passwordConfirm.value.trim(); | ||
if (passwordConfirmValue === '') { | ||
setError(passwordConfirm, '비밀번호를 입력해주세요.', 'password-confirm'); | ||
} else if (passwordConfirmValue !== passwordValue) { | ||
setError( | ||
passwordConfirm, | ||
'비밀번호가 일치하지 않습니다.', | ||
'password-confirm' | ||
); | ||
} else { | ||
setSuccess(passwordConfirm); | ||
} | ||
}; |
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,25 @@ | ||
import { handleFormSubmit, updateSubmitButtonState } from './eventFunctions.js'; | ||
|
||
const modal = document.getElementById('error-message-modal'); | ||
const closeModalButton = document.querySelector('.close-modal-button'); | ||
const form = document.getElementById('form'); | ||
const email = document.getElementById('email'); | ||
const nickname = document.getElementById('nickname'); | ||
const password = document.getElementById('password'); | ||
const passwordConfirm = document.getElementById('password-confirm'); | ||
const formButton = document.getElementById('form-button'); | ||
const passwordFields = document.querySelectorAll('.password-field'); | ||
const visibilityImages = document.querySelectorAll( | ||
'.password-visibility-image' | ||
); | ||
|
||
// eventBuilder | ||
// .get('form-button') | ||
// .event('input') | ||
// .eventService(updateSubmitButtonState); | ||
|
||
form.addEventListener('input', updateSubmitButtonState); | ||
form.addEventListener('submit', handleFormSubmit); | ||
form.addEventListener('focusout', handleFocusOut); | ||
closeModalButton.addEventListener('click', closeModal); | ||
modal.addEventListener('click', handleCloseModal); |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { validates, validationHandlersA } from './form-validation.js'; | ||
|
||
export const handleFormSubmit = (e) => { | ||
e.preventDefault(); | ||
validates.setSubmitButtonState(); | ||
if (validates.checkFormButtonDisabled()) return; | ||
const currentPage = window.location.pathname; | ||
if (currentPage.includes('signup.html')) return handleSignupProcess(); | ||
if (currentPage.includes('login.html')) return handleLoginProcess(); | ||
alert('페이지를 찾을 수 없습니다.'); | ||
}; | ||
|
||
export const updateSubmitButtonState = () => validates.setSubmitButtonState(); | ||
|
||
export const handleFocusOut = (e) => { | ||
const validateElementId = e.target.id; | ||
validationHandlersA[validateElementId](); | ||
}; | ||
|
||
export const closeModal = () => modal.close(); | ||
|
||
export const handleCloseModal = (e) => { | ||
if (isModalOutSideClicked(e)) closeModal(); | ||
}; |