diff --git a/src/components/CustomDataGrid.tsx b/src/components/CustomDataGrid.tsx index 6940b59..4121e11 100644 --- a/src/components/CustomDataGrid.tsx +++ b/src/components/CustomDataGrid.tsx @@ -12,7 +12,7 @@ interface CustomDataGridProps extends DataGridProps { resource?: string // Add this prop } -const DEV_FIELDS = ['id', 'code', 'country_code', 'city_id', 'carrier_id', 'main_color', 'left_color', 'right_color', 'logo', 'slogan', 'filename', 'arms', 'thumbnail', 'route_sys_number', 'governor_appeal', 'scale_min', 'scale_max', 'rotate', 'center_latitude', 'center_longitude', 'watermark_lu', 'watermark_rd', 'left_article', 'preview_article'] as const +const DEV_FIELDS = ['id', 'code', 'country_code', 'city_id', 'carrier_id', 'main_color', 'left_color', 'right_color', 'logo', 'slogan', 'filename', 'arms', 'thumbnail', 'route_sys_number', 'governor_appeal', 'scale_min', 'scale_max', 'rotate', 'center_latitude', 'center_longitude', 'watermark_lu', 'watermark_rd', 'left_article', 'preview_article', 'offset_x', 'offset_y'] as const export const CustomDataGrid = ({hasCoordinates = false, columns = [], resource, ...props}: CustomDataGridProps) => { // const isDev = import.meta.env.DEV diff --git a/src/pages/station/create.tsx b/src/pages/station/create.tsx index 8545af7..00b3940 100644 --- a/src/pages/station/create.tsx +++ b/src/pages/station/create.tsx @@ -1,12 +1,26 @@ -import {Box, TextField} from '@mui/material' -import {Create} from '@refinedev/mui' +import {Autocomplete, Box, TextField, Typography, Paper, Grid} from '@mui/material' +import {Create, useAutocomplete} from '@refinedev/mui' import {useForm} from '@refinedev/react-hook-form' +import {Controller} from 'react-hook-form' + +const TRANSFER_FIELDS = [ + {name: 'bus', label: 'Автобус'}, + {name: 'metro_blue', label: 'Метро (синяя)'}, + {name: 'metro_green', label: 'Метро (зеленая)'}, + {name: 'metro_orange', label: 'Метро (оранжевая)'}, + {name: 'metro_purple', label: 'Метро (фиолетовая)'}, + {name: 'metro_red', label: 'Метро (красная)'}, + {name: 'train', label: 'Электричка'}, + {name: 'tram', label: 'Трамвай'}, + {name: 'trolleybus', label: 'Троллейбус'}, +] export const StationCreate = () => { const { saveButtonProps, refineCore: {formLoading}, register, + control, formState: {errors}, } = useForm({ refineCoreProps: { @@ -14,6 +28,17 @@ export const StationCreate = () => { }, }) + const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({ + resource: 'city', + onSearch: (value) => [ + { + field: 'name', + operator: 'contains', + value, + }, + ], + }) + return ( @@ -84,6 +109,74 @@ export const StationCreate = () => { label={'Долгота *'} name="longitude" /> + + ( + option.id === field.value) || null} + onChange={(_, value) => { + field.onChange(value?.id || '') + }} + getOptionLabel={(item) => { + return item ? item.name : '' + }} + isOptionEqualToValue={(option, value) => { + return option.id === value?.id + }} + filterOptions={(options, {inputValue}) => { + return options.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase())) + }} + renderInput={(params) => } + /> + )} + /> + + + + + + {/* Группа полей пересадок */} + + + Пересадки + + + {TRANSFER_FIELDS.map((field) => ( + + + + ))} + + ) diff --git a/src/pages/station/edit.tsx b/src/pages/station/edit.tsx index d4b3040..983ec74 100644 --- a/src/pages/station/edit.tsx +++ b/src/pages/station/edit.tsx @@ -1,19 +1,45 @@ -import {Box, TextField} from '@mui/material' -import {Edit} from '@refinedev/mui' +import {Autocomplete, Box, TextField, Typography, Paper, Grid} from '@mui/material' +import {Edit, useAutocomplete} from '@refinedev/mui' import {useForm} from '@refinedev/react-hook-form' +import {Controller} from 'react-hook-form' + import {useParams} from 'react-router' import {LinkedItems} from '../../components/LinkedItems' import {type SightItem, sightFields} from './types' +const TRANSFER_FIELDS = [ + {name: 'bus', label: 'Автобус'}, + {name: 'metro_blue', label: 'Метро (синяя)'}, + {name: 'metro_green', label: 'Метро (зеленая)'}, + {name: 'metro_orange', label: 'Метро (оранжевая)'}, + {name: 'metro_purple', label: 'Метро (фиолетовая)'}, + {name: 'metro_red', label: 'Метро (красная)'}, + {name: 'train', label: 'Электричка'}, + {name: 'tram', label: 'Трамвай'}, + {name: 'trolleybus', label: 'Троллейбус'}, +] + export const StationEdit = () => { const { saveButtonProps, register, + control, formState: {errors}, } = useForm({}) const {id: stationId} = useParams<{id: string}>() + const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({ + resource: 'city', + onSearch: (value) => [ + { + field: 'name', + operator: 'contains', + value, + }, + ], + }) + return ( @@ -84,6 +110,74 @@ export const StationEdit = () => { label={'Долгота *'} name="longitude" /> + + ( + option.id === field.value) || null} + onChange={(_, value) => { + field.onChange(value?.id || '') + }} + getOptionLabel={(item) => { + return item ? item.name : '' + }} + isOptionEqualToValue={(option, value) => { + return option.id === value?.id + }} + filterOptions={(options, {inputValue}) => { + return options.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase())) + }} + renderInput={(params) => } + /> + )} + /> + + + + + + {/* Группа полей пересадок */} + + + Пересадки + + + {TRANSFER_FIELDS.map((field) => ( + + + + ))} + + {stationId && ( diff --git a/src/pages/station/list.tsx b/src/pages/station/list.tsx index 3745890..6b858f7 100644 --- a/src/pages/station/list.tsx +++ b/src/pages/station/list.tsx @@ -55,6 +55,33 @@ export const StationList = () => { align: 'left', headerAlign: 'left', }, + { + field: 'city_id', + headerName: 'ID города', + type: 'number', + minWidth: 120, + display: 'flex', + align: 'left', + headerAlign: 'left', + }, + { + field: 'offset_x', + headerName: 'Смещение (X)', + type: 'number', + minWidth: 120, + display: 'flex', + align: 'left', + headerAlign: 'left', + }, + { + field: 'offset_y', + headerName: 'Смещение (Y)', + type: 'number', + minWidth: 120, + display: 'flex', + align: 'left', + headerAlign: 'left', + }, { field: 'description', headerName: 'Описание',