From afad9c6776540858ce16c9ff43ab543fafc2e7a9 Mon Sep 17 00:00:00 2001 From: mlnwns Date: Mon, 22 Jul 2024 17:08:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=9C=A0?= =?UTF-8?q?=EB=AC=B4=EC=97=90=20=EB=94=B0=EB=A5=B8=20GET=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EC=A3=BC=EC=86=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/error/src/components/EconoCalendar.jsx | 42 +++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/FE/error/src/components/EconoCalendar.jsx b/FE/error/src/components/EconoCalendar.jsx index 9c2d838d..ce7e0110 100644 --- a/FE/error/src/components/EconoCalendar.jsx +++ b/FE/error/src/components/EconoCalendar.jsx @@ -21,6 +21,30 @@ const EconoCalendar = () => { setIsLoggedIn(!!token); }, []); + useEffect(() => { + const token = localStorage.getItem("slackToken"); + const uri = isLoggedIn ? "/api/calendar/all" : "/api/calendar/public/all"; + const config = isLoggedIn + ? { headers: { Authorization: `Bearer ${token}` } } + : {}; + + axios + .get(uri, config) + .then((res) => { + const fetchedEvents = res.data.data.map((event) => ({ + title: event.eventName, + id: event.eventId, + start: event.eventStartDate.split("T")[0], + end: event.eventEndDate.split("T")[0], + color: "#FFC0CB", + })); + setEvents(fetchedEvents); + }) + .catch((error) => { + console.error("Error fetching events:", error); + }); + }, [isLoggedIn]); + const handleDelete = () => { toast("일정이 삭제되었습니다", { style: { @@ -48,24 +72,6 @@ const EconoCalendar = () => { return `${year}-${month}-${day}`; }; - useEffect(() => { - axios - .get("/api/calendar/all") - .then((res) => { - const fetchedEvents = res.data.data.map((event) => ({ - title: event.eventName, - id: event.eventId, - start: event.eventStartDate.split("T")[0], - end: event.eventEndDate.split("T")[0], - color: "#FFC0CB", - })); - setEvents(fetchedEvents); - }) - .catch((error) => { - console.error("Error fetching events:", error); - }); - }, []); - const handleUpdateData = (newData) => { setEvents((preEvents) => [...preEvents, newData]); };