Can easily create a brother or a sister

This commit is contained in:
Pierre HUBERT 2023-08-16 14:44:36 +02:00
parent 23fb77b152
commit ee14d629d4
3 changed files with 39 additions and 7 deletions

View File

@ -0,0 +1,11 @@
// A custom hook that builds on useLocation to parse
import React from "react";
import { useLocation } from "react-router-dom";
// the query string for you.
export function useQuery(): URLSearchParams {
const { search } = useLocation();
return React.useMemo(() => new URLSearchParams(search), [search]);
}

View File

@ -8,6 +8,7 @@ import React from "react";
import { useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import { Couple, CoupleApi } from "../../api/CoupleApi"; import { Couple, CoupleApi } from "../../api/CoupleApi";
import { Member } from "../../api/MemberApi"; import { Member } from "../../api/MemberApi";
import { ServerApi } from "../../api/ServerApi";
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";
import { useSnackbar } from "../../hooks/context_providers/SnackbarProvider"; import { useSnackbar } from "../../hooks/context_providers/SnackbarProvider";
@ -19,11 +20,10 @@ import { FamilyPageTitle } from "../../widgets/FamilyPageTitle";
import { MemberItem } from "../../widgets/MemberItem"; import { MemberItem } from "../../widgets/MemberItem";
import { PropertiesBox } from "../../widgets/PropertiesBox"; import { PropertiesBox } from "../../widgets/PropertiesBox";
import { RouterLink } from "../../widgets/RouterLink"; import { RouterLink } from "../../widgets/RouterLink";
import { MemberInput } from "../../widgets/forms/MemberInput";
import { UploadPhotoButton } from "../../widgets/forms/UploadPhotoButton";
import { PropSelect } from "../../widgets/forms/SelectInput";
import { ServerApi } from "../../api/ServerApi";
import { DateInput } from "../../widgets/forms/DateInput"; import { DateInput } from "../../widgets/forms/DateInput";
import { MemberInput } from "../../widgets/forms/MemberInput";
import { PropSelect } from "../../widgets/forms/SelectInput";
import { UploadPhotoButton } from "../../widgets/forms/UploadPhotoButton";
/** /**
* Create a new couple route * Create a new couple route

View File

@ -14,6 +14,7 @@ import {
import * as EmailValidator from "email-validator"; import * as EmailValidator from "email-validator";
import React from "react"; import React from "react";
import { useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import { Couple } from "../../api/CoupleApi";
import { Member, MemberApi, fmtDate } from "../../api/MemberApi"; import { Member, MemberApi, fmtDate } from "../../api/MemberApi";
import { ServerApi } from "../../api/ServerApi"; import { ServerApi } from "../../api/ServerApi";
import { useAlert } from "../../hooks/context_providers/AlertDialogProvider"; import { useAlert } from "../../hooks/context_providers/AlertDialogProvider";
@ -22,6 +23,7 @@ import { useSnackbar } from "../../hooks/context_providers/SnackbarProvider";
import { AsyncWidget } from "../../widgets/AsyncWidget"; import { AsyncWidget } from "../../widgets/AsyncWidget";
import { useFamily } from "../../widgets/BaseFamilyRoute"; import { useFamily } from "../../widgets/BaseFamilyRoute";
import { ConfirmLeaveWithoutSaveDialog } from "../../widgets/ConfirmLeaveWithoutSaveDialog"; import { ConfirmLeaveWithoutSaveDialog } from "../../widgets/ConfirmLeaveWithoutSaveDialog";
import { CouplePhoto } from "../../widgets/CouplePhoto";
import { FamilyPageTitle } from "../../widgets/FamilyPageTitle"; import { FamilyPageTitle } from "../../widgets/FamilyPageTitle";
import { MemberItem } from "../../widgets/MemberItem"; import { MemberItem } from "../../widgets/MemberItem";
import { MemberPhoto } from "../../widgets/MemberPhoto"; import { MemberPhoto } from "../../widgets/MemberPhoto";
@ -34,8 +36,7 @@ import { PropEdit } from "../../widgets/forms/PropEdit";
import { PropSelect } from "../../widgets/forms/SelectInput"; import { PropSelect } from "../../widgets/forms/SelectInput";
import { SexSelection } from "../../widgets/forms/SexSelection"; import { SexSelection } from "../../widgets/forms/SexSelection";
import { UploadPhotoButton } from "../../widgets/forms/UploadPhotoButton"; import { UploadPhotoButton } from "../../widgets/forms/UploadPhotoButton";
import { Couple } from "../../api/CoupleApi"; import { useQuery } from "../../hooks/useQuery";
import { CouplePhoto } from "../../widgets/CouplePhoto";
/** /**
* Create a new member route * Create a new member route
@ -48,6 +49,10 @@ export function FamilyCreateMemberRoute(): React.ReactElement {
const n = useNavigate(); const n = useNavigate();
const family = useFamily(); const family = useFamily();
const parameters = useQuery();
const mother = Number(parameters.get("mother"));
const father = Number(parameters.get("father"));
const create = async (m: Member) => { const create = async (m: Member) => {
try { try {
const r = await MemberApi.Create(m); const r = await MemberApi.Create(m);
@ -68,9 +73,13 @@ export function FamilyCreateMemberRoute(): React.ReactElement {
n(family.family.URL("members")); n(family.family.URL("members"));
}; };
const member = Member.New(family.family.family_id);
if (mother) member.mother = mother;
if (father) member.father = father;
return ( return (
<MemberPage <MemberPage
member={Member.New(family.family.family_id)} member={member}
creating={true} creating={true}
editing={true} editing={true}
onCancel={cancel} onCancel={cancel}
@ -668,6 +677,18 @@ export function MemberPage(p: {
</RouterLink> </RouterLink>
)) ))
)} )}
{(member.mother || member.father) && (
<div style={{ display: "flex", justifyContent: "end" }}>
<RouterLink
to={family.family.URL(
`member/create?mother=${member.mother}&father=${member.father}`
)}
>
<Button>Nouveau</Button>
</RouterLink>
</div>
)}
</PropertiesBox> </PropertiesBox>
</Grid> </Grid>
)} )}