1
- import { Button , Group , Modal , Stack , notifications , useDisclosure , useForm } from "@quassel/ui" ;
1
+ import { Button , Group , Modal , Stack , useDisclosure , 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
- import { EntryFormValues } from "../../../../../components/questionnaire/calendar/EntryForm" ;
7
- import { useQueryClient } from "@tanstack/react-query" ;
8
- import { EntryCalendar } from "../../../../../components/questionnaire/calendar/EntryCalendar" ;
9
6
import { useEffect , useState } from "react" ;
10
7
import { components } from "../../../../../api.gen" ;
11
8
import { GapsPerDay , resolveGaps } from "../../../../../utils/entry" ;
9
+ import { QuestionnaireEntries } from "../../../../../components/questionnaire/QuestionnaireEntries" ;
12
10
13
11
const messages = i18n ( "questionnaireEntries" , {
14
12
formAction : "Continue" ,
@@ -21,67 +19,14 @@ const messages = i18n("questionnaireEntries", {
21
19
gapsDialogHighlightGaps : "Highlight gaps" ,
22
20
} ) ;
23
21
24
- function QuestionnaireEntries ( ) {
22
+ export function Entries ( ) {
25
23
const n = useNavigate ( ) ;
26
24
const p = Route . useParams ( ) ;
27
25
28
26
const t = useStore ( messages ) ;
29
27
30
- const c = useQueryClient ( ) ;
31
-
32
- const createMutation = $api . useMutation ( "post" , "/entries" ) ;
33
- const updateMutation = $api . useMutation ( "patch" , "/entries/{id}" ) ;
34
- const deleteMutation = $api . useMutation ( "delete" , "/entries/{id}" ) ;
35
28
const { data : questionnaire } = $api . useSuspenseQuery ( "get" , "/questionnaires/{id}" , { params : { path : p } } ) ;
36
29
37
- const participantId = questionnaire . participant ?. id ;
38
-
39
- const { data : languages } = $api . useQuery ( "get" , "/languages" , { params : { query : { participantId } } } ) ;
40
- const createLanguageMutation = $api . useMutation ( "post" , "/languages" , {
41
- onSuccess ( ) {
42
- notifications . show ( { message : t . notificationSuccessCreateLanguage , color : "uzhGreen" } ) ;
43
- c . refetchQueries ( $api . queryOptions ( "get" , "/languages" , { params : { query : { participantId } } } ) ) ;
44
- } ,
45
- } ) ;
46
-
47
- const { data : carers } = $api . useQuery ( "get" , "/carers" , { params : { query : { participantId } } } ) ;
48
- const createCarerMutation = $api . useMutation ( "post" , "/carers" , {
49
- onSuccess ( ) {
50
- notifications . show ( { message : t . notificationSuccessCreateCarer , color : "uzhGreen" } ) ;
51
- c . refetchQueries ( $api . queryOptions ( "get" , "/carers" , { params : { query : { participantId } } } ) ) ;
52
- } ,
53
- } ) ;
54
-
55
- const reloadEntries = ( ) => {
56
- c . invalidateQueries ( $api . queryOptions ( "get" , "/questionnaires/{id}" , { params : { path : p } } ) ) ;
57
- } ;
58
-
59
- const handleCreate = ( { carer, ...rest } : EntryFormValues , weekday : number ) => {
60
- const entryRequest = {
61
- ...rest ,
62
- carer : carer ! ,
63
- weekday,
64
- questionnaire : questionnaire . id ,
65
- } ;
66
-
67
- return createMutation . mutateAsync ( { body : entryRequest } , { onSuccess : reloadEntries } ) ;
68
- } ;
69
-
70
- const handleUpdate = ( id : number , { carer, ...rest } : Partial < EntryFormValues > , weekday : number ) => {
71
- const entryRequest = {
72
- ...rest ,
73
- carer : carer ! ,
74
- weekday,
75
- questionnaire : questionnaire . id ,
76
- } ;
77
-
78
- return updateMutation . mutateAsync ( { body : entryRequest , params : { path : { id : id . toString ( ) } } } , { onSuccess : reloadEntries } ) ;
79
- } ;
80
-
81
- const handleDelete = ( id : number ) => {
82
- return deleteMutation . mutateAsync ( { params : { path : { id : id . toString ( ) } } } , { onSuccess : reloadEntries } ) ;
83
- } ;
84
-
85
30
const [ gaps , setGaps ] = useState < GapsPerDay > ( ) ;
86
31
const [ highlightGaps , setHighlightGaps ] = useState ( false ) ;
87
32
const [ gapsDialogOpened , { open, close } ] = useDisclosure ( ) ;
@@ -130,17 +75,8 @@ function QuestionnaireEntries() {
130
75
</ Button >
131
76
</ Group >
132
77
</ Modal >
133
- < EntryCalendar
134
- entries = { questionnaire . entries ?? [ ] }
135
- gaps = { highlightGaps ? gaps : undefined }
136
- onAddEntry = { handleCreate }
137
- onUpdateEntry = { handleUpdate }
138
- onDeleteEntry = { handleDelete }
139
- carers = { carers ?? [ ] }
140
- languages = { languages ?? [ ] }
141
- onAddCarer = { ( name ) => createCarerMutation . mutateAsync ( { body : { name, participant : participantId } } ) . then ( ( { id } ) => id ) }
142
- onAddLanguage = { ( name ) => createLanguageMutation . mutateAsync ( { body : { name, participant : participantId } } ) . then ( ( { id } ) => id ) }
143
- />
78
+
79
+ < QuestionnaireEntries gaps = { highlightGaps ? gaps : undefined } questionnaire = { questionnaire } />
144
80
145
81
< Group >
146
82
< Link to = "/questionnaire/$id/period" params = { p } >
@@ -161,5 +97,5 @@ export const Route = createFileRoute("/_auth/questionnaire/_questionnaire/$id/en
161
97
params : { path : { id : params . id } } ,
162
98
} )
163
99
) ,
164
- component : QuestionnaireEntries ,
100
+ component : Entries ,
165
101
} ) ;
0 commit comments