Skip to content

Commit

Permalink
- app version = 5.2.12 (bcgov#731)
Browse files Browse the repository at this point in the history
- added constants for default name length (3 <= x <= 150)
- used default constants for default rules
- used MRAS constants for MRAS rules
- updated startAnalyzeName() to use either MRAS or default constants
  • Loading branch information
severinbeauvais authored Oct 17, 2023
1 parent 7243cba commit 69d7697
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 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": "name-request",
"version": "5.2.11",
"version": "5.2.12",
"private": true,
"appName": "Name Request UI",
"sbcName": "SBC Common Components",
Expand Down
2 changes: 2 additions & 0 deletions src/components/new-request/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const DFLT_MIN_LENGTH = 3
export const DFLT_MAX_LENGTH = 150
export const MRAS_MIN_LENGTH = 3
export const MRAS_MAX_LENGTH = 40
19 changes: 10 additions & 9 deletions src/components/new-request/name-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { Component, Prop, Vue, Watch, Emit } from 'vue-property-decorator'
import { Getter, Action } from 'vuex-class'
import { ActionBindingIF } from '@/interfaces/store-interfaces'
import { sanitizeName } from '@/plugins'
import { MRAS_MAX_LENGTH } from '@/components/new-request/constants'
import { DFLT_MIN_LENGTH, DFLT_MAX_LENGTH, MRAS_MIN_LENGTH, MRAS_MAX_LENGTH }
from '@/components/new-request/constants'
@Component({})
export default class NameInput extends Vue {
Expand Down Expand Up @@ -52,10 +53,9 @@ export default class NameInput extends Vue {
@Action setMrasSearchInfoModalVisible!: ActionBindingIF
@Action startAnalyzeName!: ActionBindingIF
readonly err_msg = 'Cannot exceed ' + MRAS_MAX_LENGTH + ' characters'
readonly defaultRules = [
v => (!v || v.length <= MRAS_MAX_LENGTH) || this.err_msg
v => (!v || v.length >= DFLT_MIN_LENGTH) || `Must be at least ${DFLT_MIN_LENGTH} characters`,
v => (!v || v.length <= DFLT_MAX_LENGTH) || `Cannot exceed ${DFLT_MAX_LENGTH} characters`
]
nameInputComponent = null
Expand All @@ -66,10 +66,11 @@ export default class NameInput extends Vue {
}
/** The array of validation rules for the MRAS corp num. */
get mrasRules (): Function[] {
get mrasRules (): any[] {
return [
v => (/^[0-9a-zA-Z-]+$/.test(v) || 'A corporate number is required'),
v => (!v || v.length <= 40) || 'Cannot exceed 40 characters' // maximum character count
v => (!v || v.length >= MRAS_MIN_LENGTH) || `Must be at least ${MRAS_MIN_LENGTH} characters`,
v => (!v || v.length <= MRAS_MAX_LENGTH) || `Cannot exceed ${MRAS_MAX_LENGTH} characters`
]
}
Expand Down Expand Up @@ -107,12 +108,12 @@ export default class NameInput extends Vue {
return ['Please enter a name for the business']
}
if (this.getErrors.includes('length')) {
if (this.getErrors.includes('min_length')) {
return ['Please enter a longer name']
}
if (this.getErrors.includes('mras_length_exceeded')) {
return [this.err_msg]
if (this.getErrors.includes('max_length')) {
return ['Please enter a shorter name']
}
return null
Expand Down
16 changes: 11 additions & 5 deletions src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { BAD_REQUEST, NOT_FOUND, OK, SERVICE_UNAVAILABLE } from 'http-status-cod
import removeAccents from 'remove-accents'
import { GetFeatureFlag, Sleep, sanitizeName } from '@/plugins'
import NamexServices from '@/services/namex-services'
import { MRAS_MIN_LENGTH, MRAS_MAX_LENGTH } from '@/components/new-request/constants'
import { DFLT_MIN_LENGTH, DFLT_MAX_LENGTH, MRAS_MIN_LENGTH, MRAS_MAX_LENGTH }
from '@/components/new-request/constants'

// List Data
import { CanJurisdictions, Designations, IntlJurisdictions, RequestActions } from '@/list-data'
Expand Down Expand Up @@ -1062,15 +1063,20 @@ export const startAnalyzeName = async ({ commit, getters }) => {
commit('setErrors', 'name')
return
}
if (getters.getName.length < MRAS_MIN_LENGTH) {
commit('setErrors', 'length')

const min = getters.isXproFlow ? MRAS_MIN_LENGTH : DFLT_MIN_LENGTH
const max = getters.isXproFlow ? MRAS_MAX_LENGTH : DFLT_MAX_LENGTH

if (getters.getName.length < min) {
commit('setErrors', 'min_length')
return
}
if (getters.getName.length > MRAS_MAX_LENGTH) {
commit('setErrors', 'mras_length_exceeded')
if (getters.getName.length > max) {
commit('setErrors', 'max_length')
return
}
}

if (getters.getErrors.length > 0) {
return
}
Expand Down

0 comments on commit 69d7697

Please sign in to comment.