-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> | ||
) | ||
} |
83 changes: 40 additions & 43 deletions
83
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,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()} /> | ||
<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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toto ale mozes vyhodit