1
- import { Button , Group , Stack , notifications } from "@quassel/ui" ;
1
+ import { Button , Group , Stack , notifications , useForm } from "@quassel/ui" ;
2
2
import { createFileRoute , Link , useNavigate } from "@tanstack/react-router" ;
3
3
import { i18n } from "../../../../../stores/i18n" ;
4
4
import { useStore } from "@nanostores/react" ;
5
5
import { $api } from "../../../../../stores/api" ;
6
6
import { EntryFormValues } from "../../../../../components/questionnaire/calendar/EntryForm" ;
7
7
import { useQueryClient } from "@tanstack/react-query" ;
8
8
import { EntryCalendar } from "../../../../../components/questionnaire/calendar/EntryCalendar" ;
9
+ import { useEffect } from "react" ;
10
+ import { components } from "../../../../../api.gen" ;
11
+ import { resolveGaps } from "../../../../../utils/entry" ;
9
12
10
13
const messages = i18n ( "questionnaireEntries" , {
11
14
formAction : "Continue" ,
@@ -23,6 +26,20 @@ function QuestionnaireEntries() {
23
26
24
27
const c = useQueryClient ( ) ;
25
28
29
+ const f = useForm < { entries : components [ "schemas" ] [ "QuestionnaireEntryDto" ] [ ] } > ( {
30
+ initialValues : {
31
+ entries : [ ] ,
32
+ } ,
33
+ validate : {
34
+ entries : ( value ) => {
35
+ const gaps = resolveGaps ( value ) ;
36
+ console . log ( gaps ) ;
37
+
38
+ return ! ! gaps . length ;
39
+ } ,
40
+ } ,
41
+ } ) ;
42
+
26
43
const createMutation = $api . useMutation ( "post" , "/entries" ) ;
27
44
const updateMutation = $api . useMutation ( "patch" , "/entries/{id}" ) ;
28
45
const deleteMutation = $api . useMutation ( "delete" , "/entries/{id}" ) ;
@@ -80,9 +97,13 @@ function QuestionnaireEntries() {
80
97
n ( { to : "/questionnaire/$id/remarks" , params : p } ) ;
81
98
} ;
82
99
100
+ useEffect ( ( ) => {
101
+ f . setValues ( { entries : questionnaire . entries } ) ;
102
+ } , [ questionnaire ] ) ;
103
+
83
104
return (
84
105
< >
85
- < form onSubmit = { handleSubmit } >
106
+ < form onSubmit = { f . onSubmit ( handleSubmit ) } >
86
107
< Stack >
87
108
< EntryCalendar
88
109
entries = { questionnaire . entries ?? [ ] }
0 commit comments