update create
& edit
for /vehicle
route
This commit is contained in:
parent
a989b80642
commit
3a912e5494
@ -4,3 +4,8 @@ export const MEDIA_TYPES = [
|
||||
{label: 'Фото', value: 1},
|
||||
{label: 'Видео', value: 2},
|
||||
]
|
||||
|
||||
export const VEHICLE_TYPES = [
|
||||
{label: 'Трамвай', value: 1},
|
||||
{label: 'Троллейбус', value: 2},
|
||||
]
|
||||
|
@ -1,8 +1,10 @@
|
||||
import {Autocomplete, Box, TextField} from '@mui/material'
|
||||
import {Autocomplete, Box, TextField, FormControl, InputLabel, Select, MenuItem, Typography} from '@mui/material'
|
||||
import {Create, useAutocomplete} from '@refinedev/mui'
|
||||
import {useForm} from '@refinedev/react-hook-form'
|
||||
import {Controller} from 'react-hook-form'
|
||||
|
||||
import {VEHICLE_TYPES} from '../../lib/constants'
|
||||
|
||||
export const VehicleCreate = () => {
|
||||
const {
|
||||
saveButtonProps,
|
||||
@ -30,23 +32,33 @@ export const VehicleCreate = () => {
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="number"
|
||||
label={'Номер рейса'}
|
||||
label="Номер рейса"
|
||||
name="tail_number"
|
||||
/>
|
||||
<TextField
|
||||
{...register('type', {
|
||||
required: 'Это поле является обязательным',
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
error={!!(errors as any)?.type}
|
||||
helperText={(errors as any)?.type?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="number"
|
||||
label={'Тип'}
|
||||
name="type"
|
||||
/>
|
||||
|
||||
<FormControl fullWidth margin="normal" error={!!errors.type}>
|
||||
<InputLabel id="vehicle-type-label">Выберите тип</InputLabel>
|
||||
<Select
|
||||
labelId="vehicle-type-label"
|
||||
label="Выберите тип"
|
||||
{...register('type', {
|
||||
required: 'Это поле является обязательным',
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
defaultValue=""
|
||||
>
|
||||
{VEHICLE_TYPES.map((option) => (
|
||||
<MenuItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
{errors.type && (
|
||||
<Typography variant="caption" color="error">
|
||||
{!!(errors as any)?.message}
|
||||
</Typography>
|
||||
)}
|
||||
</FormControl>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
|
@ -1,8 +1,10 @@
|
||||
import {Autocomplete, Box, TextField} from '@mui/material'
|
||||
import {Autocomplete, Box, TextField, FormControl, InputLabel, Select, MenuItem, Typography} from '@mui/material'
|
||||
import {Edit, useAutocomplete} from '@refinedev/mui'
|
||||
import {useForm} from '@refinedev/react-hook-form'
|
||||
import {Controller} from 'react-hook-form'
|
||||
|
||||
import {VEHICLE_TYPES} from '../../lib/constants'
|
||||
|
||||
export const VehicleEdit = () => {
|
||||
const {
|
||||
saveButtonProps,
|
||||
@ -29,28 +31,39 @@ export const VehicleEdit = () => {
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="number"
|
||||
label={'Номер рейса'}
|
||||
label="Номер рейса"
|
||||
name="tail_number"
|
||||
/>
|
||||
<TextField
|
||||
{...register('type', {
|
||||
required: 'Это поле является обязательным',
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
error={!!(errors as any)?.type}
|
||||
helperText={(errors as any)?.type?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="number"
|
||||
label={'Тип'}
|
||||
name="type"
|
||||
/>
|
||||
|
||||
<FormControl fullWidth margin="normal" error={!!errors.type}>
|
||||
<InputLabel id="vehicle-type-label">Выберите тип</InputLabel>
|
||||
<Select
|
||||
labelId="vehicle-type-label"
|
||||
label="Выберите тип"
|
||||
{...register('type', {
|
||||
required: 'Это поле является обязательным',
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
defaultValue=""
|
||||
>
|
||||
{VEHICLE_TYPES.map((option) => (
|
||||
<MenuItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
{errors.type && (
|
||||
<Typography variant="caption" color="error">
|
||||
{!!(errors as any)?.message}
|
||||
</Typography>
|
||||
)}
|
||||
</FormControl>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="city_id"
|
||||
rules={{required: 'Это поле является обязательным'}}
|
||||
defaultValue={null}
|
||||
render={({field}) => (
|
||||
<Autocomplete
|
||||
{...cityAutocompleteProps}
|
||||
|
Loading…
Reference in New Issue
Block a user