From ac623fde9b3ba21b3b47fd7276d32b71cf197794 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Wed, 16 Aug 2023 10:18:19 +0200 Subject: [PATCH] Can delete member for members route --- .../routes/family/FamilyMembersListRoute.tsx | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/geneit_app/src/routes/family/FamilyMembersListRoute.tsx b/geneit_app/src/routes/family/FamilyMembersListRoute.tsx index 97187a8..57a3b60 100644 --- a/geneit_app/src/routes/family/FamilyMembersListRoute.tsx +++ b/geneit_app/src/routes/family/FamilyMembersListRoute.tsx @@ -4,17 +4,41 @@ import { FamilyPageTitle } from "../../widgets/FamilyPageTitle"; import { Button, Tooltip } from "@mui/material"; import AddIcon from "@mui/icons-material/Add"; import { RouterLink } from "../../widgets/RouterLink"; -import { Member, dateTimestamp, fmtDate } from "../../api/MemberApi"; +import { Member, MemberApi, dateTimestamp, fmtDate } from "../../api/MemberApi"; import { DataGrid, GridActionsCellItem, GridColDef } from "@mui/x-data-grid"; import { MemberPhoto } from "../../widgets/MemberPhoto"; import DeleteIcon from "@mui/icons-material/DeleteOutlined"; import EditIcon from "@mui/icons-material/Edit"; import VisibilityIcon from "@mui/icons-material/Visibility"; +import { useAlert } from "../../hooks/context_providers/AlertDialogProvider"; +import { useConfirm } from "../../hooks/context_providers/ConfirmDialogProvider"; +import { useSnackbar } from "../../hooks/context_providers/SnackbarProvider"; export function FamilyMembersListRoute(): React.ReactElement { + const alert = useAlert(); + const confirm = useConfirm(); + const snackbar = useSnackbar(); + const family = useFamily(); - const processDeletion = async (m: Member) => {}; + const processDeletion = async (m: Member) => { + try { + if ( + !(await confirm( + `Voulez-vous vraiment supprimer la fiche de ${m.fullName} ?` + )) + ) + return; + + await MemberApi.Delete(m); + await family.reloadMembersList(); + + snackbar("La fiche du membre a été supprimée avec succès !"); + } catch (e) { + console.error(e); + alert("Echec de la suppression de la fiche ! "); + } + }; return ( <>