Can delete a family
This commit is contained in:
parent
f1d6998dd8
commit
8cc720a214
@ -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}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,15 +9,20 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import { FamilyApi } from "../../api/FamilyApi";
|
import { FamilyApi } from "../../api/FamilyApi";
|
||||||
import { ServerApi } from "../../api/ServerApi";
|
import { ServerApi } from "../../api/ServerApi";
|
||||||
import { useAlert } from "../../context_providers/AlertDialogProvider";
|
import { useAlert } from "../../context_providers/AlertDialogProvider";
|
||||||
|
import { useConfirm } from "../../context_providers/ConfirmDialogProvider";
|
||||||
import { useFamily } from "../../widgets/BaseFamilyRoute";
|
import { useFamily } from "../../widgets/BaseFamilyRoute";
|
||||||
import { formatDate } from "../../widgets/TimeWidget";
|
import { formatDate } from "../../widgets/TimeWidget";
|
||||||
|
|
||||||
export function FamilySettingsRoute(): React.ReactElement {
|
export function FamilySettingsRoute(): React.ReactElement {
|
||||||
const family = useFamily();
|
|
||||||
const alert = useAlert();
|
const alert = useAlert();
|
||||||
|
const confirm = useConfirm();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const family = useFamily();
|
||||||
|
|
||||||
const [newName, setNewName] = React.useState(family.family.name);
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card style={{ margin: "10px auto", maxWidth: "450px" }}>
|
<Card style={{ margin: "10px auto", maxWidth: "450px" }}>
|
||||||
@ -100,6 +125,17 @@ export function FamilySettingsRoute(): React.ReactElement {
|
|||||||
</Button>
|
</Button>
|
||||||
</CardActions>
|
</CardActions>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<div style={{ textAlign: "center", marginTop: "50px" }}>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
color="error"
|
||||||
|
onClick={deleteFamily}
|
||||||
|
disabled={!family.family.is_admin}
|
||||||
|
>
|
||||||
|
Supprimer la famille
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user