Fixed types and imports of types
This commit is contained in:
parent
8b6462abee
commit
5f42fa7818
5 changed files with 26 additions and 22 deletions
|
@ -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<APIResponse<UserProjectMember[]>>;
|
||||
): Promise<APIResponse<ProjectMember[]>>;
|
||||
/**
|
||||
* 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<APIResponse<NewProjMember>>;
|
||||
): Promise<APIResponse<void>>;
|
||||
|
||||
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<APIResponse<string>>;
|
||||
signReport(reportId: number, token: string): Promise<APIResponse<string>>;
|
||||
}
|
||||
|
||||
/** An instance of the API */
|
||||
|
@ -281,7 +278,7 @@ export const api: API = {
|
|||
async addUserToProject(
|
||||
user: NewProjMember,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewProjMember>> {
|
||||
): Promise<APIResponse<void>> {
|
||||
try {
|
||||
const response = await fetch("/api/addUserToProject", {
|
||||
method: "PUT",
|
||||
|
@ -520,7 +517,7 @@ export const api: API = {
|
|||
async getAllUsersProject(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<UserProjectMember[]>> {
|
||||
): Promise<APIResponse<ProjectMember[]>> {
|
||||
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" };
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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<NewProjMember>) => {
|
||||
.then((response: APIResponse<void>) => {
|
||||
if (response.success) {
|
||||
alert("Member added");
|
||||
added = true;
|
||||
|
|
|
@ -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";
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<React.SetStateAction<UserProjectMember[]>>;
|
||||
setUsersProp: Dispatch<React.SetStateAction<ProjectMember[]>>;
|
||||
}): void {
|
||||
const setUsers: Dispatch<React.SetStateAction<UserProjectMember[]>> =
|
||||
const setUsers: Dispatch<React.SetStateAction<ProjectMember[]>> =
|
||||
props.setUsersProp;
|
||||
useEffect(() => {
|
||||
const fetchUsers = async (): Promise<void> => {
|
||||
|
|
|
@ -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<UserProjectMember[]>([]);
|
||||
const [users, setUsers] = useState<ProjectMember[]>([]);
|
||||
GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers });
|
||||
if (!props.isVisible) return <></>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue