Skip to content

Conversation

@LeeCh0129
Copy link

@LeeCh0129 LeeCh0129 commented Jun 16, 2025

📌 변경 사항 개요

기존의 사이드바 목데이터를 API연동

✨ 요약

  • 커스텀 훅 useDashboard
  • 기존의 목데이터 제거
  • 대시보드 목록 API 연동
  • 기존 생성모달 URL 변경

📝 상세 내용

1. 커스텀 훅 구현 (useDashboard.ts)

  • API 호출 로직과 상태 관리 분리
  • dashboards, isLoading, error 상태 관리
  • GET /{TEAM_ID}/dashboards?navigationMethod=infiniteScroll API 연동
  • try-catch-finally 에러 처리

2. 사이드바 컴포넌트 업데이트 (Sidebar.tsx)

  • 기존의 목데이터mockDashboards 제거
  • useDashboard 훅 연동

3. 대시보드 생성 모달 업데이트 (CreateDashboardModal.tsx)

  • API 엔드포인트 수정: /dashboards/{TEAM_ID}/dashboards
  • 환경변수 NEXT_PUBLIC_TEAM_ID 활용

🔗 관련 이슈

#59

🖼️ 스크린샷

{
image

✅ 체크리스트

  • 브랜치 네이밍 컨벤션을 준수했습니다
  • 커밋 컨벤션을 준수했습니다
  • 코드가 프로젝트의 스타일 가이드라인을 준수합니다

💡 참고 사항

  • 추후 대시보드 목록에 인피니트 스크롤 적용예정

Summary by CodeRabbit

  • 신규 기능
    • 사이드바에서 대시보드 목록이 동적으로 로드되어, 대시보드가 없거나 로딩/에러 상태일 때 각각 안내 메시지가 표시됩니다.
    • 대시보드 데이터를 관리하는 새로운 훅이 도입되어, 대시보드 목록을 자동으로 불러오고 상태를 관리합니다.
  • 버그 수정
    • 대시보드 생성 시 팀별로 구분된 API 엔드포인트를 사용하여 요청이 전송됩니다.

@LeeCh0129 LeeCh0129 added this to the 2차 구현 기간 milestone Jun 16, 2025
@LeeCh0129 LeeCh0129 self-assigned this Jun 16, 2025
@LeeCh0129 LeeCh0129 added the ✨Feat 기능 개발 label Jun 16, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 16, 2025

Walkthrough

이 변경사항은 Sidebar 컴포넌트가 대시보드 목록을 정적으로 렌더링하던 방식에서 useDashboard 훅을 사용해 동적으로 데이터를 가져와 렌더링하도록 수정합니다. 또한 대시보드 생성 API 요청 URL을 팀 ID에 따라 동적으로 변경하며, useDashboard 훅이 새로 추가되었습니다.

Changes

파일/경로 변경 요약
src/app/shared/components/common/sidebar/Sidebar.tsx Sidebar가 mock 데이터 대신 useDashboard 훅을 사용해 대시보드 목록을 동적으로 렌더링하도록 변경. 로딩, 에러, 빈 목록 상태 처리 추가.
src/app/shared/components/common/sidebar/modal/CreateDashboardModal.tsx 대시보드 생성 API 요청 URL을 팀 ID 환경변수를 반영하여 동적으로 변경. 환경변수 미설정 시 에러 처리 추가.
src/app/shared/hooks/useDashboard.ts 대시보드 목록을 fetch하고 상태를 관리하는 useDashboard 커스텀 훅 신설. 환경변수 체크 및 에러 핸들링 포함.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Sidebar
    participant useDashboard
    participant API

    User->>Sidebar: 컴포넌트 마운트
    Sidebar->>useDashboard: 훅 호출
    useDashboard->>API: GET /{TEAM_ID}/dashboards
    API-->>useDashboard: 대시보드 데이터 반환
    useDashboard-->>Sidebar: 대시보드, 로딩, 에러 상태 전달
    Sidebar->>User: 대시보드 목록, 로딩/에러 메시지 렌더링

    User->>Sidebar: "대시보드 생성" 클릭
    Sidebar->>CreateDashboardModal: 모달 오픈
    User->>CreateDashboardModal: 폼 제출
    CreateDashboardModal->>API: POST /{TEAM_ID}/dashboards
    API-->>CreateDashboardModal: 생성 결과 반환
    CreateDashboardModal->>useDashboard: refetch() 호출
    useDashboard->>API: GET /{TEAM_ID}/dashboards (재요청)
    API-->>useDashboard: 최신 대시보드 데이터 반환
    useDashboard-->>Sidebar: 업데이트된 대시보드 목록 전달
Loading

Suggested reviewers

  • dkslel1225

Poem

🐰
대시보드 목록, 이제는 실시간!
훅을 타고 데이터가 춤추네
팀별로 달라지는 생성 경로
사이드바가 더욱 똑똑해졌죠
토끼도 감탄하는 코드의 변화
오늘도 개발은 신나게 hop hop!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-16T19_59_05_239Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74527cf and f65a301.

📒 Files selected for processing (3)
  • src/app/shared/components/common/sidebar/Sidebar.tsx (3 hunks)
  • src/app/shared/components/common/sidebar/modal/CreateDashboardModal.tsx (1 hunks)
  • src/app/shared/hooks/useDashboard.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/app/shared/components/common/sidebar/modal/CreateDashboardModal.tsx
  • src/app/shared/components/common/sidebar/Sidebar.tsx
  • src/app/shared/hooks/useDashboard.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (3)
src/app/shared/hooks/useDashboard.ts (2)

15-30: fetchDashboardsuseCallback으로 래핑해 참조 안정성 확보

훅의 반환값으로 refetch를 제공하고 있는데, 현재 fetchDashboards는 렌더링마다 새로 생성됩니다.
컨슈머가 useEffect 의존성 배열에 refetch를 넣거나 memoized 컴포넌트에서 사용하면 불필요한 재호출이 발생할 수 있습니다. useCallback으로 래핑해 안정적인 함수 참조를 보장해 주세요.

- const fetchDashboards = async () => {
+ const fetchDashboards = useCallback(async () => {
     ...
- }
+ }, [])

24-27: catch 블록의 오류 타입 안전성 강화

errunknown 타입이므로 바로 로그만 남기면 타입 체커가 경고합니다.
instanceof Error 체크 후 message를 사용하는 것이 안전합니다.

- } catch (err) {
-   console.error('대시보드 목록 조회 실패:', err)
-   setError('대시보드 목록을 불러오는데 실패했습니다.')
+ } catch (err) {
+   console.error('대시보드 목록 조회 실패:', err)
+   const message =
+     err instanceof Error ? err.message : '대시보드 목록을 불러오는데 실패했습니다.'
+   setError(message)
 }
