Skip to content

Conversation

@grimza99
Copy link
Collaborator

요구사항

기본

로그인페이지

  • 이메일 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 에 유효한 값을 입력하면 ‘회원가입' 버튼이 활성화 됩니다.
  • 활성화된 ‘회원가입’ 버튼을 누르면 “/signup” 로 이동합니다

심화

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

주요 변경사항

  • create signup.js file
  • create login.js file
    -create test.js file

스크린샷

스크린샷 2024-12-30 오후 6 17 10 스크린샷 2024-12-30 오후 6 17 45

멘토에게

  • 현재 �프로젝트는 해당 html에 각각 login.js, signup.js 으로 모듈 파일을 설정해 놓아 필수, 심화 요구사항은 모두 기능하는 상황입니다! *
  • 다만 login.js 파일과 signup.file 을 만든뒤에 보니 공통된 함수가 너무 많은것 같아 test.js 파일을 만들어 두 파일을 합치고 그에 맞게 수정을 한뒤에, 각 html 파일에 script 태그로 넣으려고 시도했더니 일부 기능이 구현이 되지 않습니다.
  • 많은 수정을 거쳐봤지만 어떤부분이 문제인지 제가 파악하지 못했습니다.
  • 혹시 가능하시다면 test.js 파일을 살펴 보시고 관련해서 pr 해주시면 감사한 마음으로 보완후에 다음 미션때 제출하려 합니다.

nerte and others added 10 commits December 27, 2024 15:04
login_signup.js 파일 작성, 핸들러함수를 계획하고, 각 함수가 쓰이는 html파일에 해당 js 파일을 연결, 그리고 해당 js 파일에 필요한 함수이름을 import 했다.
로그인 페이지의 비밀번호 부분 테두리 스타일과 8글자 이상 작성 에러메시지 , 빈값일 경우 에러메시지 기능 작성

중복되는 코드가 많아서 추후 정리 필요
기존에 border red 스타일이 간혹 사라졌다가 다시 나타나는 현상 수정함.
회원가입 버튼 활성화 부분 구현,
- 디렉토리 구조 정리
- 눈모양 i태그클릭시 type을 password, text로 수정하는 password_hide 함수작성,
- 에러메시지가 생김에 따라 i태그가 움직이는것 수정

-앞으로의 수정 : 코드의 중보정리, 모듈화 진행예정
중복되는 코드가 많아 signup_login.js 파일을 만들어 login.html, signup.html 두파일에 적용하려 했으나,
일부 기능이 잘 구현되지 않아 일단 test.js 파일을 작성하고 코드리뷰 이후 보완후에 util.js 파일로 지정하려 함.
@grimza99 grimza99 added the 매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. label Dec 30, 2024
@kiJu2
Copy link
Collaborator

kiJu2 commented Dec 31, 2024

스프리트 미션 하시느라 수고 많으셨어요.
학습에 도움 되실 수 있게 꼼꼼히 리뷰 하도록 해보겠습니다. 😊

Comment on lines +74 to +83
switch (email_check(Email.value) && password_checked(password.value)) {
case true:
Btn.disabled = false;

break;
case false:
Btn.disabled = true;

break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

다음과 같이 조건문을 거치지 않고 코드를 간결하게 작성할 수 있습니다 !

Suggested change
switch (email_check(Email.value) && password_checked(password.value)) {
case true:
Btn.disabled = false;
break;
case false:
Btn.disabled = true;
break;
}
Btn.disabled = !(email_check(Email.value) && password_checked(password.value));
}

}
}

