From 9782971ad67f839d6d76405cb5c01f5364722629 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Mon, 22 Jul 2024 22:19:45 +0200 Subject: [PATCH] Implement project leaving in Delete.jsx --- .../Settings/components/Delete/Delete.jsx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dashboard/src/states/Dashboard/pages/Info/components/Settings/components/Delete/Delete.jsx b/dashboard/src/states/Dashboard/pages/Info/components/Settings/components/Delete/Delete.jsx index 9edfe31..2b18bfe 100644 --- a/dashboard/src/states/Dashboard/pages/Info/components/Settings/components/Delete/Delete.jsx +++ b/dashboard/src/states/Dashboard/pages/Info/components/Settings/components/Delete/Delete.jsx @@ -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 ( - Delete project + {currentProject["role"] === undefined ? "Delete" : "Leave"} project This action cannot be undone. I hope you know what you are doing. - + {currentProject.role === undefined && } + + {currentProject.role !== undefined && } + ) } \ No newline at end of file