Fixes to adding members

This commit is contained in:
Peter KW 2024-04-04 11:26:39 +02:00
parent a1d2520d88
commit 9a0f855d2b
3 changed files with 104 additions and 93 deletions

View file

@ -1,4 +1,4 @@
import { NewProjMember } from "../Components/AddMember";
import { AddMemberInfo } from "../Components/AddMember";
import { ProjectRoleChange } from "../Components/ChangeRole";
import { projectTimes } from "../Components/GetProjectTimes";
import { ProjectMember } from "../Components/GetUsersInProject";
@ -100,7 +100,7 @@ interface API {
): Promise<APIResponse<string>>;
/** Gets a weekly report for a specific user, project and week.
* Keep in mind that the user within the token needs to be PM
* Keep in mind that the user within the token needs to be PM
* of the project to get the report, unless the user is the target user.
* @param {string} projectName The name of the project.
* @param {string} week The week number.
@ -196,7 +196,7 @@ interface API {
): Promise<APIResponse<void>>;
addUserToProject(
user: NewProjMember,
addMemberInfo: AddMemberInfo,
token: string,
): Promise<APIResponse<void>>;
@ -335,18 +335,20 @@ export const api: API = {
},
async addUserToProject(
user: NewProjMember,
addMemberInfo: AddMemberInfo,
token: string,
): Promise<APIResponse<void>> {
try {
const response = await fetch("/api/addUserToProject", {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
const response = await fetch(
`/api/addUserToProject/${addMemberInfo.projectName}/?userName=${addMemberInfo.userName}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
},
body: JSON.stringify(user),
});
);
if (!response.ok) {
return { success: false, message: "Failed to add member" };