Skip to content

Commit 3a1f3e0

Browse files
authored
Merge pull request #356 from openscript-ch/354-birthday-isnt-prefilled-when-editing-a-participant
354 birthday isnt prefilled when editing a participant
2 parents 62e6614 + e2664f8 commit 3a1f3e0

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

.changeset/unlucky-frogs-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@quassel/frontend": patch
3+
---
4+
5+
Fix prefilling participant form on edit

apps/frontend/src/routes/_auth/administration/participants/edit.$id.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { createFileRoute, useNavigate } from "@tanstack/react-router";
2-
import { components } from "../../../../api.gen";
32
import { $api } from "../../../../stores/api";
43
import { useQueryClient, useSuspenseQuery } from "@tanstack/react-query";
5-
import { Button, TextInput, useForm } from "@quassel/ui";
4+
import { Button, DateInput, Stack, TextInput, useForm } from "@quassel/ui";
65
import { useEffect } from "react";
76

8-
type FormValues = components["schemas"]["ParticipantMutationDto"];
7+
type FormValues = {
8+
id: string;
9+
birthday: Date;
10+
};
911

1012
function AdministrationParticipantsEdit() {
1113
const p = Route.useParams();
@@ -27,27 +29,30 @@ function AdministrationParticipantsEdit() {
2729
},
2830
});
2931
const f = useForm<FormValues>();
30-
const handleSubmit = (values: FormValues) => {
32+
const handleSubmit = ({ id, birthday }: FormValues) => {
3133
editParticipantMutation.mutate({
32-
body: { ...values },
34+
body: { id: +id, birthday: birthday.toISOString() },
3335
params: { path: { id: p.id } },
3436
});
3537
};
3638

3739
useEffect(() => {
38-
f.setValues(participant.data ?? {});
39-
f.resetDirty();
40+
const { birthday, id } = participant.data;
41+
42+
f.setValues({ birthday: new Date(birthday!), id: id.toString() });
4043
}, [participant.isSuccess, participant.data]);
4144

4245
return (
4346
<>
4447
<form autoComplete="off" onSubmit={f.onSubmit(handleSubmit)}>
45-
<TextInput label="Id" type="text" {...f.getInputProps("id")} required />
46-
<TextInput label="Birthday" type="date" {...f.getInputProps("birthday")} required />
48+
<Stack>
49+
<TextInput label="Id" type="text" {...f.getInputProps("id")} required />
50+
<DateInput label="Birthday" {...f.getInputProps("birthday")} required />
4751

48-
<Button type="submit" fullWidth mt="xl" loading={editParticipantMutation.isPending}>
49-
Change
50-
</Button>
52+
<Button type="submit" fullWidth loading={editParticipantMutation.isPending}>
53+
Change
54+
</Button>
55+
</Stack>
5156
</form>
5257
</>
5358
);

0 commit comments

Comments
 (0)