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 - date time fields zobrazit datum a cas #367

Merged
merged 7 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion src/components/Admin/AdminLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,25 @@ const AppMenuBar = () => {
}

export const AdminLayout = (props: LayoutProps) => {
return <Layout {...props} appBar={AppMenuBar} />
return (
<>
<Layout {...props} appBar={AppMenuBar} />
<Stack
style={{
position: 'fixed',
right: 0,
bottom: 0,
left: 0,
zIndex: 100,
padding: 6,
textAlign: 'center',
backgroundColor: '#efefef',
}}
>
<Typography color={'#000000'} fontSize={'0.8em'}>
Všetky časy sú uvedené v časovom pásme Europe/Bratislava
</Typography>
</Stack>
</>
)
}
18 changes: 18 additions & 0 deletions src/components/Admin/custom/DateTimeField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {FC} from 'react'
import {DateField, FieldProps} from 'react-admin'

export const DateTimeField: FC<FieldProps> = ({source}) => (
<DateField
source={source}
showTime={true}
options={{
timeZone: 'Europe/Bratislava',
hourCycle: 'h24',
hour: '2-digit',
minute: '2-digit',
year: 'numeric',
month: 'numeric',
day: 'numeric',
}}
/>
)
6 changes: 6 additions & 0 deletions src/components/Admin/custom/MyDateTimeInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {FC} from 'react'
import {DateTimeInput, DateTimeInputProps} from 'react-admin'

