From b1c7fb5582e1f19a69c6157125217b48eacb0ed1 Mon Sep 17 00:00:00 2001 From: maxim Date: Tue, 4 Feb 2025 14:44:56 +0300 Subject: [PATCH] init `/article` route --- src/App.tsx | 21 +++++++++++- src/components/ui/Icons.tsx | 3 +- src/pages/article/create.tsx | 49 +++++++++++++++++++++++++++ src/pages/article/edit.tsx | 44 ++++++++++++++++++++++++ src/pages/article/index.ts | 3 ++ src/pages/article/list.tsx | 65 ++++++++++++++++++++++++++++++++++++ 6 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 src/pages/article/create.tsx create mode 100644 src/pages/article/edit.tsx create mode 100644 src/pages/article/index.ts create mode 100644 src/pages/article/list.tsx diff --git a/src/App.tsx b/src/App.tsx index c4ed91f..01f197b 100644 --- a/src/App.tsx +++ b/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: , }, }, + { + 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: , + }, + }, ]} options={{ syncWithLocation: true, @@ -131,6 +144,12 @@ function App() { } /> + + } /> + } /> + } /> + + } /> { + const { + saveButtonProps, + refineCore: {formLoading}, + register, + formState: {errors}, + } = useForm({ + refineCoreProps: { + resource: 'article/', + }, + }) + + return ( + + + + + + + ) +} diff --git a/src/pages/article/edit.tsx b/src/pages/article/edit.tsx new file mode 100644 index 0000000..4d74d8c --- /dev/null +++ b/src/pages/article/edit.tsx @@ -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 ( + + + + + + + ) +} diff --git a/src/pages/article/index.ts b/src/pages/article/index.ts new file mode 100644 index 0000000..fbafdcf --- /dev/null +++ b/src/pages/article/index.ts @@ -0,0 +1,3 @@ +export * from './create' +export * from './edit' +export * from './list' diff --git a/src/pages/article/list.tsx b/src/pages/article/list.tsx new file mode 100644 index 0000000..7c99c2d --- /dev/null +++ b/src/pages/article/list.tsx @@ -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( + () => [ + { + 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 ( + <> + + + + ) + }, + }, + ], + [], + ) + + return ( + + row.id} /> + + ) +}