Merge remote-tracking branch 'origin/AlexTester' into gruppDM

This commit is contained in:
Davenludd 2024-03-28 12:10:53 +01:00
commit e589726ab2
8 changed files with 165 additions and 14 deletions

View file

@ -47,7 +47,6 @@ interface API {
* @returns {Promise<APIResponse<boolean>>} A promise containing the API response indicating if the user is a project manager.
*/
checkIfProjectManager(
username: string,
projectName: string,
token: string,
): Promise<APIResponse<boolean>>;
@ -133,6 +132,11 @@ interface API {
projectName: string,
token: string,
): Promise<APIResponse<UserProjectMember[]>>;
removeProject(
projectName: string,
token: string,
): Promise<APIResponse<string>>;
}
/** An instance of the API */
@ -190,19 +194,20 @@ export const api: API = {
},
async checkIfProjectManager(
username: string,
projectName: string,
token: string,
): Promise<APIResponse<boolean>> {
try {
const response = await fetch("/api/checkIfProjectManager", {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
const response = await fetch(
`/api/checkIfProjectManager?projectName=${projectName}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
},
body: JSON.stringify({ username, projectName }),
});
);
if (!response.ok) {
return {
@ -214,7 +219,7 @@ export const api: API = {
return { success: true, data };
}
} catch (e) {
return { success: false, message: "fuck" };
return { success: false, message: "Failed to check if project manager" };
}
},
@ -484,4 +489,34 @@ export const api: API = {
});
}
},
async removeProject(
projectName: string,
token: string,
): Promise<APIResponse<string>> {
try {
const response = await fetch(`/api/projectdelete/${projectName}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
});
if (!response.ok) {
return Promise.resolve({
success: false,
message: "Failed to remove project",
});
} else {
const data = await response.text();
return Promise.resolve({ success: true, message: data });
}
} catch (e) {
return Promise.resolve({
success: false,
message: "Failed to remove project",
});
}
},
};

View file

@ -1,17 +1,26 @@
import { useParams } from "react-router-dom";
import { api } from "../../API/API";
import BackButton from "../../Components/BackButton";
import BasicWindow from "../../Components/BasicWindow";
import Button from "../../Components/Button";
async function handleDeleteProject(
projectName: string,
token: string,
): Promise<void> {
await api.removeProject(projectName, token);
}
function AdminProjectPage(): JSX.Element {
const content = <></>;
const { projectName } = useParams();
const token = localStorage.getItem("accessToken");
const buttons = (
<>
<Button
text="Delete"
onClick={(): void => {
return;
}}
onClick={() => handleDeleteProject(projectName, token)}
type="button"
/>
<BackButton />
@ -20,4 +29,5 @@ function AdminProjectPage(): JSX.Element {
return <BasicWindow content={content} buttons={buttons} />;
}
export default AdminProjectPage;