Skip to content
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 #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions login.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ body{
outline-color: #3692FF;;
}

.error {
border:1px solid red;
}


.error-message,
.error-message-pw,
.error-message-nick,
.error-message-pwcheck {
outline-color: red;
color: red;
display: none;
}

.input::placeholder{
color: #9CA3AF;
font-weight: 400;
Expand Down
5 changes: 4 additions & 1 deletion login.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
<form class="email-box">
<label class="email-label" for ="email">이메일</label>
<input class="input" placeholder="이메일을 입력해주세요" id="email">
<div class="error-message"></div>
</form>
<form class="pw-box">
<label class="pw-label" for ="pw">비밀번호</label>
<input class="input" placeholder="비밀번호를 입력해주세요" type="password" id="pw">
<div class='error-message-pw'></div>
</form>
<button class="login-btn" onclick="location.href='/login'">로그인</button>
<button id="login" class="login-btn" onclick="location.href='/items'">로그인</button>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3:
해당 button은 disabled true로 해두는 것이 동작상 좋지 않을까요? 🧐
처음에는 input들이 비어있어서 invalid할테니까용

Suggested change
<button id="login" class="login-btn" onclick="location.href='/items'">로그인</button>
<button id="login" disabled class="login-btn" onclick="location.href='/items'">로그인</button>

<article class="easy-login-box">
<div class="easy-content">
<span>간편 로그인하기</span>
Expand All @@ -49,5 +51,6 @@
<a href="signup.html">회원가입</a>
</section>
</main>
<script src="login.js"></script>
</body>
</html>
72 changes: 72 additions & 0 deletions login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const emailInputElement = document.querySelector('#email');
const pwInputElement = document.querySelector('#pw');
const errorMessage = document.querySelector('.error-message');
const pwErrorMessage = document.querySelector('.error-message-pw');

function emailForm(e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1:
변수명 함수명은 좀 더 유의미하고 어떤 동작을 하는 지 알 수 있는 이름이면 좋겠습니다.
해당 함수에서 인자 e는 사용되지 않으니 지워주시는게 더 좋겠습니다.

Suggested change
function emailForm(e) {
function checkEmailValidation() {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3:
아래처럼도 작성 가능합니다.

const checkEmailFormatValid = (value: string) => {
  return !(value.includes("@") && value.includes("."))
}

function checkEmailValidation(e) {
  const input = e.currentTarget;
  const value = input.value.trim();

  if (!value) {
    emailInputElement.classList.add('error');
    errorMessage.textContent ="이메일을 입력해주세요."
    errorMessage.style.display = 'block';
    return ;
  }

  if (checkEmailFormatValid(value)) {
    emailInputElement.classList.add('error');
    errorMessage.textContent ="잘못된 이메일 형식입니다."
    errorMessage.style.display = 'block';
    return;
  }

  emailInputElement.classList.remove('error');
  errorMessage.style.display = 'none';
}

지금은 에러종류가 많지 않지만 나중에 에러종류가 많은 경우가 생긴다면
아래처럼 작성할 수도 있습니다.

const getEmailError = (value: string): {type: EMAIL_ERROR_TYPE} => {
  /** 이메일 input의 value를 받아 해당하는 에러 타입을 반환하는 함수 */
}


function checkEmailValidation(e) {
  const input = e.currentTarget;
  const errorType = getEmailError(input.value.trim());

  if (errorType) {
    emailInputElement.classList.add('error');
    errorMessage.textContent =ErrorMessage[errorType]
    errorMessage.style.display = 'block';
    return ;
  }

  emailInputElement.classList.remove('error');
  errorMessage.style.display = 'none';
}

if (emailInputElement.value === '') {
emailInputElement.classList.add('error');
errorMessage.textContent ="이메일을 입력해주세요."
errorMessage.style.display = 'block';
} else if (!(emailInputElement.value.includes("@")
&& emailInputElement.value.includes("."))) {
emailInputElement.classList.add('error');
errorMessage.textContent ="잘못된 이메일 형식입니다."
errorMessage.style.display = 'block';
}else{
emailInputElement.classList.remove('error');
errorMessage.style.display = 'none';
}
}

function pwForm(e) {
if (pwInputElement.value === '') {
pwInputElement.classList.add('error');
pwErrorMessage.textContent ="비밀번호를 입력해주세요."
pwErrorMessage.style.display = 'block';
} else if (pwInputElement.value.length < 8) {
pwInputElement.classList.add('error');
pwErrorMessage.textContent ="비밀번호를 8자 이상 입력해주세요."
pwErrorMessage.style.display = 'block';
}else{
pwInputElement.classList.remove('error');
pwErrorMessage.style.display = 'none';
}
}

function removeMessage(e){
if(e.target.id === "email"){
errorMessage.style.display = 'none';
}else{
pwErrorMessage.style.display = 'none';
}
}


emailInputElement.addEventListener('blur', emailForm)
emailInputElement.addEventListener('focus', removeMessage)

pwInputElement.addEventListener('blur', pwForm)
pwInputElement.addEventListener('focus', removeMessage)
Comment on lines +46 to +50
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1:
이벤트를 연결하는 코드들이 함수 선언문 사이사이에 들어가 있어서 코드 파악이 어렵습니다.
가능하면 변수 선언 => 함수 선언 => 이벤트 바인딩문 과 같은 순서처럼 관련있는 코드끼리 기준을 정해서 묶어 작성하시는 것을 추천드립니다.


// ----------------------------------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3:
어떤 기준으로 코드를 양분하신 건지 주석을 달아주시면 좋을 것 같습니다.


const loginElement = document.querySelector("#login")

function activateLogin(e){
if(emailInputElement.classList.contains('error')
|| pwInputElement.classList.contains('error')){
loginElement.style.backgroundColor = "#9CA3AF"

} else if(emailInputElement.value === '' || pwInputElement.value === ''){
loginElement.style.backgroundColor = "#9CA3AF"
}else{
loginElement.style.backgroundColor = "#3692FF"
}
Comment on lines +57 to +65
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2:
조건문의 조건을 변수로 저장해주시면 변수명을 통해 코드를 이해하기 더 쉬워집니다.

Suggested change
if(emailInputElement.classList.contains('error')
|| pwInputElement.classList.contains('error')){
loginElement.style.backgroundColor = "#9CA3AF"
} else if(emailInputElement.value === '' || pwInputElement.value === ''){
loginElement.style.backgroundColor = "#9CA3AF"
}else{
loginElement.style.backgroundColor = "#3692FF"
}
const isError =
emailInputElement.classList.contains("error") ||
pwInputElement.classList.contains("error");
const isEmpty = emailInputElement.value === "" || pwInputElement.value === "";
if (isError || isEmpty) {
loginElement.style.backgroundColor = "#9CA3AF";
return;
}
loginElement.style.backgroundColor = "#3692FF";

}

pwInputElement.addEventListener('blur', activateLogin)
emailInputElement.addEventListener('blur', activateLogin)



15 changes: 10 additions & 5 deletions signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@
<main class="container">
<form class="email-box">
<label class="email-label">이메일</label>
<input class="input" placeholder="이메일을 입력해주세요">
<input class="input" id="email" placeholder="이메일을 입력해주세요">
<div class="error-message"></div>
</form>
<form class="nickname-box">
<label class="nickname-label">닉네임</label>
<input class="input" placeholder="닉네임을 입력해주세요">
<input class="input" id="nickname" placeholder="닉네임을 입력해주세요">
<div class="error-message-nick"></div>
</form>
<form class="pw-box">
<label class="pw-label">비밀번호</label>
<input class="input" placeholder="비밀번호를 입력해주세요" type="password">
<input class="input" id="pw" placeholder="비밀번호를 입력해주세요" type="password">
<div class="error-message-pw"></div>
</form>
<form class="pw-repeat-box">
<label class="pw-repeat-label">비밀번호 확인</label>
<input class="input" placeholder="비밀번호를 다시 한 번 입력해주세요" type="password">
<input class="input" id="pwcheck" placeholder="비밀번호를 다시 한 번 입력해주세요" type="password">
<div class="error-message-pwcheck"></div>
</form>
<button class="login-btn" onclick="location.href='/login'">회원가입</button>
<button class="login-btn">회원가입</button>
<article class="easy-login-box">
<div class="easy-content">
<span>간편 로그인하기</span>
Expand All @@ -57,5 +61,6 @@
<a href="login.html">로그인</a>
</section>
</main>
<script src="signup.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2:
HTML 문서 다운로드 후 JS가 다운로드 되게 하단에 배치하신 것 같은데

하단에 배치된 스크립트는 구문분석 순서상 추후에 다운로드 되게 만들어주지만 일반적으로 스크립트 태그가 위치되는 head 요소가 아니므로 가독성 측면에서 단점이 있고 이러한 동작은 스크립트 자체 속성을 통해 이끌어 낼 수 있으므로 script async, defer 속성 사용을 추천드립니다.

https://developer.mozilla.org/ko/docs/Web/HTML/Element/script#defer
https://ko.javascript.info/script-async-defer

</body>
</html>
131 changes: 131 additions & 0 deletions signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
let signupValid = false

//ID 선택하기
const emailInputElement = document.getElementById('email');
const nickInputElement = document.getElementById('nickname');
const pwInputElement = document.getElementById('pw');
const pwCheckInputElement = document.getElementById('pwcheck');
const errorMessage = document.querySelector('.error-message');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2:
해당 변수도 errorMessage가 들어갈 요소이니 아래와 같은 이름이 더 유의미할 것 같습니다.

Suggested change
const errorMessage = document.querySelector('.error-message');
const errorMessageElement = document.querySelector('.error-message');

const nickErrorMessage = document.querySelector('.error-message-nick');
const pwErrorMessage = document.querySelector('.error-message-pw');
const pwCheckErrorMessage = document.querySelector('.error-message-pwcheck');
const signupElement = document.querySelector('.login-btn')





function emailForm(e) {
if (emailInputElement.value === '') {
emailInputElement.classList.add('error');
errorMessage.textContent = "이메일을 입력해주세요"
errorMessage.style.display = 'block';
} else if (!(emailInputElement.value.includes("@")
&& emailInputElement.value.includes("."))) {
emailInputElement.classList.add('error');
errorMessage.textContent ="잘못된 이메일 형식입니다."
errorMessage.style.display = 'block';
}else{
emailInputElement.classList.remove('error');
errorMessage.style.display = 'none';
};
};

function nickForm(e) {
if (nickInputElement.value === '') {
nickInputElement.classList.add('error');
nickErrorMessage.textContent = "닉네임을 입력해주세요."
nickErrorMessage.style.display = "block";
} else {
nickInputElement.classList.remove('error');
nickErrorMessage.style.display = 'none';
};
};

function pwForm(e) {
if (pwInputElement.value === '') {
pwInputElement.classList.add('error');
pwErrorMessage.textContent ="비밀번호를 입력해주세요."
pwErrorMessage.style.display = 'block';
} else if (pwInputElement.value.length < 8) {
pwInputElement.classList.add('error');
pwErrorMessage.textContent ="비밀번호를 8자 이상 입력해주세요."
pwErrorMessage.style.display = 'block';
}else{
pwInputElement.classList.remove('error');
pwErrorMessage.style.display = 'none';
};
};

function removeMessage(e){
if(e.target.id === "email"){
errorMessage.style.display = 'none';
} else if(e.target.id === "nickname"){
nickErrorMessage.style.display = 'none';
} else if(e.target.id === "pw"){
pwErrorMessage.style.display = 'none';
} else{
pwCheckErrorMessage.style.display = 'none';
};
};

function pwValid(e) {
if (!(pwInputElement.value === pwCheckInputElement.value)) {
pwCheckInputElement.classList.add('error');
pwCheckErrorMessage.textContent = "비밀번호가 일치하지 않습니다.."
pwCheckErrorMessage.style.display = 'block';
}else{
pwCheckInputElement.classList.remove('error');
pwCheckErrorMessage.style.display = 'none';
};
}

function activateSignup(e){
if(
emailInputElement.classList.contains('error')
|| nickInputElement.classList.contains('error')
|| pwInputElement.classList.contains('error')
|| pwCheckInputElement.classList.contains('error')
) {
signupElement.style.backgroundColor = "#9CA3AF"
} else if (
emailInputElement.value ===''
|| nickInputElement.value ===''
|| pwInputElement.value ===''
|| pwCheckInputElement.value === ''
) {
signupElement.style.backgroundColor = "#9CA3AF"
} else {
signupElement.style.backgroundColor = "#3692FF"
signupValid = true
}
}



emailInputElement.addEventListener('blur', emailForm);
nickInputElement.addEventListener('blur', nickForm);
pwInputElement.addEventListener('blur', pwForm);
pwCheckInputElement.addEventListener('blur', pwValid);

emailInputElement.addEventListener('focus',removeMessage)
nickInputElement.addEventListener('focus',removeMessage)
pwInputElement.addEventListener('focus',removeMessage)
pwCheckInputElement.addEventListener('focus',removeMessage)


emailInputElement.addEventListener('blur', activateSignup)
nickInputElement.addEventListener('blur', activateSignup)
pwInputElement.addEventListener('blur', activateSignup)
pwCheckInputElement.addEventListener('blur', activateSignup)

pwInputElement.addEventListener('change',pwValid);


function signupButton(e){
if(signupValid){
window.location.href = "/login"
}
}

signupElement.addEventListener("click",signupButton)
Loading