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

259: Flatpage create/edit preview #360

Merged
merged 3 commits into from
Apr 14, 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
14 changes: 14 additions & 0 deletions src/components/Admin/custom/FlatpagePreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {ThemeProvider} from '@mui/material/styles'
import {FC} from 'react'
import {FormDataConsumer} from 'react-admin'

import {Markdown} from '@/components/StaticSites/Markdown'
import {theme} from '@/theme'

export const FlatpagePreview: FC = () => {
return (
<ThemeProvider theme={theme}>
<FormDataConsumer>{({formData}) => <Markdown content={formData.content} />}</FormDataConsumer>
</ThemeProvider>
)
}
9 changes: 5 additions & 4 deletions src/components/Admin/custom/PostPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Stack} from '@mui/material'
import {ThemeProvider} from '@mui/material/styles'
import Grid from '@mui/material/Unstable_Grid2'
import {FC, useState} from 'react'
import {FormDataConsumer, ThemeProvider} from 'react-admin'
import {FormDataConsumer} from 'react-admin'

import {Post} from '@/components/Posts/Post'
import {PostDetail} from '@/components/Posts/PostDetail'
Expand All @@ -13,8 +14,8 @@ export const PostPreview: FC = () => {
<ThemeProvider theme={theme}>
<FormDataConsumer>
{({formData}) => (
<Grid container>
<Grid xs={6}>
<Grid container columnSpacing={5} sx={{width: '100%'}}>
<Grid xs={4}>
<Stack gap={5}>
<Post
id={0}
Expand All @@ -30,7 +31,7 @@ export const PostPreview: FC = () => {
/>
</Stack>
</Grid>
<Grid xs={6}>
<Grid xs={5}>
{isDetailOpen && <PostDetail caption={formData?.caption ?? ''} details={formData?.details ?? ''} />}
</Grid>
</Grid>
Expand Down
22 changes: 14 additions & 8 deletions src/components/Admin/resources/base/flat-page/FlatpageCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import {FC} from 'react'
import {NumberInput, required, SimpleForm, TextInput} from 'react-admin'
import {FormTab, NumberInput, required, TabbedForm, TextInput} from 'react-admin'

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

export const FlatpageCreate: FC = () => (
<MyCreate>
<SimpleForm>
<NumberInput source="id" fullWidth disabled />
<TextInput source="url" fullWidth validate={required()} />
<TextInput source="title" fullWidth validate={required()} />
<TextInput source="content" multiline fullWidth validate={required()} />
<SitesCheckboxInput source="sites" validate={required()} />
</SimpleForm>
<TabbedForm>
<FormTab label="general">
<NumberInput source="id" fullWidth disabled />
<TextInput source="url" fullWidth validate={required()} />
<TextInput source="title" fullWidth validate={required()} />
<TextInput source="content" multiline fullWidth validate={required()} />
<SitesCheckboxInput source="sites" validate={required()} />
</FormTab>
<FormTab label="preview">
<FlatpagePreview />
</FormTab>
</TabbedForm>
</MyCreate>
)
22 changes: 14 additions & 8 deletions src/components/Admin/resources/base/flat-page/FlatpageEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import {FC} from 'react'
import {NumberInput, required, SimpleForm, TextInput} from 'react-admin'
import {FormTab, NumberInput, required, TabbedForm, TextInput} from 'react-admin'

import {FlatpagePreview} from '@/components/Admin/custom/FlatpagePreview'
import {MyEdit} from '@/components/Admin/custom/MyEdit'
import {SitesCheckboxInput} from '@/components/Admin/custom/SitesCheckboxInput'

export const FlatpageEdit: FC = () => (
<MyEdit>
<SimpleForm>
<NumberInput source="id" fullWidth disabled />
<TextInput source="url" fullWidth validate={required()} />
<TextInput source="title" fullWidth validate={required()} />
<TextInput source="content" multiline fullWidth validate={required()} />
<SitesCheckboxInput source="sites" validate={required()} />
</SimpleForm>
<TabbedForm>
<FormTab label="general">
<NumberInput source="id" fullWidth disabled />
<TextInput source="url" fullWidth validate={required()} />
<TextInput source="title" fullWidth validate={required()} />
<TextInput source="content" multiline fullWidth validate={required()} />
<SitesCheckboxInput source="sites" validate={required()} />
</FormTab>
<FormTab label="preview">
<FlatpagePreview />
</FormTab>
</TabbedForm>
</MyEdit>
)
1 change: 1 addition & 0 deletions src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ declare module '@mui/material/Typography' {
export const font = Poppins({
subsets: ['latin'],
weight: ['300', '400', '600', '700', '800'],
display: 'swap',
})

const _theme = createTheme({
Expand Down
Loading