From 298df7be7705235c7838c50e17e1cab094746c6d Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sat, 26 Aug 2023 16:32:50 +0200 Subject: [PATCH] Can change disableCouplePHoto setting --- geneit_app/src/api/FamilyApi.ts | 14 ++++++++++++-- .../src/routes/family/FamilySettingsRoute.tsx | 19 +++++++++++++++++++ geneit_app/src/widgets/BaseFamilyRoute.tsx | 6 +++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/geneit_app/src/api/FamilyApi.ts b/geneit_app/src/api/FamilyApi.ts index f43bf2f..1518cac 100644 --- a/geneit_app/src/api/FamilyApi.ts +++ b/geneit_app/src/api/FamilyApi.ts @@ -83,6 +83,14 @@ export class Family implements FamilyAPI { } } +export class ExtendedFamilyInfo extends Family { + public disable_couple_photos: boolean; + constructor(p: any) { + super(p); + this.disable_couple_photos = p.disable_couple_photos; + } +} + export enum JoinFamilyResult { TooManyRequests, InvalidCode, @@ -152,13 +160,13 @@ export class FamilyApi { /** * Get information about a single family */ - static async GetSingle(id: number): Promise { + static async GetSingle(id: number): Promise { const res = await APIClient.exec({ method: "GET", uri: `/family/${id}`, }); - return new Family(res.data); + return new ExtendedFamilyInfo(res.data); } /** @@ -222,12 +230,14 @@ export class FamilyApi { static async UpdateFamily(settings: { id: number; name: string; + disable_couple_photos: boolean; }): Promise { await APIClient.exec({ method: "PATCH", uri: `/family/${settings.id}`, jsonData: { name: settings.name, + disable_couple_photos: settings.disable_couple_photos, }, }); } diff --git a/geneit_app/src/routes/family/FamilySettingsRoute.tsx b/geneit_app/src/routes/family/FamilySettingsRoute.tsx index c81e927..9f98d70 100644 --- a/geneit_app/src/routes/family/FamilySettingsRoute.tsx +++ b/geneit_app/src/routes/family/FamilySettingsRoute.tsx @@ -6,7 +6,10 @@ import { Button, CardActions, CardContent, + Checkbox, + FormControlLabel, TextField, + Tooltip, Typography, } from "@mui/material"; import React from "react"; @@ -73,6 +76,9 @@ function FamilySettingsCard(): React.ReactElement { const family = useFamily(); const [newName, setNewName] = React.useState(family.family.name); + const [disableCouplePhotos, setDisableCouplePhotos] = React.useState( + family.family.disable_couple_photos + ); const canEdit = family.family.is_admin; @@ -87,6 +93,7 @@ function FamilySettingsCard(): React.ReactElement { await FamilyApi.UpdateFamily({ id: family.family.family_id, name: newName, + disable_couple_photos: disableCouplePhotos, }); family.reloadFamilyInfo(); @@ -137,6 +144,18 @@ function FamilySettingsCard(): React.ReactElement { maxLength: ServerApi.Config.constraints.family_name_len.max, }} /> + + setDisableCouplePhotos(c)} + /> + } + label="Désactiver les photos de couple" + /> + diff --git a/geneit_app/src/widgets/BaseFamilyRoute.tsx b/geneit_app/src/widgets/BaseFamilyRoute.tsx index c6639e6..5cad174 100644 --- a/geneit_app/src/widgets/BaseFamilyRoute.tsx +++ b/geneit_app/src/widgets/BaseFamilyRoute.tsx @@ -26,7 +26,7 @@ import { } from "@mui/material"; import React from "react"; import { Outlet, useLocation, useParams } from "react-router-dom"; -import { Family, FamilyApi } from "../api/FamilyApi"; +import { ExtendedFamilyInfo, Family, FamilyApi } from "../api/FamilyApi"; import { MemberApi, MembersList } from "../api/MemberApi"; import { useAlert } from "../hooks/context_providers/AlertDialogProvider"; import { useConfirm } from "../hooks/context_providers/ConfirmDialogProvider"; @@ -36,7 +36,7 @@ import { RouterLink } from "./RouterLink"; import { CoupleApi, CouplesList } from "../api/CoupleApi"; interface FamilyContext { - family: Family; + family: ExtendedFamilyInfo; members: MembersList; couples: CouplesList; familyId: number; @@ -53,7 +53,7 @@ export function BaseFamilyRoute(): React.ReactElement { const alert = useAlert(); const confirm = useConfirm(); - const [family, setFamily] = React.useState(null); + const [family, setFamily] = React.useState(null); const [members, setMembers] = React.useState(null); const [couples, setCouples] = React.useState(null);