init /vehicle
route
This commit is contained in:
parent
88428b07f9
commit
52c746caa3
21
src/App.tsx
21
src/App.tsx
@ -23,8 +23,9 @@ import {MediaList, MediaCreate, MediaEdit, MediaShow} from './pages/media'
|
|||||||
import {ArticleList, ArticleCreate, ArticleEdit} from './pages/article'
|
import {ArticleList, ArticleCreate, ArticleEdit} from './pages/article'
|
||||||
import {SightList, SightCreate, SightEdit} from './pages/sight'
|
import {SightList, SightCreate, SightEdit} from './pages/sight'
|
||||||
import {StationList, StationCreate, StationEdit} from './pages/station'
|
import {StationList, StationCreate, StationEdit} from './pages/station'
|
||||||
|
import {VehicleList, VehicleCreate, VehicleEdit} from './pages/vehicle'
|
||||||
|
|
||||||
import {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon, SightIcon, StationIcon} from './components/ui/Icons'
|
import {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon, SightIcon, StationIcon, VehicleIcon} from './components/ui/Icons'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
@ -122,6 +123,18 @@ function App() {
|
|||||||
icon: <StationIcon />,
|
icon: <StationIcon />,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'vehicle',
|
||||||
|
list: '/vehicle',
|
||||||
|
create: '/vehicle/create',
|
||||||
|
edit: '/vehicle/edit/:id',
|
||||||
|
// добавить SHOW для vehicle->routes (https://wn.krbl.ru/vehicle/routes?id=1)
|
||||||
|
meta: {
|
||||||
|
canDelete: true,
|
||||||
|
label: 'Транспорт',
|
||||||
|
icon: <VehicleIcon />,
|
||||||
|
},
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
options={{
|
options={{
|
||||||
syncWithLocation: true,
|
syncWithLocation: true,
|
||||||
@ -185,6 +198,12 @@ function App() {
|
|||||||
<Route path="edit/:id" element={<StationEdit />} />
|
<Route path="edit/:id" element={<StationEdit />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
<Route path="/vehicle">
|
||||||
|
<Route index element={<VehicleList />} />
|
||||||
|
<Route path="create" element={<VehicleCreate />} />
|
||||||
|
<Route path="edit/:id" element={<VehicleEdit />} />
|
||||||
|
</Route>
|
||||||
|
|
||||||
<Route path="*" element={<ErrorComponent />} />
|
<Route path="*" element={<ErrorComponent />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route
|
<Route
|
||||||
|
@ -5,5 +5,6 @@ import PermMediaIcon from '@mui/icons-material/PermMedia'
|
|||||||
import FeedIcon from '@mui/icons-material/Feed'
|
import FeedIcon from '@mui/icons-material/Feed'
|
||||||
import VisibilityIcon from '@mui/icons-material/Visibility'
|
import VisibilityIcon from '@mui/icons-material/Visibility'
|
||||||
import HailIcon from '@mui/icons-material/Hail'
|
import HailIcon from '@mui/icons-material/Hail'
|
||||||
|
import DirectionsBusIcon from '@mui/icons-material/DirectionsBus'
|
||||||
|
|
||||||
export {PublicIcon as CountryIcon, LocationCityIcon as CityIcon, LocalShippingIcon as CarrierIcon, PermMediaIcon as MediaIcon, FeedIcon as ArticleIcon, VisibilityIcon as SightIcon, HailIcon as StationIcon}
|
export {PublicIcon as CountryIcon, LocationCityIcon as CityIcon, LocalShippingIcon as CarrierIcon, PermMediaIcon as MediaIcon, FeedIcon as ArticleIcon, VisibilityIcon as SightIcon, HailIcon as StationIcon, DirectionsBusIcon as VehicleIcon}
|
||||||
|
76
src/pages/vehicle/create.tsx
Normal file
76
src/pages/vehicle/create.tsx
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import {Autocomplete, Box, TextField} from '@mui/material'
|
||||||
|
import {Create, useAutocomplete} from '@refinedev/mui'
|
||||||
|
import {useForm} from '@refinedev/react-hook-form'
|
||||||
|
import {Controller} from 'react-hook-form'
|
||||||
|
|
||||||
|
export const VehicleCreate = () => {
|
||||||
|
const {
|
||||||
|
saveButtonProps,
|
||||||
|
refineCore: {formLoading},
|
||||||
|
register,
|
||||||
|
control,
|
||||||
|
formState: {errors},
|
||||||
|
} = useForm({})
|
||||||
|
|
||||||
|
const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
|
||||||
|
resource: 'city',
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Create isLoading={formLoading} saveButtonProps={saveButtonProps}>
|
||||||
|
<Box component="form" sx={{display: 'flex', flexDirection: 'column'}} autoComplete="off">
|
||||||
|
<TextField
|
||||||
|
{...register('tail_number', {
|
||||||
|
required: 'This field is required',
|
||||||
|
valueAsNumber: true,
|
||||||
|
})}
|
||||||
|
error={!!(errors as any)?.tail_number}
|
||||||
|
helperText={(errors as any)?.tail_number?.message}
|
||||||
|
margin="normal"
|
||||||
|
fullWidth
|
||||||
|
InputLabelProps={{shrink: true}}
|
||||||
|
type="number"
|
||||||
|
label={'Tail Number'}
|
||||||
|
name="tail_number"
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
{...register('type', {
|
||||||
|
required: 'This field is required',
|
||||||
|
valueAsNumber: true,
|
||||||
|
})}
|
||||||
|
error={!!(errors as any)?.type}
|
||||||
|
helperText={(errors as any)?.type?.message}
|
||||||
|
margin="normal"
|
||||||
|
fullWidth
|
||||||
|
InputLabelProps={{shrink: true}}
|
||||||
|
type="number"
|
||||||
|
label={'Type'}
|
||||||
|
name="type"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="city_id"
|
||||||
|
rules={{required: 'This field is required'}}
|
||||||
|
defaultValue={null}
|
||||||
|
render={({field}) => (
|
||||||
|
<Autocomplete
|
||||||
|
{...cityAutocompleteProps}
|
||||||
|
value={cityAutocompleteProps.options.find((option) => 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
|
||||||
|
}}
|
||||||
|
renderInput={(params) => <TextField {...params} label="Select City" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Create>
|
||||||
|
)
|
||||||
|
}
|
74
src/pages/vehicle/edit.tsx
Normal file
74
src/pages/vehicle/edit.tsx
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import {Autocomplete, Box, TextField} from '@mui/material'
|
||||||
|
import {Edit, useAutocomplete} from '@refinedev/mui'
|
||||||
|
import {useForm} from '@refinedev/react-hook-form'
|
||||||
|
import {Controller} from 'react-hook-form'
|
||||||
|
|
||||||
|
export const VehicleEdit = () => {
|
||||||
|
const {
|
||||||
|
saveButtonProps,
|
||||||
|
register,
|
||||||
|
control,
|
||||||
|
formState: {errors},
|
||||||
|
} = useForm({})
|
||||||
|
|
||||||
|
const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
|
||||||
|
resource: 'city',
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Edit saveButtonProps={saveButtonProps}>
|
||||||
|
<Box component="form" sx={{display: 'flex', flexDirection: 'column'}} autoComplete="off">
|
||||||
|
<TextField
|
||||||
|
{...register('tail_number', {
|
||||||
|
required: 'This field is required',
|
||||||
|
valueAsNumber: true,
|
||||||
|
})}
|
||||||
|
error={!!(errors as any)?.tail_number}
|
||||||
|
helperText={(errors as any)?.tail_number?.message}
|
||||||
|
margin="normal"
|
||||||
|
fullWidth
|
||||||
|
InputLabelProps={{shrink: true}}
|
||||||
|
type="number"
|
||||||
|
label={'Tail Number'}
|
||||||
|
name="tail_number"
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
{...register('type', {
|
||||||
|
required: 'This field is required',
|
||||||
|
valueAsNumber: true,
|
||||||
|
})}
|
||||||
|
error={!!(errors as any)?.type}
|
||||||
|
helperText={(errors as any)?.type?.message}
|
||||||
|
margin="normal"
|
||||||
|
fullWidth
|
||||||
|
InputLabelProps={{shrink: true}}
|
||||||
|
type="number"
|
||||||
|
label={'Type'}
|
||||||
|
name="type"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="city_id"
|
||||||
|
rules={{required: 'This field is required'}}
|
||||||
|
render={({field}) => (
|
||||||
|
<Autocomplete
|
||||||
|
{...cityAutocompleteProps}
|
||||||
|
value={cityAutocompleteProps.options.find((option) => 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
|
||||||
|
}}
|
||||||
|
renderInput={(params) => <TextField {...params} label="Select City" margin="normal" variant="outlined" error={!!errors.city_id} helperText={(errors as any)?.city_id?.message} required />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Edit>
|
||||||
|
)
|
||||||
|
}
|
3
src/pages/vehicle/index.ts
Normal file
3
src/pages/vehicle/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export * from './create'
|
||||||
|
export * from './edit'
|
||||||
|
export * from './list'
|
73
src/pages/vehicle/list.tsx
Normal file
73
src/pages/vehicle/list.tsx
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import {DataGrid, type GridColDef} from '@mui/x-data-grid'
|
||||||
|
import {DeleteButton, EditButton, List, useDataGrid} from '@refinedev/mui'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export const VehicleList = () => {
|
||||||
|
const {dataGridProps} = useDataGrid({})
|
||||||
|
|
||||||
|
const columns = React.useMemo<GridColDef[]>(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
headerName: 'ID',
|
||||||
|
type: 'number',
|
||||||
|
minWidth: 70,
|
||||||
|
display: 'flex',
|
||||||
|
align: 'left',
|
||||||
|
headerAlign: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'tail_number',
|
||||||
|
headerName: 'Tail Number',
|
||||||
|
type: 'number',
|
||||||
|
minWidth: 150,
|
||||||
|
display: 'flex',
|
||||||
|
align: 'left',
|
||||||
|
headerAlign: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'type',
|
||||||
|
headerName: 'Type',
|
||||||
|
type: 'number',
|
||||||
|
minWidth: 150,
|
||||||
|
display: 'flex',
|
||||||
|
align: 'left',
|
||||||
|
headerAlign: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'city_id',
|
||||||
|
headerName: 'City ID',
|
||||||
|
type: 'number',
|
||||||
|
minWidth: 70,
|
||||||
|
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