Skip to content

Commit f9f8208

Browse files
committed
feat: add study selection to export
1 parent 28099b6 commit f9f8208

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
1-
import { Button, Group, Radio, Stack, useForm } from "@quassel/ui";
1+
import { Button, Group, Radio, Select, Stack, useForm } from "@quassel/ui";
22
import { createFileRoute } from "@tanstack/react-router";
33
import { $api } from "../../../../stores/api";
44
import { i18n } from "../../../../stores/i18n";
55
import { useStore } from "@nanostores/react";
6+
import { useSuspenseQuery } from "@tanstack/react-query";
67

78
const messages = i18n("AdministrationExportIndexRoute", {
89
title: "Carers",
10+
studyLabel: "Study",
11+
studyPlaceholder: "Select a study",
912
formatLabel: "File format",
1013
csvLabel: "Comma-separated values (CSV)",
1114
sqlLabel: "Database export (SQL)",
1215
formAction: "Download",
1316
});
1417

1518
type FormValues = {
16-
fileType?: "csv" | "sql";
19+
fileType: "csv" | "sql";
1720
studyId?: string;
18-
period?: [Date, Date];
1921
};
2022

2123
function AdministrationExportIndex() {
2224
const t = useStore(messages);
2325
const f = useForm<FormValues>({
2426
mode: "uncontrolled",
25-
initialValues: {},
27+
initialValues: {
28+
fileType: "csv",
29+
},
2630
});
2731

32+
const studies = useSuspenseQuery($api.queryOptions("get", "/studies"));
2833
const { isDownloading, downloadFile } = $api.useDownload("/export", "dump.sql");
2934
return (
3035
<form onSubmit={f.onSubmit(() => downloadFile())}>
3136
<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")}>
3343
<Group>
34-
<Radio value="csv" label={t.csvLabel} />
44+
<Radio checked value="csv" label={t.csvLabel} />
3545
<Radio value="sql" label={t.sqlLabel} />
3646
</Group>
3747
</Radio.Group>
@@ -44,5 +54,8 @@ function AdministrationExportIndex() {
4454
}
4555

4656
export const Route = createFileRoute("/_auth/administration/export/")({
57+
loader: ({ context: { queryClient } }) => {
58+
queryClient.ensureQueryData($api.queryOptions("get", "/studies"));
59+
},
4760
component: AdministrationExportIndex,
4861
});

libs/ui/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export {
6262
Flex,
6363
Group,
6464
InputError,
65+
InputLabel,
6566
Modal,
6667
NavLink,
6768
Paper,

0 commit comments

Comments
 (0)