1- import { TableRow , TableCell , Box } from '@mui/material' ;
1+ import { TableRow , TableCell , Box , IconButton } from '@mui/material' ;
2+ import EditIcon from '@mui/icons-material/Edit' ;
23import LoadingIndicator from '../../../components/LoadingIndicator' ;
34import { datePipe } from '../../../utils/pipes' ;
45import ErrorPage from '../../ErrorPage' ;
56import { NERButton } from '../../../components/NERButton' ;
67import NERTable from '../../../components/NERTable' ;
78import { useGetAllCars } from '../../../hooks/cars.hooks' ;
89import CreateCarModal from './CreateCarFormModal' ;
10+ import EditCarModal from './EditCarFormModal' ;
11+ import { Car } from 'shared' ;
912import { useState } from 'react' ;
1013
1114const CarsTable : React . FC = ( ) => {
1215 const { data : cars , isLoading : carsIsLoading , isError : carsIsError , error : carsError } = useGetAllCars ( ) ;
1316
14- const [ openModal , setOpenModal ] = useState ( false ) ;
17+ const [ openCreateModal , setOpenCreateModal ] = useState ( false ) ;
18+ const [ editingCar , setEditingCar ] = useState < Car | null > ( null ) ;
1519
1620 if ( ! cars || carsIsLoading ) {
1721 return < LoadingIndicator /> ;
@@ -27,15 +31,31 @@ const CarsTable: React.FC = () => {
2731 < TableCell sx = { { borderBottom : index === cars . length - 1 ? 'none' : 'default' } } >
2832 { datePipe ( car . dateCreated ) }
2933 </ TableCell >
34+ < TableCell sx = { { borderBottom : index === cars . length - 1 ? 'none' : 'default' } } >
35+ < IconButton onClick = { ( ) => setEditingCar ( car ) } size = "small" >
36+ < EditIcon fontSize = "small" />
37+ </ IconButton >
38+ </ TableCell >
3039 </ TableRow >
3140 ) ) ;
3241
3342 return (
3443 < Box >
35- < CreateCarModal showModal = { openModal } handleClose = { ( ) => setOpenModal ( false ) } />
36- < NERTable columns = { [ { name : 'Car Number' } , { name : 'Car Name' } , { name : 'Date Created' } ] } rows = { carsTableRows } />
44+ < CreateCarModal showModal = { openCreateModal } handleClose = { ( ) => setOpenCreateModal ( false ) } />
45+ { editingCar && (
46+ < EditCarModal
47+ showModal = { ! ! editingCar }
48+ handleClose = { ( ) => setEditingCar ( null ) }
49+ carId = { editingCar . id }
50+ carName = { editingCar . name }
51+ />
52+ ) }
53+ < NERTable
54+ columns = { [ { name : 'Car Number' } , { name : 'Car Name' } , { name : 'Date Created' } , { name : '' } ] }
55+ rows = { carsTableRows }
56+ />
3757 < Box sx = { { display : 'flex' , justifyContent : 'right' , marginTop : '10px' } } >
38- < NERButton variant = "contained" onClick = { ( ) => setOpenModal ( true ) } >
58+ < NERButton variant = "contained" onClick = { ( ) => setOpenCreateModal ( true ) } >
3959 New Car
4060 </ NERButton >
4161 </ Box >
0 commit comments