init /article
route
This commit is contained in:
parent
b3863e5aef
commit
b1c7fb5582
21
src/App.tsx
21
src/App.tsx
@ -23,8 +23,9 @@ import {CountryList, CountryCreate, CountryEdit} from './pages/country'
|
||||
import {CityList, CityCreate, CityEdit} from './pages/city'
|
||||
import {CarrierList, CarrierCreate, CarrierEdit} from './pages/carrier'
|
||||
import {MediaList, MediaCreate, MediaEdit, MediaShow} from './pages/media'
|
||||
import {ArticleList, ArticleCreate, ArticleEdit} from './pages/article'
|
||||
|
||||
import {CountryIcon, CityIcon, CarrierIcon, MediaIcon} from './components/ui/Icons'
|
||||
import {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon} from './components/ui/Icons'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@ -86,6 +87,18 @@ function App() {
|
||||
icon: <MediaIcon />,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'article',
|
||||
list: '/article',
|
||||
create: '/article/create',
|
||||
edit: '/article/edit/:id',
|
||||
// добавить SHOW для article->media (https://wn.krbl.ru/article/2/media)
|
||||
meta: {
|
||||
canDelete: true,
|
||||
label: 'Статьи',
|
||||
icon: <ArticleIcon />,
|
||||
},
|
||||
},
|
||||
]}
|
||||
options={{
|
||||
syncWithLocation: true,
|
||||
@ -131,6 +144,12 @@ function App() {
|
||||
<Route path="show/:id" element={<MediaShow />} />
|
||||
</Route>
|
||||
|
||||
<Route path="/article">
|
||||
<Route index element={<ArticleList />} />
|
||||
<Route path="create" element={<ArticleCreate />} />
|
||||
<Route path="edit/:id" element={<ArticleEdit />} />
|
||||
</Route>
|
||||
|
||||
<Route path="*" element={<ErrorComponent />} />
|
||||
</Route>
|
||||
<Route
|
||||
|
@ -2,5 +2,6 @@ import PublicIcon from '@mui/icons-material/Public'
|
||||
import LocationCityIcon from '@mui/icons-material/LocationCity'
|
||||
import LocalShippingIcon from '@mui/icons-material/LocalShipping'
|
||||
import PermMediaIcon from '@mui/icons-material/PermMedia'
|
||||
import FeedIcon from '@mui/icons-material/Feed'
|
||||
|
||||
export {PublicIcon as CountryIcon, LocationCityIcon as CityIcon, LocalShippingIcon as CarrierIcon, PermMediaIcon as MediaIcon}
|
||||
export {PublicIcon as CountryIcon, LocationCityIcon as CityIcon, LocalShippingIcon as CarrierIcon, PermMediaIcon as MediaIcon, FeedIcon as ArticleIcon}
|
||||
|
49
src/pages/article/create.tsx
Normal file
49
src/pages/article/create.tsx
Normal file
@ -0,0 +1,49 @@
|
||||
import {Box, TextField} from '@mui/material'
|
||||
import {Create} from '@refinedev/mui'
|
||||
import {useForm} from '@refinedev/react-hook-form'
|
||||
|
||||
export const ArticleCreate = () => {
|
||||
const {
|
||||
saveButtonProps,
|
||||
refineCore: {formLoading},
|
||||
register,
|
||||
formState: {errors},
|
||||
} = useForm({
|
||||
refineCoreProps: {
|
||||
resource: 'article/',
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<Create isLoading={formLoading} saveButtonProps={saveButtonProps}>
|
||||
<Box component="form" sx={{display: 'flex', flexDirection: 'column'}} autoComplete="off">
|
||||
<TextField
|
||||
{...register('heading', {
|
||||
required: 'This field is required',
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="text"
|
||||
label={'Heading'}
|
||||
name="heading"
|
||||
/>
|
||||
<TextField
|
||||
{...register('body', {
|
||||
required: 'This field is required',
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="text"
|
||||
label={'Body'}
|
||||
name="body"
|
||||
/>
|
||||
</Box>
|
||||
</Create>
|
||||
)
|
||||
}
|
44
src/pages/article/edit.tsx
Normal file
44
src/pages/article/edit.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
import {Box, TextField} from '@mui/material'
|
||||
import {Edit} from '@refinedev/mui'
|
||||
import {useForm} from '@refinedev/react-hook-form'
|
||||
|
||||
export const ArticleEdit = () => {
|
||||
const {
|
||||
saveButtonProps,
|
||||
register,
|
||||
formState: {errors},
|
||||
} = useForm({})
|
||||
|
||||
return (
|
||||
<Edit saveButtonProps={saveButtonProps}>
|
||||
<Box component="form" sx={{display: 'flex', flexDirection: 'column'}} autoComplete="off">
|
||||
<TextField
|
||||
{...register('heading', {
|
||||
required: 'This field is required',
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="text"
|
||||
label={'Heading'}
|
||||
name="heading"
|
||||
/>
|
||||
<TextField
|
||||
{...register('body', {
|
||||
required: 'This field is required',
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="text"
|
||||
label={'Body'}
|
||||
name="body"
|
||||
/>
|
||||
</Box>
|
||||
</Edit>
|
||||
)
|
||||
}
|
3
src/pages/article/index.ts
Normal file
3
src/pages/article/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './create'
|
||||
export * from './edit'
|
||||
export * from './list'
|
65
src/pages/article/list.tsx
Normal file
65
src/pages/article/list.tsx
Normal file
@ -0,0 +1,65 @@
|
||||
import {DataGrid, type GridColDef} from '@mui/x-data-grid'
|
||||
import {DeleteButton, EditButton, List, useDataGrid} from '@refinedev/mui'
|
||||
import React from 'react'
|
||||
|
||||
export const ArticleList = () => {
|
||||
const {dataGridProps} = useDataGrid({
|
||||
resource: 'article/',
|
||||
})
|
||||
|
||||
const columns = React.useMemo<GridColDef[]>(
|
||||
() => [
|
||||
{
|
||||
field: 'id',
|
||||
headerName: 'ID',
|
||||
type: 'number',
|
||||
minWidth: 70,
|
||||
display: 'flex',
|
||||
align: 'left',
|
||||
headerAlign: 'left',
|
||||
},
|
||||
{
|
||||
field: 'heading',
|
||||
headerName: 'Heading',
|
||||
type: 'string',
|
||||
minWidth: 300,
|
||||
display: 'flex',
|
||||
align: 'left',
|
||||
headerAlign: 'left',
|
||||
},
|
||||
{
|
||||
field: 'body',
|
||||
headerName: 'Body',
|
||||
type: 'string',
|
||||
display: 'flex',
|
||||
align: 'left',
|
||||
headerAlign: 'left',
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: 'actions',
|
||||
headerName: 'Actions',
|
||||
align: 'right',
|
||||
headerAlign: 'center',
|
||||
minWidth: 100,
|
||||
sortable: false,
|
||||
display: 'flex',
|
||||
renderCell: function render({row}) {
|
||||
return (
|
||||
<>
|
||||
<EditButton hideText recordItemId={row.id} />
|
||||
<DeleteButton hideText recordItemId={row.id} />
|
||||
</>
|
||||
)
|
||||
},
|
||||
},
|
||||
],
|
||||
[],
|
||||
)
|
||||
|
||||
return (
|
||||
<List>
|
||||
<DataGrid {...dataGridProps} columns={columns} getRowId={(row: any) => row.id} />
|
||||
</List>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user