Skip to content

Commit 80c2a0a

Browse files
author
Uttam Singh
committed
Fix: dynamic logo load for AdminDashboard
1 parent 13080c5 commit 80c2a0a

File tree

1 file changed

+24
-37
lines changed

1 file changed

+24
-37
lines changed

frontend/src/pages/AdminDashboard.jsx

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,28 @@ export default function AdminDashboard() {
1111
});
1212

1313
const [message, setMessage] = useState("");
14-
const [users, setUsers] = useState([]);
1514
const [dropdownOpen, setDropdownOpen] = useState(false);
1615
const [isCompact, setIsCompact] = useState(false);
1716
const dropdownRef = useRef(null);
17+
const [logoSrc, setLogoSrc] = useState(""); // ✅ Dynamic logo handler
18+
19+
// === Logo handling ===
20+
useEffect(() => {
21+
const logoPath = `${import.meta.env.BASE_URL || "/"}edme_logo.png`;
22+
23+
// Check if logo exists on Render
24+
fetch(logoPath)
25+
.then((res) => {
26+
if (res.ok) setLogoSrc(logoPath);
27+
else throw new Error("Logo not found");
28+
})
29+
.catch(() => {
30+
// fallback hosted logo
31+
setLogoSrc(
32+
"https://upload.wikimedia.org/wikipedia/commons/f/fc/Edme_logo_placeholder.png"
33+
);
34+
});
35+
}, []);
1836

1937
// === Handle Input Change ===
2038
const handleChange = (e) =>
@@ -35,7 +53,6 @@ export default function AdminDashboard() {
3553
const data = await res.json();
3654
if (data.ok) {
3755
setMessage("✅ User created successfully!");
38-
fetchUsers();
3956
setFormData({
4057
name: "",
4158
email: "",
@@ -52,24 +69,7 @@ export default function AdminDashboard() {
5269
}
5370
};
5471

55-
// === Fetch Users ===
56-
const fetchUsers = async () => {
57-
try {
58-
const res = await fetch(
59-
"https://fat-eibl-backend-x1sp.onrender.com/users/all"
60-
);
61-
const data = await res.json();
62-
if (data.ok) setUsers(data.users);
63-
} catch (e) {
64-
console.error(e);
65-
}
66-
};
67-
68-
useEffect(() => {
69-
fetchUsers();
70-
}, []);
71-
72-
// === Handle Click Outside Dropdown ===
72+
// === Handle Dropdown ===
7373
useEffect(() => {
7474
const handleClickOutside = (event) => {
7575
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
@@ -107,7 +107,7 @@ export default function AdminDashboard() {
107107
>
108108
<div style={styles.navLeft}>
109109
<img
110-
src={`${process.env.PUBLIC_URL}/edme_logo.png`}
110+
src={logoSrc}
111111
alt="FAT-EIBL Logo"
112112
style={{
113113
...styles.logo,
@@ -259,9 +259,7 @@ export default function AdminDashboard() {
259259
);
260260
}
261261

262-
//
263-
// === INLINE STYLES ===
264-
//
262+
// === STYLES ===
265263
const styles = {
266264
container: {
267265
background: "#f7f9fc",
@@ -291,7 +289,6 @@ const styles = {
291289
color: "#dce7ff",
292290
textDecoration: "none",
293291
fontWeight: "500",
294-
transition: "color 0.3s ease",
295292
},
296293
activeLink: {
297294
color: "#fff",
@@ -300,18 +297,8 @@ const styles = {
300297
paddingBottom: "2px",
301298
},
302299
userMenu: { position: "relative" },
303-
userWrapper: {
304-
display: "flex",
305-
alignItems: "center",
306-
gap: "8px",
307-
cursor: "pointer",
308-
},
309-
avatar: {
310-
width: "40px",
311-
height: "40px",
312-
borderRadius: "50%",
313-
border: "2px solid #fff",
314-
},
300+
userWrapper: { display: "flex", alignItems: "center", gap: "8px", cursor: "pointer" },
301+
avatar: { width: "40px", height: "40px", borderRadius: "50%", border: "2px solid #fff" },
315302
userName: { color: "#fff", fontWeight: "500" },
316303
dropdown: {
317304
position: "absolute",

0 commit comments

Comments
 (0)