1
- import { Box , MenuItem } from "@mui/material"
1
+ import { Box , MenuItem } from "@mui/material" ;
2
2
import { useCallback , useMemo , useState } from "react" ;
3
3
4
4
import "./CommodityDetailsSection.scss" ;
@@ -8,7 +8,10 @@ import { PERMIT_TYPES, PermitType } from "../../../../../types/PermitType";
8
8
import { Autocomplete } from "../../../../../../../common/components/form/subFormComponents/Autocomplete" ;
9
9
import { Controller , useFormContext } from "react-hook-form" ;
10
10
import { 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" ;
12
15
import { getDefaultRequiredVal } from "../../../../../../../common/helpers/util" ;
13
16
import { ApplicationFormData } from "../../../../../types/application" ;
14
17
import { ChangeCommodityTypeDialog } from "./ChangeCommodityTypeDialog" ;
@@ -29,7 +32,9 @@ export const CommodityDetailsSection = ({
29
32
selectedCommodityType ?: Nullable < string > ;
30
33
onChangeCommodityType : ( commodityType : string ) => void ;
31
34
} ) => {
32
- const [ newCommodityType , setNewCommodityType ] = useState < string | undefined > ( ) ;
35
+ const [ newCommodityType , setNewCommodityType ] = useState <
36
+ string | undefined
37
+ > ( ) ;
33
38
34
39
const selectedCommodityOption = useMemo ( ( ) => {
35
40
return getDefaultRequiredVal (
@@ -50,16 +55,19 @@ export const CommodityDetailsSection = ({
50
55
trigger ( "permitData.permittedCommodity.commodityType" ) ;
51
56
} ;
52
57
53
- const handleCommodityTypeChange = useCallback ( ( updatedCommodityType : string ) => {
54
- if ( selectedCommodityType === updatedCommodityType ) return ;
58
+ const handleCommodityTypeChange = useCallback (
59
+ ( updatedCommodityType : string ) => {
60
+ if ( selectedCommodityType === updatedCommodityType ) return ;
55
61
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
+ }
60
66
61
- handleConfirmChangeCommodityType ( updatedCommodityType ) ;
62
- } , [ selectedCommodityType ] ) ;
67
+ handleConfirmChangeCommodityType ( updatedCommodityType ) ;
68
+ } ,
69
+ [ selectedCommodityType ] ,
70
+ ) ;
63
71
64
72
return permitType === PERMIT_TYPES . STOS ? (
65
73
< Box className = "commodity-details-section" >
@@ -73,10 +81,11 @@ export const CommodityDetailsSection = ({
73
81
rules = { {
74
82
required : { value : true , message : requiredMessage ( ) } ,
75
83
validate : {
76
- mustSelect : ( value ) => value !== DEFAULT_COMMODITY_SELECT_VALUE || requiredMessage ( ) ,
84
+ mustSelect : ( value ) =>
85
+ value !== DEFAULT_COMMODITY_SELECT_VALUE || requiredMessage ( ) ,
77
86
} ,
78
87
} }
79
- render = { ( { fieldState : { error} } ) => (
88
+ render = { ( { fieldState : { error } } ) => (
80
89
< Autocomplete
81
90
label = { {
82
91
id : "commodity-type-label" ,
@@ -100,11 +109,16 @@ export const CommodityDetailsSection = ({
100
109
{ option . label }
101
110
</ MenuItem >
102
111
) ,
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 ,
104
114
} }
105
- helperText = { error ?. message ? {
106
- errors : [ error . message ] ,
107
- } : undefined }
115
+ helperText = {
116
+ error ?. message
117
+ ? {
118
+ errors : [ error . message ] ,
119
+ }
120
+ : undefined
121
+ }
108
122
/>
109
123
) }
110
124
/>
0 commit comments