1- import { Box , MenuItem } from "@mui/material"
1+ import { Box , MenuItem } from "@mui/material" ;
22import { useCallback , useMemo , useState } from "react" ;
33
44import "./CommodityDetailsSection.scss" ;
@@ -8,7 +8,10 @@ import { PERMIT_TYPES, PermitType } from "../../../../../types/PermitType";
88import { Autocomplete } from "../../../../../../../common/components/form/subFormComponents/Autocomplete" ;
99import { Controller , useFormContext } from "react-hook-form" ;
1010import { Nullable } from "../../../../../../../common/types/common" ;
11- import { DEFAULT_COMMODITY_SELECT_OPTION , DEFAULT_COMMODITY_SELECT_VALUE } from "../../../../../constants/constants" ;
11+ import {
12+ DEFAULT_COMMODITY_SELECT_OPTION ,
13+ DEFAULT_COMMODITY_SELECT_VALUE ,
14+ } from "../../../../../constants/constants" ;
1215import { getDefaultRequiredVal } from "../../../../../../../common/helpers/util" ;
1316import { ApplicationFormData } from "../../../../../types/application" ;
1417import { ChangeCommodityTypeDialog } from "./ChangeCommodityTypeDialog" ;
@@ -29,7 +32,9 @@ export const CommodityDetailsSection = ({
2932 selectedCommodityType ?: Nullable < string > ;
3033 onChangeCommodityType : ( commodityType : string ) => void ;
3134} ) => {
32- const [ newCommodityType , setNewCommodityType ] = useState < string | undefined > ( ) ;
35+ const [ newCommodityType , setNewCommodityType ] = useState <
36+ string | undefined
37+ > ( ) ;
3338
3439 const selectedCommodityOption = useMemo ( ( ) => {
3540 return getDefaultRequiredVal (
@@ -50,16 +55,19 @@ export const CommodityDetailsSection = ({
5055 trigger ( "permitData.permittedCommodity.commodityType" ) ;
5156 } ;
5257
53- const handleCommodityTypeChange = useCallback ( ( updatedCommodityType : string ) => {
54- if ( selectedCommodityType === updatedCommodityType ) return ;
58+ const handleCommodityTypeChange = useCallback (
59+ ( updatedCommodityType : string ) => {
60+ if ( selectedCommodityType === updatedCommodityType ) return ;
5561
56- if ( selectedCommodityType !== DEFAULT_COMMODITY_SELECT_VALUE ) {
57- setNewCommodityType ( updatedCommodityType ) ;
58- return ;
59- }
62+ if ( selectedCommodityType !== DEFAULT_COMMODITY_SELECT_VALUE ) {
63+ setNewCommodityType ( updatedCommodityType ) ;
64+ return ;
65+ }
6066
61- handleConfirmChangeCommodityType ( updatedCommodityType ) ;
62- } , [ selectedCommodityType ] ) ;
67+ handleConfirmChangeCommodityType ( updatedCommodityType ) ;
68+ } ,
69+ [ selectedCommodityType ] ,
70+ ) ;
6371
6472 return permitType === PERMIT_TYPES . STOS ? (
6573 < Box className = "commodity-details-section" >
@@ -73,10 +81,11 @@ export const CommodityDetailsSection = ({
7381 rules = { {
7482 required : { value : true , message : requiredMessage ( ) } ,
7583 validate : {
76- mustSelect : ( value ) => value !== DEFAULT_COMMODITY_SELECT_VALUE || requiredMessage ( ) ,
84+ mustSelect : ( value ) =>
85+ value !== DEFAULT_COMMODITY_SELECT_VALUE || requiredMessage ( ) ,
7786 } ,
7887 } }
79- render = { ( { fieldState : { error} } ) => (
88+ render = { ( { fieldState : { error } } ) => (
8089 < Autocomplete
8190 label = { {
8291 id : "commodity-type-label" ,
@@ -100,11 +109,16 @@ export const CommodityDetailsSection = ({
100109 { option . label }
101110 </ MenuItem >
102111 ) ,
103- isOptionEqualToValue : ( option , value ) => option . value === value . value && option . label === value . label ,
112+ isOptionEqualToValue : ( option , value ) =>
113+ option . value === value . value && option . label === value . label ,
104114 } }
105- helperText = { error ?. message ? {
106- errors : [ error . message ] ,
107- } : undefined }
115+ helperText = {
116+ error ?. message
117+ ? {
118+ errors : [ error . message ] ,
119+ }
120+ : undefined
121+ }
108122 />
109123 ) }
110124 />
0 commit comments