Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RA Profile #483

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/Admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import {SolutionCreate} from './resources/competition/solution/SolutionCreate'
import {SolutionEdit} from './resources/competition/solution/SolutionEdit'
import {SolutionList} from './resources/competition/solution/SolutionList'
import {SolutionShow} from './resources/competition/solution/SolutionShow'
import {ProfileCreate} from './resources/personal/profiles/ProfileCreate'
import {ProfileList} from './resources/personal/profiles/ProfileList'
import {ProfileShow} from './resources/personal/profiles/ProfileShow'
import {useAuthProvider} from './useAuthProvider'

export const Admin: FC = () => {
Expand Down Expand Up @@ -110,7 +113,13 @@ export const Admin: FC = () => {
create={EventRegistrationCreate}
/>
<Resource name="personal/schools" recordRepresentation="verbose_name" />
<Resource name="personal/profiles" recordRepresentation="verbose_name" />
<Resource
name="personal/profiles"
recordRepresentation="verbose_name"
list={ProfileList}
show={ProfileShow}
create={ProfileCreate}
/>
<Resource name="competition/late-tag" recordRepresentation="name" />
</ReactAdmin>
)
Expand Down
24 changes: 24 additions & 0 deletions src/components/Admin/resources/personal/profiles/ProfileCreate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {FC} from 'react'
import {AutocompleteInput, ReferenceInput, required, SimpleForm, TextInput} from 'react-admin'

import {MyCreate} from '@/components/Admin/custom/MyCreate'

export const ProfileCreate: FC = () => (
<MyCreate
transform={(record) => {
const {school, ...rest} = record
return {...rest, school_id: school}
}}
>
<SimpleForm>
<TextInput source="first_name" label="Meno" validate={required()} />
<TextInput source="last_name" label="Priezvisko" validate={required()} />
<ReferenceInput source="school" reference="personal/schools">
<AutocompleteInput optionText="verbose_name" fullWidth validate={required()} label="Škola" />
</ReferenceInput>
<ReferenceInput source="grade" reference="competition/grade">
<AutocompleteInput optionText="name" fullWidth validate={required()} label="Ročník" />
</ReferenceInput>
</SimpleForm>
</MyCreate>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// For now we have decided we do not want to edit user profile in React Admin
15 changes: 15 additions & 0 deletions src/components/Admin/resources/personal/profiles/ProfileList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {FC} from 'react'
import {Datagrid, List, ReferenceField, TextField} from 'react-admin'

export const ProfileList: FC = () => (
<List>
<Datagrid rowClick="show">
<TextField source="first_name" label="Meno" />
<TextField source="last_name" label="Priezvisko" />
<TextField source="school.verbose_name" label="Škola" />
<ReferenceField source="grade" reference="competition/grade" label="Ročník">
<TextField source="tag" />
</ReferenceField>
</Datagrid>
</List>
)
17 changes: 17 additions & 0 deletions src/components/Admin/resources/personal/profiles/ProfileShow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {FC} from 'react'
import {ReferenceField, SimpleShowLayout, TextField} from 'react-admin'

import {MyShow} from '@/components/Admin/custom/MyShow'

export const ProfileShow: FC = () => (
<MyShow>
<SimpleShowLayout>
<TextField source="first_name" label="Meno" />
<TextField source="last_name" label="Priezvisko" />
<TextField source="school.verbose_name" label="Škola" />
<ReferenceField source="grade" reference="competition/grade" label="Ročník">
<TextField source="tag" />
</ReferenceField>
</SimpleShowLayout>
</MyShow>
)
Loading