diff --git a/client/pages/dashboards/DevLinkDashboard.tsx b/client/pages/dashboards/DevLinkDashboard.tsx index 889de865..3c3f6441 100644 --- a/client/pages/dashboards/DevLinkDashboard.tsx +++ b/client/pages/dashboards/DevLinkDashboard.tsx @@ -38,20 +38,41 @@ export default function DevLinkDashboard() { const token = session?.access_token; if (!token) throw new Error("No auth token"); - const profileRes = await fetch(`${API_BASE}/api/devlink/profile`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (profileRes.ok) setProfile(await profileRes.json()); + try { + const profileRes = await fetch(`${API_BASE}/api/devlink/profile`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (profileRes.ok) { + const data = await profileRes.json(); + setProfile(data); + } + } catch (err) { + console.error("Failed to load profile:", err); + } - const oppRes = await fetch(`${API_BASE}/api/devlink/opportunities`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (oppRes.ok) setOpportunities(await oppRes.json()); + try { + const oppRes = await fetch(`${API_BASE}/api/devlink/opportunities`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (oppRes.ok) { + const data = await oppRes.json(); + setOpportunities(Array.isArray(data) ? data : []); + } + } catch (err) { + console.error("Failed to load opportunities:", err); + } - const teamsRes = await fetch(`${API_BASE}/api/devlink/teams`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (teamsRes.ok) setTeams(await teamsRes.json()); + try { + const teamsRes = await fetch(`${API_BASE}/api/devlink/teams`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (teamsRes.ok) { + const data = await teamsRes.json(); + setTeams(Array.isArray(data) ? data : []); + } + } catch (err) { + console.error("Failed to load teams:", err); + } } catch (error) { console.error("Failed to load DEV-LINK data", error); } finally { diff --git a/client/pages/dashboards/FoundationDashboard.tsx b/client/pages/dashboards/FoundationDashboard.tsx index 8da8c67e..6bf405da 100644 --- a/client/pages/dashboards/FoundationDashboard.tsx +++ b/client/pages/dashboards/FoundationDashboard.tsx @@ -58,22 +58,28 @@ export default function FoundationDashboard() { const token = session?.access_token; if (!token) throw new Error("No auth token"); - // Load courses - const coursesRes = await fetch(`${API_BASE}/api/foundation/courses`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (coursesRes.ok) { - const data = await coursesRes.json(); - setCourses(Array.isArray(data) ? data : []); + try { + const coursesRes = await fetch(`${API_BASE}/api/foundation/courses`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (coursesRes.ok) { + const data = await coursesRes.json(); + setCourses(Array.isArray(data) ? data : []); + } + } catch (err: any) { + console.error("Failed to load courses:", err); } - // Load mentorships - const mentorRes = await fetch(`${API_BASE}/api/foundation/mentorships`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (mentorRes.ok) { - const data = await mentorRes.json(); - setMentorships(data.as_mentee || []); + try { + const mentorRes = await fetch(`${API_BASE}/api/foundation/mentorships`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (mentorRes.ok) { + const data = await mentorRes.json(); + setMentorships(data.as_mentee || []); + } + } catch (err: any) { + console.error("Failed to load mentorships:", err); } } catch (error: any) { console.error("Failed to load dashboard data", error); diff --git a/client/pages/dashboards/LabsDashboard.tsx b/client/pages/dashboards/LabsDashboard.tsx index 59dc30b6..e810be0c 100644 --- a/client/pages/dashboards/LabsDashboard.tsx +++ b/client/pages/dashboards/LabsDashboard.tsx @@ -39,28 +39,53 @@ export default function LabsDashboard() { const token = session?.access_token; if (!token) throw new Error("No auth token"); - const tracksRes = await fetch(`${API_BASE}/api/labs/research-tracks`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (tracksRes.ok) setResearchTracks(await tracksRes.json()); + try { + const tracksRes = await fetch(`${API_BASE}/api/labs/research-tracks`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (tracksRes.ok) { + const data = await tracksRes.json(); + setResearchTracks(Array.isArray(data) ? data : []); + } + } catch (err) { + console.error("Failed to load research tracks:", err); + } - const bountiesRes = await fetch(`${API_BASE}/api/labs/bounties`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (bountiesRes.ok) setBounties(await bountiesRes.json()); + try { + const bountiesRes = await fetch(`${API_BASE}/api/labs/bounties`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (bountiesRes.ok) { + const data = await bountiesRes.json(); + setBounties(Array.isArray(data) ? data : []); + } + } catch (err) { + console.error("Failed to load bounties:", err); + } - const pubRes = await fetch(`${API_BASE}/api/labs/publications`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (pubRes.ok) setPublications(await pubRes.json()); + try { + const pubRes = await fetch(`${API_BASE}/api/labs/publications`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (pubRes.ok) { + const data = await pubRes.json(); + setPublications(Array.isArray(data) ? data : []); + } + } catch (err) { + console.error("Failed to load publications:", err); + } - const ipRes = await fetch(`${API_BASE}/api/labs/ip-portfolio`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (ipRes.ok) { - const data = await ipRes.json(); - setIpPortfolio(data); - setIsAdmin(data?.is_admin || false); + try { + const ipRes = await fetch(`${API_BASE}/api/labs/ip-portfolio`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (ipRes.ok) { + const data = await ipRes.json(); + setIpPortfolio(data); + setIsAdmin(data?.is_admin || false); + } + } catch (err) { + console.error("Failed to load IP portfolio:", err); } } catch (error) { console.error("Failed to load LABS data", error); diff --git a/client/pages/dashboards/StaffDashboard.tsx b/client/pages/dashboards/StaffDashboard.tsx index 0e7fa77f..5c539e43 100644 --- a/client/pages/dashboards/StaffDashboard.tsx +++ b/client/pages/dashboards/StaffDashboard.tsx @@ -39,25 +39,53 @@ export default function StaffDashboard() { const token = session?.access_token; if (!token) throw new Error("No auth token"); - const memberRes = await fetch(`${API_BASE}/api/staff/me`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (memberRes.ok) setStaffMember(await memberRes.json()); + try { + const memberRes = await fetch(`${API_BASE}/api/staff/me`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (memberRes.ok) { + const data = await memberRes.json(); + setStaffMember(data); + } + } catch (err) { + console.error("Failed to load staff member data:", err); + } - const okrRes = await fetch(`${API_BASE}/api/staff/okrs`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (okrRes.ok) setOkrs(await okrRes.json()); + try { + const okrRes = await fetch(`${API_BASE}/api/staff/okrs`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (okrRes.ok) { + const data = await okrRes.json(); + setOkrs(Array.isArray(data) ? data : []); + } + } catch (err) { + console.error("Failed to load OKRs:", err); + } - const invRes = await fetch(`${API_BASE}/api/staff/invoices`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (invRes.ok) setInvoices(await invRes.json()); + try { + const invRes = await fetch(`${API_BASE}/api/staff/invoices`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (invRes.ok) { + const data = await invRes.json(); + setInvoices(Array.isArray(data) ? data : []); + } + } catch (err) { + console.error("Failed to load invoices:", err); + } - const dirRes = await fetch(`${API_BASE}/api/staff/directory`, { - headers: { Authorization: `Bearer ${token}` }, - }); - if (dirRes.ok) setDirectory(await dirRes.json()); + try { + const dirRes = await fetch(`${API_BASE}/api/staff/directory`, { + headers: { Authorization: `Bearer ${token}` }, + }); + if (dirRes.ok) { + const data = await dirRes.json(); + setDirectory(Array.isArray(data) ? data : []); + } + } catch (err) { + console.error("Failed to load directory:", err); + } } catch (error) { console.error("Failed to load STAFF data", error); } finally {