From 8cc720a214b9984105eb1d2cfdf9a321b71538a3 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Wed, 12 Jul 2023 17:58:03 +0200 Subject: [PATCH] Can delete a family --- geneit_app/src/api/FamilyApi.ts | 10 +++++ .../src/routes/family/FamilySettingsRoute.tsx | 38 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/geneit_app/src/api/FamilyApi.ts b/geneit_app/src/api/FamilyApi.ts index 864dcea..e1aeaa0 100644 --- a/geneit_app/src/api/FamilyApi.ts +++ b/geneit_app/src/api/FamilyApi.ts @@ -202,4 +202,14 @@ export class FamilyApi { }, }); } + + /** + * Delete a family + */ + static async DeleteFamily(family: Family) { + await APIClient.exec({ + method: "DELETE", + uri: `/family/${family.family_id}`, + }); + } } diff --git a/geneit_app/src/routes/family/FamilySettingsRoute.tsx b/geneit_app/src/routes/family/FamilySettingsRoute.tsx index 02c860e..acfcae9 100644 --- a/geneit_app/src/routes/family/FamilySettingsRoute.tsx +++ b/geneit_app/src/routes/family/FamilySettingsRoute.tsx @@ -9,15 +9,20 @@ import { Typography, } from "@mui/material"; import React from "react"; +import { useNavigate } from "react-router-dom"; import { FamilyApi } from "../../api/FamilyApi"; import { ServerApi } from "../../api/ServerApi"; import { useAlert } from "../../context_providers/AlertDialogProvider"; +import { useConfirm } from "../../context_providers/ConfirmDialogProvider"; import { useFamily } from "../../widgets/BaseFamilyRoute"; import { formatDate } from "../../widgets/TimeWidget"; export function FamilySettingsRoute(): React.ReactElement { - const family = useFamily(); const alert = useAlert(); + const confirm = useConfirm(); + const navigate = useNavigate(); + + const family = useFamily(); const [newName, setNewName] = React.useState(family.family.name); @@ -45,6 +50,26 @@ export function FamilySettingsRoute(): React.ReactElement { } }; + const deleteFamily = async () => { + try { + if ( + !(await confirm( + "Voulez-vous vraiment supprimer cette famille, et toute les données qui s'y rattachent ? Cette opération est absolument irréversible !" + )) + ) + return; + + await FamilyApi.DeleteFamily(family.family); + + await alert("La famille a été supprimée avec succès !"); + + navigate("/"); + } catch (e) { + console.error(e); + alert("Echec de la suppression de la famille !"); + } + }; + return ( <> @@ -100,6 +125,17 @@ export function FamilySettingsRoute(): React.ReactElement { + +
+ +
); }