diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index e7de646..f0b024b 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -1,13 +1,13 @@ +import { NewProjMember } from "../Components/AddMember"; +import { ProjectMember } from "../Components/GetUsersInProject"; import { NewWeeklyReport, NewUser, User, Project, NewProject, - UserProjectMember, WeeklyReport, StrNameChange, - NewProjMember, } from "../Types/goTypes"; /** @@ -137,7 +137,7 @@ interface API { getAllUsersProject( projectName: string, token: string, - ): Promise>; + ): Promise>; /** * Changes the username of a user in the database. * @param {StrNameChange} data The object containing the previous and new username. @@ -151,7 +151,7 @@ interface API { addUserToProject( user: NewProjMember, token: string, - ): Promise>; + ): Promise>; removeProject( projectName: string, @@ -165,10 +165,7 @@ interface API { * @param {number} reportId The id of the report to sign * @param {string} token The authentication token */ - signReport( - reportId: number, - token: string, - ): Promise>; + signReport(reportId: number, token: string): Promise>; } /** An instance of the API */ @@ -281,7 +278,7 @@ export const api: API = { async addUserToProject( user: NewProjMember, token: string, - ): Promise> { + ): Promise> { try { const response = await fetch("/api/addUserToProject", { method: "PUT", @@ -520,7 +517,7 @@ export const api: API = { async getAllUsersProject( projectName: string, token: string, - ): Promise> { + ): Promise> { try { const response = await fetch(`/api/getUsersProject/${projectName}`, { method: "GET", @@ -536,7 +533,7 @@ export const api: API = { message: "Failed to get users", }); } else { - const data = (await response.json()) as UserProjectMember[]; + const data = (await response.json()) as ProjectMember[]; return Promise.resolve({ success: true, data }); } } catch (e) { @@ -622,5 +619,5 @@ export const api: API = { } catch (e) { return { success: false, message: "Failed to sign report" }; } - } + }, }; diff --git a/frontend/src/Components/AddMember.tsx b/frontend/src/Components/AddMember.tsx index d29be68..194afe8 100644 --- a/frontend/src/Components/AddMember.tsx +++ b/frontend/src/Components/AddMember.tsx @@ -1,5 +1,10 @@ import { APIResponse, api } from "../API/API"; -import { NewProjMember } from "../Types/goTypes"; + +export interface NewProjMember { + username: string; + role: string; + projectname: string; +} /** * Tries to add a member to a project @@ -21,7 +26,7 @@ function AddMember(props: { memberToAdd: NewProjMember }): boolean { props.memberToAdd, localStorage.getItem("accessToken") ?? "", ) - .then((response: APIResponse) => { + .then((response: APIResponse) => { if (response.success) { alert("Member added"); added = true; diff --git a/frontend/src/Components/AddUserToProject.tsx b/frontend/src/Components/AddUserToProject.tsx index 9f4439b..2f5e6af 100644 --- a/frontend/src/Components/AddUserToProject.tsx +++ b/frontend/src/Components/AddUserToProject.tsx @@ -1,8 +1,7 @@ import { useState } from "react"; -import { NewProjMember } from "../Types/goTypes"; import Button from "./Button"; import GetAllUsers from "./GetAllUsers"; -import AddMember from "./AddMember"; +import AddMember, { NewProjMember } from "./AddMember"; import BackButton from "./BackButton"; /** diff --git a/frontend/src/Components/GetUsersInProject.tsx b/frontend/src/Components/GetUsersInProject.tsx index acdd965..a682d3f 100644 --- a/frontend/src/Components/GetUsersInProject.tsx +++ b/frontend/src/Components/GetUsersInProject.tsx @@ -1,7 +1,11 @@ import { Dispatch, useEffect } from "react"; -import { UserProjectMember } from "../Types/goTypes"; import { api } from "../API/API"; +export interface ProjectMember { + Username: string; + UserRole: string; +} + /** * Gets all projects that user is a member of * @param props - A setStateAction for the array you want to put projects in @@ -12,9 +16,9 @@ import { api } from "../API/API"; */ function GetUsersInProject(props: { projectName: string; - setUsersProp: Dispatch>; + setUsersProp: Dispatch>; }): void { - const setUsers: Dispatch> = + const setUsers: Dispatch> = props.setUsersProp; useEffect(() => { const fetchUsers = async (): Promise => { diff --git a/frontend/src/Components/ProjectInfoModal.tsx b/frontend/src/Components/ProjectInfoModal.tsx index 3075b19..27d4e6e 100644 --- a/frontend/src/Components/ProjectInfoModal.tsx +++ b/frontend/src/Components/ProjectInfoModal.tsx @@ -1,7 +1,6 @@ import { useState } from "react"; import Button from "./Button"; -import { UserProjectMember } from "../Types/goTypes"; -import GetUsersInProject from "./GetUsersInProject"; +import GetUsersInProject, { ProjectMember } from "./GetUsersInProject"; import { Link } from "react-router-dom"; function ProjectInfoModal(props: { @@ -10,7 +9,7 @@ function ProjectInfoModal(props: { onClose: () => void; onClick: (username: string) => void; }): JSX.Element { - const [users, setUsers] = useState([]); + const [users, setUsers] = useState([]); GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers }); if (!props.isVisible) return <>;