diff --git a/geneit_app/src/App.tsx b/geneit_app/src/App.tsx
index 2d5a9fd..7346164 100644
--- a/geneit_app/src/App.tsx
+++ b/geneit_app/src/App.tsx
@@ -16,6 +16,7 @@ import { BaseAuthenticatedPage } from "./widgets/BaseAuthenticatedPage";
import { BaseFamilyRoute } from "./widgets/BaseFamilyRoute";
import { BaseLoginPage } from "./widgets/BaseLoginpage";
import { FamilyUsersListRoute } from "./routes/family/FamilyUsersListRoute";
+import { FamilySettingsRoute } from "./routes/family/FamilySettingsRoute";
interface AuthContext {
signedIn: boolean;
@@ -46,6 +47,7 @@ export function App(): React.ReactElement {
} />
}>
} />
+ } />
} />
} />
diff --git a/geneit_app/src/api/FamilyApi.ts b/geneit_app/src/api/FamilyApi.ts
index 6e7032f..864dcea 100644
--- a/geneit_app/src/api/FamilyApi.ts
+++ b/geneit_app/src/api/FamilyApi.ts
@@ -186,4 +186,20 @@ export class FamilyApi {
uri: `/family/${user.family_id}/user/${user.user_id}`,
});
}
+
+ /**
+ * Update a family settings
+ */
+ static async UpdateFamily(settings: {
+ id: number;
+ name: string;
+ }): Promise {
+ await APIClient.exec({
+ method: "PATCH",
+ uri: `/family/${settings.id}`,
+ jsonData: {
+ name: settings.name,
+ },
+ });
+ }
}
diff --git a/geneit_app/src/routes/family/FamilySettingsRoute.tsx b/geneit_app/src/routes/family/FamilySettingsRoute.tsx
new file mode 100644
index 0000000..02c860e
--- /dev/null
+++ b/geneit_app/src/routes/family/FamilySettingsRoute.tsx
@@ -0,0 +1,105 @@
+import {
+ Alert,
+ Box,
+ Button,
+ Card,
+ CardActions,
+ CardContent,
+ TextField,
+ Typography,
+} from "@mui/material";
+import React from "react";
+import { FamilyApi } from "../../api/FamilyApi";
+import { ServerApi } from "../../api/ServerApi";
+import { useAlert } from "../../context_providers/AlertDialogProvider";
+import { useFamily } from "../../widgets/BaseFamilyRoute";
+import { formatDate } from "../../widgets/TimeWidget";
+
+export function FamilySettingsRoute(): React.ReactElement {
+ const family = useFamily();
+ const alert = useAlert();
+
+ const [newName, setNewName] = React.useState(family.family.name);
+
+ const canEdit = family.family.is_admin;
+
+ const [error, setError] = React.useState(null);
+ const [success, setSuccess] = React.useState(null);
+
+ const updateFamily = async () => {
+ try {
+ setError(null);
+ setSuccess(null);
+
+ await FamilyApi.UpdateFamily({
+ id: family.family.family_id,
+ name: newName,
+ });
+
+ family.reloadFamilyInfo();
+
+ alert("Les paramètres de la famille ont été mis à jour avec succès !");
+ } catch (e) {
+ console.error(e);
+ setError("Echec de la mise à jour des paramètres de la famille !");
+ }
+ };
+
+ return (
+ <>
+
+ {error && {error}}
+ {success && {success}}
+
+
+
+ Paramètres de la famille
+
+
+
+
+
+
+
+ setNewName(e.target.value)}
+ inputProps={{
+ maxLength: ServerApi.Config.constraints.family_name_len.max,
+ }}
+ />
+
+
+
+
+
+
+ >
+ );
+}
diff --git a/geneit_backend/src/controllers/families_controller.rs b/geneit_backend/src/controllers/families_controller.rs
index b38ce25..5b5f4c0 100644
--- a/geneit_backend/src/controllers/families_controller.rs
+++ b/geneit_backend/src/controllers/families_controller.rs
@@ -98,6 +98,13 @@ pub async fn update(
f: FamilyInPathWithAdminMembership,
req: web::Json,
) -> HttpResult {
+ if !StaticConstraints::default()
+ .family_name_len
+ .validate(&req.name)
+ {
+ return Ok(HttpResponse::BadRequest().body("Invalid family name!"));
+ }
+
let mut family = families_service::get_by_id(f.family_id()).await?;
family.name = req.0.name;
families_service::update_family(&family).await?;