diff --git a/src/components/SideBarLeft.jsx b/src/components/SideBarLeft.jsx index 0b1f3d1..9e01d76 100644 --- a/src/components/SideBarLeft.jsx +++ b/src/components/SideBarLeft.jsx @@ -17,13 +17,15 @@ import { export default function SideBarLeft() { const [isCalendarInfoOpen, setCalendarInfoOpen] = useState(false); const [selectedCalendar, setSelectedCalendar] = useState(null); - const [myCalendars, setMyCalendars] = useState([]); - const [subscribedCalendars, setSubscribedCalendars] = useState([]); - const navigate = useNavigate(); + const navigate = useNavigate(); const [checked, setChecked] = useState({}); const [isInviteOpen, setIsInviteOpen] = useState(false); - const [isCreateCalendarOpen, setIsCreateCalendarOpen] = useState(false); + const [isCreateOpen, setIsCreateCalendarOpen] = useState(false); + + const [myCalendars, setMyCalendars] = useState([]); + const [subscribedCalendars, setSubscribedCalendars] = useState([]); + const [dday, setDday] = useState([]); const { loggedIn, userInfo } = useAuth(); @@ -31,7 +33,7 @@ export default function SideBarLeft() { async function fetchData() { try { const token = localStorage.getItem("token"); - const [myCalendarsResponse, subscribedCalendarsResponse] = + const [myCalendarsResponse, subscribedCalendarsResponse, ddayResponse] = await Promise.all([ axios.get("/api/calendars/admins", { headers: { Authorization: `Bearer ${token}` }, @@ -39,6 +41,9 @@ export default function SideBarLeft() { axios.get(`/api/users/${userInfo.user_id}/subscriptions`, { headers: { Authorization: `Bearer ${token}` }, }), + axios.get(`/api/users/${userInfo.user_id}/favorite-events`, { + headers: { Authorization: `Bearer ${token}` }, + }), ]); if (myCalendarsResponse.status === 200) { @@ -47,6 +52,9 @@ export default function SideBarLeft() { if (subscribedCalendarsResponse.status === 200) { setSubscribedCalendars(subscribedCalendarsResponse.data); } + if (ddayResponse.status === 200) { + setDday(ddayResponse.data.favorite_events); + } } catch (error) { console.error("캘린더 데이터를 가져오는 중 오류 발생:", error); } @@ -55,7 +63,7 @@ export default function SideBarLeft() { if (userInfo?.user_id) { fetchData(); } - }, [userInfo, isCalendarInfoOpen, isCreateCalendarOpen]); + }, [userInfo, isCalendarInfoOpen, isCreateOpen]); const handleToggle = (id) => { setChecked((prev) => ({ @@ -195,7 +203,7 @@ export default function SideBarLeft() { )} - {isCreateCalendarOpen && ( + {isCreateOpen && (
@@ -210,12 +218,33 @@ export default function SideBarLeft() { /> )} +
+ +
); } - -const dDayItems = [ - { day: "D-1", description: "evento 배포" }, - { day: "D-6", description: "푸딩즈 회식!" }, - { day: "D-69", description: "졸업 언제하냐" }, -]; diff --git a/src/mocks/handlers/eventHandlers.js b/src/mocks/handlers/eventHandlers.js index 8c8c623..2b2e175 100644 --- a/src/mocks/handlers/eventHandlers.js +++ b/src/mocks/handlers/eventHandlers.js @@ -168,10 +168,44 @@ export const eventHandlers = [ // 캘린더 삭제 mockEventData.splice(eventIndex, 1); - // 200 OK 응답 반환 return res( ctx.status(200), ctx.json({ message: "이벤트가 성공적으로 삭제되었습니다." }), ); }), + + rest.get("/api/users/:userId/favorite-events", (req, res, ctx) => { + const { userId } = req.params; + const token = req.headers.get("Authorization"); + + if (!token || token !== "Bearer fake_token") { + return res( + ctx.status(40), + ctx.json({ + error: "인증 실패", + message: "로그인이 필요합니다. 다시 로그인해 주세요.", + }), + ); + } + + return res( + ctx.status(200), + ctx.json({ + favorite_events: [ + { + favorite_event_id: 1, + event_id: 1, + event_title: "프로젝트 끝!", + d_day: "2024-12-11", + }, + { + favorite_event_id: 2, + event_id: 2, + event_title: "2025년", + d_day: "2025-01-01", + }, + ], + }), + ); + }), ];