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

React Admin - Functional events create/edit #255

Merged
merged 2 commits into from
Dec 9, 2023
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
8 changes: 6 additions & 2 deletions src/components/Admin/custom/MyCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {FC, PropsWithChildren} from 'react'
import {Create} from 'react-admin'
import {Create, CreateProps} from 'react-admin'

export const MyCreate: FC<PropsWithChildren> = ({children}) => <Create redirect="show">{children}</Create>
export const MyCreate: FC<PropsWithChildren<CreateProps>> = ({children, ...rest}) => (
<Create redirect="show" {...rest}>
{children}
</Create>
)
6 changes: 3 additions & 3 deletions src/components/Admin/custom/MyEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {FC, PropsWithChildren} from 'react'
import {Edit} from 'react-admin'
import {Edit, EditProps} from 'react-admin'

import {MyEditActions} from './MyEditActions'

export const MyEdit: FC<PropsWithChildren> = ({children}) => (
<Edit actions={<MyEditActions />} mutationMode="pessimistic" redirect="show">
export const MyEdit: FC<PropsWithChildren<EditProps>> = ({children, ...rest}) => (
<Edit actions={<MyEditActions />} mutationMode="pessimistic" redirect="show" {...rest}>
{children}
</Edit>
)
80 changes: 37 additions & 43 deletions src/components/Admin/resources/competition/event/EventCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,45 @@
import {FC} from 'react'
import {
ArrayInput,
DateTimeInput,
FormTab,
NumberInput,
required,
SimpleFormIterator,
TabbedForm,
TextInput,
} from 'react-admin'
import {Checkbox, FormControlLabel} from '@mui/material'
import {FC, useState} from 'react'
import {DateTimeInput, Labeled, NumberInput, required, SimpleForm, TextInput} from 'react-admin'

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

export const EventCreate: FC = () => (
<MyCreate>
<TabbedForm>
<FormTab label="general">
<NumberInput source="id" fullWidth disabled />
export const EventCreate: FC = () => {
// initial false, necakame, ze mame registration link uz ready
const [includeRegLink, setIncludeRegLink] = useState(false)

return (
<MyCreate
transform={(record) => {
// bud musime pridat cely registration object, alebo poslat null. ideal je si to tu ohandlit explicitne,
// nie je uplne jasne, ako inak presvedcit react admina, aby ako ten cely objekt poslat null
if (!includeRegLink) record.registration_link = null
return record
}}
>
<SimpleForm>
<NumberInput source="year" fullWidth validate={required()} />
<TextInput source="school_year" fullWidth validate={required()} />
<span>napr. 2023/2024</span>
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth validate={required()} />
<DateTimeInput source="start" fullWidth validate={required()} />
<DateTimeInput source="end" fullWidth validate={required()} />
<CompetitionInput source="competition" fullWidth validate={required()} />

<span>TODO: always sends null as registration_link</span>
<TextInput source="registration_link" fullWidth hidden disabled defaultValue={null} parse={() => null} />
{/* <NumberInput source="registration_link.id" fullWidth disabled />
<TextInput source="registration_link.url" fullWidth />
<DateInput source="registration_link.start" fullWidth />
<DateInput source="registration_link.end" fullWidth />
<TextInput source="registration_link.additional_info" fullWidth /> */}
</FormTab>
<FormTab label="publications">
<span>TODO: publikacie treba vediet nahrat, nie tu editovat db</span>
<ArrayInput source="publication_set" defaultValue={[]}>
<SimpleFormIterator>
<NumberInput source="id" fullWidth disabled />
<TextInput source="name" fullWidth validate={required()} />
<TextInput source="file" fullWidth validate={required()} />
<NumberInput source="publication_type" fullWidth />
<NumberInput source="event" fullWidth disabled />
<NumberInput source="order" fullWidth />
</SimpleFormIterator>
</ArrayInput>
</FormTab>
</TabbedForm>
</MyCreate>
)
<FormControlLabel
control={<Checkbox checked={includeRegLink} onChange={(e) => setIncludeRegLink(e.target.checked)} />}
label="Pridať registračný link"
/>
{includeRegLink && (
<Labeled label="Registration link">
<>
<NumberInput source="registration_link.id" fullWidth disabled />
<TextInput source="registration_link.url" fullWidth validate={required()} />
<DateTimeInput source="registration_link.start" fullWidth validate={required()} />
<DateTimeInput source="registration_link.end" fullWidth validate={required()} />
<TextInput source="registration_link.additional_info" fullWidth validate={required()} />
</>
</Labeled>
)}
</SimpleForm>
</MyCreate>
)
}
83 changes: 40 additions & 43 deletions src/components/Admin/resources/competition/event/EventEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
import {FC} from 'react'
import {
ArrayInput,
DateTimeInput,
FormTab,
NumberInput,
required,
SimpleFormIterator,
TabbedForm,
TextInput,
} from 'react-admin'
import {Checkbox, FormControlLabel} from '@mui/material'
import {FC, useState} from 'react'
import {DateTimeInput, Labeled, NumberInput, required, SimpleForm, TextInput} from 'react-admin'

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

export const EventEdit: FC = () => (
<MyEdit>
<TabbedForm>
<FormTab label="general">
<NumberInput source="id" fullWidth disabled />
export const EventEdit: FC = () => {
// initial true, nech vidime vsetky fieldy, ktore ideme editovat
const [includeRegLink, setIncludeRegLink] = useState(true)

return (
<MyEdit
transform={(record) => {
// bud musime pridat cely registration object, alebo poslat null. ideal je si to tu ohandlit explicitne,
// nie je uplne jasne, ako inak presvedcit react admina, aby ako ten cely objekt poslat null
if (!includeRegLink) record.registration_link = null
// publication_set je nested field, sme dohodnuti, ze neposielame a publikacie handlujeme inak
delete record.publication_set
return record
}}
>
<SimpleForm>
{/* <NumberInput source="id" fullWidth disabled /> */}
<NumberInput source="year" fullWidth validate={required()} />
Copy link
Member

Choose a reason for hiding this comment

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

toto ale mozes vyhodit

<TextInput source="school_year" fullWidth validate={required()} />
<span>napr. 2023/2024</span>
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth validate={required()} />
<DateTimeInput source="start" fullWidth validate={required()} />
<DateTimeInput source="end" fullWidth validate={required()} />
<CompetitionInput source="competition" fullWidth validate={required()} />

<span>TODO: always sends null as registration_link</span>
<TextInput source="registration_link" fullWidth hidden disabled defaultValue={null} parse={() => null} />
{/* <NumberInput source="registration_link.id" fullWidth disabled />
<TextInput source="registration_link.url" fullWidth />
<DateInput source="registration_link.start" fullWidth />
<DateInput source="registration_link.end" fullWidth />
<TextInput source="registration_link.additional_info" fullWidth /> */}
</FormTab>
<FormTab label="publications">
<span>TODO: publikacie treba vediet nahrat, nie tu editovat db</span>
<ArrayInput source="publication_set" defaultValue={[]}>
<SimpleFormIterator>
<NumberInput source="id" fullWidth disabled />
<TextInput source="name" fullWidth validate={required()} />
<TextInput source="file" fullWidth validate={required()} />
<NumberInput source="publication_type" fullWidth />
<NumberInput source="event" fullWidth disabled />
<NumberInput source="order" fullWidth />
</SimpleFormIterator>
</ArrayInput>
</FormTab>
</TabbedForm>
</MyEdit>
)
<FormControlLabel
control={<Checkbox checked={includeRegLink} onChange={(e) => setIncludeRegLink(e.target.checked)} />}
label="Upraviť registračný link"
/>
{includeRegLink && (
<Labeled label="Registration link">
<>
<NumberInput source="registration_link.id" fullWidth disabled />
<TextInput source="registration_link.url" fullWidth validate={required()} />
<DateTimeInput source="registration_link.start" fullWidth validate={required()} />
<DateTimeInput source="registration_link.end" fullWidth validate={required()} />
<TextInput source="registration_link.additional_info" fullWidth validate={required()} />
</>
</Labeled>
)}
</SimpleForm>
</MyEdit>
)
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import {FC} from 'react'
import {BooleanField, Datagrid, DateField, FunctionField, List, NumberField, RaRecord, TextField} from 'react-admin'
import {Datagrid, DateField, FunctionField, List, NumberField, RaRecord, TextField} from 'react-admin'

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

export const EventList: FC = () => (
<List>
<Datagrid rowClick="show">
<NumberField source="id" />
<CompetitionField source="competition" />
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateField source="start" />
<DateField source="end" />
<TextField source="additional_name" />

<BooleanField source="can_participate" />
<BooleanField source="is_registered" />

<TextField source="registration_link.url" />

<FunctionField<RaRecord>
source="publication_set"
label="Publication count"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {FC} from 'react'
import {
ArrayField,
BooleanField,
Datagrid,
DateField,
NumberField,
Expand All @@ -20,9 +19,6 @@ export const EventShow: FC = () => (
<TabbedShowLayout>
<Tab label="general">
<SimpleShowLayout>
<TextField source="registration_link.url" />

<NumberField source="id" />
<CompetitionField source="competition" />
<NumberField source="year" />
<NumberField source="season_code" />
Expand All @@ -31,10 +27,6 @@ export const EventShow: FC = () => (
<DateField source="end" />
<TextField source="additional_name" />

<BooleanField source="can_participate" />
<BooleanField source="is_registered" />

<NumberField source="registration_link.id" />
<TextField source="registration_link.url" />
<DateField source="registration_link.start" />
<DateField source="registration_link.end" />
Expand All @@ -45,7 +37,6 @@ export const EventShow: FC = () => (
<SimpleShowLayout>
<ArrayField source="publication_set">
<Datagrid>
<NumberField source="id" />
<TextField source="name" />
<TextField source="file" />
<NumberField source="publication_type" />
Expand Down
Loading