src/app/shared/components/common/sidebar/Sidebar.tsx (1)

53-74: 중첩 삼항 연산자 가독성 저하

로딩/에러/빈 배열/정상 렌더링을 하나의 중첩 삼항으로 처리하면 유지보수가 어려워집니다.
별도 렌더링 함수 또는 early return 패턴으로 분리하면 가독성이 향상됩니다.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f210b1c and 74527cf.

📒 Files selected for processing (3)
  • src/app/shared/components/common/sidebar/Sidebar.tsx (3 hunks)
  • src/app/shared/components/common/sidebar/modal/CreateDashboardModal.tsx (1 hunks)
  • src/app/shared/hooks/useDashboard.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/app/shared/components/common/sidebar/Sidebar.tsx (2)
src/app/shared/hooks/useDashboard.ts (1)
  • useDashboard (8-37)
src/app/shared/components/common/sidebar/DashboardItem.tsx (1)
  • DashboardItem (7-47)
src/app/shared/hooks/useDashboard.ts (1)
src/app/shared/types/dashboard.ts (1)
  • DashboardListResponse (13-17)

Comment on lines +45 to 46
const response = await api.post(`/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards`, formData)

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

팀 ID 환경 변수 누락 시 잘못된 엔드포인트 호출 가능성

NEXT_PUBLIC_TEAM_ID가 정의되지 않은 경우 "/undefined/dashboards"로 POST 요청이 전송됩니다.
API 호출 전 유효성을 점검하여 사용자에게 경고하거나 모달을 닫는 등의 처리가 필요합니다.

- const response = await api.post(`/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards`, formData)
+ if (!process.env.NEXT_PUBLIC_TEAM_ID) {
+   alert('팀 정보가 설정되지 않았습니다.')
+   return
+ }
+ const response = await api.post(
+   `/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards`,
+   formData,
+ )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const response = await api.post(`/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards`, formData)
if (!process.env.NEXT_PUBLIC_TEAM_ID) {
alert('팀 정보가 설정되지 않았습니다.')
return
}
const response = await api.post(
`/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards`,
formData,
)
🤖 Prompt for AI Agents
In src/app/shared/components/common/sidebar/modal/CreateDashboardModal.tsx
around lines 45 to 46, the code uses process.env.NEXT_PUBLIC_TEAM_ID directly in
the API endpoint without checking if it is defined. To fix this, add a
validation step before making the API call to verify that NEXT_PUBLIC_TEAM_ID is
set. If it is undefined, handle the case by showing a user warning or closing
the modal to prevent sending a request to an invalid endpoint.

@LeeCh0129 LeeCh0129 linked an issue Jun 17, 2025 that may be closed by this pull request
2 tasks
Copy link

@Insung-Jo Insung-Jo left a comment

Choose a reason for hiding this comment

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

연동 수고 많으셨습니다! 환경 변수 같은 경우는 추후에 문제가 발생할 수도 있으니 논의를 통해서 통일 하는 게 좋을 거 같네요🤔

@LeeCh0129 LeeCh0129 merged commit add9be2 into develop Jun 17, 2025
2 checks passed
Copy link
Contributor

@yuj2n yuj2n left a comment

Choose a reason for hiding this comment

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

.env 파일 작성 내용 공유해주시면 이후 API 연동 시 그에 맞게 작업할 수 있을 것 같습니다!!

Comment on lines +15 to +41
const fetchDashboards = useCallback(async () => {
try {
setIsLoading(true)
setError(null)

if (!process.env.NEXT_PUBLIC_TEAM_ID) {
throw new Error('NEXT_PUBLIC_TEAM_ID 환경변수가 설정되지 않았습니다.')
}

const response = await api.get<DashboardListResponse>(
`/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards?navigationMethod=infiniteScroll`,
)
setDashboards(response.data.dashboards)
} catch (err) {
console.error('대시보드 목록 조회 실패:', err)
setError('대시보드 목록을 불러오는데 실패했습니다.')
} finally {
setIsLoading(false)
}
}, [])

useEffect(() => {
fetchDashboards()
}, [fetchDashboards])

return { dashboards, isLoading, error, refetch: fetchDashboards }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

여기서 환경변수 설정 여부를 파악하고 대시보드 목록을 조회해오는 구조군용!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨Feat 기능 개발

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Feat: 사이드바 대시보드 목록 API 연동

4 participants