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

Added create/list/show/edit for schools to RA #476

Merged
merged 6 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
19 changes: 18 additions & 1 deletion src/components/Admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 @@ -112,7 +116,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 @@ -121,6 +132,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})` : ''}`
rtrembecky marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
</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>
)
Loading