-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React Admin - Functional events create/edit (#255)
* admin: functional events create/edit * remove commented out ID
- Loading branch information
1 parent
5df8ae8
commit 891e3da
Showing
6 changed files
with
86 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
80
src/components/Admin/resources/competition/event/EventCreate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
82 changes: 39 additions & 43 deletions
82
src/components/Admin/resources/competition/event/EventEdit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,47 @@ | ||
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="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> | ||
</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> | ||
) | ||
} |
8 changes: 1 addition & 7 deletions
8
src/components/Admin/resources/competition/event/EventList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters