@@ -21,7 +21,10 @@ const schema = yup.object().shape({
2121 manufacturerName : yup . string ( ) . optional ( ) ,
2222 manufacturerPartNumber : yup . string ( ) . optional ( ) ,
2323 quantity : yup . number ( ) . optional ( ) ,
24- price : yup . number ( ) . optional ( ) ,
24+ price : yup
25+ . number ( )
26+ . transform ( ( value , originalValue ) => ( originalValue === '' ? undefined : value ) )
27+ . optional ( ) ,
2528 unitName : yup . string ( ) . optional ( ) ,
2629 linkUrl : yup . string ( ) . optional ( ) ,
2730 notes : yup . string ( ) . optional ( ) ,
@@ -97,7 +100,7 @@ const MaterialForm: React.FC<MaterialFormProps> = ({
97100 quantity : defaultValues ?. quantity ?? 1 ,
98101 manufacturerName : defaultValues ?. manufacturerName ?? '' ,
99102 pdmFileName : defaultValues ?. pdmFileName ,
100- price : defaultValues ?. price ?? 0 ,
103+ price : defaultValues ?. price ,
101104 unitName : defaultValues ?. unitName ,
102105 linkUrl : defaultValues ?. linkUrl ?? '' ,
103106 notes : defaultValues ?. notes ,
@@ -124,12 +127,8 @@ const MaterialForm: React.FC<MaterialFormProps> = ({
124127 }
125128
126129 const onSubmitWrapper = ( data : MaterialFormInput ) : void => {
127- const price = data . price ? Math . round ( data . price * 100 ) : undefined ;
128- const subtotal = price
129- ? data . quantity != null
130- ? parseFloat ( ( data . quantity * price ) . toFixed ( 2 ) )
131- : undefined
132- : undefined ;
130+ const price = data . price != null ? Math . round ( data . price * 100 ) : undefined ;
131+ const subtotal = price != null && data . quantity != null ? parseFloat ( ( data . quantity * price ) . toFixed ( 2 ) ) : undefined ;
133132 onSubmit ( { ...data , subtotal, price, quantity : data . quantity != null ? new Decimal ( data . quantity ) : undefined } ) ;
134133 } ;
135134
0 commit comments