Skip to content

Commit

Permalink
Added create/list/show/edit for schools to RA (#476)
Browse files Browse the repository at this point in the history
* Added create/list/show/edit for schools to RA

* Removed unneceseary form transform

* Changed to built-in email validation

* Fixed lint errors

* Fixed even more lint errors
  • Loading branch information
vgeffer committed Nov 24, 2024
1 parent c4dd973 commit 7ad655b
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/Admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ 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 {SchoolCreate} from './resources/personal/schools/SchoolCreate'
import {SchoolEdit} from './resources/personal/schools/SchoolEdit'
import {SchoolList} from './resources/personal/schools/SchoolList'
import {SchoolShow} from './resources/personal/schools/SchoolShow'
import {useAuthProvider} from './useAuthProvider'

export const Admin: FC = () => {
Expand Down Expand Up @@ -118,7 +122,14 @@ export const Admin: FC = () => {
show={EventRegistrationShow}
create={EventRegistrationCreate}
/>
<Resource name="personal/schools" recordRepresentation="verbose_name" />
<Resource
name="personal/schools"
recordRepresentation="verbose_name"
list={SchoolList}
show={SchoolShow}
edit={SchoolEdit}
create={SchoolCreate}
/>
<Resource
name="personal/profiles"
recordRepresentation="verbose_name"
Expand All @@ -127,6 +138,12 @@ export const Admin: FC = () => {
create={ProfileCreate}
/>
<Resource name="competition/late-tag" recordRepresentation="name" />
<Resource
name="personal/districts"
recordRepresentation={(record) => {
return `${record.name} ${record.abbreviation ? `(${record.abbreviation})` : ''}`
}}
/>
</ReactAdmin>
)
}
35 changes: 35 additions & 0 deletions src/components/Admin/resources/personal/schools/SchoolCreate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {FC} from 'react'
import {AutocompleteInput, email, ReferenceInput, required, SimpleForm, TextInput} from 'react-admin'

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

export const SchoolCreate: FC = () => (
<MyCreate>
<SimpleForm>
<TextInput
fullWidth
source="name"
helperText="Oficiálny názov školy. Napr. Gymnázium Jura Hronca"
validate={required()}
/>
<TextInput fullWidth source="street" validate={required()} />
<TextInput fullWidth source="city" validate={required()} />
<TextInput fullWidth source="zip_code" helperText="PSČ školy" validate={required()} />
<ReferenceInput source="district" reference="personal/districts">
<AutocompleteInput fullWidth validate={required()} />
</ReferenceInput>
<TextInput
fullWidth
source="abbreviation"
helperText="Skratka školy. Zadávajte v tvare napr.: SNov3BA (Druh školy, adresa, číslo, okres)"
validate={required()}
/>
<TextInput
fullWidth
source="email"
helperText="Emailový kontakt na školu. Ak neexistuje všeobecný, tak napr. na riaditeľa/vyučujúceho"
validate={email()}
/>
</SimpleForm>
</MyCreate>
)
35 changes: 35 additions & 0 deletions src/components/Admin/resources/personal/schools/SchoolEdit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {FC} from 'react'
import {AutocompleteInput, email, ReferenceInput, required, SimpleForm, TextInput} from 'react-admin'

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

export const SchoolEdit: FC = () => (
<MyEdit>
<SimpleForm>
<TextInput
fullWidth
source="name"
helperText="Oficiálny názov školy. Napr. Gymnázium Jura Hronca"
validate={required()}
/>
<TextInput fullWidth source="street" validate={required()} />
<TextInput fullWidth source="city" validate={required()} />
<TextInput fullWidth source="zip_code" helperText="PSČ školy" validate={required()} />
<ReferenceInput source="district" reference="personal/districts">
<AutocompleteInput fullWidth validate={required()} />
</ReferenceInput>
<TextInput
fullWidth
source="abbreviation"
helperText="Skratka školy. Zadávajte v tvare napr.: SNov3BA (Druh školy, adresa, číslo, okres)"
validate={required()}
/>
<TextInput
fullWidth
source="email"
helperText="Emailový kontakt na školu. Ak neexistuje všeobecný, tak napr. na riaditeľa/vyučujúceho"
validate={email()}
/>
</SimpleForm>
</MyEdit>
)
15 changes: 15 additions & 0 deletions src/components/Admin/resources/personal/schools/SchoolList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {FC} from 'react'
import {Datagrid, List, TextField} from 'react-admin'

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

export const SchoolList: FC = () => (
<List>
<Datagrid rowClick="show">
<TruncatedTextField source="name" maxTextWidth={60} />
<TextField source="street" />
<TextField source="city" />
<TextField source="abbreviation" />
</Datagrid>
</List>
)
17 changes: 17 additions & 0 deletions src/components/Admin/resources/personal/schools/SchoolShow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {FC} from 'react'
import {EmailField, ReferenceField, SimpleShowLayout, TextField} from 'react-admin'

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

export const SchoolShow: FC = () => (
<MyShow>
<SimpleShowLayout>
<TextField source="name" />
<TextField source="street" />
<TextField source="zip_code" />
<ReferenceField source="district" reference="personal/districts" />
<TextField source="abbreviation" />
<EmailField source="email" />
</SimpleShowLayout>
</MyShow>
)

0 comments on commit 7ad655b

Please sign in to comment.