Implement project leaving in Delete.jsx

This commit is contained in:
Mathias Wagner
2024-07-22 22:19:45 +02:00
parent 1804684ded
commit 9782971ad6

View File

@ -1,6 +1,6 @@
import {Box, Button, Typography} from "@mui/material";
import {Delete as DeleteIcon} from "@mui/icons-material";
import {deleteRequest} from "@/common/utils/RequestUtil.js";
import {Delete as DeleteIcon, Logout} from "@mui/icons-material";
import {deleteRequest, postRequest} from "@/common/utils/RequestUtil.js";
import {useContext} from "react";
import {ProjectContext} from "@/states/Dashboard/contexts/Project";
@ -15,14 +15,26 @@ export const Delete = () => {
}
}
const leaveProject = async () => {
try {
await postRequest(`/project/${currentProject.id}/leave`);
await updateProjects();
} catch (e) {
console.error(e.message);
}
}
return (
<Box sx={{border: 1.5, borderColor: 'red', borderRadius: 1.5, p: 2.5, width: {xs: "100%", lg: "33%"}}}>
<Typography variant="h5" fontWeight={700}>Delete project</Typography>
<Typography variant="h5" fontWeight={700}>{currentProject["role"] === undefined ? "Delete" : "Leave"} project</Typography>
<Typography variant="body1" color="text.secondary" fontWeight={500}>
This action cannot be undone. I hope you know what you are doing.
</Typography>
<Button variant="contained" sx={{mt: 2}} color="error" startIcon={<DeleteIcon/>} onClick={deleteProject}>Löschen</Button>
{currentProject.role === undefined && <Button variant="contained" sx={{mt: 2}} color="error" startIcon={<DeleteIcon/>} onClick={deleteProject}>Delete</Button>}
{currentProject.role !== undefined && <Button variant="contained" sx={{mt: 2}} color="error" startIcon={<Logout/>} onClick={leaveProject}>Leave</Button>}
</Box>
)
}