1- import React , { useState } from 'react' ;
2- import { Grid } from '@mui/material' ;
1+ import React , { useRef , useState } from 'react' ;
2+ import { Box , Grid } from '@mui/material' ;
33import { Car , ProjectPreview , wbsPipe } from 'shared' ;
44import NERModal from '../../../../../components/NERModal' ;
55import NERAutocomplete from '../../../../../components/NERAutocomplete' ;
@@ -10,8 +10,6 @@ interface CopyBOMViewProps {
1010 onHide : ( ) => void ;
1111 cars : Car [ ] ;
1212 projects : ProjectPreview [ ] ;
13- selectedProject : ProjectPreview | null ;
14- setSelectedProject : ( project : ProjectPreview | null ) => void ;
1513 onCopy : ( materialIds : string [ ] ) => Promise < void > ;
1614}
1715
@@ -20,12 +18,12 @@ const CopyBOMView: React.FC<CopyBOMViewProps> = ({
2018 onHide,
2119 cars,
2220 projects,
23- selectedProject,
24- setSelectedProject,
2521 onCopy
2622} ) => {
2723 const [ selectedCar , setSelectedCar ] = useState < Car | null > ( null ) ;
28- const [ selectedMaterialIds , setSelectedMaterialIds ] = useState < string [ ] > ( [ ] ) ;
24+ const [ selectedProject , setSelectedProject ] = useState < ProjectPreview | null > ( null ) ;
25+ const [ hasSelection , setHasSelection ] = useState ( false ) ;
26+ const selectedMaterialIdsRef = useRef < string [ ] > ( [ ] ) ;
2927
3028 const carOptions = cars . map ( ( car ) => ( {
3129 label : `${ car . wbsNum . carNumber } - ${ car . name } ` ,
@@ -42,7 +40,7 @@ const CopyBOMView: React.FC<CopyBOMViewProps> = ({
4240 } ) ) ;
4341
4442 const handleSubmit = async ( ) => {
45- await onCopy ( selectedMaterialIds ) ;
43+ await onCopy ( selectedMaterialIdsRef . current ) ;
4644 } ;
4745
4846 return (
@@ -53,7 +51,7 @@ const CopyBOMView: React.FC<CopyBOMViewProps> = ({
5351 submitText = "Copy BOM"
5452 cancelText = "Cancel"
5553 onSubmit = { handleSubmit }
56- disabled = { selectedMaterialIds . length === 0 }
54+ disabled = { ! hasSelection }
5755 showCloseButton
5856 paperProps = { { minWidth : '700px' } }
5957 >
@@ -96,11 +94,32 @@ const CopyBOMView: React.FC<CopyBOMViewProps> = ({
9694 />
9795 </ Grid >
9896
99- { selectedProject && (
100- < Grid item xs = { 12 } >
101- < CopyBOMProjectSection selectedProject = { selectedProject } onSelectionChange = { setSelectedMaterialIds } />
102- </ Grid >
103- ) }
97+ < Grid item xs = { 12 } >
98+ { selectedProject ? (
99+ < CopyBOMProjectSection
100+ selectedProject = { selectedProject }
101+ onSelectionChange = { ( ids ) => {
102+ selectedMaterialIdsRef . current = ids ;
103+ setHasSelection ( ids . length > 0 ) ;
104+ } }
105+ />
106+ ) : (
107+ < Box
108+ sx = { {
109+ height : '300px' ,
110+ border : '1px dashed' ,
111+ borderColor : 'grey.400' ,
112+ borderRadius : '4px' ,
113+ display : 'flex' ,
114+ alignItems : 'center' ,
115+ justifyContent : 'center' ,
116+ color : 'grey.500'
117+ } }
118+ >
119+ Select a project to view its materials
120+ </ Box >
121+ ) }
122+ </ Grid >
104123 </ Grid >
105124 </ NERModal >
106125 ) ;
0 commit comments