init /sight
route
This commit is contained in:
parent
b1c7fb5582
commit
7a6764cf32
24
src/App.tsx
24
src/App.tsx
@ -16,16 +16,14 @@ import {Register} from './pages/register'
|
||||
import {ForgotPassword} from './pages/forgotPassword'
|
||||
import {authProvider} from './authProvider'
|
||||
|
||||
// import {BlogPostList, BlogPostCreate, BlogPostEdit, BlogPostShow} from './pages/blog-posts'
|
||||
// import {CategoryList, CategoryCreate, CategoryEdit, CategoryShow} from './pages/categories'
|
||||
|
||||
import {CountryList, CountryCreate, CountryEdit} from './pages/country'
|
||||
import {CityList, CityCreate, CityEdit} from './pages/city'
|
||||
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 {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon} from './components/ui/Icons'
|
||||
import {CountryIcon, CityIcon, CarrierIcon, MediaIcon, ArticleIcon, SightIcon} from './components/ui/Icons'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@ -99,6 +97,18 @@ function App() {
|
||||
icon: <ArticleIcon />,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'sight',
|
||||
list: '/sight',
|
||||
create: '/sight/create',
|
||||
edit: '/sight/edit/:id',
|
||||
// добавить SHOW для sight->article (https://wn.krbl.ru/sight/2/article)
|
||||
meta: {
|
||||
canDelete: true,
|
||||
label: 'Вид',
|
||||
icon: <SightIcon />,
|
||||
},
|
||||
},
|
||||
]}
|
||||
options={{
|
||||
syncWithLocation: true,
|
||||
@ -150,6 +160,12 @@ function App() {
|
||||
<Route path="edit/:id" element={<ArticleEdit />} />
|
||||
</Route>
|
||||
|
||||
<Route path="/sight">
|
||||
<Route index element={<SightList />} />
|
||||
<Route path="create" element={<SightCreate />} />
|
||||
<Route path="edit/:id" element={<SightEdit />} />
|
||||
</Route>
|
||||
|
||||
<Route path="*" element={<ErrorComponent />} />
|
||||
</Route>
|
||||
<Route
|
||||
|
@ -3,5 +3,6 @@ import LocationCityIcon from '@mui/icons-material/LocationCity'
|
||||
import LocalShippingIcon from '@mui/icons-material/LocalShipping'
|
||||
import PermMediaIcon from '@mui/icons-material/PermMedia'
|
||||
import FeedIcon from '@mui/icons-material/Feed'
|
||||
import VisibilityIcon from '@mui/icons-material/Visibility'
|
||||
|
||||
export {PublicIcon as CountryIcon, LocationCityIcon as CityIcon, LocalShippingIcon as CarrierIcon, PermMediaIcon as MediaIcon, FeedIcon as ArticleIcon}
|
||||
export {PublicIcon as CountryIcon, LocationCityIcon as CityIcon, LocalShippingIcon as CarrierIcon, PermMediaIcon as MediaIcon, FeedIcon as ArticleIcon, VisibilityIcon as SightIcon}
|
||||
|
93
src/pages/sight/create.tsx
Normal file
93
src/pages/sight/create.tsx
Normal file
@ -0,0 +1,93 @@
|
||||
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 SightCreate = () => {
|
||||
const {
|
||||
saveButtonProps,
|
||||
refineCore: {formLoading},
|
||||
register,
|
||||
control,
|
||||
formState: {errors},
|
||||
} = useForm({
|
||||
refineCoreProps: {
|
||||
resource: 'sight/',
|
||||
},
|
||||
})
|
||||
|
||||
const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({
|
||||
resource: 'city',
|
||||
})
|
||||
|
||||
return (
|
||||
<Create isLoading={formLoading} saveButtonProps={saveButtonProps}>
|
||||
<Box component="form" sx={{display: 'flex', flexDirection: 'column'}} autoComplete="off">
|
||||
<TextField
|
||||
{...register('name', {
|
||||
required: 'This field is required',
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="text"
|
||||
label={'Name'}
|
||||
name="name"
|
||||
/>
|
||||
<TextField
|
||||
{...register('latitude', {
|
||||
required: 'This field is required',
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="number"
|
||||
label={'Latitude'}
|
||||
name="latitude"
|
||||
/>
|
||||
<TextField
|
||||
{...register('longitude', {
|
||||
required: 'This field is required',
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="number"
|
||||
label={'Longitude'}
|
||||
name="longitude"
|
||||
/>
|
||||
|
||||
<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>
|
||||
)
|
||||
}
|
87
src/pages/sight/edit.tsx
Normal file
87
src/pages/sight/edit.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
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 SightEdit = () => {
|
||||
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('name', {
|
||||
required: 'This field is required',
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="text"
|
||||
label={'Name'}
|
||||
name="name"
|
||||
/>
|
||||
<TextField
|
||||
{...register('latitude', {
|
||||
required: 'This field is required',
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="number"
|
||||
label={'Latitude'}
|
||||
name="latitude"
|
||||
/>
|
||||
<TextField
|
||||
{...register('longitude', {
|
||||
required: 'This field is required',
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
error={!!(errors as any)?.title}
|
||||
helperText={(errors as any)?.title?.message}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
InputLabelProps={{shrink: true}}
|
||||
type="number"
|
||||
label={'Longitude'}
|
||||
name="longitude"
|
||||
/>
|
||||
<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>
|
||||
</Edit>
|
||||
)
|
||||
}
|
3
src/pages/sight/index.ts
Normal file
3
src/pages/sight/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './create'
|
||||
export * from './edit'
|
||||
export * from './list'
|
84
src/pages/sight/list.tsx
Normal file
84
src/pages/sight/list.tsx
Normal file
@ -0,0 +1,84 @@
|
||||
import {DataGrid, type GridColDef} from '@mui/x-data-grid'
|
||||
import {DeleteButton, EditButton, List, useDataGrid} from '@refinedev/mui'
|
||||
import React from 'react'
|
||||
|
||||
export const SightList = () => {
|
||||
const {dataGridProps} = useDataGrid({
|
||||
resource: 'sight/',
|
||||
})
|
||||
|
||||
const columns = React.useMemo<GridColDef[]>(
|
||||
() => [
|
||||
{
|
||||
field: 'id',
|
||||
headerName: 'ID',
|
||||
type: 'number',
|
||||
minWidth: 70,
|
||||
display: 'flex',
|
||||
align: 'left',
|
||||
headerAlign: 'left',
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
headerName: 'Name',
|
||||
type: 'string',
|
||||
minWidth: 200,
|
||||
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: '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