From 7d97909d06dc5ad561dfaf3ce5a488e7154f9134 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Fri, 11 Aug 2023 11:09:40 +0200 Subject: [PATCH] Can set member country --- geneit_app/src/api/MemberApi.ts | 11 +++ .../src/routes/family/FamilyMemberRoute.tsx | 79 +++++++++++-------- geneit_app/src/widgets/forms/PropEdit.tsx | 8 +- geneit_app/src/widgets/forms/SelectInput.tsx | 38 +++++++++ 4 files changed, 101 insertions(+), 35 deletions(-) create mode 100644 geneit_app/src/widgets/forms/SelectInput.tsx diff --git a/geneit_app/src/api/MemberApi.ts b/geneit_app/src/api/MemberApi.ts index d14d0ef..22e83ea 100644 --- a/geneit_app/src/api/MemberApi.ts +++ b/geneit_app/src/api/MemberApi.ts @@ -148,6 +148,17 @@ export class Member implements MemberDataApi { day: this.death_day, }; } + + get hasContactInfo(): boolean { + return this.email || + this.phone || + this.address || + this.city || + this.postal_code || + this.country + ? true + : false; + } } export function fmtDate(d?: DateValue): string { diff --git a/geneit_app/src/routes/family/FamilyMemberRoute.tsx b/geneit_app/src/routes/family/FamilyMemberRoute.tsx index b7d24b5..b36400d 100644 --- a/geneit_app/src/routes/family/FamilyMemberRoute.tsx +++ b/geneit_app/src/routes/family/FamilyMemberRoute.tsx @@ -1,11 +1,11 @@ import ClearIcon from "@mui/icons-material/Clear"; import DeleteIcon from "@mui/icons-material/Delete"; import EditIcon from "@mui/icons-material/Edit"; +import FileDownloadIcon from "@mui/icons-material/FileDownload"; import SaveIcon from "@mui/icons-material/Save"; import { Button, Grid, Stack } from "@mui/material"; import * as EmailValidator from "email-validator"; import React from "react"; -import FileDownloadIcon from "@mui/icons-material/FileDownload"; import { useNavigate, useParams } from "react-router-dom"; import { Member, MemberApi } from "../../api/MemberApi"; import { ServerApi } from "../../api/ServerApi"; @@ -16,15 +16,16 @@ import { AsyncWidget } from "../../widgets/AsyncWidget"; import { useFamily } from "../../widgets/BaseFamilyRoute"; import { ConfirmLeaveWithoutSaveDialog } from "../../widgets/ConfirmLeaveWithoutSaveDialog"; import { FamilyPageTitle } from "../../widgets/FamilyPageTitle"; +import { MemberPhoto } from "../../widgets/MemberPhoto"; import { PropertiesBox } from "../../widgets/PropertiesBox"; +import { RouterLink } from "../../widgets/RouterLink"; import { DateInput } from "../../widgets/forms/DateInput"; +import { MemberInput } from "../../widgets/forms/MemberInput"; import { PropCheckbox } from "../../widgets/forms/PropCheckbox"; import { PropEdit } from "../../widgets/forms/PropEdit"; +import { PropSelect } from "../../widgets/forms/SelectInput"; import { SexSelection } from "../../widgets/forms/SexSelection"; import { UploadPhotoButton } from "../../widgets/forms/UploadPhotoButton"; -import { MemberPhoto } from "../../widgets/MemberPhoto"; -import { RouterLink } from "../../widgets/RouterLink"; -import { MemberInput } from "../../widgets/forms/MemberInput"; /** * Create a new member route @@ -494,34 +495,50 @@ export function MemberPage(p: { {/* Contact */} - - - {/* Email */} - { - member.email = v; - updatedMember(); - }} - size={ServerApi.Config.constraints.member_email} - checkValue={(e) => EmailValidator.validate(e)} - /> + {(p.editing || member.hasContactInfo) && ( + + + {/* Email */} + { + member.email = v; + updatedMember(); + }} + size={ServerApi.Config.constraints.member_email} + checkValue={(e) => EmailValidator.validate(e)} + /> - {/* Phone number */} - { - member.phone = v; - updatedMember(); - }} - size={ServerApi.Config.constraints.member_phone} - /> - - + {/* Phone number */} + { + member.phone = v; + updatedMember(); + }} + size={ServerApi.Config.constraints.member_phone} + /> + + {/* Country */} + { + member.country = o; + updatedMember(); + }} + value={member.country} + options={ServerApi.Config.countries.map((c) => { + return { label: c.fr, value: c.code }; + })} + /> + + + )} {/* Bio */} diff --git a/geneit_app/src/widgets/forms/PropEdit.tsx b/geneit_app/src/widgets/forms/PropEdit.tsx index 00c4cd9..e55efb6 100644 --- a/geneit_app/src/widgets/forms/PropEdit.tsx +++ b/geneit_app/src/widgets/forms/PropEdit.tsx @@ -8,8 +8,8 @@ export function PropEdit(p: { label: string; editable: boolean; value?: string; - onValueChange: (newVal: string | undefined) => void; - size: LenConstraint; + onValueChange?: (newVal: string | undefined) => void; + size?: LenConstraint; checkValue?: (s: string) => boolean; }): React.ReactElement { if (((!p.editable && p.value) ?? "") === "") return <>; @@ -19,12 +19,12 @@ export function PropEdit(p: { label={p.label} value={p.value} onChange={(e) => - p.onValueChange( + p.onValueChange?.( e.target.value.length === 0 ? undefined : e.target.value ) } inputProps={{ - maxLength: p.size.max, + maxLength: p.size?.max, }} InputProps={{ readOnly: !p.editable, diff --git a/geneit_app/src/widgets/forms/SelectInput.tsx b/geneit_app/src/widgets/forms/SelectInput.tsx new file mode 100644 index 0000000..d6fb527 --- /dev/null +++ b/geneit_app/src/widgets/forms/SelectInput.tsx @@ -0,0 +1,38 @@ +import { FormControl, InputLabel, MenuItem, Select } from "@mui/material"; +import { PropEdit } from "./PropEdit"; + +export interface SelectOption { + value: string; + label: string; +} + +export function PropSelect(p: { + value?: string; + editing: boolean; + label: string; + options: SelectOption[]; + onValueChange: (o?: string) => void; +}): React.ReactElement { + if (!p.editing && !p.value) return <>; + + if (!p.editing) { + const value = p.options.find((o) => o.value === p.value)?.label; + return ; + } + return ( + + {p.label} + + + ); +}