init /route
route
This commit is contained in:
parent
52c746caa3
commit
dda02078cc
22
src/App.tsx
22
src/App.tsx
@ -24,8 +24,9 @@ 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 {VehicleList, VehicleCreate, VehicleEdit} from './pages/vehicle'
|
||||||
|
import {RouteList, RouteCreate, RouteEdit} from './pages/route'
|
||||||
|
|
||||||
import {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon, SightIcon, StationIcon, VehicleIcon} from './components/ui/Icons'
|
import {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon, SightIcon, StationIcon, VehicleIcon, RouteIcon} from './components/ui/Icons'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
@ -135,6 +136,19 @@ function App() {
|
|||||||
icon: <VehicleIcon />,
|
icon: <VehicleIcon />,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'route',
|
||||||
|
list: '/route',
|
||||||
|
create: '/route/create',
|
||||||
|
edit: '/route/edit/:id',
|
||||||
|
// добавить SHOW для route->station (https://wn.krbl.ru/route/station)
|
||||||
|
// добавить SHOW для route->vehicle (https://wn.krbl.ru/route/vehicle)
|
||||||
|
meta: {
|
||||||
|
canDelete: true,
|
||||||
|
label: 'Маршруты',
|
||||||
|
icon: <RouteIcon />,
|
||||||
|
},
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
options={{
|
options={{
|
||||||
syncWithLocation: true,
|
syncWithLocation: true,
|
||||||
@ -204,6 +218,12 @@ function App() {
|
|||||||
<Route path="edit/:id" element={<VehicleEdit />} />
|
<Route path="edit/:id" element={<VehicleEdit />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
<Route path="/route">
|
||||||
|
<Route index element={<RouteList />} />
|
||||||
|
<Route path="create" element={<RouteCreate />} />
|
||||||
|
<Route path="edit/:id" element={<RouteEdit />} />
|
||||||
|
</Route>
|
||||||
|
|
||||||
<Route path="*" element={<ErrorComponent />} />
|
<Route path="*" element={<ErrorComponent />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route
|
<Route
|
||||||
|
@ -6,5 +6,6 @@ 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'
|
import DirectionsBusIcon from '@mui/icons-material/DirectionsBus'
|
||||||
|
import ForkLeftIcon from '@mui/icons-material/ForkLeft'
|
||||||
|
|
||||||
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}
|
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, ForkLeftIcon as RouteIcon}
|
||||||
|
59
src/pages/route/create.tsx
Normal file
59
src/pages/route/create.tsx
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import {Box, TextField, FormControlLabel, Checkbox} from '@mui/material'
|
||||||
|
import {Create} from '@refinedev/mui'
|
||||||
|
import {useForm} from '@refinedev/react-hook-form'
|
||||||
|
import {Controller} from 'react-hook-form'
|
||||||
|
|
||||||
|
export const RouteCreate = () => {
|
||||||
|
const {
|
||||||
|
saveButtonProps,
|
||||||
|
refineCore: {formLoading},
|
||||||
|
register,
|
||||||
|
control,
|
||||||
|
formState: {errors},
|
||||||
|
} = useForm({
|
||||||
|
refineCoreProps: {
|
||||||
|
resource: 'route/',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Create isLoading={formLoading} saveButtonProps={saveButtonProps}>
|
||||||
|
<Box component="form" sx={{display: 'flex', flexDirection: 'column'}} autoComplete="off">
|
||||||
|
<TextField
|
||||||
|
{...register('carrier_id', {
|
||||||
|
required: 'This field is required',
|
||||||
|
valueAsNumber: true,
|
||||||
|
})}
|
||||||
|
error={!!(errors as any)?.carrier_id}
|
||||||
|
helperText={(errors as any)?.carrier_id?.message}
|
||||||
|
margin="normal"
|
||||||
|
fullWidth
|
||||||
|
InputLabelProps={{shrink: true}}
|
||||||
|
type="number"
|
||||||
|
label={'Carrier ID'}
|
||||||
|
name="carrier_id"
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
{...register('route_number', {
|
||||||
|
required: 'This field is required',
|
||||||
|
setValueAs: (value) => String(value),
|
||||||
|
})}
|
||||||
|
error={!!(errors as any)?.route_number}
|
||||||
|
helperText={(errors as any)?.route_number?.message}
|
||||||
|
margin="normal"
|
||||||
|
fullWidth
|
||||||
|
InputLabelProps={{shrink: true}}
|
||||||
|
type="text"
|
||||||
|
label={'Route Number'}
|
||||||
|
name="route_number"
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="route_direction" // boolean
|
||||||
|
control={control}
|
||||||
|
defaultValue={false}
|
||||||
|
render={({field}: {field: any}) => <FormControlLabel control={<Checkbox {...field} checked={field.value} onChange={(e) => field.onChange(e.target.checked)} />} label="Route Direction" />}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Create>
|
||||||
|
)
|
||||||
|
}
|
54
src/pages/route/edit.tsx
Normal file
54
src/pages/route/edit.tsx
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import {Box, TextField, FormControlLabel, Checkbox} from '@mui/material'
|
||||||
|
import {Edit} from '@refinedev/mui'
|
||||||
|
import {useForm} from '@refinedev/react-hook-form'
|
||||||
|
import {Controller} from 'react-hook-form'
|
||||||
|
|
||||||
|
export const RouteEdit = () => {
|
||||||
|
const {
|
||||||
|
saveButtonProps,
|
||||||
|
register,
|
||||||
|
control,
|
||||||
|
formState: {errors},
|
||||||
|
} = useForm({})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Edit saveButtonProps={saveButtonProps}>
|
||||||
|
<Box component="form" sx={{display: 'flex', flexDirection: 'column'}} autoComplete="off">
|
||||||
|
<TextField
|
||||||
|
{...register('carrier_id', {
|
||||||
|
required: 'This field is required',
|
||||||
|
valueAsNumber: true,
|
||||||
|
})}
|
||||||
|
error={!!(errors as any)?.carrier_id}
|
||||||
|
helperText={(errors as any)?.carrier_id?.message}
|
||||||
|
margin="normal"
|
||||||
|
fullWidth
|
||||||
|
InputLabelProps={{shrink: true}}
|
||||||
|
type="number"
|
||||||
|
label={'Carrier ID'}
|
||||||
|
name="carrier_id"
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
{...register('route_number', {
|
||||||
|
required: 'This field is required',
|
||||||
|
setValueAs: (value) => String(value),
|
||||||
|
})}
|
||||||
|
error={!!(errors as any)?.route_number}
|
||||||
|
helperText={(errors as any)?.route_number?.message}
|
||||||
|
margin="normal"
|
||||||
|
fullWidth
|
||||||
|
InputLabelProps={{shrink: true}}
|
||||||
|
type="text"
|
||||||
|
label={'Route Number'}
|
||||||
|
name="route_number"
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="route_direction" // boolean
|
||||||
|
control={control}
|
||||||
|
defaultValue={false}
|
||||||
|
render={({field}: {field: any}) => <FormControlLabel control={<Checkbox {...field} checked={field.value} onChange={(e) => field.onChange(e.target.checked)} />} label="Route Direction" />}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Edit>
|
||||||
|
)
|
||||||
|
}
|
3
src/pages/route/index.ts
Normal file
3
src/pages/route/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export * from './create'
|
||||||
|
export * from './edit'
|
||||||
|
export * from './list'
|
74
src/pages/route/list.tsx
Normal file
74
src/pages/route/list.tsx
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import {DataGrid, type GridColDef} from '@mui/x-data-grid'
|
||||||
|
import {DeleteButton, EditButton, List, useDataGrid} from '@refinedev/mui'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export const RouteList = () => {
|
||||||
|
const {dataGridProps} = useDataGrid({
|
||||||
|
resource: 'route/',
|
||||||
|
})
|
||||||
|
|
||||||
|
const columns = React.useMemo<GridColDef[]>(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
headerName: 'ID',
|
||||||
|
type: 'number',
|
||||||
|
minWidth: 70,
|
||||||
|
display: 'flex',
|
||||||
|
align: 'left',
|
||||||
|
headerAlign: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'carrier_id',
|
||||||
|
headerName: 'Carrier ID',
|
||||||
|
type: 'number',
|
||||||
|
minWidth: 70,
|
||||||
|
display: 'flex',
|
||||||
|
align: 'left',
|
||||||
|
headerAlign: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'route_number',
|
||||||
|
headerName: 'Route Number',
|
||||||
|
type: 'string',
|
||||||
|
minWidth: 150,
|
||||||
|
display: 'flex',
|
||||||
|
align: 'left',
|
||||||
|
headerAlign: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'route_direction',
|
||||||
|
headerName: 'Route Direction',
|
||||||
|
type: 'boolean',
|
||||||
|
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