-
Notifications
You must be signed in to change notification settings - Fork 2
✨feat: 헤더 API 연동 #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨feat: 헤더 API 연동 #85
Changes from all commits
7018c31
87fab0b
63061c7
84dcc8f
6bff947
4286ed6
828abf9
ef28cc5
050f912
761fc98
208a9e9
014c115
e820949
eb6dd9d
c39a3d2
e820e39
f226e67
f0ed638
d4cffcc
aab7719
c054e68
11d99f5
898d8e6
423b098
fdbef31
9f1433c
c801675
c2ee79a
ce774d3
7a3d269
61ee4ec
d859068
694e306
be57a9c
27487fb
c3067b8
7eaea05
2a1c7e4
18cacdf
861ed90
89584e9
2081282
322800a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,11 @@ | ||
| import Header from '@components/common/header/Header' | ||
|
|
||
| import Sidebar from '@/app/shared/components/common/sidebar/Sidebar' | ||
|
|
||
| export default function AboutLayout({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode | ||
| }) { | ||
| return ( | ||
| <> | ||
| <Sidebar /> | ||
| <div className="pl-300"> | ||
| <Header /> | ||
| <main>{children}</main> | ||
| </div> | ||
| </> | ||
| <div> | ||
| <main>{children}</main> | ||
| </div> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // src/app/features/dashboard/api/invitation.ts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import api from '@lib/axios' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type InvitationRequest = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| email: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dashboardId: number | string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const inviteUser = async ({ email, dashboardId }: InvitationRequest) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await api.post( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards/${dashboardId}/invitations`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| email, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return response.data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 에러 핸들링과 환경 변수 검증을 추가하세요. API 함수에 다음 개선사항을 적용하는 것을 권장합니다:
+type InvitationResponse = {
+ // API 응답 구조에 맞게 정의
+ success: boolean
+ message?: string
+}
+
-export const inviteUser = async ({ email, dashboardId }: InvitationRequest) => {
+export const inviteUser = async ({ email, dashboardId }: InvitationRequest): Promise<InvitationResponse> => {
+ if (!process.env.NEXT_PUBLIC_TEAM_ID) {
+ throw new Error('NEXT_PUBLIC_TEAM_ID 환경 변수가 설정되지 않았습니다.')
+ }
+
+ try {
const response = await api.post(
`/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards/${dashboardId}/invitations`,
{
email,
},
)
return response.data
+ } catch (error) {
+ console.error('사용자 초대 중 오류 발생:', error)
+ throw error
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| 'use client' | ||
|
|
||
| import api from '@lib/axios' | ||
| import axios from 'axios' | ||
| import { useRouter } from 'next/navigation' | ||
| import React, { useState } from 'react' | ||
|
|
||
| type DeleteDashboardButtonProps = { | ||
| dashboardId: string | ||
| } | ||
|
|
||
| export default function DeleteDashboardButton({ | ||
| dashboardId, | ||
| }: DeleteDashboardButtonProps) { | ||
| const router = useRouter() | ||
| const [isDeleting, setIsDeleting] = useState(false) | ||
|
|
||
| console.log('DeleteDashboardButton 렌더됨:', dashboardId) | ||
|
|
||
| const handleDelete = async () => { | ||
| const confirmed = confirm( | ||
| '정말로 이 대시보드를 삭제하시겠습니까? 삭제 후 되돌릴 수 없습니다.', | ||
| ) | ||
|
|
||
| if (!confirmed) return | ||
|
|
||
| try { | ||
| setIsDeleting(true) | ||
|
|
||
| if (!process.env.NEXT_PUBLIC_TEAM_ID) { | ||
| throw new Error('NEXT_PUBLIC_TEAM_ID 환경변수가 설정되지 않았습니다.') | ||
| } | ||
|
|
||
| await api.delete( | ||
| `/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards/${dashboardId}`, | ||
| ) | ||
|
|
||
| // 삭제 후 대시보드 목록 페이지로 이동 | ||
| router.push('/dashboard') | ||
| } catch (error: unknown) { | ||
| if (axios.isAxiosError(error)) { | ||
| const message = | ||
| error.response?.data?.message || | ||
| '대시보드 삭제 중 오류가 발생했습니다.' | ||
| console.error('대시보드 삭제 오류:', message) | ||
| alert(message) // 또는 showError(message) 등으로 사용자에게 표시 | ||
| } else { | ||
| console.error('대시보드 삭제 오류:', error) | ||
| alert('알 수 없는 오류가 발생했습니다.') | ||
| } | ||
| } finally { | ||
| setIsDeleting(false) | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <button | ||
| onClick={handleDelete} | ||
| disabled={isDeleting} | ||
| className={`Text-black my-8 rounded-8 font-semibold transition-opacity ${ | ||
| isDeleting ? 'cursor-not-allowed opacity-50' : 'hover:opacity-90' | ||
| }`} | ||
| > | ||
| 대시보드 삭제하기 | ||
| </button> | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
에러 처리 추가를 고려해보세요.
API 함수가 잘 구조화되어 있지만, 에러 핸들링이 누락되어 있습니다. try-catch 블록이나 상위 레벨에서의 에러 처리 방식을 고려해보세요.
export const inviteUser = async ({ email, dashboardId }: InvitationRequest) => { + try { const response = await api.post( `/${process.env.NEXT_PUBLIC_TEAM_ID}/dashboards/${dashboardId}/invitations`, { email, }, ) return response.data + } catch (error) { + console.error('Failed to invite user:', error) + throw error + } }📝 Committable suggestion
🤖 Prompt for AI Agents