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 2 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 @@ -38,6 +38,10 @@ 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 {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 @@ -109,9 +113,22 @@ 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" />
<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>
)
}
42 changes: 42 additions & 0 deletions src/components/Admin/resources/personal/schools/SchoolCreate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {FC} from 'react'
import {AutocompleteInput, ReferenceInput, required, SimpleForm, TextInput} from 'react-admin'

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

export const SchoolCreate: FC = () => {
const validateEmail = (value: string) => {
if (value && !/^[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,}$/iu.test(value)) return 'Zadaj platnú emailovú adresu'
}

return (
<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={validateEmail}
/>
</SimpleForm>
</MyCreate>
)
}
41 changes: 41 additions & 0 deletions src/components/Admin/resources/personal/schools/SchoolEdit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {FC} from 'react'
import {AutocompleteInput, ReferenceInput, required, SimpleForm, TextInput} from 'react-admin'

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

export const SchoolEdit: FC = () => {
const validateEmail = (value: string) => {
if (value && !/^[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,}$/iu.test(value)) return 'Zadaj platnú emailovú adresu'
}

return (
<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={validateEmail}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/>
</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