Skip to content

Conversation

@yuj2n
Copy link
Contributor

@yuj2n yuj2n commented Jun 17, 2025

📌 변경 사항 개요

토스트 세팅 및 추상화

✨ 요약

토스트 세팅 및 추상화

📝 상세 내용

Toaster 컴포넌트 속성 설명

옵션 설명
position "top-right" 등 원하는 위치 설정 가능
richColors 예쁜 색상 테마 적용
closeButton 토스트에 닫기 버튼 표시

토스트 적용 및 사용

import { showSuccess, showError } from '@/lib/toast';
import { useMutation } from '@tanstack/react-query';

const { mutate } = useMutation({
  mutationFn: () => axios.post('/api/vote'),
  onSuccess: () => {
    showSuccess('투표가 완료되었습니다!');
  },
  onError: () => {
    showError('투표에 실패했습니다. 다시 시도해주세요.');
  },
});
  • 추가적인 사용(react-hook-form의 onSubmit 내부에서 토스트 사용)
const onSubmit = (data) => {
  try {
    // ...API 호출
    showSuccess('저장이 완료되었습니다!');
  } catch (e) {
    showError('저장 중 오류가 발생했습니다.');
  }
};

부가적인 사항

  • 사이드 바 너비만큼 헤더와 내부 요소에 pl-300을 주는 것이 좋을 것 같아 스타일 수정하였습니다!
  • 토스트의 경우 sonner로 간단하게 app/layout 쪽에 전체 적용해두어서 사용하는 곳에서 toast.ts만 불러와서 타입(성공, 실패, 정보)만 정해주시면 사용 가능합니다
  • 토스트 디자인은 추후 시간이 남으면 수정하도록 하겠습니당
  • 화면 이동하여도 토스트가 사라지지 않고 남아있어 사용자 UX에 피해가 가지 않을 것 같습니당 : )

🔗 관련 이슈

🖼️ 스크린샷

20250617_135949.mp4

✅ 체크리스트

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

💡 참고 사항

Summary by CodeRabbit

  • New Features
    • 성공, 에러, 정보성 토스트 알림 기능이 추가되었습니다. 버튼 클릭 시 알림이 표시됩니다.
  • Style
    • 헤더와 레이아웃의 패딩 및 구조가 일부 조정되어 화면 배치가 개선되었습니다.
  • Chores
    • 사용하지 않는 테마 토글 컴포넌트가 제거되었습니다.

@yuj2n yuj2n added this to the 2차 구현 기간 milestone Jun 17, 2025
@yuj2n yuj2n self-assigned this Jun 17, 2025
@yuj2n yuj2n added the ✨Feat 기능 개발 label Jun 17, 2025
@yuj2n yuj2n linked an issue Jun 17, 2025 that may be closed by this pull request
2 tasks
@coderabbitai
Copy link

coderabbitai bot commented Jun 17, 2025

Walkthrough

레이아웃 및 대시보드 수정 페이지에 토스트 알림 기능이 추가되었습니다. 레이아웃 구조가 일부 변경되고, 토스트 유틸리티 모듈이 새로 도입되었습니다. 또한, 헤더 컴포넌트의 패딩이 조정되었습니다.

Changes

파일/경로 변경 요약
src/app/dashboard/[id]/edit/layout.tsx 외부 <div>를 React fragment로 변경, Header와 children을 별도 div 및 main으로 구조 변경
src/app/dashboard/[id]/edit/page.tsx 기본 컴포넌트를 토스트 버튼 및 핸들러가 포함된 클라이언트 컴포넌트로 교체
src/app/layout.tsx Toaster 컴포넌트 추가, ThemeToggle import 제거
src/app/shared/components/common/header/Header.tsx 헤더 컨테이너의 왼쪽 패딩(pl-300) 제거
src/app/shared/lib/toast.ts showSuccess, showError, showInfo 토스트 함수 추가

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DashBoardEditPage
    participant toast.ts (유틸리티)
    participant Toaster

    User->>DashBoardEditPage: "성공 토스트" 버튼 클릭
    DashBoardEditPage->>toast.ts: showSuccess("대시보드가 성공적으로 저장되었습니다.")
    toast.ts->>Toaster: 성공 토스트 표시

    User->>DashBoardEditPage: "에러 토스트" 버튼 클릭
    DashBoardEditPage->>toast.ts: showError("저장 중 오류가 발생했습니다.")
    toast.ts->>Toaster: 에러 토스트 표시
Loading

Possibly related PRs

  • ✨Feat: 공동 사용자 프로필 구현 #51: 같은 파일(src/app/dashboard/[id]/edit/layout.tsx)의 AboutLayout 컴포넌트 레이아웃 구조를 변경하는 PR로, 본 PR과 직접적인 코드 레벨의 연관성이 높음.

Suggested labels

💄Modify

Suggested reviewers

  • Insung-Jo

Poem

🐇
토스트가 번쩍, 버튼이 딸깍
대시보드 수정, 레이아웃도 착착
성공과 에러, 알림이 반짝
헤더는 더 깔끔, 코드는 더 산뜻
오늘도 토끼는 기쁘게 깡총!

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-17T05_10_51_908Z-debug-0.log

✨ 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.

@yuj2n yuj2n changed the base branch from main to develop June 17, 2025 05:05
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: 0

