Skip to content

Conversation

@LeeTaegyung
Copy link
Collaborator

@LeeTaegyung LeeTaegyung commented Apr 25, 2025

요구사항

기본

로그인

  • 이메일 input에서 focus out 할 때, 값이 없을 경우 input에 빨강색 테두리와 아래에 "이메일을 입력해주세요." 빨강색 에러 메세지를 보입니다.
  • 이메일 input에서 focus out 할 때, 이메일 형식에 맞지 않는 경우 input에 빨강색 테두리와 아래에 "잘못된 이메일 형식입니다" 빨강색 에러 메세지를 보입니다.
  • 비밀번호 input에서 focus out 할 때, 값이 없을 경우 아래에 "비밀번호를 입력해주세요." 에러 메세지를 보입니다
  • 비밀번호 input에서 focus out 할 때, 값이 8자 미만일 경우 아래에 "비밀번호를 8자 이상 입력해주세요." 에러 메세지를 보입니다.
  • input 에 빈 값이 있거나 에러 메세지가 있으면 '로그인' 버튼은 비활성화 됩니다.
  • input 에 유효한 값을 입력하면 '로그인' 버튼이 활성화 됩니다.
  • 활성화된 '로그인' 버튼을 누르면 "/items" 로 이동합니다

회원가입

  • 이메일 input에서 focus out 할 때, 값이 없을 경우 input에 빨강색 테두리와 아래에 "이메일을 입력해주세요." 빨강색 에러 메세지를 보입니다.
  • 이메일 input에서 focus out 할 때, 이메일 형식에 맞지 않는 경우 input에 빨강색 테두리와 아래에 "잘못된 이메일 형식입니다" 빨강색 에러 메세지를 보입니다.
  • 닉네임 input에서 focus out 할 때, 값이 없을 경우 input에 빨강색 테두리와 아래에 "닉네임을 입력해주세요." 빨강색 에러 메세지를 보입니다.
  • 비밀번호 input에서 focus out 할 때, 값이 없을 경우 아래에 "비밀번호를 입력해주세요." 에러 메세지를 보입니다
  • 비밀번호 input에서 focus out 할 때, 값이 8자 미만일 경우 아래에 "비밀번호를 8자 이상 입력해주세요." 에러 메세지를 보입니다.
  • 비밀번호 input과 비밀번호 확인 input의 값이 다른 경우, 비밀번호 확인 input 아래에 "비밀번호가 일치하지 않습니다.." 에러 메세지를 보입니다.
  • input 에 빈 값이 있거나 에러 메세지가 있으면 '회원가입' 버튼은 비활성화 됩니다.
  • input 에 유효한 값을 입력하면 '회원가입' 버튼이 활성화 됩니다.
  • 활성화된 '회원가입' 버튼을 누르면 로그인 페이지로 이동합니다

심화

  • 눈 모양 아이콘 클릭시 비밀번호의 문자열이 보이기도 하고, 가려지기도 합니다.
  • 비밀번호의 문자열이 가려질 때는 눈 모양 아이콘에는 사선이 그어져있고, 비밀번호의 문자열이 보일 때는 사선이 없는 눈 모양 아이콘이 보이도록 합니다.

스크린샷

로그인 페이지

입력값 없을 때
image

형식에 맞지 않는 값일 때
image

형식에 맞는 값일 때
image

input에 에러 메세지가 있을 때
image

회원가입 페이지

입력값 없을 때
image

형식에 맞지 않는 값일 때
image

형식에 맞는 값일 때
image

input에 에러 메세지가 있을 때
image

심화

image
image

멘토에게

  • 재사용이 가능한 부분이나 기능이 비슷한 부분을 모아서 하다 보니, 코드가 가독성이 떨어지고 복잡해진 거 같습니다. 기능을 구현할 때 어떤 기준으로 나누는 것이 좋을까요?
  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

@LeeTaegyung LeeTaegyung added the 매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. label Apr 25, 2025
@addiescode-sj addiescode-sj self-requested a review April 29, 2025 04:22
Copy link
Collaborator

@addiescode-sj addiescode-sj left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!
제가 드린 코멘트처럼 재사용가능한 비즈니스 로직과 UI의 불필요한 결합만 제거한다면 코드가 훨씬 간결해지고 코드 양도 많이 줄어들수있을것같아요. 참고해보시고 리팩토링해보세요!

주요 리뷰 포인트

  • 유지보수를 고려한 개발 (단일 책임 원칙)
  • 네이밍

}

/* validation 통과시 */
.form__input-box.isPass .input {
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: isPass보다는 isValid 정도가 적당할것같네요!


const VALIDATION_RULE = {
nickname: {
noValue: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: noValue => isEmpty 어떨까요?
복잡해보이는 네이밍을 기피하는것도 좋은 리팩토링이랍니다 :)

참고

Comment on lines 140 to 151
function togglePassword(e) {
if (!e.target.closest(".input-box__toggle")) return;
const pwBox = e.target.closest(".input-box__input");
const inputBox = pwBox.querySelector(".input");
if (pwBox.classList.contains("pw_show")) {
pwBox.classList.remove("pw_show");
inputBox.setAttribute("type", "password");
} else {
pwBox.classList.add("pw_show");
inputBox.setAttribute("type", "input");
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

classList.toggle을 사용하면 좀더 간결하게 만들어줄수있겠네요 :)
참고

function togglePassword(e) {
  if (!e.target.closest(".input-box__toggle")) return;
  const pwBox = e.target.closest(".input-box__input");
  const inputBox = pwBox.querySelector(".input");
  const isShow = pwBox.classList.toggle("pw_show");
  inputBox.setAttribute("type", isShow ? "text" : "password");
}

}

// validation 검사
function checkValidation({ target }) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

해당 함수는 비즈니스 로직과 UI가 불필요하게 결합되어있어 재사용이 불가하고, 하는일이 많아 복잡해보여요.
아래와 같이 분리해 단일 책임을 가질수있도록 리팩토링해볼까요?

  • 유효성 검사 (추후 재사용 가능한 단위로 함수 분리해 모듈화)
  • 이벤트 리스너 연결 및 UI 업데이트

// 항목별 validation 검사
switch (targetId) {
case "nickname":
isValidation = checkValidationNickname(targetValue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

위에서 얘기했던 코멘트처럼 비즈니스 로직과 UI를 분리하게된다면 이렇게 checkValidation{Nickname} 과 같이 nickname, password, email에 해당하는 개별 함수들을 더이상 따로 만들지않아도 되겠죠? :)

Comment on lines 130 to 137
if (!isValidation) {
// 항목별 validation 실패시
createErrorMsg(VALIDATION_RULE[targetId].validation.msg, inputBox);
} else {
// 항목별 validation 통과시
inputBox.classList.add("isPass");
}
checkAllPass();
Copy link
Collaborator

Choose a reason for hiding this comment

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

이런 코드 흐름 너무 좋네요 👍 js에 대한 기본적인 이해도가 좋으신것같아요!

@addiescode-sj
Copy link
Collaborator

질문에 대한 답변

멘토에게

  • 재사용이 가능한 부분이나 기능이 비슷한 부분을 모아서 하다 보니, 코드가 가독성이 떨어지고 복잡해진 거 같습니다. 기능을 구현할 때 어떤 기준으로 나누는 것이 좋을까요?
  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

본문 내에서 상세히 답변드렸습니다! :)

@addiescode-sj addiescode-sj merged commit 305d791 into codeit-bootcamp-frontend:Basic-이태경 May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants