diff --git a/src/App.tsx b/src/App.tsx index 7ed1a53..bde900f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,6 +21,7 @@ import {authProvider} from './authProvider' import {CountryList, CountryCreate, CountryEdit} from './pages/country' import {CityList, CityCreate, CityEdit} from './pages/city' +import {CarrierList, CarrierCreate, CarrierEdit} from './pages/carrier' function App() { return ( @@ -76,6 +77,15 @@ function App() { canDelete: true, }, }, + { + name: 'carrier', + list: '/carrier', + create: '/carrier/create', + edit: '/carrier/edit/:id', + meta: { + canDelete: true, + }, + }, ]} options={{ syncWithLocation: true, @@ -120,6 +130,12 @@ function App() { } /> + + } /> + } /> + } /> + + } /> { + const { + saveButtonProps, + refineCore: {formLoading}, + register, + control, + formState: {errors}, + } = useForm({}) + + const {autocompleteProps: cityAutocompleteProps} = useAutocomplete({ + resource: 'city', + }) + + return ( + + + ( + 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) => } + /> + )} + /> + + + + + + + ) +} diff --git a/src/pages/carrier/edit.tsx b/src/pages/carrier/edit.tsx new file mode 100644 index 0000000..235ab5a --- /dev/null +++ b/src/pages/carrier/edit.tsx @@ -0,0 +1,59 @@ +import {Box, TextField} from '@mui/material' +import {Edit} from '@refinedev/mui' +import {useForm} from '@refinedev/react-hook-form' + +export const CarrierEdit = () => { + const { + saveButtonProps, + register, + formState: {errors}, + } = useForm() + + return ( + + + + + + + + + + ) +} diff --git a/src/pages/carrier/index.ts b/src/pages/carrier/index.ts new file mode 100644 index 0000000..fbafdcf --- /dev/null +++ b/src/pages/carrier/index.ts @@ -0,0 +1,3 @@ +export * from './create' +export * from './edit' +export * from './list' diff --git a/src/pages/carrier/list.tsx b/src/pages/carrier/list.tsx new file mode 100644 index 0000000..e5ba46a --- /dev/null +++ b/src/pages/carrier/list.tsx @@ -0,0 +1,65 @@ +import {DataGrid, type GridColDef} from '@mui/x-data-grid' +import {DeleteButton, EditButton, List, useDataGrid} from '@refinedev/mui' +import React from 'react' + +export const CarrierList = () => { + const {dataGridProps} = useDataGrid({}) + + const columns = React.useMemo( + () => [ + { + field: 'id', + headerName: 'ID', + type: 'number', + minWidth: 50, + align: 'left', + headerAlign: 'left', + }, + { + field: 'city_id', + headerName: 'City ID', + type: 'number', + minWidth: 100, + align: 'left', + headerAlign: 'left', + }, + { + field: 'full_name', + headerName: 'Full Name', + type: 'string', + minWidth: 200, + }, + { + field: 'short_name', + headerName: 'Short 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 ( + + + + ) +}