1- import React , { useState } from "react" ;
1+ import React , { useEffect , useState } from "react" ;
22import SideMenu from "@/components/sideMenu/SideMenu" ;
33import HeaderDashboard from "@/components/gnb/HeaderDashboard" ;
44import InvitedDashBoard from "@/components/table/invited/InvitedDashBoard" ;
5- import type { Dashboard } from "@/components/sideMenu/dashboard" ;
6- import DashboardAddButton from "@/components/button/DashboardAddButton" ;
75import CardButton from "@/components/button/CardButton" ;
86import { PaginationBtn } from "@/components/button/PaginationBtn" ;
7+ import NewDashboard from "@/components/modal/NewDashboard" ;
8+ import DashboardAddButton from "@/components/button/DashboardAddButton" ;
9+ import { getDashboards } from "@/api/dashboard" ;
10+ import { useRouter } from "next/router" ;
11+
12+ interface Dashboard {
13+ id : number ;
14+ title : string ;
15+ color : string ;
16+ userId : number ;
17+ createdAt : string ;
18+ updatedAt : string ;
19+ createdByMe : boolean ;
20+ }
921
1022export default function MyDashboardPage ( ) {
11- const teamId = "13" ;
12- const [ dashCards , setDashCards ] = useState < string [ ] > ( [ ] ) ;
23+ const teamId = "13-4" ;
24+ const router = useRouter ( ) ;
25+ const [ dashboardList , setDashboardList ] = useState < Dashboard [ ] > ( [ ] ) ;
1326 const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
27+ const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
1428 const itemsPerPage = 6 ;
1529
16- const handleAddDashboard = ( ) => {
17- const newTitle = `대시보드 ${ dashCards . length } ` ;
18- setDashCards ( ( prev ) => [ ...prev , newTitle ] ) ;
19- } ;
20-
21- const totalPages = Math . ceil ( ( dashCards . length + 1 ) / itemsPerPage ) ;
30+ const totalPages = Math . ceil ( ( dashboardList . length + 1 ) / itemsPerPage ) ; // +1 for the add button
2231 const startIndex = ( currentPage - 1 ) * itemsPerPage ;
32+
2333 const currentItems = [
24- < DashboardAddButton key = "add" onClick = { handleAddDashboard } /> ,
25- ...dashCards . map ( ( title , index ) => (
26- < CardButton key = { index } > { title } </ CardButton >
34+ < DashboardAddButton key = "add" onClick = { ( ) => setIsModalOpen ( true ) } /> ,
35+ ...dashboardList . map ( ( dashboard ) => (
36+ < CardButton
37+ key = { dashboard . id }
38+ title = { dashboard . title }
39+ showCrown = { dashboard . createdByMe }
40+ color = { dashboard . color }
41+ onClick = { ( ) => router . push ( `/dashboard/${ dashboard . id } ` ) }
42+ />
2743 ) ) ,
2844 ] . slice ( startIndex , startIndex + itemsPerPage ) ;
2945
46+ const fetchDashboards = async ( ) => {
47+ try {
48+ const res = await getDashboards ( { teamId } ) ;
49+ setDashboardList ( res . dashboards ) ;
50+ } catch ( error ) {
51+ console . error ( "대시보드 불러오기 실패:" , error ) ;
52+ }
53+ } ;
54+
55+ useEffect ( ( ) => {
56+ fetchDashboards ( ) ;
57+ } , [ teamId ] ) ;
58+
3059 const handlePrevPage = ( ) => {
3160 if ( currentPage > 1 ) setCurrentPage ( ( prev ) => prev - 1 ) ;
3261 } ;
@@ -37,12 +66,12 @@ export default function MyDashboardPage() {
3766
3867 return (
3968 < div className = "flex h-screen overflow-hidden" >
40- < SideMenu teamId = "13-4" />
69+ < SideMenu teamId = { teamId } dashboardList = { dashboardList } />
4170
4271 < div className = "flex flex-col flex-1 overflow-hidden" >
4372 < HeaderDashboard />
4473
45- < main className = "flex-1 overflow-auto px-[80px ] pt-[40px] pb-10 bg-[#f9f9f9] space-y-10" >
74+ < main className = "flex-1 overflow-auto px-[25px ] pt-[40px] pb-10 bg-[#f9f9f9] space-y-10" >
4675 { /* 대시보드 카드 + 페이지네이션 */ }
4776 < section className = "flex flex-col items-start space-y-6" >
4877 < div className = "flex flex-wrap gap-x-[20px] gap-y-[16px] w-full max-w-[1100px]" >
@@ -73,6 +102,16 @@ export default function MyDashboardPage() {
73102 </ div >
74103 </ main >
75104 </ div >
105+
106+ { /* 새로운 대시보드 모달 */ }
107+ { isModalOpen && (
108+ < NewDashboard
109+ onClose = { ( ) => {
110+ setIsModalOpen ( false ) ;
111+ fetchDashboards ( ) ; // 생성 후 목록 새로고침
112+ } }
113+ />
114+ ) }
76115 </ div >
77116 ) ;
78117}
0 commit comments