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 1 commit
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
80 changes: 36 additions & 44 deletions src/components/Admin/resources/personal/schools/SchoolCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,40 @@ import {AutocompleteInput, ReferenceInput, required, SimpleForm, TextInput} from

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

export const SchoolCreate: FC = () => (
<MyCreate
transform={(record) => {
return {
name: record.name,
street: record.street,
city: record.city,
zip_code: record.zip_code,
district: record.district,
abbreviation: record.abbreviation,
email: record.email,
}
}}
>
<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>
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'
}

<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={(value: string) => {
if (value && !/^[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,}$/iu.test(value)) return 'Zadaj platnú emailovú adresu'
}}
/>
</SimpleForm>
</MyCreate>
)
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>
)
}
81 changes: 36 additions & 45 deletions src/components/Admin/resources/personal/schools/SchoolEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,39 @@ import {AutocompleteInput, ReferenceInput, required, SimpleForm, TextInput} from

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

export const SchoolEdit: FC = () => (
<MyEdit
transform={(record) => {
return {
id: record.code,
name: record.name,
street: record.street,
city: record.city,
zip_code: record.zip_code,
district: record.district,
abbreviation: record.abbreviation,
email: record.email,
}
}}
>
<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={(value: string) => {
if (value && !/^[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,}$/iu.test(value)) return 'Zadaj platnú emailovú adresu'
}}
/>
</SimpleForm>
</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>
)
}
Loading