function Email_focus_out(e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(제안) 함수명은 동사로 작성되며, 변수/함수명은 카멜케이스로 작성되는게 일반적이예요 😊

Suggested change
function Email_focus_out(e) {
function handleFocusOutEmailInput(e) {

일반적으로 변수는 명사, 함수는 동사로 지어요.
boolean의 경우 isValidEmail와 같이 is, are, has로 시작하기도 합니다. =)

함수의 경우 다음과 같은 단어들이 접두사가 될 수 있어요:

  • get
  • fetch
  • push
  • update
  • create
  • calculate
  • set
  • 등등 ...

일반적인 네이밍 컨벤션 보기

Comment on lines +30 to +35
function tag_delete(i) {
let isTag = Error_message[i].querySelector("a");
if (isTag) {
Error_message[i].lastChild.remove();
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

줄임말 보다는 의도를 명확히 전달해보는건 어떨까요?

Suggested change
function tag_delete(i) {
let isTag = Error_message[i].querySelector("a");
if (isTag) {
Error_message[i].lastChild.remove();
}
}
function tag_delete(errorMessageIndex) {
let isTag = Error_message[errorMessageIndex].querySelector("a");
if (isTag) {
Error_message[errorMessageIndex].lastChild.remove();
}
}

물론 btn, pw 등 편의를 위해서 사용되기도 하나, 명확한 클래스 이름을 사용하시는게 더욱 의도된 바를 전달하기 쉽습니다.

이는 "닌자 코드"에 해당하는 문법입니다:
약어 사용하기
팀에 한 글자 짜리 변수나 모호한 변수명을 사용하지 못하게 하는 제약이 있다면 약어를 쓰는 기지를 발휘하세요. 변수명은 짧을수록 좋으니까요.

예시:

list → lst.
userAgent → ua.
browser → brsr.
등등…
모든 걸 줄여서 당신의 코드를 읽을 가치가 있는 직감이 뛰어난 개발자만 유지보수를 담당 할 수 있게 해 놓읍시다.


위 문서는 "이렇게 해라 !"가 아니라, "이를 지양하자 !"라는 것으로 작성된 문서 내용입니다. 😊
물론 oAuth(Open Authorization), sms(Short Message Service) 와 같이 내용이 길어서 통상적으로 줄임말을 사용하는 경우도 있기는 하기에 무조건 풀 텍스트를 사용하자 라는 차원은 아님을 전달드립니다. 😊

Comment on lines +56 to +70
function Password_focus_out(e, x) {
let input = e.target.value;
tag_delete(x);
if (!password_checked(input)) {
e.target.classList.add("input_red_border");
const text = document.createElement("a");
text.textContent =
input === ""
? "비밀번호를 입력해주세요"
: "비밀번호를 8자 이상 입력해주세요";
Error_message[x].prepend(text);
} else {
e.target.classList.remove("input_red_border");
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 마찬가지로 카멜케이스, 동사, 그리고 줄임말을 방지하면 다음과 같이 적용해볼 수 있어요 😊

Suggested change
function Password_focus_out(e, x) {
let input = e.target.value;
tag_delete(x);
if (!password_checked(input)) {
e.target.classList.add("input_red_border");
const text = document.createElement("a");
text.textContent =
input === ""
? "비밀번호를 입력해주세요"
: "비밀번호를 8자 이상 입력해주세요";
Error_message[x].prepend(text);
} else {
e.target.classList.remove("input_red_border");
}
}
function handleFocusOutPasswordInput(event, errorMessageIndex) {
let input = event.target.value;
tag_delete(errorMessageIndex);
if (!password_checked(input)) {
event.target.classList.add("input_red_border");
const text = document.createElement("a");
text.textContent =
input === ""
? "비밀번호를 입력해주세요"
: "비밀번호를 8자 이상 입력해주세요";
Error_message[errorMessageIndex].prepend(text);
} else {
event.target.classList.remove("input_red_border");
}
}

Comment on lines +103 to +109
function is_form_value() {
let array = [];
for (let i = 0; i < 4; i++) {
array.push(Boolean(Input[i].value));
}
return array.every((x) => x == true);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

해당 함수를 같이 분석해봅시다 !

먼저, 4라는 숫자가 무엇일까요? 의미를 파악하기 어려워요. 의미에 대한 힌트가 존재하지 않기에 가독성을 떨어트릴 수 있어요.
이를 마법수(*Magic Number)로 불려요.

*Magic Number: 이를테면, 은행에서 이자를 구하는 프로그램 코드 중간에 2.7182818 이라는 숫자가 등장했을 때, 수학을 좀 아는 사람은 이를 자연 상수(Euler's number) 로 생각할 것이다. 그런데 사실 작성자의 의도는 그냥 은행 정책에 따른 이율을 구하기 위해 필요한 숫자를 그냥 넣은 것이었다면? 이 경우 왜인지 추측하기 굉장히 헷갈리고 결국 이 코드를 작성했던 사람에게 가서 물어보는게 가장 정확하다. 이미 퇴사했다면 아마 진정한 의미는 영영 알 수 없을지도 모른다.
출처: https://jake-seo-dev.tistory.com/155 [제이크서 위키 블로그:티스토리]

Copy link
Collaborator

Choose a reason for hiding this comment

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

또한 4로 한정짓지 않고 Inputlength를 사용해볼 수 있어요.

아마 추측하기로는 의도하신 것은 "Input의 값을 모두 조회해라 !" 로 해석됩니다 !

Suggested change
function is_form_value() {
let array = [];
for (let i = 0; i < 4; i++) {
array.push(Boolean(Input[i].value));
}
return array.every((x) => x == true);
}
function is_form_value() {
let array = [];
for (let i = 0; i < Input.length; i++) {
array.push(Boolean(Input[i].value));
}
return array.every((x) => x == true);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

더 나아가서, array라는 값도 결국 Inputvalue들을 형변환하여 입력하는게 목적으로 보여요.

Suggested change
function is_form_value() {
let array = [];
for (let i = 0; i < 4; i++) {
array.push(Boolean(Input[i].value));
}
return array.every((x) => x == true);
}
function is_form_value() {
const inputArray = Array.from(Input);
const inputArrayValues = inputArray.map((input) => Boolean(input.value));
return inputArrayValues.every((x) => x == true);
}

따라서 for문이 아닌 map으로 사용하게 된다면 배열의 처음부터 끝까지 조회할 수 있을거예요:

map() 메서드는 배열 내의 모든 요소 각각에 대하여 주어진 함수를 호출한 결과를 모아 새로운 배열을 반환합니다.

예제:

const array1 = [1, 4, 9, 16];

// Pass a function to map
const map1 = array1.map((x) => x * 2);

console.log(map1);
// Expected output: Array [2, 8, 18, 32]

MDN

Copy link
Collaborator

Choose a reason for hiding this comment

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

최종적으로 ! 🚀

Suggested change
function is_form_value() {
let array = [];
for (let i = 0; i < 4; i++) {
array.push(Boolean(Input[i].value));
}
return array.every((x) => x == true);
}
function isFormValid() { // 카멜 케이스로 변경
return Array.from(Input).every((input) => Boolean(input.value));
}

메써드 체이닝(*Method Chaning)을 통하여 개발할 수 있습니다. 또한 map의 역할을 every 내부에서 수행할 수 있을거예요.

*Method Chaning

image

메서드가 객체를 반환하게 되면 메서드의 반환 값인 객체를 통해 또 다른 함수를 호출할 수 있다. 이러한 프로그래밍 패턴을 메서드 체이닝(Method Chaining)이라 부른다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

질문에 대한 답변 !

공통적인 논리를 재사용하는 발상이 정말 좋습니다 ! 유지보수 차원에서 이러한 패턴은 좋은 패턴이지요 ! 👍
(의견) 핸들러(element를 직접 다루는)는 각 페이지마다, 그리고 유효성 검사와 같이 특정 공통적인 자원(비밀번호, 이메일 등)과 연관된 함수는 분리해볼 수 있겠네요 😊

(의견222) auth라는 키워드로 네이밍을 지어보면 어떨까요?

@kiJu2
Copy link
Collaborator

kiJu2 commented Dec 31, 2024

정말 수고 많으셨습니다 선향님 !
직접 탐구하고 개발하신 흔적이 많이 보여서 너무 기쁠 따름입니다 !
끈기와 탐구력이 정말 좋으신 것 같아요. ㅎㅎㅎ

앞으로도 함께 개선해서 개발 역량을 키워봅시다 ! 👍👍

@kiJu2
Copy link
Collaborator

kiJu2 commented Dec 31, 2024

그리고.. 충돌이 일어난 것 같아요 Resolve Conflicts 버튼을 눌러서 충돌을 해결해주실 수 있으실까요?

@kiJu2 kiJu2 merged commit 58d3fcd into codeit-bootcamp-frontend:Basic-유선향 Dec 31, 2024
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