From 88428b07f963219278159892ffb57b887d01f452 Mon Sep 17 00:00:00 2001 From: maxim Date: Tue, 4 Feb 2025 15:34:12 +0300 Subject: [PATCH] init `/station` route --- src/App.tsx | 23 +++++++++- src/components/ui/Icons.tsx | 3 +- src/pages/station/create.tsx | 77 +++++++++++++++++++++++++++++++++ src/pages/station/edit.tsx | 72 +++++++++++++++++++++++++++++++ src/pages/station/index.ts | 3 ++ src/pages/station/list.tsx | 83 ++++++++++++++++++++++++++++++++++++ 6 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 src/pages/station/create.tsx create mode 100644 src/pages/station/edit.tsx create mode 100644 src/pages/station/index.ts create mode 100644 src/pages/station/list.tsx diff --git a/src/App.tsx b/src/App.tsx index 8aedd53..d8960d1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,8 +22,9 @@ import {CarrierList, CarrierCreate, CarrierEdit} from './pages/carrier' import {MediaList, MediaCreate, MediaEdit, MediaShow} from './pages/media' import {ArticleList, ArticleCreate, ArticleEdit} from './pages/article' import {SightList, SightCreate, SightEdit} from './pages/sight' +import {StationList, StationCreate, StationEdit} from './pages/station' -import {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon, SightIcon} from './components/ui/Icons' +import {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon, SightIcon, StationIcon} from './components/ui/Icons' function App() { return ( @@ -105,10 +106,22 @@ function App() { // добавить SHOW для sight->article (https://wn.krbl.ru/sight/2/article) meta: { canDelete: true, - label: 'Вид', + label: 'Виды', icon: , }, }, + { + name: 'station', + list: '/station', + create: '/station/create', + edit: '/station/edit/:id', + // добавить SHOW для station->sight (https://wn.krbl.ru/station/2/sight) + meta: { + canDelete: true, + label: 'Остановки', + icon: , + }, + }, ]} options={{ syncWithLocation: true, @@ -166,6 +179,12 @@ function App() { } /> + + } /> + } /> + } /> + + } /> { + const { + saveButtonProps, + refineCore: {formLoading}, + register, + formState: {errors}, + } = useForm({ + refineCoreProps: { + resource: 'station/', + }, + }) + + return ( + + + + + + + + + ) +} diff --git a/src/pages/station/edit.tsx b/src/pages/station/edit.tsx new file mode 100644 index 0000000..f886e57 --- /dev/null +++ b/src/pages/station/edit.tsx @@ -0,0 +1,72 @@ +import {Box, TextField} from '@mui/material' +import {Edit} from '@refinedev/mui' +import {useForm} from '@refinedev/react-hook-form' + +export const StationEdit = () => { + const { + saveButtonProps, + register, + formState: {errors}, + } = useForm({}) + + return ( + + + + + + + + + ) +} diff --git a/src/pages/station/index.ts b/src/pages/station/index.ts new file mode 100644 index 0000000..fbafdcf --- /dev/null +++ b/src/pages/station/index.ts @@ -0,0 +1,3 @@ +export * from './create' +export * from './edit' +export * from './list' diff --git a/src/pages/station/list.tsx b/src/pages/station/list.tsx new file mode 100644 index 0000000..997625f --- /dev/null +++ b/src/pages/station/list.tsx @@ -0,0 +1,83 @@ +import {DataGrid, type GridColDef} from '@mui/x-data-grid' +import {DeleteButton, EditButton, List, useDataGrid} from '@refinedev/mui' +import React from 'react' + +export const StationList = () => { + const {dataGridProps} = useDataGrid({ + resource: 'station/', + }) + + const columns = React.useMemo( + () => [ + { + field: 'id', + headerName: 'ID', + type: 'number', + minWidth: 70, + display: 'flex', + align: 'left', + headerAlign: 'left', + }, + { + field: 'name', + headerName: 'Name', + type: 'string', + minWidth: 300, + display: 'flex', + align: 'left', + headerAlign: 'left', + }, + { + field: 'latitude', + headerName: 'Latitude', + type: 'number', + minWidth: 150, + display: 'flex', + align: 'left', + headerAlign: 'left', + }, + { + field: 'longitude', + headerName: 'Longitude', + type: 'number', + minWidth: 150, + display: 'flex', + align: 'left', + headerAlign: 'left', + }, + { + field: 'description', + headerName: 'Description', + 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} /> + + ) +}