Co-authored-by: al8763be <al8763be@users.noreply.github.com>
This commit is contained in:
parent
e1b410c850
commit
d4cc556366
8 changed files with 155 additions and 4 deletions
|
@ -133,6 +133,11 @@ interface API {
|
|||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<UserProjectMember[]>>;
|
||||
|
||||
removeProject(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<string>>;
|
||||
}
|
||||
|
||||
/** An instance of the API */
|
||||
|
@ -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",
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue