Skip to content

Commit 99b6de6

Browse files
authored
Merge pull request #113 from hyeonjiroh/feat/#112/mydashboard-page
refactor: #112/나의 대시보드 페이지 컴포넌트 분리
2 parents 0ba049d + 5b9d468 commit 99b6de6

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import { cookies } from "next/headers";
2+
import DashboardListSection from "./_components/DashboardListSection";
3+
import InvitationSection from "./_components/InvitationSection";
4+
15
export 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
}

0 commit comments

Comments
 (0)