mirror of
https://github.com/gnmyt/LicenseAPI.git
synced 2026-01-11 02:31:46 +00:00
Implement project leaving in Delete.jsx
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import {Box, Button, Typography} from "@mui/material";
|
import {Box, Button, Typography} from "@mui/material";
|
||||||
import {Delete as DeleteIcon} from "@mui/icons-material";
|
import {Delete as DeleteIcon, Logout} from "@mui/icons-material";
|
||||||
import {deleteRequest} from "@/common/utils/RequestUtil.js";
|
import {deleteRequest, postRequest} from "@/common/utils/RequestUtil.js";
|
||||||
import {useContext} from "react";
|
import {useContext} from "react";
|
||||||
import {ProjectContext} from "@/states/Dashboard/contexts/Project";
|
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 (
|
return (
|
||||||
<Box sx={{border: 1.5, borderColor: 'red', borderRadius: 1.5, p: 2.5, width: {xs: "100%", lg: "33%"}}}>
|
<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}>
|
<Typography variant="body1" color="text.secondary" fontWeight={500}>
|
||||||
This action cannot be undone. I hope you know what you are doing.
|
This action cannot be undone. I hope you know what you are doing.
|
||||||
</Typography>
|
</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>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user