Fixed types and imports of types

This commit is contained in:
Peter KW 2024-03-31 20:54:00 +02:00
parent 8b6462abee
commit 5f42fa7818
5 changed files with 26 additions and 22 deletions

View file

@ -1,13 +1,13 @@
import { NewProjMember } from "../Components/AddMember";
import { ProjectMember } from "../Components/GetUsersInProject";
import { import {
NewWeeklyReport, NewWeeklyReport,
NewUser, NewUser,
User, User,
Project, Project,
NewProject, NewProject,
UserProjectMember,
WeeklyReport, WeeklyReport,
StrNameChange, StrNameChange,
NewProjMember,
} from "../Types/goTypes"; } from "../Types/goTypes";
/** /**
@ -137,7 +137,7 @@ interface API {
getAllUsersProject( getAllUsersProject(
projectName: string, projectName: string,
token: string, token: string,
): Promise<APIResponse<UserProjectMember[]>>; ): Promise<APIResponse<ProjectMember[]>>;
/** /**
* Changes the username of a user in the database. * Changes the username of a user in the database.
* @param {StrNameChange} data The object containing the previous and new username. * @param {StrNameChange} data The object containing the previous and new username.
@ -151,7 +151,7 @@ interface API {
addUserToProject( addUserToProject(
user: NewProjMember, user: NewProjMember,
token: string, token: string,
): Promise<APIResponse<NewProjMember>>; ): Promise<APIResponse<void>>;
removeProject( removeProject(
projectName: string, projectName: string,
@ -165,10 +165,7 @@ interface API {
* @param {number} reportId The id of the report to sign * @param {number} reportId The id of the report to sign
* @param {string} token The authentication token * @param {string} token The authentication token
*/ */
signReport( signReport(reportId: number, token: string): Promise<APIResponse<string>>;
reportId: number,
token: string,
): Promise<APIResponse<string>>;
} }
/** An instance of the API */ /** An instance of the API */
@ -281,7 +278,7 @@ export const api: API = {
async addUserToProject( async addUserToProject(
user: NewProjMember, user: NewProjMember,
token: string, token: string,
): Promise<APIResponse<NewProjMember>> { ): Promise<APIResponse<void>> {
try { try {
const response = await fetch("/api/addUserToProject", { const response = await fetch("/api/addUserToProject", {
method: "PUT", method: "PUT",
@ -520,7 +517,7 @@ export const api: API = {
async getAllUsersProject( async getAllUsersProject(
projectName: string, projectName: string,
token: string, token: string,
): Promise<APIResponse<UserProjectMember[]>> { ): Promise<APIResponse<ProjectMember[]>> {
try { try {
const response = await fetch(`/api/getUsersProject/${projectName}`, { const response = await fetch(`/api/getUsersProject/${projectName}`, {
method: "GET", method: "GET",
@ -536,7 +533,7 @@ export const api: API = {
message: "Failed to get users", message: "Failed to get users",
}); });
} else { } else {
const data = (await response.json()) as UserProjectMember[]; const data = (await response.json()) as ProjectMember[];
return Promise.resolve({ success: true, data }); return Promise.resolve({ success: true, data });
} }
} catch (e) { } catch (e) {
@ -622,5 +619,5 @@ export const api: API = {
} catch (e) { } catch (e) {
return { success: false, message: "Failed to sign report" }; return { success: false, message: "Failed to sign report" };
} }
} },
}; };

View file

@ -1,5 +1,10 @@
import { APIResponse, api } from "../API/API"; 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 * Tries to add a member to a project
@ -21,7 +26,7 @@ function AddMember(props: { memberToAdd: NewProjMember }): boolean {
props.memberToAdd, props.memberToAdd,
localStorage.getItem("accessToken") ?? "", localStorage.getItem("accessToken") ?? "",
) )
.then((response: APIResponse<NewProjMember>) => { .then((response: APIResponse<void>) => {
if (response.success) { if (response.success) {
alert("Member added"); alert("Member added");
added = true; added = true;

View file

@ -1,8 +1,7 @@
import { useState } from "react"; import { useState } from "react";
import { NewProjMember } from "../Types/goTypes";
import Button from "./Button"; import Button from "./Button";
import GetAllUsers from "./GetAllUsers"; import GetAllUsers from "./GetAllUsers";
import AddMember from "./AddMember"; import AddMember, { NewProjMember } from "./AddMember";
import BackButton from "./BackButton"; import BackButton from "./BackButton";
/** /**

View file

@ -1,7 +1,11 @@
import { Dispatch, useEffect } from "react"; import { Dispatch, useEffect } from "react";
import { UserProjectMember } from "../Types/goTypes";
import { api } from "../API/API"; import { api } from "../API/API";
export interface ProjectMember {
Username: string;
UserRole: string;
}
/** /**
* Gets all projects that user is a member of * Gets all projects that user is a member of
* @param props - A setStateAction for the array you want to put projects in * @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: { function GetUsersInProject(props: {
projectName: string; projectName: string;
setUsersProp: Dispatch<React.SetStateAction<UserProjectMember[]>>; setUsersProp: Dispatch<React.SetStateAction<ProjectMember[]>>;
}): void { }): void {
const setUsers: Dispatch<React.SetStateAction<UserProjectMember[]>> = const setUsers: Dispatch<React.SetStateAction<ProjectMember[]>> =
props.setUsersProp; props.setUsersProp;
useEffect(() => { useEffect(() => {
const fetchUsers = async (): Promise<void> => { const fetchUsers = async (): Promise<void> => {

View file

@ -1,7 +1,6 @@
import { useState } from "react"; import { useState } from "react";
import Button from "./Button"; import Button from "./Button";
import { UserProjectMember } from "../Types/goTypes"; import GetUsersInProject, { ProjectMember } from "./GetUsersInProject";
import GetUsersInProject from "./GetUsersInProject";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
function ProjectInfoModal(props: { function ProjectInfoModal(props: {
@ -10,7 +9,7 @@ function ProjectInfoModal(props: {
onClose: () => void; onClose: () => void;
onClick: (username: string) => void; onClick: (username: string) => void;
}): JSX.Element { }): JSX.Element {
const [users, setUsers] = useState<UserProjectMember[]>([]); const [users, setUsers] = useState<ProjectMember[]>([]);
GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers }); GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers });
if (!props.isVisible) return <></>; if (!props.isVisible) return <></>;