Skip to content

Commit 47eb285

Browse files
authored
Merge pull request #129 from rover1523/mypage
[Fix] mypage: SideMenu 수정, 대시보드에서 카드 클릭시 모달창 나오게 설정
2 parents 06d03c0 + 26ae42f commit 47eb285

File tree

7 files changed

+75
-66
lines changed

7 files changed

+75
-66
lines changed

src/api/card.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axiosInstance from "./axiosInstance";
2-
import type { CardType } from "@/types/cards"; // Dashboard 타입 import
2+
import type { CardDetailType } from "@/types/cards"; // Dashboard 타입 import
33
import { apiRoutes } from "@/api/apiRoutes";
44

55
/** 1. 카드 이미지 업로드 */
@@ -114,34 +114,13 @@ export const updateCard = async ({
114114
return response.data;
115115
};
116116

117-
// 카드 목록 조회
118-
export const getCardsByColumn = async ({
119-
columnId,
120-
cursorId,
121-
size = 10,
122-
}: {
123-
columnId: number;
124-
cursorId?: number;
125-
size?: number;
126-
}) => {
127-
const res = await axiosInstance.get(apiRoutes.cards(), {
128-
params: {
129-
columnId,
130-
cursorId,
131-
size,
132-
},
133-
});
134-
135-
return res.data;
136-
};
137-
138-
// 카드 상세 조회
139-
export async function getCardDetail(cardId: number): Promise<CardType> {
117+
//카드조회
118+
export async function getCardDetail(cardId: number): Promise<CardDetailType> {
140119
try {
141120
// apiRoutes를 사용하여 URL 동적 생성
142121
const url = apiRoutes.cardDetail(cardId);
143122
const response = await axiosInstance.get(url);
144-
return response.data as CardType;
123+
return response.data as CardDetailType;
145124
} catch (error) {
146125
console.error("대시보드 데이터를 불러오는 데 실패했습니다.", error);
147126
throw error;

src/components/columnCard/Column.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useState } from "react";
22
import Image from "next/image";
33
import { CardType } from "@/types/task";
4+
import { CardDetailType } from "@/types/cards";
45
import Card from "./Card";
56
import TodoModal from "@/components/modalInput/ToDoModal";
67
import TodoButton from "@/components/button/TodoButton";
@@ -9,6 +10,7 @@ import ColumnDeleteModal from "@/components/columnCard/ColumnDeleteModal";
910
import { updateColumn, deleteColumn } from "@/api/columns";
1011
import { getDashboardMembers } from "@/api/card";
1112
import { MemberType } from "@/types/users";
13+
import CardDetailModal from "../modalDashboard/CardDetailModal";
1214
import { TEAM_ID } from "@/constants/team";
1315

1416
type ColumnProps = {
@@ -31,8 +33,12 @@ export default function Column({
3133
const [members, setMembers] = useState<
3234
{ id: number; userId: number; nickname: string }[]
3335
>([]);
36+
const [selectedCard, setSelectedCard] = useState<CardDetailType | null>(null);
37+
38+
const handleCloseDetailModal = () => {
39+
setSelectedCard(null);
40+
};
3441

35-
// ✅ 멤버 불러오기
3642
useEffect(() => {
3743
const fetchMembers = async () => {
3844
try {
@@ -125,12 +131,35 @@ export default function Column({
125131
typeof window !== "undefined" && window.innerWidth < 768;
126132
if (isMobile && index > 0) return null;
127133
return (
128-
<Card
134+
<div
129135
key={task.id}
130-
{...task}
131-
imageUrl={task.imageUrl}
132-
assignee={task.assignee}
133-
/>
136+
onClick={() =>
137+
setSelectedCard({
138+
id: task.id,
139+
title: task.title,
140+
tags: task.tags,
141+
dueDate: task.dueDate,
142+
assignee: {
143+
...task.assignee,
144+
profileImageUrl: task.assignee.profileImageUrl ?? "",
145+
},
146+
imageUrl: task.imageUrl ?? null,
147+
description: task.description ?? "",
148+
columnId: task.columnId,
149+
dashboardId: task.dashboardId,
150+
status: columnTitle,
151+
createdAt: new Date().toISOString(),
152+
updatedAt: new Date().toISOString(),
153+
})
154+
}
155+
>
156+
<Card
157+
key={task.id}
158+
{...task}
159+
imageUrl={task.imageUrl}
160+
assignee={task.assignee}
161+
/>
162+
</div>
134163
);
135164
})}
136165
</div>
@@ -166,6 +195,14 @@ export default function Column({
166195
onClose={() => setIsDeleteModalOpen(false)}
167196
onDelete={handleDeleteColumn}
168197
/>
198+
{selectedCard && (
199+
<CardDetailModal
200+
card={selectedCard}
201+
onClose={handleCloseDetailModal}
202+
currentUserId={selectedCard.assignee.id}
203+
dashboardId={dashboardId}
204+
/>
205+
)}
169206
</div>
170207
);
171208
}

src/components/modalDashboard/CardDetail.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Image from "next/image";
2-
import { CardType } from "@/types/cards";
2+
import { CardDetailType } from "@/types/cards";
33
import { ProfileIcon } from "./profelicon";
44

55
interface CardDetailProps {
6-
card: CardType;
6+
card: CardDetailType;
77
columnName: string;
88
}
99

src/components/modalDashboard/CardDetailModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import CardInput from "@/components/modalInput/CardInput";
66
import { useMutation, useQueryClient } from "@tanstack/react-query";
77
import { createComment } from "@/api/comment";
88
import { deleteCard } from "@/api/card";
9-
import type { CardType } from "@/types/cards";
9+
import type { CardDetailType } from "@/types/cards";
1010
import TaskModal from "@/components/modalInput/TaskModal"; // 경로는 실제 위치에 맞게 조정하세요
1111

1212
interface CardDetailModalProps {
13-
card: CardType;
13+
card: CardDetailType;
1414
currentUserId: number;
1515
dashboardId: number;
1616
onClose: () => void;
@@ -22,7 +22,7 @@ export default function CardDetailPage({
2222
dashboardId,
2323
onClose,
2424
}: CardDetailModalProps) {
25-
const [cardData, setCardData] = useState<CardType>(card);
25+
const [cardData, setCardData] = useState<CardDetailType>(card);
2626
const [commentText, setCommentText] = useState("");
2727
const [showMenu, setShowMenu] = useState(false);
2828
const [isEditModalOpen, setIsEditModalOpen] = useState(false);

src/components/modalInput/ToDoModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import ModalImage from "@/components/modalInput/ModalImage";
77
import TextButton from "@/components/modalInput/TextButton";
88

99
interface TaskModalProps {
10-
onClose: () => void;
1110
isOpen: boolean;
11+
onClose: () => void;
1212
teamId: string;
1313
dashboardId: number;
1414
columnId: number;

src/pages/mypage.tsx

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
1-
// import React, { useState, useEffect } from "react";
1+
import React, { useState, useEffect } from "react";
22
import HeaderMyPage from "@/components/gnb/HeaderDashboard";
33
import SideMenu from "@/components/sideMenu/SideMenu";
44
import ProfileCard from "@/components/card/Profile";
55
import ChangePassword from "@/components/card/ChangePassword";
6+
import { Dashboard, getDashboards } from "@/api/dashboards";
7+
import { useAuthGuard } from "@/hooks/useAuthGuard";
68
import { TEAM_ID } from "@/constants/team";
7-
// import { getDashboards } from "@/api/dashboards";
89

910
export default function MyPage() {
10-
// const teamId = "13-4";
11-
//const [dashboardList, setDashboardList] = useState<Dashboard[]>([]);
11+
const { user, isInitialized } = useAuthGuard();
12+
const [dashboards, setDashboards] = useState<Dashboard[]>([]);
1213

13-
/*interface Dashboard {
14-
id: number;
15-
title: string;
16-
color: string;
17-
userId: number;
18-
createdAt: string;
19-
updatedAt: string;
20-
createdByMe: boolean;
21-
}*/
14+
const fetchDashboards = async () => {
15+
try {
16+
const res = await getDashboards({});
17+
setDashboards(res.dashboards); // 👉 정상 저장
18+
} catch (error) {
19+
console.error("대시보드 불러오기 실패:", error);
20+
}
21+
};
2222

23-
/* SideMenu 값 불러오기 */
24-
// const fetchDashboards = async () => {
25-
// try {
26-
// const res = await getDashboards({ teamId });
27-
// setDashboardList(res.dashboards);
28-
// } catch (error) {
29-
// console.error("대시보드 불러오기 실패:", error);
30-
// }
31-
// };
32-
33-
// useEffect(() => {
34-
// fetchDashboards();
35-
// }, [teamId]);
23+
useEffect(() => {
24+
if (isInitialized && user) {
25+
fetchDashboards();
26+
}
27+
}, [isInitialized, user]);
3628

3729
return (
3830
<div className="flex">
39-
<SideMenu teamId={TEAM_ID} dashboardList={[]} />
31+
<SideMenu teamId={TEAM_ID} dashboardList={dashboards} />
4032
<div className="flex flex-col w-full">
4133
<HeaderMyPage variant="mypage" />
42-
<div className="flex flex-col items-center w-full mt-10">
34+
<div className="flex flex-col justify-start w-full mt-10">
4335
<ProfileCard />
4436
<ChangePassword />
4537
</div>

src/types/cards.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface Assignee {
44
id: number;
55
}
66

7-
export interface CardType {
7+
export interface CardDetailType {
88
status: string;
99
id: number;
1010
title: string;
@@ -16,4 +16,5 @@ export interface CardType {
1616
columnId: number;
1717
createdAt: string;
1818
updatedAt: string;
19+
dashboardId: number;
1920
}

0 commit comments

Comments
 (0)