Skip to content

Commit d77f9e7

Browse files
authored
Merge pull request #878 from bcgov/feature-solr-merged
Release: Solr changes to Main for Test Deployment
2 parents a055a1b + ecf7273 commit d77f9e7

1 file changed

Lines changed: 107 additions & 8 deletions

File tree

app/src/components/new-request/business-lookup.vue

Lines changed: 107 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
id="business-lookup"
66
>
77
<v-autocomplete
8-
v-model:search-input="searchField"
8+
:search-input.sync="searchField"
99
filled
1010
no-filter
1111
:hide-no-data="state != States.NO_RESULTS"
1212
:items="searchResults"
1313
:loading="state === States.SEARCHING"
1414
:name="Math.random()"
15-
append-icon="mdi-magnify"
15+
:error-messages="errorMessages"
1616
autocomplete="chrome-off"
1717
autofocus
1818
hint="Search by name, incorporation or registration number of an existing business"
@@ -32,6 +32,13 @@
3232
:size="24"
3333
:width="2"
3434
/>
35+
<div
36+
v-else
37+
class="magnify-icon-wrapper"
38+
@click="onMagnifyClick"
39+
>
40+
<v-icon>mdi-magnify</v-icon>
41+
</div>
3542
</template>
3643

3744
<template #no-data>
@@ -88,6 +95,11 @@ export default class BusinessLookup extends Vue {
8895
// enum for template
8996
readonly States = States
9097
98+
mounted (): void {
99+
console.log('✨ BusinessLookup component mounted')
100+
console.log('🔎 Initial state:', { state: this.state, searchField: this.searchField })
101+
}
102+
91103
/** V-model for search field. */
92104
searchField = ''
93105
@@ -101,6 +113,9 @@ export default class BusinessLookup extends Vue {
101113
lookupLabel = ''
102114
lookupNoActiveText = ''
103115
116+
/** Error messages for validation. */
117+
errorMessages = [] as Array<string>
118+
104119
/** Called when searchField property has changed. */
105120
@Watch('searchField')
106121
onSearchFieldChanged (): void {
@@ -123,15 +138,38 @@ export default class BusinessLookup extends Vue {
123138
}
124139
125140
private onSearchInputDebounced = debounce(async (that: this) => {
126-
// safety check
127-
if (that.searchField && that.searchField.length > 2) {
128-
that.state = States.SEARCHING
129-
that.searchResults = await BusinessLookupServices.search(that.searchField, that.searchStatus).catch(() => [])
141+
// Support two search modes:
142+
// 1. Business number (BC1234567 format) - full format required
143+
// 2. Company name - minimum 3 characters
144+
const validBusinessNumberPattern = /^[A-Za-z]{1,3}\d{7}$/
145+
const trimmedInput = that.searchField?.trim() || ''
146+
const minNameSearchLength = 3
130147
131-
// display appropriate section
148+
if (!trimmedInput) {
149+
// Empty - reset
150+
that.errorMessages = []
151+
that.searchResults = []
152+
that.state = States.INITIAL
153+
} else if (validBusinessNumberPattern.test(trimmedInput)) {
154+
// Mode 1: Valid business number format - search
155+
console.log('✅ Searching by business number...')
156+
that.errorMessages = []
157+
that.state = States.SEARCHING
158+
const upperInput = trimmedInput.toUpperCase()
159+
that.searchResults = await BusinessLookupServices.search(upperInput, that.searchStatus).catch(() => [])
160+
that.state = (that.searchResults.length > 0) ? States.SHOW_RESULTS : States.NO_RESULTS
161+
} else if (trimmedInput.length >= minNameSearchLength) {
162+
// Mode 2: Company name search (minimum 3 characters)
163+
console.log('✅ Searching by company name...')
164+
that.errorMessages = []
165+
that.state = States.SEARCHING
166+
const upperInput = trimmedInput.toUpperCase()
167+
that.searchResults = await BusinessLookupServices.search(upperInput, that.searchStatus).catch(() => [])
132168
that.state = (that.searchResults.length > 0) ? States.SHOW_RESULTS : States.NO_RESULTS
133169
} else {
134-
// reset variables
170+
// Invalid - too short for name search, not valid business number
171+
console.log('⚠️ Invalid format for incorporation or registration number')
172+
that.errorMessages = ['Invalid format for incorporation or registration number']
135173
that.searchResults = []
136174
that.state = States.INITIAL
137175
}
@@ -152,6 +190,54 @@ export default class BusinessLookup extends Vue {
152190
state: input.status
153191
}
154192
}
193+
194+
/** Handle magnifying glass click - search by business number or company name. */
195+
async onMagnifyClick (): Promise<void> {
196+
// Support two search modes:
197+
// 1. Business number (BC1234567 format) - full format required
198+
// 2. Company name - minimum 3 characters
199+
const validBusinessNumberPattern = /^[A-Za-z]{1,3}\d{7}$/
200+
const trimmedInput = this.searchField?.trim() || ''
201+
const minNameSearchLength = 3
202+
203+
console.log('🔍 Magnify click fired!', { searchField: trimmedInput })
204+
205+
if (!trimmedInput) {
206+
console.log('⚠️ Empty search field')
207+
this.errorMessages = ['Enter a search term']
208+
this.searchResults = []
209+
this.state = States.INITIAL
210+
} else if (validBusinessNumberPattern.test(trimmedInput)) {
211+
// Mode 1: Business number search
212+
console.log('✅ Searching by business number...')
213+
this.errorMessages = []
214+
this.state = States.SEARCHING
215+
const upperInput = trimmedInput.toUpperCase()
216+
this.searchResults = await BusinessLookupServices.search(upperInput, this.searchStatus).catch((err) => {
217+
console.error('❌ Search error:', err)
218+
return []
219+
})
220+
console.log('📊 Results:', this.searchResults.length)
221+
this.state = (this.searchResults.length > 0) ? States.SHOW_RESULTS : States.NO_RESULTS
222+
} else if (trimmedInput.length >= minNameSearchLength) {
223+
// Mode 2: Company name search
224+
console.log('✅ Searching by company name...')
225+
this.errorMessages = []
226+
this.state = States.SEARCHING
227+
const upperInput = trimmedInput.toUpperCase()
228+
this.searchResults = await BusinessLookupServices.search(upperInput, this.searchStatus).catch((err) => {
229+
console.error('❌ Search error:', err)
230+
return []
231+
})
232+
console.log('📊 Results:', this.searchResults.length)
233+
this.state = (this.searchResults.length > 0) ? States.SHOW_RESULTS : States.NO_RESULTS
234+
} else {
235+
console.log('⚠️ Invalid format for incorporation or registration number')
236+
this.errorMessages = ['Invalid format for incorporation or registration number']
237+
this.searchResults = []
238+
this.state = States.INITIAL
239+
}
240+
}
155241
}
156242
</script>
157243

@@ -162,6 +248,19 @@ export default class BusinessLookup extends Vue {
162248
font-size: $px-12;
163249
}
164250
251+
.magnify-icon-wrapper {
252+
cursor: pointer;
253+
display: flex;
254+
align-items: center;
255+
justify-content: center;
256+
padding: 4px;
257+
user-select: none;
258+
259+
&:hover {
260+
opacity: 0.7;
261+
}
262+
}
263+
165264
p {
166265
color: $gray7;
167266
}

0 commit comments

Comments
 (0)