Skip to content

Commit

Permalink
feat: 로그인 유무에 따른 GET요청주소 변경
Browse files Browse the repository at this point in the history
feat: 로그인 유무에 따른 GET요청주소 변경
  • Loading branch information
mlnwns authored Jul 22, 2024
2 parents f00a819 + afad9c6 commit 50079b7
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions FE/error/src/components/EconoCalendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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]);
};
Expand Down

0 comments on commit 50079b7

Please sign in to comment.