100 ? "text-sm" : "text-lg font-bold"
- } p-0 m-0`}
+ className={`${title.length > 100 ? "text-sm" : "text-lg font-bold"
+ } p-0 m-0`}
>
{title}
From c99a8501b12da1d2f5bda3fa746d1cefd308b913 Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 25 Oct 2024 23:17:42 -0400
Subject: [PATCH 02/13] Update Profile page prepared for backend work on
profile data
---
src/shared/pages/Profile.js | 126 -----------------------------------
src/shared/pages/Profile.tsx | 51 ++++++++++++++
2 files changed, 51 insertions(+), 126 deletions(-)
delete mode 100644 src/shared/pages/Profile.js
create mode 100644 src/shared/pages/Profile.tsx
diff --git a/src/shared/pages/Profile.js b/src/shared/pages/Profile.js
deleted file mode 100644
index deac5f14..00000000
--- a/src/shared/pages/Profile.js
+++ /dev/null
@@ -1,126 +0,0 @@
-import React, { useEffect } from "react";
-import { useState } from "react";
-import ProfileAvatar from "../components/UIElements/ProfileAvatar.tsx";
-import ProfileDescription from "../../staff/components/ProfileDescription.tsx";
-import ProfileOpportunities from "../../staff/components/ProfileOpportunities.tsx";
-import EditProfile from "./EditProfile";
-import useGlobalContext from "../../context/global/useGlobalContext";
-
-const PROFILES = {
- d1: {
- name: "Peter Johnson",
- image: "https://www.bu.edu/com/files/2015/08/Katz-James-3.jpg",
- researchCenter: "Computational Fake Center",
- department: "Computer Science",
- email: "johnp@rpi.edu",
- role: "admin",
- description: `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
- eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
- pharetra sit amet aliquam id diam maecenas ultricies mi. Montes
- nascetur ridiculus mus mauris vitae ultricies leo. Porttitor massa
- id neque aliquam. Malesuada bibendum arcu vitae elementum. Nulla
- aliquet porrsus mattis molestie aiaculis at erat pellentesque.
- At risus viverra adipiscing at.
- Tincidunt tortor aliquam nulla facilisi cras fermentum odio eu
- feugiat. Eget fUt eu sem integer vitae justo
- eget magna fermentum. Lobortis feugiat vivamus at augue eget arcu
- dictum. Et tortor at risus viverra adipiscing at in tellus.
- Suspendisse sed nisi lacus sed viverra tellus. Potenti nullam ac
- tortor vitae. Massa id neque aliquam vestibulum. Ornare arcu odio ut
- sem nulla pharetra. Quam id leo in vitae turpis massa. Interdum
- velit euismod in pellentesque massa placerat duis ultricies lacus.
- Maecenas sed enim ut sem viverra aliquet eget sit amet. Amet
- venenatis urna cursus eget nunc scelerisque viverra mauris. Interdum
- varius sit amet mattis. Aliquet nec ullamcorper sit amet risus
- nullam. Aliquam faucibus purus in massa tempor nec feugiat. Vitae
- turpis massa sed elementum tempus. Feugiat in ante metus dictum at
- tempor. Malesuada nunc vel risus commodo viverra maecenas accumsan.
- Integer vitae justo.`,
- },
-};
-
-const ProfilePage = () => {
- const [editMode, setEditMode] = useState(false);
- const [profileFound, setProfileFound] = useState(false);
- const [profile, setProfile] = useState(null);
-
- const state = useGlobalContext();
- const { loggedIn } = state;
-
- const changeEditMode = () => {
- setEditMode(!editMode);
- };
-
- const { id } = state;
-
- const fetchProfile = async () => {
- const response = await fetch(
- `${process.env.REACT_APP_BACKEND_SERVER}/getProfessorProfile/${id}`
- );
-
- if (response) {
- let data = await response.json();
- setProfile(data);
- setProfileFound(true);
- } else {
- setProfileFound(false);
- }
- };
-
- useEffect(() => {
- if (id) {
- fetchProfile();
- }
- }, []);
-
- var editButton = (
-
- {editMode ? "Cancel Changes" : "Edit Profile"}
-
- );
-
- const profilePage = (
-
- );
-
- return (
-
-
- {!loggedIn ? (
- "Please log in to view your profile"
- ) : profileFound ? (
- <>
- {loggedIn && editButton}
- {loggedIn && editMode && }
- {loggedIn && !editMode && profilePage}
- >
- ) : (
- "Profile not found"
- )}
-
-
-
-
-
-
-
-
-
- );
-};
-
-export default ProfilePage;
diff --git a/src/shared/pages/Profile.tsx b/src/shared/pages/Profile.tsx
new file mode 100644
index 00000000..51dfa8e5
--- /dev/null
+++ b/src/shared/pages/Profile.tsx
@@ -0,0 +1,51 @@
+import React, { useEffect } from "react";
+import { useState } from "react";
+import ProfileComponents from "../components/Profile/ProfileComponents.tsx";
+// import EditProfile from "./EditProfile";
+
+const ProfilePage = (authenticated) => {
+
+ if (authenticated[0] === false) {
+ window.location.href = "/login";
+ }
+
+ // const [editMode, setEditMode] = useState(false);
+ const [profile, setProfile] = useState
(null);
+
+ // const changeEditMode = () => {
+ // setEditMode(!editMode);
+ // };
+
+ const fetchProfile = async () => {
+ const response = await fetch(
+ `${process.env.REACT_APP_BACKEND_SERVER}/profile`
+ );
+
+ if (response.ok) {
+ const data = await response.json();
+ setProfile(data);
+ } else {
+ setProfile(false);
+ }
+ };
+
+ useEffect(() => {
+ fetchProfile();
+ }, []);
+
+ // const editButton = (
+ //
+ // {editMode ? "Cancel Changes" : "Edit Profile"}
+ //
+ // );
+
+ return (
+ <>
+ {profile === null && "Loading..."}
+ {profile && typeof profile === "object" && }
+ {profile === false && "Profile not found"}
+ >
+ );
+};
+
+export default ProfilePage;
From 408aa7080f6d5c8e02dc32278cc906649cb5b85e Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 25 Oct 2024 23:18:04 -0400
Subject: [PATCH 03/13] Create component to handle profile items Used in
Profile Page and Staff Page
---
.../components/Profile/ProfileComponents.tsx | 29 +++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 src/shared/components/Profile/ProfileComponents.tsx
diff --git a/src/shared/components/Profile/ProfileComponents.tsx b/src/shared/components/Profile/ProfileComponents.tsx
new file mode 100644
index 00000000..42d92147
--- /dev/null
+++ b/src/shared/components/Profile/ProfileComponents.tsx
@@ -0,0 +1,29 @@
+import React from "react";
+import ProfileAvatar from "./ProfileAvatar.tsx";
+import ProfileDescription from "./ProfileDescription.tsx";
+import ProfileOpportunities from "./ProfileOpportunities.tsx";
+
+interface Profile {
+ name: string;
+ image: string;
+ department: string;
+ description: string;
+ website?: string;
+}
+
+const ProfileComponents = ({ profile, staffId }: { profile: Profile, staffId?: string }) => {
+ return (
+
+ );
+}
+
+export default ProfileComponents;
From 2fc01bce7deb21af4d44e0bf1dacefd031377456 Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 25 Oct 2024 23:18:13 -0400
Subject: [PATCH 04/13] Use new profile components
---
src/staff/pages/Staff.tsx | 36 +++++++-----------------------------
1 file changed, 7 insertions(+), 29 deletions(-)
diff --git a/src/staff/pages/Staff.tsx b/src/staff/pages/Staff.tsx
index c777f4ea..9003e59b 100644
--- a/src/staff/pages/Staff.tsx
+++ b/src/staff/pages/Staff.tsx
@@ -1,12 +1,10 @@
import React, { useState, useEffect } from "react";
-import ProfileAvatar from "../../shared/components/UIElements/ProfileAvatar.tsx";
-import ProfileDescription from "../components/ProfileDescription.tsx";
-import ProfileOpportunities from "../components/ProfileOpportunities.tsx";
+import ProfileComponents from "../../shared/components/Profile/ProfileComponents.tsx";
import { useParams } from "react-router";
const StaffPage = () => {
const { staffId } = useParams();
- const [profile, setProfile] = useState<{ name?: string; image?: string; department?: string; description?: string; website?: string } | "not found" | null>(null);
+ const [profile, setProfile] = useState(null);
const checkProfile = (data) => {
return data.name && data.image && data.department && data.description;
@@ -18,13 +16,13 @@ const StaffPage = () => {
);
if (!response.ok) {
- setProfile("not found");
+ setProfile(false);
} else {
const data = await response.json();
if (checkProfile(data)) {
setProfile(data);
} else {
- setProfile("not found");
+ setProfile(false);
console.log(data);
}
}
@@ -34,31 +32,11 @@ const StaffPage = () => {
fetchProfile();
}, []);
- const profileComponents = (
-
-
- {typeof profile === "object" && profile !== null && (
-
- )}
- {typeof profile === "object" && profile !== null && (
-
- )}
-
- {staffId && }
-
- );
-
return (
<>
- {!profile && "Loading..."}
- {typeof profile === "object" && profileComponents}
- {profile === "not found" && "Profile not found"}
+ {profile === null && "Loading..."}
+ {profile && typeof profile === "object" && }
+ {profile === false && "Profile not found"}
>
);
};
From fab0e2cf61dd3da4b1806311160c50274cb0ab69 Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 25 Oct 2024 23:18:29 -0400
Subject: [PATCH 05/13] Update App.tsx for new typescript file
---
src/App.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/App.tsx b/src/App.tsx
index b6788dca..e0fcdabe 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -10,7 +10,7 @@ import StaffPage from "./staff/pages/Staff.tsx";
import Department from "./staff/pages/Department.tsx";
import CreatePost from "./staff/pages/CreatePost.js";
import IndividualPost from "./opportunities/pages/IndividualPost.js";
-import ProfilePage from "./shared/pages/Profile.js";
+import ProfilePage from "./shared/pages/Profile.tsx";
import LoginRedirection from "./auth/Login.tsx";
import LogoutRedirection from "./auth/Logout.tsx";
import { GlobalContextProvider } from "./context/global/GlobalContextProvider.js";
From 2837a81ba346dff2d51c32f591b0eb09388969b6 Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 22 Nov 2024 16:24:04 -0500
Subject: [PATCH 06/13] clean up auth context use
---
src/context/AuthContext.tsx | 11 +++++++----
src/shared/components/Navigation/MainNavigation.tsx | 7 +++++--
src/shared/components/Navigation/StickyFooter.tsx | 7 +++++--
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx
index add455b5..ab76457f 100644
--- a/src/context/AuthContext.tsx
+++ b/src/context/AuthContext.tsx
@@ -1,4 +1,6 @@
-import React, { createContext, useState, useContext } from 'react';
+import React, { createContext, useState, useContext, useEffect } from 'react';
+import { ReactNode } from 'react';
+
const AuthContext = createContext<{
auth: { isAuthenticated: boolean; token: string | null };
@@ -11,9 +13,6 @@ const AuthContext = createContext<{
logout: () => { },
loadToken: () => { }
});
-
-import { ReactNode } from 'react';
-
interface AuthProviderProps {
children: ReactNode;
}
@@ -43,6 +42,10 @@ export const AuthProvider = ({ children }: AuthProviderProps) => {
}
};
+ useEffect(() => {
+ loadToken();
+ }, []);
+
return (
{children}
diff --git a/src/shared/components/Navigation/MainNavigation.tsx b/src/shared/components/Navigation/MainNavigation.tsx
index 2bcb4042..62131eea 100644
--- a/src/shared/components/Navigation/MainNavigation.tsx
+++ b/src/shared/components/Navigation/MainNavigation.tsx
@@ -2,11 +2,14 @@ import React from "react";
import { Disclosure } from "@headlessui/react";
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline";
import { Link, NavLink, useLocation } from "react-router-dom";
+import { useAuth } from "../../../context/AuthContext.tsx";
-export default function MainNavigation(authenticated) {
+export default function MainNavigation() {
+
+ const { auth } = useAuth();
const location = useLocation().pathname;
- const routes = authenticated.authenticated[1]
+ const routes = auth.isAuthenticated
? [
{ name: "Jobs", href: "/jobs", current: true },
{ name: "Create", href: "/create", current: false },
diff --git a/src/shared/components/Navigation/StickyFooter.tsx b/src/shared/components/Navigation/StickyFooter.tsx
index 976a7c12..196bb07d 100644
--- a/src/shared/components/Navigation/StickyFooter.tsx
+++ b/src/shared/components/Navigation/StickyFooter.tsx
@@ -1,10 +1,13 @@
import React from "react";
import { Link } from "react-router-dom";
import logo from "../../../images/LabConnect_Logo.webp";
+import { useAuth } from "../../../context/AuthContext.tsx";
-export default function StickyFooter(authenticated) {
+export default function StickyFooter() {
- const routes = authenticated.authenticated[1]
+ const { auth } = useAuth();
+
+ const routes = auth.isAuthenticated
? [
{ name: "Jobs", href: "/jobs", current: true },
{ name: "Create", href: "/create", current: false },
From 9f9bb153c8ea62274dd265952d4878e3170e16af Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 22 Nov 2024 18:39:15 -0500
Subject: [PATCH 07/13] minor fixes to auth things
---
src/auth/Logout.tsx | 2 +-
src/auth/Token.tsx | 43 ++++++++++++++++++++++++-------------------
2 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/src/auth/Logout.tsx b/src/auth/Logout.tsx
index 1d31e828..08b71716 100644
--- a/src/auth/Logout.tsx
+++ b/src/auth/Logout.tsx
@@ -32,7 +32,7 @@ export default function LogoutRedirection() {
}
}
logoutUser();
- }, [auth, logout]);
+ }, [logout, auth.token]);
return null; // Since this component doesn't need to render anything
};
\ No newline at end of file
diff --git a/src/auth/Token.tsx b/src/auth/Token.tsx
index 515f5d87..411cf617 100644
--- a/src/auth/Token.tsx
+++ b/src/auth/Token.tsx
@@ -1,4 +1,5 @@
import { useAuth } from "../context/AuthContext.tsx";
+import { useEffect } from "react";
export default function Token() {
@@ -7,26 +8,30 @@ export default function Token() {
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code");
- if (code) {
- fetch(`${process.env.REACT_APP_BACKEND_SERVER}/token`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ code }),
- })
- .then((response) => response.json())
- .then((data) => {
- const token = data.token;
- if (token) {
- login(token);
- return null;
- }
+ useEffect(() => {
+ async function fetchToken(code: string) {
+ fetch(`${process.env.REACT_APP_BACKEND_SERVER}/token`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ code }),
})
- .catch((error) => console.error("Error fetching token:", error));
- } else {
- window.location.href = "/";
- }
+ .then((response) => response.json())
+ .then((data) => {
+ const token = data.token;
+ if (token) {
+ login(token);
+ window.location.href = "/";
+ return null;
+ }
+ })
+ .catch((error) => console.error("Error fetching token:", error));
+ }
+ if (code) {
+ fetchToken(code);
+ }
+ }, [code, login]);
return null;
}
\ No newline at end of file
From 737aff83dae5b8c722b12a50c2bfc94cf426bc9d Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 22 Nov 2024 18:41:52 -0500
Subject: [PATCH 08/13] Complete profile page
---
src/shared/pages/Profile.tsx | 59 ++++++++++++++++++++++--------------
1 file changed, 37 insertions(+), 22 deletions(-)
diff --git a/src/shared/pages/Profile.tsx b/src/shared/pages/Profile.tsx
index 51dfa8e5..5859efaf 100644
--- a/src/shared/pages/Profile.tsx
+++ b/src/shared/pages/Profile.tsx
@@ -1,37 +1,54 @@
import React, { useEffect } from "react";
import { useState } from "react";
import ProfileComponents from "../components/Profile/ProfileComponents.tsx";
+import { useAuth } from "../../context/AuthContext.tsx";
// import EditProfile from "./EditProfile";
-const ProfilePage = (authenticated) => {
+export default function ProfilePage() {
+ const { auth } = useAuth();
- if (authenticated[0] === false) {
+ if (!auth.isAuthenticated) {
window.location.href = "/login";
}
// const [editMode, setEditMode] = useState(false);
- const [profile, setProfile] = useState(null);
+ interface Profile {
+ id: string;
+ name: string;
+ image: string;
+ department: string;
+ description: string;
+ website?: string;
+ }
+
+ const [profile, setProfile] = useState(null);
// const changeEditMode = () => {
// setEditMode(!editMode);
// };
- const fetchProfile = async () => {
- const response = await fetch(
- `${process.env.REACT_APP_BACKEND_SERVER}/profile`
- );
-
- if (response.ok) {
- const data = await response.json();
- setProfile(data);
- } else {
- setProfile(false);
- }
- };
-
useEffect(() => {
+ const fetchProfile = async () => {
+ const response = await fetch(
+ `${process.env.REACT_APP_BACKEND_SERVER}/profile`, {
+ headers: {
+ Authorization: `Bearer ${auth.token}`,
+ },
+ }
+ );
+
+ if (response.ok) {
+ const data = await response.json();
+ // if (data.lab_manager) {
+ // window.location.href = "/staff/" + data.id;
+ // }
+ setProfile(data);
+ } else {
+ setProfile(false);
+ }
+ };
fetchProfile();
- }, []);
+ }, [auth.token]);
// const editButton = (
//
@@ -40,12 +57,10 @@ const ProfilePage = (authenticated) => {
// );
return (
- <>
+
{profile === null && "Loading..."}
- {profile && typeof profile === "object" && }
+ {profile && typeof profile === "object" && }
{profile === false && "Profile not found"}
- >
+
);
};
-
-export default ProfilePage;
From 2052a4fbd9328e0bf51fc45661e95e773a91394e Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 22 Nov 2024 18:42:02 -0500
Subject: [PATCH 09/13] fix key prop error
---
src/staff/components/DepartmentItems.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/staff/components/DepartmentItems.tsx b/src/staff/components/DepartmentItems.tsx
index e0862184..02b07f54 100644
--- a/src/staff/components/DepartmentItems.tsx
+++ b/src/staff/components/DepartmentItems.tsx
@@ -8,7 +8,7 @@ const DepartmentItems = ({ items }) => {
{items.map((item) => {
return (
{
DepartmentItems.propTypes = {
items: PropTypes.arrayOf(
PropTypes.shape({
- id: PropTypes.string.isRequired,
+ school_id: PropTypes.string.isRequired,
department_id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
image: PropTypes.string.isRequired,
From f3499b7027e832293490177e9254570e2e5333e8 Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 22 Nov 2024 18:42:10 -0500
Subject: [PATCH 10/13] fix type
---
src/staff/pages/Departments.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/staff/pages/Departments.tsx b/src/staff/pages/Departments.tsx
index ac6df925..8235e638 100644
--- a/src/staff/pages/Departments.tsx
+++ b/src/staff/pages/Departments.tsx
@@ -11,7 +11,7 @@ export default function Departments() {
}
const [departments, setDepartments] = useState<
- { id: string; department_id: string; title: string; image: string }[] | string | null
+ { school_id: string; department_id: string; title: string; image: string }[] | string | null
>(null);
useEffect(() => {
From f231f8727d66a983a2ff62dd4fbcaca386de3916 Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 22 Nov 2024 18:42:24 -0500
Subject: [PATCH 11/13] fix profile components and profile opportunities
---
.../components/Profile/ProfileComponents.tsx | 42 +++++++++++----
.../Profile/ProfileOpportunities.tsx | 51 +++++++------------
2 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/src/shared/components/Profile/ProfileComponents.tsx b/src/shared/components/Profile/ProfileComponents.tsx
index 42d92147..d09c1e1a 100644
--- a/src/shared/components/Profile/ProfileComponents.tsx
+++ b/src/shared/components/Profile/ProfileComponents.tsx
@@ -2,6 +2,8 @@ import React from "react";
import ProfileAvatar from "./ProfileAvatar.tsx";
import ProfileDescription from "./ProfileDescription.tsx";
import ProfileOpportunities from "./ProfileOpportunities.tsx";
+import SEO from "..//SEO.tsx";
+import Breadcrumb from "../UIElements/Breadcrumb.tsx";
interface Profile {
name: string;
@@ -11,18 +13,36 @@ interface Profile {
website?: string;
}
-const ProfileComponents = ({ profile, staffId }: { profile: Profile, staffId?: string }) => {
+const ProfileComponents = ({ profile, id, staff }: { profile: Profile, id: string, staff: boolean }) => {
return (
-
+ <>
+
+ {staff && }
+
+ >
);
}
diff --git a/src/shared/components/Profile/ProfileOpportunities.tsx b/src/shared/components/Profile/ProfileOpportunities.tsx
index cf1e41e2..cc659444 100644
--- a/src/shared/components/Profile/ProfileOpportunities.tsx
+++ b/src/shared/components/Profile/ProfileOpportunities.tsx
@@ -1,44 +1,37 @@
import React from "react";
import LargeTextCard from "../UIElements/LargeTextCard.tsx";
-import PropTypes from "prop-types";
import { useState, useEffect } from "react";
+import { useAuth } from "../../../context/AuthContext.tsx";
-const ProfileOpportunities = ({ id }) => {
+export default function ProfileOpportunities({ id, staff }: { id: string, staff: boolean }) {
+ const { auth } = useAuth();
const [opportunities, setOpportunities] = useState | null | "no response">(null);
- const fetchOpportunities = async () => {
- const response = await fetch(
- `${process.env.REACT_APP_BACKEND_SERVER}/staff/opportunities/${id}`
- );
-
- if (!response.ok) {
- throw new Error(
- `Network response was not ok - Status: ${response.status}`
+ useEffect(() => {
+ async function setData() {
+ const response = await fetch(
+ `${process.env.REACT_APP_BACKEND_SERVER}/${staff ? "staff" : "profile"}/opportunities/${id}`, {
+ headers: {
+ Authorization: `Bearer ${auth.token}`,
+ },
+ }
);
- }
-
- const data = await response.json();
- return data["data"];
- };
- async function setData() {
- const response = await fetchOpportunities();
- if (response) {
- setOpportunities(response);
- } else {
- setOpportunities("no response");
+ if (response.ok) {
+ const data = await response.json();
+ setOpportunities(data);
+ } else {
+ setOpportunities("no response");
+ }
}
- }
- useEffect(() => {
setData();
- }, []);
+ }, [auth.token, id, staff]);
const opportunityList = (
{id &&
- opportunities &&
- typeof opportunities === "object" &&
+ Array.isArray(opportunities) &&
opportunities.map((opportunity) => (
{
);
};
-
-ProfileOpportunities.propTypes = {
- id: PropTypes.string.isRequired,
-};
-
-export default ProfileOpportunities;
From dfd9f303f5ff62242d782ca05a9c6742f603248e Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 22 Nov 2024 18:42:32 -0500
Subject: [PATCH 12/13] update staff page
---
src/staff/pages/Staff.tsx | 63 +++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 32 deletions(-)
diff --git a/src/staff/pages/Staff.tsx b/src/staff/pages/Staff.tsx
index 8aedf2d1..5f7abf12 100644
--- a/src/staff/pages/Staff.tsx
+++ b/src/staff/pages/Staff.tsx
@@ -1,55 +1,54 @@
import React, { useState, useEffect } from "react";
import ProfileComponents from "../../shared/components/Profile/ProfileComponents.tsx";
import { useParams } from "react-router";
-import SEO from "../../shared/components/SEO.tsx";
import { useAuth } from "../../context/AuthContext.tsx";
export default function StaffPage() {
const { auth } = useAuth();
- if (!auth.isAuthenticated) {
- window.location.href = "/login";
- }
-
const { staffId } = useParams();
const [profile, setProfile] = useState(null);
- const checkProfile = (data) => {
- return data.name && data.image && data.department && data.description;
- };
+ useEffect(() => {
+ const fetchProfile = async () => {
+ const response = await fetch(
+ `${process.env.REACT_APP_BACKEND_SERVER}/staff/${staffId}`, {
+ headers: {
+ Authorization: `Bearer ${auth.token}`,
+ },
+ }
+ );
- const fetchProfile = async () => {
- const response = await fetch(
- `${process.env.REACT_APP_BACKEND_SERVER}/staff/${staffId}`, {
- headers: {
- Authorization: `Bearer ${auth.token}`,
- },
- }
- );
+ if (!response.ok) {
+ setProfile(false);
+ } else {
+ const data = await response.json();
+ if (checkProfile(data)) {
+ setProfile(data);
+ } else {
+ setProfile(false);
+ console.log(data);
+ }
+ }
+ };
- if (!response.ok) {
+ if (!auth.isAuthenticated) {
+ window.location.href = "/login";
+ } else if (!staffId) {
setProfile(false);
} else {
- const data = await response.json();
- if (checkProfile(data)) {
- setProfile(data);
- } else {
- setProfile(false);
- console.log(data);
- }
+ fetchProfile();
}
- };
-
- useEffect(() => {
- fetchProfile();
- }, []);
+ const checkProfile = (data: { name: string; image: string; department: string; description: string }) => {
+ return data.name && data.image && data.department && data.description;
+ };
+ }, [auth.token, staffId, auth.isAuthenticated]);
return (
<>
-
{profile === null && "Loading..."}
- {profile && typeof profile === "object" && }
- {profile === false && "Profile not found"}
+ {profile && typeof profile === "object" && staffId && }
+ {profile === false && Profile not found }
>
);
};
From dc096c4912a72f67401d7ba685356188ccb16a89 Mon Sep 17 00:00:00 2001
From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com>
Date: Fri, 22 Nov 2024 18:50:22 -0500
Subject: [PATCH 13/13] ignore js as those files will be convereted and are
riddled with lint errors
---
.github/workflows/eslint.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml
index d1dc50a3..a2e7a67d 100644
--- a/.github/workflows/eslint.yml
+++ b/.github/workflows/eslint.yml
@@ -23,6 +23,6 @@ jobs:
- name: Run EsLint
uses: sibiraj-s/action-eslint@v3
with:
- eslint-args: "src/**/*.{js,jsx,ts,tsx} --max-warnings=0"
- extensions: "js,jsx,ts,tsx"
+ eslint-args: "src/**/*.{ts,tsx} --max-warnings=0"
+ extensions: "ts,tsx"
annotations: true