diff --git a/src/components/Admin/custom/MyDateInput.tsx b/src/components/Admin/custom/MyDateInput.tsx deleted file mode 100644 index 94a6389c..00000000 --- a/src/components/Admin/custom/MyDateInput.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import {DateTime} from 'luxon' -import {ComponentProps, FC} from 'react' -import {DateInput} from 'react-admin' - -const backendFormat = 'dd.MM.yyyy HH:mm:ss' - -// used to convert BE weird format of 01.01.2020 18:00:00 to 01-01-2020 input format -// https://moment.github.io/luxon/#/formatting -// TODO: ale blbost, upravi sa to aj tak nazad na ISO vs ISODate: https://github.com/ZdruzenieSTROM/webstrom-backend/issues/257 -const dateFormatter = (v: string) => DateTime.fromFormat(v, backendFormat).toISODate() - -// used to convert input format of 01-01-2020 to 01-01-2020TT00:00:00.000+02:00 BE-expected format -// https://moment.github.io/luxon/#/parsing -const dateParser = (v: string) => DateTime.fromISO(v).toISO() - -export const MyDateInput: FC> = (props) => ( - -) diff --git a/src/components/Admin/custom/SitesCheckboxInput.tsx b/src/components/Admin/custom/SitesCheckboxInput.tsx index 492a5113..194a1d43 100644 --- a/src/components/Admin/custom/SitesCheckboxInput.tsx +++ b/src/components/Admin/custom/SitesCheckboxInput.tsx @@ -1,14 +1,9 @@ -import {CheckboxGroupInput, required} from 'react-admin' +import {CheckboxGroupInput} from 'react-admin' + +import {seminarIdToName} from '@/utils/useSeminarInfo' + +const choices = Object.entries(seminarIdToName).map(([id, name]) => ({id, name})) export const SitesCheckboxInput: typeof CheckboxGroupInput = (props) => ( - + ) diff --git a/src/components/Admin/custom/TruncatedTextField.tsx b/src/components/Admin/custom/TruncatedTextField.tsx new file mode 100644 index 00000000..8ea3aede --- /dev/null +++ b/src/components/Admin/custom/TruncatedTextField.tsx @@ -0,0 +1,16 @@ +import {FC} from 'react' +import {FieldProps, useRecordContext} from 'react-admin' + +type TruncatedTextFieldProps = FieldProps & { + maxTextWidth: number +} + +export const TruncatedTextField: FC = ({source, maxTextWidth}) => { + const record = useRecordContext() + if (!record || !source) return null + + const text = record[source] + const isString = typeof text === 'string' + + return {isString && text.length > maxTextWidth ? text.slice(0, maxTextWidth - 3) + '...' : text} +} diff --git a/src/components/Admin/resources/cms/post/PostCreate.tsx b/src/components/Admin/resources/cms/post/PostCreate.tsx index 5b8a5a12..a4f34eb5 100644 --- a/src/components/Admin/resources/cms/post/PostCreate.tsx +++ b/src/components/Admin/resources/cms/post/PostCreate.tsx @@ -1,26 +1,35 @@ import {FC} from 'react' -import {ArrayInput, Create, FormTab, required, SimpleFormIterator, TabbedForm, TextInput} from 'react-admin' +import { + ArrayInput, + Create, + DateTimeInput, + FormTab, + NumberInput, + required, + SimpleFormIterator, + TabbedForm, + TextInput, +} from 'react-admin' -import {MyDateInput} from '@/components/Admin/custom/MyDateInput' import {SitesCheckboxInput} from '@/components/Admin/custom/SitesCheckboxInput' export const PostCreate: FC = () => ( - {/* */} + - {/* */} - - - + + + + - {/* */} + diff --git a/src/components/Admin/resources/cms/post/PostEdit.tsx b/src/components/Admin/resources/cms/post/PostEdit.tsx index ce21a24e..5f344b9b 100644 --- a/src/components/Admin/resources/cms/post/PostEdit.tsx +++ b/src/components/Admin/resources/cms/post/PostEdit.tsx @@ -1,7 +1,16 @@ import {FC} from 'react' -import {ArrayInput, Edit, FormTab, NumberInput, required, SimpleFormIterator, TabbedForm, TextInput} from 'react-admin' +import { + ArrayInput, + DateTimeInput, + Edit, + FormTab, + NumberInput, + required, + SimpleFormIterator, + TabbedForm, + TextInput, +} from 'react-admin' -import {MyDateInput} from '@/components/Admin/custom/MyDateInput' import {MyEditActions} from '@/components/Admin/custom/MyEditActions' import {SitesCheckboxInput} from '@/components/Admin/custom/SitesCheckboxInput' @@ -13,10 +22,10 @@ export const PostEdit: FC = () => ( - - - - + + + + diff --git a/src/components/Admin/resources/cms/post/PostList.tsx b/src/components/Admin/resources/cms/post/PostList.tsx index b34fed3a..6447afb6 100644 --- a/src/components/Admin/resources/cms/post/PostList.tsx +++ b/src/components/Admin/resources/cms/post/PostList.tsx @@ -1,18 +1,25 @@ import {FC} from 'react' -import {Datagrid, DateField, List, NumberField, TextField} from 'react-admin' +import {Datagrid, DateField, FunctionField, List, NumberField, RaRecord, TextField} from 'react-admin' + +import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField' +import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField' export const PostList: FC = () => ( - - + + - {/* */} - {/* */} + + + source="links" + label="Link count" + render={(record) => record && {record['links'].length}} + /> )