export const MyDateTimeInput: FC<DateTimeInputProps> = ({source, ...rest}) => (
<DateTimeInput source={source} helperText={'Please provide time in Europe/Bratislava timezone'} {...rest} />
)
2 changes: 1 addition & 1 deletion src/components/Admin/custom/PostPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const PostPreview: FC = () => {
caption={formData?.caption ?? ''}
short_text={formData?.short_text ?? ''}
details={formData?.details ?? ''}
added_at={formData?.added_at ?? ''}
added_at={formData?.added_at ?? new Date().toISOString()}
Copy link
Collaborator

Choose a reason for hiding this comment

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

rozmyslam, ze mozno tie added_at inputy schovame 🤔 ukazovat tam toto mi pride off, lebo hodnota toho fieldu sa aj tak (z nejakeho dovodu) generuje automaticky, tak ked pises post 5 minut, tak to vlastne nie je pravda 😄 ale neviem, nezalezi na tom

visible_after={formData?.visible_after ?? ''}
visible_until={formData?.visible_until ?? ''}
sites={formData?.sites ?? []}
Expand Down
9 changes: 5 additions & 4 deletions src/components/Admin/resources/cms/post/PostCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {FC} from 'react'
import {ArrayInput, DateTimeInput, FormTab, required, SimpleFormIterator, TabbedForm, TextInput} from 'react-admin'
import {ArrayInput, FormTab, required, SimpleFormIterator, TabbedForm, TextInput} from 'react-admin'

import {MyCreate} from '@/components/Admin/custom/MyCreate'
import {MyDateTimeInput} from '@/components/Admin/custom/MyDateTimeInput'
import {PostPreview} from '@/components/Admin/custom/PostPreview'
import {SitesCheckboxInput} from '@/components/Admin/custom/SitesCheckboxInput'

Expand All @@ -13,9 +14,9 @@ export const PostCreate: FC = () => {
<TextInput source="caption" fullWidth validate={required()} />
<TextInput source="short_text" fullWidth validate={required()} />
<TextInput source="details" multiline fullWidth />
<DateTimeInput source="added_at" fullWidth disabled />
<DateTimeInput source="visible_after" fullWidth validate={required()} />
<DateTimeInput source="visible_until" fullWidth validate={required()} />
<MyDateTimeInput source="added_at" fullWidth disabled defaultValue={new Date().toISOString()} />
<MyDateTimeInput source="visible_after" fullWidth validate={required()} />
<MyDateTimeInput source="visible_until" fullWidth validate={required()} />
<SitesCheckboxInput source="sites" validate={required()} />
</FormTab>
<FormTab label="links">
Expand Down
9 changes: 5 additions & 4 deletions src/components/Admin/resources/cms/post/PostEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {FC} from 'react'
import {ArrayInput, DateTimeInput, FormTab, required, SimpleFormIterator, TabbedForm, TextInput} from 'react-admin'
import {ArrayInput, FormTab, required, SimpleFormIterator, TabbedForm, TextInput} from 'react-admin'

import {MyDateTimeInput} from '@/components/Admin/custom/MyDateTimeInput'
import {MyEdit} from '@/components/Admin/custom/MyEdit'
import {PostPreview} from '@/components/Admin/custom/PostPreview'
import {SitesCheckboxInput} from '@/components/Admin/custom/SitesCheckboxInput'
Expand All @@ -12,9 +13,9 @@ export const PostEdit: FC = () => (
<TextInput source="caption" fullWidth validate={required()} />
<TextInput source="short_text" fullWidth validate={required()} />
<TextInput source="details" multiline fullWidth />
<DateTimeInput source="added_at" fullWidth disabled />
<DateTimeInput source="visible_after" fullWidth validate={required()} />
<DateTimeInput source="visible_until" fullWidth validate={required()} />
<MyDateTimeInput source="added_at" fullWidth disabled />
<MyDateTimeInput source="visible_after" fullWidth validate={required()} />
<MyDateTimeInput source="visible_until" fullWidth validate={required()} />
<SitesCheckboxInput source="sites" validate={required()} />
</FormTab>
<FormTab label="links">
Expand Down
9 changes: 5 additions & 4 deletions src/components/Admin/resources/cms/post/PostList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {FC} from 'react'
import {Datagrid, DateField, FunctionField, List, RaRecord, TextField} from 'react-admin'
import {Datagrid, FunctionField, List, RaRecord, TextField} from 'react-admin'

import {DateTimeField} from '@/components/Admin/custom/DateTimeField'
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField'
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField'

Expand All @@ -10,9 +11,9 @@ export const PostList: FC = () => (
<TextField source="caption" />
<TruncatedTextField source="short_text" maxTextWidth={50} />
<TruncatedTextField source="details" maxTextWidth={50} />
<DateField source="added_at" />
<DateField source="visible_after" />
<DateField source="visible_until" />
<DateTimeField source="added_at" />
<DateTimeField source="visible_after" />
<DateTimeField source="visible_until" />
<SitesArrayField source="sites" />
<FunctionField<RaRecord>
source="links"
Expand Down
9 changes: 5 additions & 4 deletions src/components/Admin/resources/cms/post/PostShow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {FC} from 'react'
import {ArrayField, Datagrid, DateField, Show, SimpleShowLayout, Tab, TabbedShowLayout, TextField} from 'react-admin'
import {ArrayField, Datagrid, Show, SimpleShowLayout, Tab, TabbedShowLayout, TextField} from 'react-admin'

import {DateTimeField} from '@/components/Admin/custom/DateTimeField'
import {MyShowActions} from '@/components/Admin/custom/MyShowActions'
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField'

Expand All @@ -12,9 +13,9 @@ export const PostShow: FC = () => (
<TextField source="caption" />
<TextField source="short_text" />
<TextField source="details" />
<DateField source="added_at" />
<DateField source="visible_after" />
<DateField source="visible_until" />
<DateTimeField source="added_at" />
<DateTimeField source="visible_after" />
<DateTimeField source="visible_until" />
<SitesArrayField source="sites" />
</SimpleShowLayout>
</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {FC} from 'react'
import {
ArrayField,
Datagrid,
DateField,
FunctionField,
NumberField,
RaRecord,
Expand All @@ -13,6 +12,7 @@ import {
TextField,
} from 'react-admin'

import {DateTimeField} from '@/components/Admin/custom/DateTimeField'
import {MyShow} from '@/components/Admin/custom/MyShow'
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField'
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField'
Expand Down Expand Up @@ -45,8 +45,8 @@ export const CompetitionShow: FC = () => (
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateField source="start" />
<DateField source="end" />
<DateTimeField source="start" />
<DateTimeField source="end" />
<FunctionField<RaRecord>
source="publication_set"
label="Publication count"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {FC} from 'react'
import {
DateField,
FunctionField,
Labeled,
NumberField,
Expand All @@ -11,6 +10,8 @@ import {
useRedirect,
} from 'react-admin'

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

export const UpcomingOrCurrentEvent: FC = () => {
const record = useRecordContext()
const redirect = useRedirect()
Expand All @@ -25,13 +26,13 @@ export const UpcomingOrCurrentEvent: FC = () => {
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateField source="start" />
<DateField source="end" />
<DateTimeField source="start" />
<DateTimeField source="end" />
<TextField source="additional_name" />

<TextField source="registration_link.url" />
<DateField source="registration_link.start" />
<DateField source="registration_link.end" />
<DateTimeField source="registration_link.start" />
<DateTimeField source="registration_link.end" />
<TextField source="registration_link.additional_info" />

<FunctionField<RaRecord>
Expand Down
20 changes: 6 additions & 14 deletions src/components/Admin/resources/competition/event/EventCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import {Checkbox, FormControlLabel} from '@mui/material'
import {FC, useState} from 'react'
import {
DateTimeInput,
Labeled,
NumberInput,
ReferenceInput,
required,
SelectInput,
SimpleForm,
TextInput,
} from 'react-admin'
import {Labeled, NumberInput, ReferenceInput, required, SelectInput, SimpleForm, TextInput} from 'react-admin'

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

export const EventCreate: FC = () => {
// initial false, necakame, ze mame registration link uz ready
Expand All @@ -29,8 +21,8 @@ export const EventCreate: FC = () => {
<SimpleForm>
<NumberInput source="year" helperText="ročník súťaže, napr. 48" fullWidth validate={required()} />
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth validate={required()} />
<DateTimeInput source="start" fullWidth validate={required()} />
<DateTimeInput source="end" fullWidth validate={required()} />
<MyDateTimeInput source="start" fullWidth validate={required()} />
<MyDateTimeInput source="end" fullWidth validate={required()} />
<ReferenceInput source="competition" reference="competition/competition">
<SelectInput fullWidth validate={required()} />
</ReferenceInput>
Expand All @@ -43,8 +35,8 @@ export const EventCreate: FC = () => {
<>
<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()} />
<MyDateTimeInput source="registration_link.start" fullWidth validate={required()} />
<MyDateTimeInput source="registration_link.end" fullWidth validate={required()} />
<TextInput source="registration_link.additional_info" fullWidth />
</>
</Labeled>
Expand Down
20 changes: 6 additions & 14 deletions src/components/Admin/resources/competition/event/EventEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {Checkbox, FormControlLabel} from '@mui/material'
import {FC, useState} from 'react'
import {
DateTimeInput,
Labeled,
NumberInput,
ReferenceInput,
required,
SelectInput,
SimpleForm,
TextInput,
} from 'react-admin'
import {Labeled, NumberInput, ReferenceInput, required, SelectInput, SimpleForm, TextInput} from 'react-admin'

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

export const EventEdit: FC = () => {
Expand All @@ -31,8 +23,8 @@ export const EventEdit: FC = () => {
<SimpleForm>
<NumberInput source="year" helperText="ročník súťaže, napr. 48" fullWidth validate={required()} />
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth validate={required()} />
<DateTimeInput source="start" fullWidth validate={required()} />
<DateTimeInput source="end" fullWidth validate={required()} />
<MyDateTimeInput source="start" fullWidth validate={required()} />
<MyDateTimeInput source="end" fullWidth validate={required()} />
<ReferenceInput source="competition" reference="competition/competition">
<SelectInput fullWidth validate={required()} />
</ReferenceInput>
Expand All @@ -45,8 +37,8 @@ export const EventEdit: FC = () => {
<>
<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()} />
<MyDateTimeInput source="registration_link.start" fullWidth validate={required()} />
<MyDateTimeInput source="registration_link.end" fullWidth validate={required()} />
<TextInput source="registration_link.additional_info" fullWidth />
</>
</Labeled>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {FC} from 'react'
import {Datagrid, DateField, FunctionField, List, NumberField, RaRecord, ReferenceField, TextField} from 'react-admin'
import {Datagrid, FunctionField, List, NumberField, RaRecord, ReferenceField, TextField} from 'react-admin'

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

export const EventList: FC = () => (
<List>
Expand All @@ -8,8 +10,8 @@ export const EventList: FC = () => (
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateField source="start" />
<DateField source="end" />
<DateTimeField source="start" />
<DateTimeField source="end" />
<TextField source="additional_name" />
<TextField source="registration_link.url" />
<FunctionField<RaRecord>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Admin/resources/competition/event/EventShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {FC} from 'react'
import {
ArrayField,
Datagrid,
DateField,
NumberField,
ReferenceField,
SimpleShowLayout,
Expand All @@ -11,6 +10,7 @@ import {
TextField,
} from 'react-admin'

import {DateTimeField} from '@/components/Admin/custom/DateTimeField'
import {MyShow} from '@/components/Admin/custom/MyShow'

export const EventShow: FC = () => (
Expand All @@ -22,13 +22,13 @@ export const EventShow: FC = () => (
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateField source="start" />
<DateField source="end" />
<DateTimeField source="start" />
<DateTimeField source="end" />
<TextField source="additional_name" />

<TextField source="registration_link.url" />
<DateField source="registration_link.start" />
<DateField source="registration_link.end" />
<DateTimeField source="registration_link.start" />
<DateTimeField source="registration_link.end" />
<TextField source="registration_link.additional_info" />
</SimpleShowLayout>
</Tab>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {FC} from 'react'
import {
CheckboxGroupInput,
DateTimeInput,
NumberInput,
ReferenceArrayInput,
ReferenceInput,
Expand All @@ -12,6 +11,7 @@ import {
} from 'react-admin'

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

export const SemesterCreate: FC = () => (
<MyCreate>
Expand All @@ -22,8 +22,8 @@ export const SemesterCreate: FC = () => (
<NumberInput source="year" helperText="ročník súťaže, napr. 48" fullWidth validate={required()} />
<NumberInput source="season_code" fullWidth validate={required()} />
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth />
<DateTimeInput source="start" fullWidth validate={required()} />
<DateTimeInput source="end" fullWidth validate={required()} />
<MyDateTimeInput source="start" fullWidth validate={required()} />
<MyDateTimeInput source="end" fullWidth validate={required()} />
<TextInput source="additional_name" fullWidth />
{/* nechavam viditelne disabled nech sa rozhodneme, co s tym. BE nam posiela ID,
neviem, ci vieme updatnut cely objekt tym, ze ho pribalim, ako v EventEdit...
Expand Down
Loading
Loading