Can disable couple photos #5

Merged
pierre merged 7 commits from disable_couple_photos into master 2023-08-26 14:55:24 +00:00
3 changed files with 34 additions and 5 deletions
Showing only changes of commit 298df7be77 - Show all commits

View File

@ -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 { export enum JoinFamilyResult {
TooManyRequests, TooManyRequests,
InvalidCode, InvalidCode,
@ -152,13 +160,13 @@ export class FamilyApi {
/** /**
* Get information about a single family * Get information about a single family
*/ */
static async GetSingle(id: number): Promise<Family> { static async GetSingle(id: number): Promise<ExtendedFamilyInfo> {
const res = await APIClient.exec({ const res = await APIClient.exec({
method: "GET", method: "GET",
uri: `/family/${id}`, uri: `/family/${id}`,
}); });
return new Family(res.data); return new ExtendedFamilyInfo(res.data);
} }
/** /**
@ -222,12 +230,14 @@ export class FamilyApi {
static async UpdateFamily(settings: { static async UpdateFamily(settings: {
id: number; id: number;
name: string; name: string;
disable_couple_photos: boolean;
}): Promise<void> { }): Promise<void> {
await APIClient.exec({ await APIClient.exec({
method: "PATCH", method: "PATCH",
uri: `/family/${settings.id}`, uri: `/family/${settings.id}`,
jsonData: { jsonData: {
name: settings.name, name: settings.name,
disable_couple_photos: settings.disable_couple_photos,
}, },
}); });
} }

View File

@ -6,7 +6,10 @@ import {
Button, Button,
CardActions, CardActions,
CardContent, CardContent,
Checkbox,
FormControlLabel,
TextField, TextField,
Tooltip,
Typography, Typography,
} from "@mui/material"; } from "@mui/material";
import React from "react"; import React from "react";
@ -73,6 +76,9 @@ function FamilySettingsCard(): React.ReactElement {
const family = useFamily(); const family = useFamily();
const [newName, setNewName] = React.useState(family.family.name); const [newName, setNewName] = React.useState(family.family.name);
const [disableCouplePhotos, setDisableCouplePhotos] = React.useState(
family.family.disable_couple_photos
);
const canEdit = family.family.is_admin; const canEdit = family.family.is_admin;
@ -87,6 +93,7 @@ function FamilySettingsCard(): React.ReactElement {
await FamilyApi.UpdateFamily({ await FamilyApi.UpdateFamily({
id: family.family.family_id, id: family.family.family_id,
name: newName, name: newName,
disable_couple_photos: disableCouplePhotos,
}); });
family.reloadFamilyInfo(); family.reloadFamilyInfo();
@ -137,6 +144,18 @@ function FamilySettingsCard(): React.ReactElement {
maxLength: ServerApi.Config.constraints.family_name_len.max, maxLength: ServerApi.Config.constraints.family_name_len.max,
}} }}
/> />
<Tooltip title="Les photos de couple ne sont pas utilisées en pratique dans les arbres généalogiques. Il est possible de masquer les formulaires d'édition de photos de couple pour limiter le risque de confusion.">
<FormControlLabel
disabled={!canEdit}
control={
<Checkbox
checked={disableCouplePhotos}
onChange={(_e, c) => setDisableCouplePhotos(c)}
/>
}
label="Désactiver les photos de couple"
/>
</Tooltip>
</Box> </Box>
</CardContent> </CardContent>
<CardActions> <CardActions>

View File

@ -26,7 +26,7 @@ import {
} from "@mui/material"; } from "@mui/material";
import React from "react"; import React from "react";
import { Outlet, useLocation, useParams } from "react-router-dom"; 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 { MemberApi, MembersList } from "../api/MemberApi";
import { useAlert } from "../hooks/context_providers/AlertDialogProvider"; import { useAlert } from "../hooks/context_providers/AlertDialogProvider";
import { useConfirm } from "../hooks/context_providers/ConfirmDialogProvider"; import { useConfirm } from "../hooks/context_providers/ConfirmDialogProvider";
@ -36,7 +36,7 @@ import { RouterLink } from "./RouterLink";
import { CoupleApi, CouplesList } from "../api/CoupleApi"; import { CoupleApi, CouplesList } from "../api/CoupleApi";
interface FamilyContext { interface FamilyContext {
family: Family; family: ExtendedFamilyInfo;
members: MembersList; members: MembersList;
couples: CouplesList; couples: CouplesList;
familyId: number; familyId: number;
@ -53,7 +53,7 @@ export function BaseFamilyRoute(): React.ReactElement {
const alert = useAlert(); const alert = useAlert();
const confirm = useConfirm(); const confirm = useConfirm();
const [family, setFamily] = React.useState<null | Family>(null); const [family, setFamily] = React.useState<null | ExtendedFamilyInfo>(null);
const [members, setMembers] = React.useState<null | MembersList>(null); const [members, setMembers] = React.useState<null | MembersList>(null);
const [couples, setCouples] = React.useState<null | CouplesList>(null); const [couples, setCouples] = React.useState<null | CouplesList>(null);