From c80eb44cf4d83b2bf5ea6e58dc16b34db97aa2f1 Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 20:37:31 +0200 Subject: [PATCH] remove project --- .../src/pages/subjectsPage/ProjectsView.tsx | 3 ++- .../src/pages/subjectsPage/SubjectsPage.tsx | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/frontend/src/pages/subjectsPage/ProjectsView.tsx b/frontend/frontend/src/pages/subjectsPage/ProjectsView.tsx index 43dc2b66..4675535e 100644 --- a/frontend/frontend/src/pages/subjectsPage/ProjectsView.tsx +++ b/frontend/frontend/src/pages/subjectsPage/ProjectsView.tsx @@ -329,7 +329,8 @@ export function ProjectsView({ } deleteEvent={() => deleteAssignment( - project.index + project.assignment + .project_id ) } archiveEvent={() => diff --git a/frontend/frontend/src/pages/subjectsPage/SubjectsPage.tsx b/frontend/frontend/src/pages/subjectsPage/SubjectsPage.tsx index 273023ca..7ec6b040 100644 --- a/frontend/frontend/src/pages/subjectsPage/SubjectsPage.tsx +++ b/frontend/frontend/src/pages/subjectsPage/SubjectsPage.tsx @@ -164,19 +164,20 @@ export function SubjectsPage() { } const [openDeletePopup, setOpenDeletePopup] = useState(false) - const [deleteIndex, setDeleteIndex] = useState(0) + const [deleteId, setDeleteId] = useState(0) const [openArchivePopup, setOpenArchivePopup] = useState(false) const [archiveIndex, setArchiveIndex] = useState(0) - const deleteAssignment = (index: number) => { - setDeleteIndex(index) + const deleteAssignment = (id: number) => { + setDeleteId(id) setOpenDeletePopup(true) } const doDelete = async () => { - setAssignments(assignments.filter((_, i) => i !== deleteIndex)) + setAssignments( + assignments.filter((project) => project.project_id !== deleteId) + ) try { - const deletedAssignment = assignments[deleteIndex] - await instance.delete(`/projecten/${deletedAssignment.project_id}/`) + await instance.delete(`/projecten/${deleteId}/`) } catch (error) { console.error('Error deleting data:', error) }