diff --git a/src/App.tsx b/src/App.tsx index c91c90bf..765b0dc8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,6 +14,7 @@ import PastProgramsPage from "./pages/PastProgramsPage"; import StudentDashboard from "./pages/StudentDashboard"; import RegistrationForm from "./pages/RegistrationForm"; import NotFoundPage from "./pages/404"; +import ProjectStats from "./pages/ProjectStat"; function App() { return ( @@ -61,6 +62,10 @@ function App() { path={ROUTER_PATHS.PASTPROGRAMS} element={} /> + } + /> } /> diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 40aaea15..e7ac0419 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -17,6 +17,7 @@ const LINKS = [ { name: "PROJECTS", link: ROUTER_PATHS.PROJECTS_LIST }, // { name: "TESTIMONIALS", link: ROUTER_PATHS.TESTIMONIALS }, { name: "FAQs", link: ROUTER_PATHS.FAQ }, + { name: "PROJECT STATS", link: ROUTER_PATHS.ALL_PROJECT_STATS }, ]; function BrandLogo() { diff --git a/src/pages/ProjectStat.tsx b/src/pages/ProjectStat.tsx new file mode 100644 index 00000000..c1ab0a29 --- /dev/null +++ b/src/pages/ProjectStat.tsx @@ -0,0 +1,76 @@ +import { useEffect, useState } from "react"; +import { useParams } from "react-router-dom"; // Import useParams for accessing route parameters +import { makeRequest } from "../util/backend"; +import { useAuthContext } from "../util/auth"; +import { IEndpointTypes } from "../util/types"; +//import { Console } from "console"; + +function ProjectStats() { + console.log("abcd") + const authContext = useAuthContext(); + const [projectStats, setProjectStats] = useState< + IEndpointTypes["stats/projects"]["response"] | null + >(null); + const [error, setError] = useState(null); + + // Access the project ID from the route parameters + const { } = useParams(); + + useEffect(() => { + // Make a request to the specific project stats endpoint + makeRequest("stats/projects", "get", null, authContext.jwt) + .then((response) => { + console.log(response) + if (response.is_ok) { + setProjectStats(response.response); + } else { + setError("Error fetching project stats."); + console.log(response.response); + } + }) + .catch((e) => { + setError("Error fetching project stats."); + console.log(e); + }); + }, []); + + return ( +
+

+ Project Stats +

+ {error !== null ? ( +

{error}

+ ) : projectStats !== null ? ( +
+ + + + + + + + {/* Add more columns as needed */} + + + + {projectStats.projects.map((project) => ( + + + + + + {/* Add more cells as needed */} + + ))} + +
Project NameRepository LinkCommit CountPull Count
{project.name}{project.repo_link}{project.commit_count}{project.pull_count}
+
+ ) : ( + null + )} +
+ ); +} + +export default ProjectStats; diff --git a/src/util/types.ts b/src/util/types.ts index 8b9cd673..ee4ed2b9 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -78,6 +78,16 @@ export interface IEndpointTypes { students: IStudentInfo[]; }; }; + "stats/projects": { + request: null; + response: { + name: string; + username: string; + email: string; + projects: IProjectDashboardInfo[]; + students: IStudentInfo[]; + }; + }; [route: `project/${number}`]: { request: null; response: IProject;