Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
severinbeauvais committed Aug 28, 2023
1 parent 397d0c4 commit b084357
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 33 deletions.
60 changes: 45 additions & 15 deletions src/components/new-request/business-fetch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
append-icon="mdi-magnify"
autocomplete="chrome-off"
autofocus
:error-messages="errorMessages"
filled
@change="onItemSelected()"
@click:append="onItemSelected()"
Expand All @@ -24,8 +25,8 @@
<script lang="ts">
import Vue from 'vue'
import { Component, Emit } from 'vue-property-decorator'
import { BusinessLookupResultIF, FormType } from '@/interfaces'
import { Sleep } from '@/plugins'
import { Action } from 'vuex-class'
import { FormType } from '@/interfaces'
import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module'
import { EntityStates } from '@bcrs-shared-components/enums'
Expand All @@ -40,17 +41,23 @@ enum States {
*/
@Component({})
export default class BusinessFetch extends Vue {
// Enum for template
readonly States = States
// Refs
$refs!: {
searchField: FormType
}
// enum for template
readonly States = States
// Store actions
@Action fetchCorpNum!: (corpNum: string) => Promise<any>
/** V-model for search field. */
searchField = ''
/** For custom error messages. */
errorMessages: string[] = []
/** State of this component. */
state = States.INITIAL
Expand All @@ -62,23 +69,46 @@ export default class BusinessFetch extends Vue {
/** When an item has been selected, emits event with business object. */
@Emit('business')
async onItemSelected (): Promise<BusinessLookupResultIF> {
async onItemSelected (): Promise<any> {
console.log(`*** validating = [${this.searchField}]`)
const valid = this.$refs.searchField.validate()
if (!valid) return
// set state and perform search
// perform search
// *** BC0871408 ***
// *** FM1041131 ***
this.state = States.SEARCHING
await Sleep(1000) // *** TODO: perform search here
const result = await this.fetchCorpNum(this.searchField).catch(e => null)
console.log('*** result =', result)
// set state and return result
this.state = States.SUMMARY
return {
identifier: this.searchField,
legalType: CorpTypeCd.BC_COMPANY,
bn: '',
status: EntityStates.ACTIVE,
name: this.searchField
if (result) {
this.state = States.SUMMARY
// return LEAR result
if (result.identifier) {
return {
identifier: result.identifier,
legalType: result.legalType,
name: result.legalName,
status: result.state
}
}
// return COLIN result
// *** TODO: implement this when endpoint is available
return {
identifier: this.searchField,
legalType: CorpTypeCd.BC_COMPANY,
bn: '',
status: EntityStates.ACTIVE,
name: this.searchField
}
}
// show error for 5 seconds
this.state = States.INITIAL
this.errorMessages = ['BUSINESS NOT FOUND']
setTimeout(() => { this.errorMessages = [] }, 5000)
}
}
</script>
33 changes: 25 additions & 8 deletions src/components/new-request/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,21 @@
<!-- Business Lookup/Fetch -->
<v-col v-if="showBusinessLookup" cols="12" md="6">
<template v-if="!business">
<BusinessLookup v-if="getIsAuthenticated" @business="business=$event"/>
<BusinessFetch v-else @business="business=$event"/>
<BusinessLookup v-if="getIsAuthenticated" @business="onBusiness($event)"/>
<BusinessFetch v-else @business="onBusiness($event)"/>
</template>
<div v-else class="d-flex justify-space-between align-center">
<v-text-field
append-outer-icon="mdi-close"
disabled
append-icon="mdi-close"
readonly
filled
hide-details
:value="business.name"
@click:append="onBusiness(null)"
/>
<div @click="business=null">
<!-- <div @click="onBusiness(null)" class="business-close-container">
<v-icon color="primary">mdi-close</v-icon>
</div>
</div> -->
</div>
</v-col>

Expand Down Expand Up @@ -363,7 +364,7 @@ export default class Search extends Mixins(CommonMixin, NrAffiliationMixin) {
readonly EntityType = EntityType
activeActionGroup = NaN
showRequestActionTooltip = false
business = null as BusinessLookupResultIF
business = null
private mounted () {
this.$nextTick(() => {
Expand Down Expand Up @@ -560,6 +561,12 @@ export default class Search extends Mixins(CommonMixin, NrAffiliationMixin) {
return this.getEntityTextFromValue || 'specified business type'
}
/** Event handled for business lookup/fetch. */
onBusiness (business: any): void {
this.business = business
this.entity_type_cd = this.business?.legalType || null
}
/**
* If user is authenticated, create draft business and redirect to Dashboard.
* If user is not authenticated, redirect to login screen then redirect back.
Expand Down Expand Up @@ -590,7 +597,7 @@ export default class Search extends Mixins(CommonMixin, NrAffiliationMixin) {
this.setDesignation('')
// clear "Select a Business Type" field when "View all business types" or Society is selected
if (!this.entity_type_cd || this.entity_type_cd === EntityType.INFO) {
this.$refs.selectBusinessTypeRef.reset()
this.$refs.selectBusinessTypeRef && this.$refs.selectBusinessTypeRef.reset()
}
}
Expand Down Expand Up @@ -673,6 +680,16 @@ export default class Search extends Mixins(CommonMixin, NrAffiliationMixin) {
display: none;
}
// place this container on top of the (disabled) business name text field
.business-close-container {
position: absolute;
right: 52px;
:hover {
cursor: pointer;
}
}
// set content colour when hovering over list items
.v-list-item:hover .v-list-item__content,
.list-item:hover {
Expand Down
2 changes: 1 addition & 1 deletion src/list-data/request-action-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export const XproMapping: MappingI = {
}

export const ColinRequestActions = [
NrRequestActionCodes.AMALGAMATE,
NrRequestActionCodes.CHANGE_NAME,
NrRequestActionCodes.CONVERSION,
NrRequestActionCodes.RESTORE
]

// *** TODO: should these be from FF instead?
export const ColinRequestTypes = [
EntityType.BC,
EntityType.CC,
Expand Down
5 changes: 3 additions & 2 deletions src/services/business-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default class BusinessServices {
}

/** Fetches a business record. */
static async fetchBusiness (businessId: number): Promise<any> {
return axios.get(`${BusinessServices.legalApiUrl}/businesses/${businessId}`)
static async fetchBusiness (identifier: string): Promise<any> {
return axios.get(`${BusinessServices.legalApiUrl}/businesses/${identifier}`)
.then(response => response.data?.business)
}
}
19 changes: 12 additions & 7 deletions src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { BAD_REQUEST, NOT_FOUND, OK, SERVICE_UNAVAILABLE } from 'http-status-codes'
import removeAccents from 'remove-accents'
import { GetFeatureFlag, Sleep, sanitizeName } from '@/plugins'
import BusinessServices from '@/services/business-services'
import NamexServices from '@/services/namex-services'
import { MRAS_MIN_LENGTH, MRAS_MAX_LENGTH } from '@/components/new-request/constants'

Expand Down Expand Up @@ -318,20 +319,24 @@ export const checkCOLIN = ({ getters }, corpNum: string) => {
// check entity for the corp num first
let url = `${appBaseURL}/businesses/${corpNum}`
return axios.get(url, {}).catch(error => {
if (error.response && error.response.status === 404) {
if (error.response?.status === NOT_FOUND) {
// Remove BC prefix as Colin only supports base number with no prefix for BC's
const cleanedCorpNum = corpNum.replace(/^BC+/i, '')
url = `${appBaseURL}/colin/${cleanedCorpNum}`
return axios.post(url, {}).then(response => {
if (response.data.directors === 'Not Available' && response.data.incorporated === 'Not Available') {
const error = new Error('Not Found')
return Promise.reject(error)
// *** TODO: refactor / clean this up
// url = `${appBaseURL}/colin/${cleanedCorpNum}`
// return axios.post(url, {}).then(response => {
return BusinessServices.fetchBusiness(corpNum).then(response => {
if (
response.data.directors === 'Not Available' &&
response.data.incorporated === 'Not Available'
) {
return Promise.reject(new Error('Not Found'))
}
}).catch(error => {
return Promise.reject(error)
})
} else {
return Promise.reject(error)
return Promise.reject(new Error('Invalid Response'))
}
})
}
Expand Down

0 comments on commit b084357

Please sign in to comment.