Skip to content

Commit 58cc71a

Browse files
committed
feat: fetch participant data on new questionnaire view
1 parent f89f673 commit 58cc71a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

apps/frontend/src/components/questionnaire/PeriodForm.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ export function PeriodForm({ onSave, actionLabel, period, prevEndDate }: PeriodF
2727
const t = useStore(messages);
2828

2929
const f = useForm<PeriodFormValues>({
30+
mode: "uncontrolled",
3031
initialValues: {
3132
range: [prevEndDate ? getNext("month", prevEndDate) : null, null],
3233
title: "",
3334
},
3435
validate: {
3536
range([start]) {
36-
console.log(start);
37-
console.log(prevEndDate && getNext("month", prevEndDate));
38-
3937
if (prevEndDate && +getNext("month", prevEndDate) !== +start!) {
4038
return t.validationStartDate;
4139
}

apps/frontend/src/routes/_auth/questionnaire/_questionnaire/new.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useStore } from "@nanostores/react";
44
import { PeriodForm, PeriodFormValues } from "../../../../components/questionnaire/PeriodForm";
55
import { $api } from "../../../../stores/api";
66
import { $questionnaire } from "../../../../stores/questionnaire";
7+
import { useEffect } from "react";
78

89
const messages = i18n("questionnaireNew", {
910
title: "Create new period of life",
@@ -16,6 +17,14 @@ function QuestionnaireNew() {
1617

1718
const questionnaire = useStore($questionnaire);
1819

20+
const { data: participant } = $api.useQuery("get", "/participants/{id}", {
21+
params: { path: { id: questionnaire!.participant.id.toString() } },
22+
});
23+
24+
useEffect(() => {
25+
if (participant) $questionnaire.set({ ...questionnaire!, participant });
26+
}, [participant]);
27+
1928
const createQuestionnaireMutation = $api.useMutation("post", "/questionnaires", {
2029
onSuccess: (questionnaire) => {
2130
n({ to: "/questionnaire/$id/entries", params: { id: questionnaire.id.toString() } });

0 commit comments

Comments
 (0)