Skip to content

Conversation

@najitwo
Copy link
Collaborator

@najitwo najitwo commented Nov 9, 2024

요구사항

기본

회원가입

  • 유효한 정보를 입력하고 스웨거 명세된 “/auth/signUp”으로 POST 요청해서 성공 응답을 받으면 회원가입이 완료됩니다.
  • 회원가입이 완료되면 “/login”로 이동합니다.
  • 회원가입 페이지에 접근시 로컬 스토리지에 accessToken이 있는 경우 ‘/’ 페이지로 이동합니다.

로그인

  • 회원가입을 성공한 정보를 입력하고 스웨거 명세된 “/auth/signIp”으로 POST 요청을 하면 로그인이 완료됩니다.
  • 로그인이 완료되면 로컬 스토리지에 accessToken을 저장하고 “/” 로 이동합니다.
  • 로그인/회원가입 페이지에 접근시 로컬 스토리지에 accessToken이 있는 경우 ‘/’ 페이지로 이동합니다.

메인

  • 로컬 스토리지에 accessToken이 있는 경우 상단바 ‘로그인’ 버튼이 판다 이미지로 바뀝니다.

심화

  • 로그인, 회원가입 기능에 react-hook-form을 활용해봅니다.

변경 사항

  • 미션 요구사항에 로컬 스토리지를 사용하라고 되있어서 인증 관련 로직을 context API에서 custom hook으로 변경했습니다.

배포 사이트

https://najimarket.vercel.app/

@najitwo najitwo requested a review from GANGYIKIM November 9, 2024 13:42
@najitwo najitwo added the 매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. label Nov 9, 2024
Copy link
Collaborator

@GANGYIKIM GANGYIKIM left a comment

Choose a reason for hiding this comment

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

지원님 이번 스프린트 미션 고생하셨습니다~

<div className={`${styles.bannerBottomImg} ${styles.img}`}></div>
</div>
</section>
<footer className={styles.footerContainer}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

P3:
footer는 따로 분리하지 않아도 되나요?

const { list } = await fetchData(BASE_URL, {
query: { keyword: typeof keyword === "string" ? keyword : "" },
});
const { list } = await fetchData<Record<string, ArticleProps[]>>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

P1:
지금 선언해주신 Record<string, ArticleProps[]> 타입이 의미하는 것은 객체의 키가 string 타입이고, 그 값은 ArticleProps 타입을 가진 배열이라는 뜻입니다.
의도하신 바는 아마 list 키값에 ArticleProps[] 타입을 가진 배열이 응답값으로 내려온다는 것이므로 아래 코드가 더 적절해보입니다.

Suggested change
const { list } = await fetchData<Record<string, ArticleProps[]>>(
const { list } = await fetchData<{ list: ArticleProps[] }>(

body: { content: comment },
}
);
setComment("");
Copy link
Collaborator

Choose a reason for hiding this comment

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

P2:
react-hook-form을 사용하시니 해당 form에서 reset 함수를 사용하시면 더 좋을 것 같습니다~

Copy link
Collaborator

Choose a reason for hiding this comment

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

P3:
fetchData가 method 들을 모두 커버하다보니 로직이 커지는 것 같아요.
fetchDatat 라는 하나의 함수로 유지하고 싶으시면 내부 로직을 분리하시는 것을 추천드려요.

const fetchData = async<T>(...) => {
  const { method } = options;

  switch(method) {
    case 'POST': 
      postData(...);
    case 'PUT':
      putData(...);
    case 'PATCH':
      patchData(...);
    case 'DELETE':
      deleteData(...);

    case 'GET':
    default:
      getData(...)
  }
}

error?: FieldError;
}

const FormInput = <T extends FieldValues>({
Copy link
Collaborator

Choose a reason for hiding this comment

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

P3:
react-hook-form의 register 함수를 실행해서 반환값을 받도록 하면 더 깔끔하지 않았을까싶네요.

Comment on lines +49 to +54
<div
tabIndex={0}
role="button"
className={styles.dropdownButton}
onClick={toggleDropdown}
>
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 태그가 아니라 div 태그를 쓰시고 tabIndex, onClick을 추가하신 이유가 있을까요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

P3:
react-hook-form을 설치하셨으니 나중에 이 부분도 해당 라이브러리를 사용하는 방향으로 수정하시면 더 좋을 것 같습니다~

register={register}
required="이메일을 입력해주세요."
pattern={{
value: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
Copy link
Collaborator

Choose a reason for hiding this comment

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

P2:
정규 표현식이 로그인, 회원가입에서 공용으로 쓰이니 따로 객체에 저장해두시고 같이 쓰시면 더 좋을 것 같습니다.
에러메시지도 여러 페이지에서 반복적으로 사용된다면 동일합니다~

@GANGYIKIM GANGYIKIM merged commit c432a31 into codeit-bootcamp-frontend:Next-나지원 Nov 12, 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