-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from openscript-ch/32-implement-child-id-entr…
…y-and-csv-import-for-series 32 implement child id entry and csv import for series
- Loading branch information
Showing
16 changed files
with
197 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@quassel/frontend": patch | ||
"@quassel/backend": patch | ||
"@quassel/ui": patch | ||
--- | ||
|
||
Add participant csv import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ declare global { | |
? T[S] | ||
: never; | ||
} | ||
|
||
export type OneOrMany<T> = T | T[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
apps/frontend/src/routes/_auth/administration/participants/import.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Button, ColumnType, DSVImport, ImportInput, ImportPreview, useForm } from "@quassel/ui"; | ||
import { createFileRoute, useNavigate } from "@tanstack/react-router"; | ||
import { $api } from "../../../../stores/api"; | ||
import { components } from "../../../../api.gen"; | ||
|
||
type ImportType = { id: string; birthday: string }; | ||
type FormValues = components["schemas"]["ParticipantCreationDto"][]; | ||
|
||
const columns: ColumnType<ImportType>[] = [ | ||
{ key: "id", label: "Child ID" }, | ||
{ key: "birthday", label: "Birthday" }, | ||
]; | ||
|
||
function AdministrationParticipantsImport() { | ||
const n = useNavigate(); | ||
const createParticipantMutation = $api.useMutation("post", "/participants", { | ||
onSuccess: () => { | ||
n({ to: "/administration/participants" }); | ||
}, | ||
}); | ||
const f = useForm<FormValues>({ | ||
mode: "uncontrolled", | ||
initialValues: [], | ||
}); | ||
const handleSubmit = (values: FormValues) => { | ||
createParticipantMutation.mutate({ body: Object.values(values) }); | ||
}; | ||
const mapValues = (values: ImportType[]): FormValues => { | ||
return values.map((value) => ({ | ||
id: parseInt(value.id), | ||
birthday: value.birthday, | ||
})); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={f.onSubmit(handleSubmit)}> | ||
<DSVImport<ImportType> columns={columns} onChange={(values) => f.setValues(mapValues(values))}> | ||
<ImportInput /> | ||
<ImportPreview /> | ||
</DSVImport> | ||
|
||
<Button type="submit" fullWidth mt="xl" loading={createParticipantMutation.isPending}> | ||
Create | ||
</Button> | ||
</form> | ||
); | ||
} | ||
|
||
export const Route = createFileRoute("/_auth/administration/participants/import")({ | ||
component: AdministrationParticipantsImport, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Textarea } from "@mantine/core"; | ||
import { useDSVImport } from "react-dsv-import"; | ||
|
||
export function ImportInput() { | ||
const [, dispatch] = useDSVImport(); | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
dispatch({ type: "setRaw", raw: event.target.value }); | ||
}; | ||
|
||
return <Textarea rows={15} onChange={handleChange} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Table, TableData } from "@mantine/core"; | ||
import { useDSVImport } from "react-dsv-import"; | ||
|
||
export function ImportPreview() { | ||
const [context] = useDSVImport(); | ||
|
||
const data: TableData = { | ||
head: context.columns.map((c) => c.label), | ||
body: context.parsed?.map((r) => context.columns.map((c) => r[c.key])), | ||
}; | ||
|
||
return <Table data={data} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.