|
1 |
| -import { Button } from "@quassel/ui"; |
| 1 | +import { Button, Group, Radio, Stack, useForm } from "@quassel/ui"; |
2 | 2 | import { createFileRoute } from "@tanstack/react-router";
|
3 | 3 | import { $api } from "../../../../stores/api";
|
| 4 | +import { i18n } from "../../../../stores/i18n"; |
| 5 | +import { useStore } from "@nanostores/react"; |
| 6 | + |
| 7 | +const messages = i18n("AdministrationExportIndexRoute", { |
| 8 | + title: "Carers", |
| 9 | + formatLabel: "File format", |
| 10 | + csvLabel: "Comma-separated values (CSV)", |
| 11 | + sqlLabel: "Database export (SQL)", |
| 12 | + formAction: "Download", |
| 13 | +}); |
| 14 | + |
| 15 | +type FormValues = { |
| 16 | + fileType?: "csv" | "sql"; |
| 17 | + studyId?: string; |
| 18 | + period?: [Date, Date]; |
| 19 | +}; |
4 | 20 |
|
5 | 21 | function AdministrationExportIndex() {
|
| 22 | + const t = useStore(messages); |
| 23 | + const f = useForm<FormValues>({ |
| 24 | + mode: "uncontrolled", |
| 25 | + initialValues: {}, |
| 26 | + }); |
| 27 | + |
6 | 28 | const { isDownloading, downloadFile } = $api.useDownload("/export", "dump.sql");
|
7 | 29 | return (
|
8 |
| - <div> |
9 |
| - <Button loading={isDownloading} onClick={() => downloadFile()}> |
10 |
| - Download |
11 |
| - </Button> |
12 |
| - </div> |
| 30 | + <form onSubmit={f.onSubmit(() => downloadFile())}> |
| 31 | + <Stack> |
| 32 | + <Radio.Group label={t.formatLabel}> |
| 33 | + <Group> |
| 34 | + <Radio value="csv" label={t.csvLabel} /> |
| 35 | + <Radio value="sql" label={t.sqlLabel} /> |
| 36 | + </Group> |
| 37 | + </Radio.Group> |
| 38 | + <Button type="submit" loading={isDownloading}> |
| 39 | + {t.formAction} |
| 40 | + </Button> |
| 41 | + </Stack> |
| 42 | + </form> |
13 | 43 | );
|
14 | 44 | }
|
15 | 45 |
|
|
0 commit comments