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: 로그아웃 시 렌더링 하지 않아야 할 부분 반영 #113

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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
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
Loading