🧹 Nitpick comments (4)
src/app/shared/lib/toast.ts (1)

3-5: API 확장성을 위해 제네릭 매개변수‧옵션 수용 형태로 리팩터링 제안

현재 문자열만 받도록 제한돼 있어 커스텀 JSX, 아이콘, duration 등 추가 옵션을 지정하기 어렵습니다. sonnerReactNode와 옵션 객체를 모두 지원하므로, 아래처럼 타입을 확장해 두면 재사용성이 높아집니다.

-import { toast } from 'sonner'
-
-export const showSuccess = (message: string) => toast.success(message)
-export const showError = (message: string) => toast.error(message)
-export const showInfo = (message: string) => toast.message(message) // 성공, 실패가 아닌 정보
+import { toast, type ToastOptions, type RichToastContent } from 'sonner'
+
+type Content = RichToastContent | string
+type Options = ToastOptions
+
+export const showSuccess = (message: Content, options?: Options) =>
+  toast.success(message, options)
+export const showError = (message: Content, options?: Options) =>
+  toast.error(message, options)
+export const showInfo = (message: Content, options?: Options) =>
+  toast.message(message, options) // 성공·실패가 아닌 일반 정보
src/app/dashboard/[id]/edit/layout.tsx (1)

13-16: 중첩 레이아웃에서 <main> 요소 중복 사용 주의

최상위 페이지에서도 <main>이 사용될 가능성이 있으므로, HTML 문서 내에 <main>이 2개 이상 생기지 않는지 점검해 주세요. 필요하다면 section이나 별도 래퍼로 대체하는 것이 접근성 측면에서 안전합니다.

src/app/dashboard/[id]/edit/page.tsx (2)

6-13: 핸들러를 useCallback으로 래핑해 불필요한 재생성 방지

렌더링마다 새 함수가 만들어져 하위 컴포넌트에 프롭으로 전달될 때 불필요한 리렌더를 유발할 수 있습니다.

-import { showError, showSuccess } from '@lib/toast'
+import React, { useCallback } from 'react'
+import { showError, showSuccess } from '@lib/toast'

-  const handleSuccess = () => {
-    showSuccess('대시보드가 성공적으로 저장되었습니다.')
-  }
-  const handleError = () => {
-    showError('저장 중 오류가 발생했습니다.')
-  }
+  const handleSuccess = useCallback(() => {
+    showSuccess('대시보드가 성공적으로 저장되었습니다.')
+  }, [])
+
+  const handleError = useCallback(() => {
+    showError('저장 중 오류가 발생했습니다.')
+  }, [])

18-21: <button>type="button"을 명시해 폼 내부 오동작 방지

추후 이 버튼들이 <form> 안으로 이동할 경우, 기본 submit 이벤트로 인해 예기치 않은 페이지 새로고침이 발생할 수 있습니다.

-        <button onClick={handleSuccess}>성공 토스트</button>
-        <button onClick={handleError}>에러 토스트</button>
+        <button type="button" onClick={handleSuccess}>성공 토스트</button>
+        <button type="button" onClick={handleError}>에러 토스트</button>
📜 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 d3e054f.

📒 Files selected for processing (5)
  • src/app/dashboard/[id]/edit/layout.tsx (1 hunks)
  • src/app/dashboard/[id]/edit/page.tsx (1 hunks)
  • src/app/layout.tsx (2 hunks)
  • src/app/shared/components/common/header/Header.tsx (1 hunks)
  • src/app/shared/lib/toast.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/app/layout.tsx (1)
src/app/providers.tsx (1)
  • Providers (7-21)
src/app/dashboard/[id]/edit/page.tsx (1)
src/app/shared/lib/toast.ts (2)
  • showSuccess (3-3)
  • showError (4-4)
🔇 Additional comments (2)
src/app/shared/components/common/header/Header.tsx (1)

17-17: 좌측 패딩 제거로 인한 레이아웃 영향 점검 필요

pl-300을 Header에서 제거했으므로, Header를 단독으로 사용하는 다른 화면이 있다면 콘텐츠가 사이드바와 겹치지 않는지 한번 더 확인해 주세요.

src/app/layout.tsx (1)

24-27: Server Component 내부에서 Toaster 사용 시 Hydration 문제 여부 확인

RootLayout은 서버 컴포넌트이지만, Toaster는 훅을 사용하는 클라이언트 컴포넌트입니다. 현재 Providers'use client' 이므로 하위에 배치해도 문제없어야 하나, 실제 빌드/SSR 단계에서 “Hooks can’t be used in a Server Component” 경고가 발생하지 않는지 한번 더 빌드 로그를 확인해 주세요.

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.

토스트 세팅 수고 많으셨습니다! 👍 👍

Copy link
Contributor

@dkslel1225 dkslel1225 left a comment

Choose a reason for hiding this comment

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

토스트 세팅 수고하셨어요! 사용법 설명 감사합니당

Copy link

@LeeCh0129 LeeCh0129 left a comment

Choose a reason for hiding this comment

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

토스트 세팅 고생하셨어요~👍👍

@yuj2n yuj2n merged commit b40a8e9 into develop Jun 17, 2025
2 checks passed
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: 토스트 세팅 및 추상화

5 participants