Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18722 - Update foreign business validation rules #602

Merged
merged 11 commits into from
Dec 20, 2023
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-create-ui",
"version": "5.6.16",
"version": "5.6.17",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand Down
36 changes: 29 additions & 7 deletions src/components/Amalgamation/AmalgamatingBusinesses.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ import { AmalgamationMixin, CommonMixin } from '@/mixins'
import { BusinessLookupServices } from '@/services'
import { BusinessLookup } from '@bcrs-shared-components/business-lookup'
import { Jurisdiction } from '@bcrs-shared-components/jurisdiction'
import { MrasJurisdictions } from '@bcrs-shared-components/jurisdiction/list-data'
import { AmalgamatingBusinessIF, BusinessLookupResultIF, EmptyBusinessLookup } from '@/interfaces'
import { AmlRoles, AmlTypes, EntityStates } from '@/enums'
import { JurisdictionLocation } from '@bcrs-shared-components/enums'
Expand Down Expand Up @@ -229,27 +230,46 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
legalName = null
corpNumber = null
isCan = false
isForeignBusinessValid = false
isMrasJurisdiction = false
jurisdictionErrorMessage = ''
// Null for no validation, false for invalid, true for valid
isForeignBusinessValid = null

// Button properties
isAddingAmalgamatingBusiness = false
isAddingAmalgamatingForeignBusiness = false

/** TextField rules for "Add an Amalgamating Foreign Business" Panel. */
get foreignBusinessLegalNameRules (): Array<(v) => boolean | string> {
return [ v => !!v || 'Full legal name is required' ]
return [
v => !!v || 'Full legal name is required',
v => (!v || v.length >= 3) || 'Must be at least 3 characters',
v => (!v || v.length <= 150) || 'Cannot exceed 150 characters'
]
}

get foreignBusinessCorpNumberRules (): Array<(v) => boolean | string> {
return [ v => !!v || 'Corporate number is required' ]
return [
v => (!this.isMrasJurisdiction || (!!v && /^[0-9a-zA-Z-]+$/.test(v))) ||
'Corporate number is required',
v => (!v || v.length >= 3) || 'Must be at least 3 characters',
v => (!v || v.length <= 40) || 'Cannot exceed 40 characters'
]
}

/** Called when Jurisdiction menu item is changed. */
onJurisdictionChange (jurisdiction: any): void {
this.jurisdiction = jurisdiction
this.isCan = jurisdiction.group === 0
this.jurisdictionErrorMessage = this.jurisdiction ? '' : 'Required.'
this.jurisdictionErrorMessage = this.jurisdiction ? '' : 'Home jurisdiction is required'
this.isMrasJurisdiction = MrasJurisdictions.includes(
this.jurisdiction.text.toLowerCase()
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
)

// Update validation on jurisdiction change
if (this.isForeignBusinessValid !== null) {
this.validateAddAmalgamatingForeignBusiness()
}
}

async saveAmalgamatingBusiness (businessLookup: BusinessLookupResultIF): Promise<void> {
Expand Down Expand Up @@ -364,9 +384,9 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
/** Validate Add Amalgamating Foreign Business. */
validateAddAmalgamatingForeignBusiness (): void {
this.isForeignBusinessValid = (
this.jurisdiction &&
this.legalName &&
this.corpNumber
!!this.jurisdiction &&
!!this.legalName &&
(!this.isMrasJurisdiction || !!this.corpNumber)
)
this.jurisdictionErrorMessage = this.jurisdiction ? '' : 'Home jurisdiction is required'
this.$refs.foreignBusinessForm.validate()
Expand All @@ -384,10 +404,12 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
)

// Reset "Add an Amalgamating Foreign Business" Panel on change
this.isForeignBusinessValid = null
this.jurisdiction = null
this.legalName = null
this.corpNumber = null
this.jurisdictionErrorMessage = ''
this.isMrasJurisdiction = false
}
}
</script>
Expand Down
Loading