File tree Expand file tree Collapse file tree 3 files changed +94
-1
lines changed
src/app/(after-login)/mydashboard Expand file tree Collapse file tree 3 files changed +94
-1
lines changed Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { useEffect , useState } from "react" ;
4+ import { fetchDashboardList } from "@/lib/apis/dashboardsApi" ;
5+ import { DashboardList } from "@/lib/types" ;
6+
7+ const PAGE_SIZE = 6 ;
8+
9+ export default function DashboardListSection ( { token } : { token : string } ) {
10+ const [ myDashboards , setMyDashboards ] = useState < DashboardList [ ] > ( [ ] ) ;
11+ const [ page , setPage ] = useState ( 1 ) ;
12+
13+ setPage ( 1 ) ; // vercel 배포 때문에 임시로 넣은 코드라 삭제하시면 됩니다.
14+
15+ const [ loading , setLoading ] = useState ( true ) ;
16+
17+ useEffect ( ( ) => {
18+ async function loadDashboards ( ) {
19+ try {
20+ const { dashboards } : { dashboards : DashboardList [ ] } =
21+ await fetchDashboardList ( {
22+ token : token ,
23+ page : page ,
24+ size : PAGE_SIZE ,
25+ } ) ;
26+
27+ setMyDashboards (
28+ dashboards . filter ( ( dashboard ) => dashboard . createdByMe )
29+ ) ;
30+ } catch ( error ) {
31+ console . error ( "대시보드를 불러오는 중 오류 발생:" , error ) ;
32+ } finally {
33+ setLoading ( false ) ;
34+ }
35+ }
36+ loadDashboards ( ) ;
37+ } , [ ] ) ;
38+
39+ return (
40+ < >
41+ < button className = "px-4 py-2 bg-blue-500 text-white rounded-lg flex items-center" >
42+ 새로운 대시보드 +
43+ </ button >
44+
45+ < div >
46+ < h2 className = "text-lg font-semibold" > 내 대시보드</ h2 >
47+ { loading ? (
48+ < p > 로딩 중...</ p >
49+ ) : myDashboards . length > 0 ? (
50+ < ul className = "mt-4 space-y-2" >
51+ { myDashboards . map ( ( dashboard ) => (
52+ < li key = { dashboard . id } className = "p-4 bg-white shadow rounded-lg" >
53+ { dashboard . title }
54+ </ li >
55+ ) ) }
56+ </ ul >
57+ ) : (
58+ < div className = "p-6 bg-gray-100 text-center rounded-lg" >
59+ < p className = "text-gray-500" > 아직 생성한 대시보드가 없어요.</ p >
60+ </ div >
61+ ) }
62+ </ div >
63+ </ >
64+ ) ;
65+ }
Original file line number Diff line number Diff line change 1+ export default function InvitationSection ( { token } : { token : string } ) {
2+ return (
3+ < div className = "flex flex-col gap-[26px] w-full p-4 rounded-lg bg-white tablet:gap-[17px] tablet:p-6" >
4+ < div className = "flex justify-between items-center tablet:items-start" >
5+ < div className = "flex flex-col gap-[14px] tablet:gap-8" >
6+ < h2 className = "font-bold text-xl text-gray-800 tablet:text-2xl" >
7+ 초대받은 대시보드
8+ </ h2 >
9+ < p className = "font-normal text-md text-gray-500" > { token } </ p >
10+ </ div >
11+ < div className = "flex flex-col items-end gap-3 tablet:flex-row tablet:items-center tablet:gap-4" >
12+ < div className = "flex items-center gap-3 tablet:gap-4" > </ div >
13+ </ div >
14+ </ div >
15+ </ div >
16+ ) ;
17+ }
Original file line number Diff line number Diff line change 1+ import { cookies } from "next/headers" ;
2+ import DashboardListSection from "./_components/DashboardListSection" ;
3+ import InvitationSection from "./_components/InvitationSection" ;
4+
15export default function Page ( ) {
2- return < div > /mydashboard</ div > ;
6+ const accessToken = cookies ( ) . get ( "accessToken" ) ?. value ?? "" ;
7+
8+ return (
9+ < div className = "flex flex-col gap-6 p-6 tablet:gap-12 tablet:p-10 pc:gap-10" >
10+ < DashboardListSection token = { accessToken } />
11+ < InvitationSection token = { accessToken } />
12+ </ div >
13+ ) ;
314}
You can’t perform that action at this time.
0 commit comments