11import { yupResolver } from '@hookform/resolvers/yup' ;
2- import { FormControl , FormHelperText , FormLabel } from '@mui/material' ;
3- import { useForm } from 'react-hook-form' ;
2+ import { FormControl , FormHelperText , FormLabel , MenuItem , Select } from '@mui/material' ;
3+ import { Controller , useForm } from 'react-hook-form' ;
4+ import { Car } from 'shared' ;
45import * as yup from 'yup' ;
56import NERFormModal from '../../../components/NERFormModal' ;
67import ReactHookTextField from '../../../components/ReactHookTextField' ;
@@ -14,9 +15,10 @@ interface AddGanttProjectModalProps {
1415 showModal : boolean ;
1516 handleClose : ( ) => void ;
1617 addProject : ( project : { name : string ; carNumber : number } ) => void ;
18+ cars : Car [ ] ;
1719}
1820
19- const AddGanttProjectModal : React . FC < AddGanttProjectModalProps > = ( { showModal, handleClose, addProject } ) => {
21+ const AddGanttProjectModal : React . FC < AddGanttProjectModalProps > = ( { showModal, handleClose, addProject, cars } ) => {
2022 const onSubmit = async ( data : { name : string ; carNumber : number } ) => {
2123 addProject ( data ) ;
2224 handleClose ( ) ;
@@ -40,7 +42,7 @@ const AddGanttProjectModal: React.FC<AddGanttProjectModalProps> = ({ showModal,
4042 open = { showModal }
4143 onHide = { handleClose }
4244 title = "New Project"
43- reset = { ( ) => reset ( { name : '' } ) }
45+ reset = { ( ) => reset ( { name : '' , carNumber : 0 } ) }
4446 handleUseFormSubmit = { handleSubmit }
4547 onFormSubmit = { onSubmit }
4648 formId = "new-project-form"
@@ -51,9 +53,22 @@ const AddGanttProjectModal: React.FC<AddGanttProjectModalProps> = ({ showModal,
5153 < ReactHookTextField name = "name" control = { control } sx = { { width : 1 } } />
5254 < FormHelperText error > { errors . name ?. message } </ FormHelperText >
5355 </ FormControl >
54- < FormControl >
55- < FormLabel > Car Number</ FormLabel >
56- < ReactHookTextField name = "carNumber" control = { control } sx = { { width : 1 } } />
56+ < FormControl fullWidth >
57+ < FormLabel > Car</ FormLabel >
58+ < Controller
59+ name = "carNumber"
60+ control = { control }
61+ render = { ( { field : { onChange, value } } ) => (
62+ < Select error = { ! ! errors . carNumber } value = { value } onChange = { onChange } >
63+ { cars &&
64+ cars . toReversed ( ) . map ( ( car ) => (
65+ < MenuItem key = { car . wbsElementId } value = { car . wbsNum . carNumber } >
66+ { car . name }
67+ </ MenuItem >
68+ ) ) }
69+ </ Select >
70+ ) }
71+ />
5772 < FormHelperText error > { errors . carNumber ?. message } </ FormHelperText >
5873 </ FormControl >
5974 </ NERFormModal >
0 commit comments