Skip to content

Commit

Permalink
18722 - Update foreign business validation rules (bcgov#602)
Browse files Browse the repository at this point in the history
* Update mras corp number rules

* Add test code

* Fix foreign jurisdiction validations

* Corp Number only required if Mras

* Update validation on jurisdiction change

* Update isForeignBusinessValid

* Fix typo

* Use common Mras list

* Add comments to foreign business validation

* Update != to !==

* Update version to 5.6.17
  • Loading branch information
leodube-aot authored and JazzarKarim committed Jan 26, 2024
1 parent 7a6eed4 commit 7b6c78d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
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()
)
// 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

0 comments on commit 7b6c78d

Please sign in to comment.