Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 로그인 유무에 따른 GET요청주소 변경 #108

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading