diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index fdd45e2..bb84940 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -6,14 +6,17 @@ import Form2 from "./components/Form2";
import Form3 from "./components/Form3";
import LoginForm from "./components/LoginForm";
import Cookies from "js-cookie";
-import { ToastContainer } from "react-toastify";
+import { fetchAllData, ALL_ITEMS_UPDATED_EVENT } from "./utils/fetchData";
+import { myToast } from "./utils/toastify";
function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
useEffect(() => {
- if (Cookies.get("token")) {
+ const token = Cookies.get("token");
+ if (token) {
setIsLoggedIn(true);
+ fetchAllData(token);
}
localStorage.setItem("borrowableItems", JSON.stringify([]));
@@ -21,8 +24,17 @@ function App() {
}, []);
// Mock flow without real logic: show the three sections stacked for design preview
+ const handleLogout = () => {
+ Cookies.remove("token");
+ localStorage.removeItem("allItems");
+ // Let listeners refresh from empty state
+ window.dispatchEvent(new Event(ALL_ITEMS_UPDATED_EVENT));
+ myToast("Logged out successfully!", "success");
+ setIsLoggedIn(false);
+ };
+
return isLoggedIn ? (
-
+
@@ -32,22 +44,7 @@ function App() {
) : (
- <>
- setIsLoggedIn(true)} />
-
- >
+ setIsLoggedIn(true)} />
);
}
diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx
index fcd95d2..e891823 100644
--- a/frontend/src/components/Header.tsx
+++ b/frontend/src/components/Header.tsx
@@ -1,7 +1,10 @@
import React from "react";
-import Cookies from "js-cookie";
-const Header: React.FC = () => {
+type HeaderProps = {
+ onLogout: () => void;
+};
+
+const Header: React.FC = ({ onLogout }) => {
return (
@@ -11,12 +14,8 @@ const Header: React.FC = () => {
Schnell und unkompliziert Equipment reservieren