@@ -24,6 +24,7 @@ import { getDefaultRequiredVal } from "../../../helpers/util";
24
24
import { IDIR_ROUTES } from "../../../../routes/constants" ;
25
25
import { Nullable } from "../../../types/common" ;
26
26
import {
27
+ SEARCH_BY_FILTERS ,
27
28
SearchByFilter ,
28
29
SearchEntity ,
29
30
SearchFields ,
@@ -34,6 +35,7 @@ import OnRouteBCContext from "../../../authentication/OnRouteBCContext";
34
35
const SEARCH_BY_PERMIT_OPTIONS = [
35
36
{ label : "Permit Number" , value : "permitNumber" } ,
36
37
{ label : "Plate Number" , value : "plate" } ,
38
+ { label : "VIN (last 6 digits)" , value : "vin" } ,
37
39
] ;
38
40
39
41
const SEARCH_BY_COMPANY_OPTIONS = [
@@ -118,7 +120,9 @@ export const SearchFilter = ({
118
120
reValidateMode : "onBlur" ,
119
121
} ) ;
120
122
121
- const { handleSubmit, setValue, control } = formMethods ;
123
+ const { handleSubmit, setValue, control, watch } = formMethods ;
124
+
125
+ const searchByFilter = watch ( "searchByFilter" ) ;
122
126
123
127
const handleSearchEntityChange = ( searchEntity : string ) => {
124
128
setValue ( "searchEntity" , searchEntity as SearchEntity ) ;
@@ -128,11 +132,13 @@ export const SearchFilter = ({
128
132
"searchByFilter" ,
129
133
updatedSearchByOptions [ 0 ] . value as SearchByFilter ,
130
134
) ;
135
+ setValue ( "searchString" , "" ) ;
131
136
} ;
132
137
133
138
const handleSearchByChange = ( event : SelectChangeEvent ) => {
134
139
const searchBy = event . target . value ;
135
140
setValue ( "searchByFilter" , searchBy as SearchByFilter ) ;
141
+ setValue ( "searchString" , "" ) ;
136
142
} ;
137
143
138
144
const handleSearchValueChange = (
@@ -142,6 +148,12 @@ export const SearchFilter = ({
142
148
setValue ( "searchString" , searchString ) ;
143
149
} ;
144
150
151
+ const handleSearchValueKeyDown = ( event : React . KeyboardEvent ) => {
152
+ if ( event . key === "Enter" ) {
153
+ handleSubmit ( onSubmit ) ( ) ;
154
+ }
155
+ } ;
156
+
145
157
const onSubmit = ( data : FieldValues ) => {
146
158
const searchFields = Object . entries ( data )
147
159
. map ( ( [ key , value ] ) => `${ key } =${ value } ` )
@@ -231,7 +243,11 @@ export const SearchFilter = ({
231
243
className = "search-by__value"
232
244
value = { value }
233
245
onChange = { handleSearchValueChange }
234
- inputProps = { { maxLength : 100 } }
246
+ onKeyDown = { handleSearchValueKeyDown }
247
+ inputProps = { {
248
+ maxLength :
249
+ searchByFilter === SEARCH_BY_FILTERS . VIN ? 6 : 100 ,
250
+ } }
235
251
/>
236
252
) }
237
253
/>
0 commit comments