22 Accordion ,
33 AccordionDetails ,
44 AccordionSummary ,
5+ Button ,
56 FormControl ,
67 FormHelperText ,
78 FormLabel ,
@@ -14,7 +15,7 @@ import {
1415} from '@mui/material' ;
1516import { Box } from '@mui/system' ;
1617import { Control , Controller , FieldErrors , UseFormHandleSubmit , UseFormSetValue , UseFormWatch } from 'react-hook-form' ;
17- import { Assembly , Manufacturer , MaterialType , Unit } from 'shared' ;
18+ import { Assembly , Manufacturer , Material , MaterialType , Unit } from 'shared' ;
1819import ReactHookTextField from '../../../../../components/ReactHookTextField' ;
1920import { MaterialFormInput } from './MaterialForm' ;
2021import NERFormModal from '../../../../../components/NERFormModal' ;
@@ -26,6 +27,7 @@ import { displayEnum } from '../../../../../utils/pipes';
2627import { MaterialStatus } from 'shared' ;
2728import React , { useState } from 'react' ;
2829import { AddCircle } from '@mui/icons-material' ;
30+ import SelectMaterialToCopyModal from './SelectMaterialToCopyModal' ;
2931
3032export interface MaterialFormViewProps {
3133 submitText : 'Add' | 'Edit' ;
@@ -42,7 +44,6 @@ export interface MaterialFormViewProps {
4244 watch : UseFormWatch < MaterialFormInput > ;
4345 createManufacturer : ( name : string ) => void ;
4446 setValue : UseFormSetValue < MaterialFormInput > ;
45- copyFromExistingBomAction ?: React . ReactNode ;
4647 fromRRForm ?: boolean ;
4748}
4849
@@ -77,6 +78,23 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
7778 const price = watch ( 'price' ) ;
7879 const subtotal = quantity && price ? quantity * price : 0 ;
7980
81+ const [ copyModalOpen , setCopyModalOpen ] = React . useState ( false ) ;
82+
83+ const handleCopySelect = ( m : Material ) => {
84+ setValue ( 'name' , m . name ?? '' ) ;
85+ setValue ( 'materialTypeName' , m . materialTypeName ?? '' ) ;
86+ setValue ( 'manufacturerName' , m . manufacturerName ?? '' ) ;
87+ setValue ( 'manufacturerPartNumber' , m . manufacturerPartNumber ?? '' ) ;
88+ setValue ( 'pdmFileName' , m . pdmFileName ?? '' ) ;
89+ setValue ( 'linkUrl' , m . linkUrl ?? '' ) ;
90+ setValue ( 'quantity' , m . quantity != null ? Number ( m . quantity ) : undefined ) ;
91+ setValue ( 'unitName' , m . unitName ?? undefined ) ;
92+ setValue ( 'price' , m . price != null ? m . price / 100 : undefined ) ;
93+ setValue ( 'notes' , m . notes ?? '' ) ;
94+ setValue ( 'assemblyId' , undefined ) ;
95+
96+ setCopyModalOpen ( false ) ;
97+ } ;
8098 const optionalFields = (
8199 < Grid container spacing = { 2 } >
82100 < Grid item xs = { 12 } >
@@ -504,7 +522,7 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
504522 ) }
505523 </ Grid >
506524 </ Grid >
507- { /* submitText === 'Add' && (
525+ { submitText === 'Add' && (
508526 < Grid item xs = { 12 } sx = { { pl : 0 , pr : 0 } } >
509527 < Box
510528 sx = { {
@@ -514,7 +532,7 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
514532 < Button
515533 variant = "contained"
516534 disableElevation
517- onClick={() => {} }
535+ onClick = { ( ) => setCopyModalOpen ( true ) }
518536 sx = { {
519537 mx : 0 ,
520538 textTransform : 'none' ,
@@ -527,7 +545,13 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
527545 </ Button >
528546 </ Box >
529547 </ Grid >
530- )*/ }
548+ ) }
549+ < SelectMaterialToCopyModal
550+ open = { copyModalOpen }
551+ onHide = { ( ) => setCopyModalOpen ( false ) }
552+ onSelect = { handleCopySelect }
553+ assemblies = { assemblies ?? [ ] }
554+ />
531555 </ NERFormModal >
532556 ) ;
533557} ;
0 commit comments