Skip to content

Commit aa6fd98

Browse files
authored
Merge pull request #118 from hyeonjiroh/feat/#112/mydashboard-page
feat: #112/나의 대시보드 페이지 내 대시보드 목록
2 parents b482dff + deb5201 commit aa6fd98

File tree

4 files changed

+103
-30
lines changed

4 files changed

+103
-30
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useModalStore } from "@/lib/store/useModalStore";
2+
import Button from "@/components/common/button/Button";
3+
import Image from "next/image";
4+
import AddIcon from "../../../../../public/icon/add_icon.svg";
5+
6+
export default function AddDashboardButton() {
7+
const { openModal } = useModalStore();
8+
9+
return (
10+
<Button
11+
variant="whiteGray"
12+
onClick={() => openModal("createDashboard")}
13+
className="flex gap-3 w-full min-h-[58px] rounded-lg tablet:h-[68px] pc:h-[70px]"
14+
>
15+
<div className="font-semibold text-md text-gray-800 tablet:text-lg">
16+
새로운 대시보드
17+
</div>
18+
<Image
19+
src={AddIcon}
20+
className="w-[20px] h-[20px] tablet:w-[22px] tablet:h-[22px]"
21+
alt=""
22+
/>
23+
</Button>
24+
);
25+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useRouter } from "next/navigation";
2+
import Button from "@/components/common/button/Button";
3+
import Image from "next/image";
4+
import CrownIcon from "../../../../../public/icon/crown_icon.svg";
5+
import ArrowIcon from "../../../../../public/icon/arrow_right_icon.svg";
6+
7+
export default function DashboardCard({
8+
id,
9+
title,
10+
color,
11+
createdByMe,
12+
}: {
13+
id: number;
14+
title: string;
15+
color: string;
16+
createdByMe: boolean;
17+
}) {
18+
const router = useRouter();
19+
20+
return (
21+
<Button
22+
variant="whiteGray"
23+
onClick={() => {
24+
router.push(`/dashboard/${id}`);
25+
}}
26+
className="flex justify-between items-center gap-3 w-full min-h-[58px] px-5 rounded-lg tablet:h-[68px] pc:h-[70px]"
27+
>
28+
<div className="flex gap-3 pc:gap-4">
29+
<div className="flex items-center">
30+
<div
31+
style={{ background: color }}
32+
className="w-2 h-2 rounded-full"
33+
></div>
34+
</div>
35+
<div className="flex items-center gap-1 overflow-hidden tablet:gap-[6px] pc:gap-2">
36+
<div className="font-semibold text-md text-gray-800 truncate tablet:text-lg">
37+
{title}
38+
</div>
39+
{createdByMe && (
40+
<Image
41+
src={CrownIcon}
42+
className="w-[15px] h-3 tablet:w-[18px] tablet:h-[14px] pc:w-5 pc:h-4"
43+
alt=""
44+
/>
45+
)}
46+
</div>
47+
</div>
48+
<Image src={ArrowIcon} width={18} height={18} alt="" />
49+
</Button>
50+
);
51+
}

src/app/(after-login)/mydashboard/_components/DashboardListSection.tsx

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { useEffect, useState } from "react";
44
import { fetchDashboardList } from "@/lib/apis/dashboardsApi";
55
import { DashboardList } from "@/lib/types";
66
import Pagination from "@/components/common/pagination-button/PaginationButton";
7+
import AddDashboardButton from "./AddDashboardButton";
8+
import DashboardCard from "./DashboardCard";
79

8-
const PAGE_SIZE = 6;
10+
const PAGE_SIZE = 5;
911

1012
export default function DashboardListSection({ token }: { token: string }) {
1113
const [myDashboards, setMyDashboards] = useState<DashboardList[]>([]);
1214
const [page, setPage] = useState(1);
13-
const [totalPages, setTotalPages] = useState(1);
15+
const [totalPages, setTotalPages] = useState(0);
1416
const [loading, setLoading] = useState(false);
1517

1618
useEffect(() => {
@@ -19,16 +21,16 @@ export default function DashboardListSection({ token }: { token: string }) {
1921
try {
2022
const {
2123
dashboards,
22-
total,
23-
}: { dashboards: DashboardList[]; total: number } =
24+
totalCount,
25+
}: { dashboards: DashboardList[]; totalCount: number } =
2426
await fetchDashboardList({
2527
token,
2628
page,
2729
size: PAGE_SIZE,
2830
});
2931

3032
setMyDashboards(dashboards.filter((d) => d.createdByMe));
31-
setTotalPages(Math.ceil(total / PAGE_SIZE));
33+
setTotalPages(Math.floor(totalCount / 6));
3234
} catch (error) {
3335
console.error("대시보드를 불러오는 중 오류 발생:", error);
3436
} finally {
@@ -39,36 +41,30 @@ export default function DashboardListSection({ token }: { token: string }) {
3941
}, [page, token]);
4042

4143
return (
42-
<div className="max-w-[1022px]">
43-
<button className="px-4 py-2 bg-blue-500 text-white rounded-lg flex items-center">
44-
새로운 대시보드 +
45-
</button>
46-
47-
<div>
48-
<h2 className="text-lg font-semibold">내 대시보드</h2>
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-
!loading && (
59-
<div className="p-6 bg-gray-100 text-center rounded-lg">
60-
<p className="text-gray-500">아직 생성한 대시보드가 없어요.</p>
61-
</div>
62-
)
63-
)}
44+
<div className="flex flex-col max-w-[1022px] gap-4 pc:gap-3">
45+
<div className="grid grid-cols-1 gap-2 items-stretch tablet:grid-cols-2 tablet:gap-[10px] pc:grid-cols-3 pc:gap-3">
46+
<AddDashboardButton />
47+
{myDashboards.map((dashboard) => (
48+
<DashboardCard
49+
key={dashboard.id}
50+
id={dashboard.id}
51+
title={dashboard.title}
52+
color={dashboard.color}
53+
createdByMe={dashboard.createdByMe}
54+
/>
55+
))}
6456

6557
{loading && (
6658
<div className="flex justify-center mt-4">
67-
<div className="w-6 h-6 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"></div>
59+
<div className="w-6 h-6 border-4 border-gray-500 border-t-transparent rounded-full animate-spin"></div>
6860
</div>
6961
)}
70-
71-
<div className="flex justify-center mt-4">
62+
</div>
63+
<div className="flex justify-end">
64+
<div className="flex items-center gap-3 tablet:gap-4">
65+
<p className="font-normal text-xs text-gray-800 tablet:text-md">
66+
{totalPages} 페이지 중 {page}
67+
</p>
7268
<Pagination
7369
currentPage={page}
7470
totalPages={totalPages}

src/components/common/pagination-button/PaginationButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const PaginationButton = ({
4141
"w-10 h-10 flex items-center justify-center",
4242
"border border-[#d9d9d9]",
4343
"rounded-[4px]",
44+
"bg-white",
4445
!props.disabled && [
4546
"transition-colors",
4647
"hover:bg-gray-50 hover:border-gray-400",

0 commit comments

Comments
 (0)