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 { Couple, CoupleApi } from "../../api/CoupleApi";
import { Member } from "../../api/MemberApi";
import { ServerApi } from "../../api/ServerApi";
import { useAlert } from "../../hooks/context_providers/AlertDialogProvider";
import { useConfirm } from "../../hooks/context_providers/ConfirmDialogProvider";
import { useSnackbar } from "../../hooks/context_providers/SnackbarProvider";
@ -19,11 +20,10 @@ import { FamilyPageTitle } from "../../widgets/FamilyPageTitle";
import { MemberItem } from "../../widgets/MemberItem";
import { PropertiesBox } from "../../widgets/PropertiesBox";
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 { MemberInput } from "../../widgets/forms/MemberInput";
import { PropSelect } from "../../widgets/forms/SelectInput";
import { UploadPhotoButton } from "../../widgets/forms/UploadPhotoButton";
/**
* Create a new couple route

View File

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