Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary of ChangesHello @g-hyxn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 게시글 삭제 기능을 도입하고, 이를 위한 사용자 친화적인 삭제 확인 모달을 구현합니다. 기존의 단순한 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
이번 PR은 게시글 삭제 기능과 관련 모달을 구현한 변경 사항을 담고 있습니다. 전반적으로 기능은 잘 구현되었으나, 몇 가지 개선점을 제안합니다.
첫째, 모든 사용자에게 삭제 버튼이 노출되는 것은 사용자 경험을 해칠 수 있습니다. 관리자에게만 버튼이 보이도록 조건부 렌더링을 다시 추가하는 것이 좋겠습니다. 기존의 isAdmin 함수는 컴포넌트 내에서 JWT를 직접 다루는 문제가 있었으므로, 이를 제거한 것은 좋지만 사용자 역할 확인은 중앙화된 방식(예: Context API)으로 개선하여 적용하는 것을 권장합니다.
둘째, API 에러 처리 시 axios.isAxiosError 타입 가드를 사용하면 코드를 더 안정적이고 명확하게 만들 수 있습니다.
자세한 내용은 각 파일의 인라인 코멘트를 참고해주세요.
| if (typeof error === 'object' && error !== null && 'response' in error) { | ||
| const status = (error as { response?: { status?: number } }).response | ||
| ?.status; | ||
|
|
||
| if (status === 401) toast.error('로그인이 필요합니다.'); | ||
| else if (status === 403) toast.error('관리자 권한이 없습니다.'); | ||
| else if (status === 404) toast.error('게시글을 찾을 수 없습니다.'); | ||
| else toast.error('게시글 삭제에 실패했습니다.'); | ||
| if (status === 401) { | ||
| toast.error('로그인이 필요합니다.'); | ||
| } else if (status === 403) { | ||
| toast.error('관리자 권한이 없습니다.'); | ||
| } else if (status === 404) { | ||
| toast.error('게시글을 찾을 수 없습니다.'); | ||
| } else { | ||
| toast.error('게시글 삭제에 실패했습니다.'); | ||
| } | ||
| } else { | ||
| toast.error('서버와 통신할 수 없습니다.'); | ||
| } |
There was a problem hiding this comment.
Axios 에러를 처리할 때 axios.isAxiosError 타입 가드를 사용하는 것이 더 안정적이고 간결합니다. 현재의 typeof error === 'object' && error !== null && 'response' in error 방식 대신 axios.isAxiosError(error)를 사용하면 코드가 더 명확해지고, Axios가 제공하는 타입 안전성을 활용할 수 있습니다. 이를 위해 파일 상단에 import axios from 'axios';를 추가해야 합니다.
if (axios.isAxiosError(error)) {
const status = error.response?.status;
if (status === 401) {
toast.error('로그인이 필요합니다.');
} else if (status === 403) {
toast.error('관리자 권한이 없습니다.');
} else if (status === 404) {
toast.error('게시글을 찾을 수 없습니다.');
} else {
toast.error('게시글 삭제에 실패했습니다.');
}
} else {
toast.error('서버와 통신할 수 없습니다.');
}
| <button | ||
| onClick={() => setIsDeleteModalOpen(true)} | ||
| className="cursor-pointer" | ||
| > | ||
| <Delete /> | ||
| </button> |
There was a problem hiding this comment.
삭제 버튼이 이제 모든 사용자에게 표시됩니다. 권한이 없는 사용자가 삭제 버튼을 클릭하고 모달에서 확인을 누르면 '관리자 권한이 없습니다'라는 오류 메시지를 받게 됩니다. 이는 사용자 경험에 좋지 않습니다.
이전의 isAdmin 함수는 컴포넌트 내에서 JWT를 직접 파싱하는 등 문제가 있어 제거한 것은 좋은 결정입니다. 하지만 사용자 역할에 따라 버튼을 조건부로 렌더링하는 로직은 유지하는 것이 좋습니다.
사용자 정보를 관리하는 전역 상태(Context API, Redux 등)나 커스텀 훅(예: useUser)을 사용하여 사용자의 역할을 확인하고, 관리자일 경우에만 이 삭제 버튼이 보이도록 수정하는 것을 권장합니다.
💡 배경 및 개요
📃 작업내용
🙋♂️ 리뷰노트
✅ PR 체크리스트
.env,노션,README)"API 개발 완료됐어요","환경값 추가되었어요")🎸 기타