Skip to content

Commit

Permalink
Merge pull request #113 from JNU-econovation/FE
Browse files Browse the repository at this point in the history
feat: 로그아웃 시 렌더링 하지 않아야 할 부분 반영
  • Loading branch information
mlnwns authored Jul 22, 2024
2 parents b585ec0 + 9624891 commit ae5025c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
26 changes: 17 additions & 9 deletions FE/error/src/components/EconoCalendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ import axios from "axios";
import CreateModal from "./scheduleCreate/CreateModal";
import CheckCalendar from "./scheduleCheck/CheckCalendar";

const EconoCalendar = () => {
const EconoCalendar = ({ isLoggedIn, setIsLoggedIn }) => {
const [events, setEvents] = useState([]);
const [selectID, setSelectID] = useState("");
const [checkModalIsOpen, setCheckModalIsOpen] = useState(false);
const [createModalIsOpen, setCreateModalIsOpen] = useState(false);
const [selectedDate, setSelectedDate] = useState("");
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [token, setToken] = useState(null);

useEffect(() => {
const storedToken = localStorage.getItem("slackToken");
setToken(storedToken);
setIsLoggedIn(!!storedToken);
}, []);

useEffect(() => {
const uri = isLoggedIn ? "/api/calendar/all" : "/api/calendar/public/all";
const config = isLoggedIn
? { headers: { Authorization: `Bearer ${token}` } }
const isUserLoggedIn = !!storedToken;
setIsLoggedIn(isUserLoggedIn);

const uri = isUserLoggedIn
? "/api/calendar/all"
: "/api/calendar/public/all";
const config = isUserLoggedIn
? { headers: { Authorization: `Bearer ${storedToken}` } }
: {};

axios
Expand All @@ -44,7 +45,7 @@ const EconoCalendar = () => {
.catch((error) => {
console.error("Error fetching events:", error);
});
}, [isLoggedIn, token]);
}, []);

const handleDelete = () => {
toast("일정이 삭제되었습니다", {
Expand Down Expand Up @@ -88,6 +89,13 @@ const EconoCalendar = () => {
localStorage.removeItem("slackToken");
setIsLoggedIn(false);
setToken(null);
// } else {
// const newToken = "dummyToken" + Math.random().toString(36).substr(2, 9); // 임의의 토큰 생성
// localStorage.setItem("slackToken", newToken);
// setToken(newToken);
// setIsLoggedIn(true);
// }
//TODO: 추후 아래 코드로 변경
} else {
window.location.href = "/login";
}
Expand Down
3 changes: 2 additions & 1 deletion FE/error/src/pages/MainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const MainPage = () => {
const addNewIndividualFilter = (newIndividualFilter) => {
setFilterIndividualLists([...filterIndividualLists, newIndividualFilter]);
};

const addNewGroupFilter = (newGroupFilter) => {
setFilterGroupLists([...filterGroupLists, newGroupFilter]);
};
Expand Down Expand Up @@ -46,7 +47,7 @@ const MainPage = () => {
)}
</FilterFrame>
</SideBar>
<EconoCalendar />
<EconoCalendar isLoggedIn={isLoggedIn} setIsLoggedIn={setIsLoggedIn} />
</CalendarPage>
</div>
);
Expand Down

0 comments on commit ae5025c

Please sign in to comment.