diff --git a/src/App.tsx b/src/App.tsx index 60d99a0..7ed1a53 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,7 +2,7 @@ import {Refine, Authenticated} from '@refinedev/core' import {DevtoolsPanel, DevtoolsProvider} from '@refinedev/devtools' import {RefineKbar, RefineKbarProvider} from '@refinedev/kbar' -import {AuthPage, ErrorComponent, useNotificationProvider, RefineSnackbarProvider, ThemedLayoutV2} from '@refinedev/mui' +import {ErrorComponent, useNotificationProvider, RefineSnackbarProvider, ThemedLayoutV2} from '@refinedev/mui' import dataProvider from '@refinedev/simple-rest' import CssBaseline from '@mui/material/CssBaseline' @@ -20,6 +20,7 @@ import {authProvider} from './authProvider' // import {CategoryList, CategoryCreate, CategoryEdit, CategoryShow} from './pages/categories' import {CountryList, CountryCreate, CountryEdit} from './pages/country' +import {CityList, CityCreate, CityEdit} from './pages/city' function App() { return ( @@ -66,6 +67,15 @@ function App() { canDelete: true, }, }, + { + name: 'city', + list: '/city', + create: '/city/create', + edit: '/city/edit/:id', + meta: { + canDelete: true, + }, + }, ]} options={{ syncWithLocation: true, @@ -104,6 +114,12 @@ function App() { } /> + + } /> + } /> + } /> + + } /> { + const { + saveButtonProps, + refineCore: {formLoading}, + register, + control, + formState: {errors}, + } = useForm({}) + + const {autocompleteProps: countryAutocompleteProps} = useAutocomplete({ + resource: 'country', + }) + + return ( + + + ( + { + field.onChange(value?.code || '') + }} + getOptionLabel={(item) => { + return item?.code || '' + }} + isOptionEqualToValue={(option, value) => { + return option.code === value?.code + }} + renderInput={(params) => } + /> + )} + /> + + + + ) +} diff --git a/src/pages/city/edit.tsx b/src/pages/city/edit.tsx new file mode 100644 index 0000000..181ebdc --- /dev/null +++ b/src/pages/city/edit.tsx @@ -0,0 +1,45 @@ +import {Box, TextField} from '@mui/material' +import {Edit} from '@refinedev/mui' +import {useForm} from '@refinedev/react-hook-form' + +export const CityEdit = () => { + const { + saveButtonProps, + register, + formState: {errors}, + } = useForm({}) + + return ( + + + + + + + + ) +} diff --git a/src/pages/city/index.ts b/src/pages/city/index.ts new file mode 100644 index 0000000..fbafdcf --- /dev/null +++ b/src/pages/city/index.ts @@ -0,0 +1,3 @@ +export * from './create' +export * from './edit' +export * from './list' diff --git a/src/pages/city/list.tsx b/src/pages/city/list.tsx new file mode 100644 index 0000000..9a996a6 --- /dev/null +++ b/src/pages/city/list.tsx @@ -0,0 +1,59 @@ +import {DataGrid, type GridColDef} from '@mui/x-data-grid' +import {DeleteButton, EditButton, List, useDataGrid} from '@refinedev/mui' +import React from 'react' + +export const CityList = () => { + const {dataGridProps} = useDataGrid({}) + + const columns = React.useMemo( + () => [ + { + field: 'id', + headerName: 'ID', + type: 'number', + minWidth: 50, + align: 'left', + headerAlign: 'left', + }, + { + field: 'country_code', + headerName: 'Country Code', + type: 'string', + minWidth: 150, + align: 'left', + headerAlign: 'left', + }, + { + field: 'name', + headerName: 'City Name', + type: 'string', + minWidth: 150, + flex: 1, + }, + { + field: 'actions', + headerName: 'Actions', + align: 'right', + headerAlign: 'center', + minWidth: 120, + sortable: false, + display: 'flex', + renderCell: function render({row}) { + return ( + <> + + + + ) + }, + }, + ], + [], + ) + + return ( + + + + ) +}