Skip to content

Commit 733842a

Browse files
committed
feat: custom import components
1 parent 0b3557e commit 733842a

File tree

8 files changed

+53
-31
lines changed

8 files changed

+53
-31
lines changed

apps/frontend/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"openapi-fetch": "0.13.3",
3131
"openapi-react-query": "0.2.8",
3232
"react": "^18.3.1",
33-
"react-dom": "^18.3.1",
34-
"react-dsv-import": "^0.4.6"
33+
"react-dom": "^18.3.1"
3534
},
3635
"devDependencies": {
3736
"@tanstack/router-devtools": "^1.90.0",

apps/frontend/src/routes/_auth/administration/participants/import.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
import { ColumnType, DSVImport, ImportInput, ImportPreview } from "@quassel/ui";
12
import { createFileRoute } from "@tanstack/react-router";
2-
import { ColumnType, DSVImport } from "react-dsv-import";
33

4-
type BasicType = { forename: string; surname: string; email: string };
4+
type BasicType = { childId: string; birthday: string };
55

66
const columns: ColumnType<BasicType>[] = [
7-
{ key: "forename", label: "Forename" },
8-
{ key: "surname", label: "Surname" },
9-
{ key: "email", label: "Email" },
7+
{ key: "childId", label: "Child ID" },
8+
{ key: "birthday", label: "Birthday" },
109
];
1110

1211
function AdministrationParticipantsImport() {
1312
return (
1413
<div>
1514
<DSVImport<BasicType> columns={columns}>
16-
<DSVImport.TextareaInput />
17-
<DSVImport.TablePreview />
15+
<ImportInput />
16+
<ImportPreview />
1817
</DSVImport>
1918
</div>
2019
);

docs/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ The following steps describe how to set up the application system:
115115
- `SESSION_SALT` to a 8byte random hex string with `openssl rand -hex 8`
116116
- `DATABASE_PASSWORD` set a more secure password for the database
117117
- **frontend**:
118-
- `API_URL` point to the API endpoint (e.g. "https://api.test.example.com")
118+
- `API_URL` point to the API endpoint (e.g. "<https://api.test.example.com>")
119119
1. Run application system
120120

121121
```bash

libs/ui/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
"@mantine/dates": "7.14.3",
3131
"@mantine/form": "7.14.3",
3232
"@mantine/hooks": "7.14.3",
33-
"@tabler/icons-react": "3.25.0",
33+
"@tabler/icons-react": "3.26.0",
3434
"dayjs": "^1.11.13",
3535
"react": "^18.3.1",
3636
"react-dom": "^18.3.1",
37-
"react-dsv-import": "^0.4.6"
37+
"react-dsv-import": "^0.4.10"
3838
},
3939
"devDependencies": {
4040
"@eslint/js": "^9.17.0",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Textarea } from "@mantine/core";
2+
import { useDSVImport } from "react-dsv-import";
3+
4+
export function ImportInput() {
5+
const [, dispatch] = useDSVImport();
6+
7+
const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
8+
dispatch({ type: "setRaw", raw: event.target.value });
9+
};
10+
11+
return <Textarea rows={15} onChange={handleChange} />;
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Table, TableData } from "@mantine/core";
2+
import { useDSVImport } from "react-dsv-import";
3+
4+
export function ImportPreview() {
5+
const [context] = useDSVImport();
6+
7+
const data: TableData = {
8+
head: context.columns.map((c) => c.label),
9+
body: context.parsed?.map((r) => context.columns.map((c) => r[c.key])),
10+
};
11+
12+
return <Table data={data} />;
13+
}

libs/ui/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export { formatDate, getTime, getDateFromTimeAndWeekday, getNext } from "./utils
3737

3838
// custom components
3939
export { Brand } from "./components/Brand";
40+
export { ImportInput } from "./components/ImportInput";
41+
export { ImportPreview } from "./components/ImportPreview";
4042
export { MonthPicker } from "./components/MonthPicker";
4143

4244
// external components

pnpm-lock.yaml

Lines changed: 16 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)