1
- import { Button , Group , Radio , Stack , useForm } from "@quassel/ui" ;
1
+ import { Button , Group , Radio , Select , Stack , useForm } from "@quassel/ui" ;
2
2
import { createFileRoute } from "@tanstack/react-router" ;
3
3
import { $api } from "../../../../stores/api" ;
4
4
import { i18n } from "../../../../stores/i18n" ;
5
5
import { useStore } from "@nanostores/react" ;
6
+ import { useSuspenseQuery } from "@tanstack/react-query" ;
6
7
7
8
const messages = i18n ( "AdministrationExportIndexRoute" , {
8
9
title : "Carers" ,
10
+ studyLabel : "Study" ,
11
+ studyPlaceholder : "Select a study" ,
9
12
formatLabel : "File format" ,
10
13
csvLabel : "Comma-separated values (CSV)" ,
11
14
sqlLabel : "Database export (SQL)" ,
12
15
formAction : "Download" ,
13
16
} ) ;
14
17
15
18
type FormValues = {
16
- fileType ? : "csv" | "sql" ;
19
+ fileType : "csv" | "sql" ;
17
20
studyId ?: string ;
18
- period ?: [ Date , Date ] ;
19
21
} ;
20
22
21
23
function AdministrationExportIndex ( ) {
22
24
const t = useStore ( messages ) ;
23
25
const f = useForm < FormValues > ( {
24
26
mode : "uncontrolled" ,
25
- initialValues : { } ,
27
+ initialValues : {
28
+ fileType : "csv" ,
29
+ } ,
26
30
} ) ;
27
31
32
+ const studies = useSuspenseQuery ( $api . queryOptions ( "get" , "/studies" ) ) ;
28
33
const { isDownloading, downloadFile } = $api . useDownload ( "/export" , "dump.sql" ) ;
29
34
return (
30
35
< form onSubmit = { f . onSubmit ( ( ) => downloadFile ( ) ) } >
31
36
< Stack >
32
- < Radio . Group label = { t . formatLabel } >
37
+ < Select
38
+ label = { t . studyLabel }
39
+ placeholder = { t . studyPlaceholder }
40
+ data = { studies . data . map ( ( s ) => ( { label : s . title , value : s . id . toString ( ) } ) ) }
41
+ />
42
+ < Radio . Group label = { t . formatLabel } withAsterisk { ...f . getInputProps ( "fileType" ) } >
33
43
< Group >
34
- < Radio value = "csv" label = { t . csvLabel } />
44
+ < Radio checked value = "csv" label = { t . csvLabel } />
35
45
< Radio value = "sql" label = { t . sqlLabel } />
36
46
</ Group >
37
47
</ Radio . Group >
@@ -44,5 +54,8 @@ function AdministrationExportIndex() {
44
54
}
45
55
46
56
export const Route = createFileRoute ( "/_auth/administration/export/" ) ( {
57
+ loader : ( { context : { queryClient } } ) => {
58
+ queryClient . ensureQueryData ( $api . queryOptions ( "get" , "/studies" ) ) ;
59
+ } ,
47
60
component : AdministrationExportIndex ,
48
61
} ) ;
0 commit comments