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 , TextField } 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,20 +42,33 @@ 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"
4749 showCloseButton
50+ paperProps = { { width : '350px' } }
4851 >
49- < FormControl sx = { { marginRight : '10px' } } >
52+ < FormControl >
5053 < FormLabel > Project Name</ FormLabel >
5154 < ReactHookTextField name = "name" control = { control } sx = { { width : 1 } } />
5255 < FormHelperText error > { errors . name ?. message } </ FormHelperText >
5356 </ FormControl >
54- < FormControl >
55- < FormLabel > Car Number</ FormLabel >
56- < ReactHookTextField name = "carNumber" control = { control } sx = { { width : 1 } } />
57+ < FormControl fullWidth >
58+ < FormLabel > Car</ FormLabel >
59+ < Controller
60+ name = "carNumber"
61+ control = { control }
62+ render = { ( { field : { onChange, value } } ) => (
63+ < TextField select onChange = { onChange } value = { value } fullWidth >
64+ { cars ?. toReversed ( ) . map ( ( car ) => (
65+ < MenuItem key = { car . wbsElementId } value = { car . wbsNum . carNumber } >
66+ { car . name }
67+ </ MenuItem >
68+ ) ) }
69+ </ TextField >
70+ ) }
71+ />
5772 < FormHelperText error > { errors . carNumber ?. message } </ FormHelperText >
5873 </ FormControl >
5974 </ NERFormModal >
0 commit comments