Skip to content

Commit

Permalink
4602 Name Request Correct Component (bcgov#15)
Browse files Browse the repository at this point in the history
* initial commit

* Updated for initial PR

* Removed padding class

* Pr Comments Update

* Initial Commit. Form Implementation

* Wrap up NameRequest UI correction

* import clean up

* Console clean up

* Pr Updates
  • Loading branch information
cameron-eyds authored Sep 9, 2020
1 parent e6151a6 commit 4cee36c
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 78 deletions.
26 changes: 16 additions & 10 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
@okay="saveErrorDialog = false"
/>

<name-request-error-dialog
attach="#app"
:type="nameRequestErrorType"
:dialog="nameRequestErrorDialog"
@close="nameRequestErrorDialog = false"
/>

<confirm-dialog
ref="confirm"
attach="#app"
Expand Down Expand Up @@ -136,7 +143,8 @@ import * as Views from '@/views'

// Dialogs, mixins, interfaces, etc
import { AccountAuthorizationDialog, BcolErrorDialog, NameRequestInvalidErrorDialog, ConfirmDialog, FetchErrorDialog,
InvalidIncorporationApplicationDialog, PaymentErrorDialog, SaveErrorDialog, FileAndPayInvalidNameRequestDialog
InvalidIncorporationApplicationDialog, PaymentErrorDialog, SaveErrorDialog, FileAndPayInvalidNameRequestDialog,
NameRequestErrorDialog
} from '@/components/dialogs'
import { BcolMixin, DateMixin, FilingTemplateMixin, LegalApiMixin } from '@/mixins'
import { FilingDataIF, ActionBindingIF, ConfirmDialogType } from '@/interfaces'
Expand All @@ -155,6 +163,7 @@ import { SessionStorageKeys } from 'sbc-common-components/src/util/constants'
AccountAuthorizationDialog,
FetchErrorDialog,
InvalidIncorporationApplicationDialog,
NameRequestErrorDialog,
PaymentErrorDialog,
SaveErrorDialog,
ConfirmDialog,
Expand Down Expand Up @@ -200,6 +209,8 @@ export default class App extends Mixins(BcolMixin, DateMixin, FilingTemplateMixi
private saveErrorDialog: boolean = false
private nameRequestInvalidErrorDialog: boolean = false
private nameRequestInvalidType: string = ''
private nameRequestErrorDialog: boolean = false
private nameRequestErrorType: string = ''
private saveErrors: Array<object> = []
private saveWarnings: Array<object> = []
private fileAndPayInvalidNameRequestDialog: boolean = false
Expand Down Expand Up @@ -290,15 +301,10 @@ export default class App extends Mixins(BcolMixin, DateMixin, FilingTemplateMixi
})

// listen for name request invalid error events
this.$root.$on('name-request-invalid-error', async error => {
console.log('NR error during File and Pay =', error) // eslint-disable-line no-console
this.fileAndPayInvalidNameRequestDialog = true
})

// listen for name request retrieve error events
this.$root.$on('name-request-retrieve-error', async () => {
console.log('Error while retrieving NR during File and Pay') // eslint-disable-line no-console
this.nameRequestInvalidErrorDialog = true
this.$root.$on('invalid-name-request', async error => {
console.log('Name request error:', error) // eslint-disable-line no-console
this.nameRequestErrorType = error
this.nameRequestErrorDialog = true
})

// if we are already authenticated then go right to init
Expand Down
53 changes: 41 additions & 12 deletions src/components/Company/CompanyName/CorrectNameOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@
<v-expansion-panel-header class="name-options-header">{{item.description}}</v-expansion-panel-header>
<v-expansion-panel-content class="name-options-content">
<v-container>
<component :is="item.component" :key="item.id" />
<component
:is="item.component"
:key="item.id"
:submit="submit"
@done="emitDone($event)"
@isValid="isFormValid = $event"
/>
</v-container>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>

<div class="action-btns my-3">
<v-fade-transition hide-on-leave>
<v-btn id="done-btn" large color="primary" @click="emitSave()"><span>Done</span></v-btn>
</v-fade-transition>
<v-btn
id="done-btn"
large color="primary"
@click="submitNameCorrection"
:disabled="!isFormValid"
:loading="isLoading"
>
<span>Done</span>
</v-btn>

<v-btn id="cancel-btn" large @click="emitCancel"><span>Cancel</span></v-btn>
</div>
Expand All @@ -29,6 +41,9 @@
// Libraries
import { Component, Emit, Prop, Vue } from 'vue-property-decorator'
// Components
import CorrectNameRequest from './CorrectNameRequest.vue'
// Interfaces & Enums
import { CorrectNameOptionIF } from '@/interfaces'
import { CorrectionTypes } from '@/enums'
Expand All @@ -40,14 +55,21 @@ import { CorrectionTypes } from '@/enums'
* 2. If this options list is only passed one value the option panel will be open by default.
* 3. The parent component will have to watch for the 'save' and 'cancel' events and handle them accordingly.
*/
@Component({})
@Component({
components: {
CorrectNameRequest
}
})
export default class CorrectNameOptions extends Vue {
/** The options to display */
@Prop() private correctionNameChoices: Array<string>
@Prop() correctionNameChoices: Array<string>
// local properties
private displayedOptions: Array<CorrectNameOptionIF> = []
private panel = null as number
private submit = false
private isLoading = false
private isFormValid = false
private correctionNameOptions: Array<CorrectNameOptionIF> = [
{
id: CorrectionTypes.CORRECT_NAME,
Expand All @@ -62,7 +84,7 @@ export default class CorrectNameOptions extends Vue {
{
id: CorrectionTypes.CORRECT_NEW_NR,
description: 'Use a new name request number',
component: '' // CorrectNameRequest
component: CorrectNameRequest
}
]
Expand All @@ -74,16 +96,23 @@ export default class CorrectNameOptions extends Vue {
if (this.correctionNameChoices.length === 1) this.panel = 0 // open by default if only 1 option
}
/** save name correction */
@Emit('save')
private emitSave (): void {
// Pass up event data for parent to handle setting to store etc
/** Trigger form submission */
private submitNameCorrection (): void {
this.isLoading = true
this.submit = !this.submit
}
/** Inform Parent name correction process is done. */
@Emit('done')
private emitDone (isSaved: boolean): void {
this.isLoading = false
if (isSaved) this.panel = null
}
/** cancel name correction */
@Emit('cancel')
private emitCancel (): void {
this.panel = 0
this.panel = null
}
}
</script>
Expand Down
141 changes: 141 additions & 0 deletions src/components/Company/CompanyName/CorrectNameRequest.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<template>
<v-form ref="correctNrForm" v-model="valid" lazy-validation>
<v-text-field
v-model="nameRequestNumber"
filled
label="Enter a Name Request Number"
hint="Example: NR 1234567"
req
persistent-hint
:rules="entityNumRules"
data-test="business-identifier"
></v-text-field>
<v-text-field
v-model="entityPhone"
filled
label="Enter the Applicant Phone Number"
hint="Example: 555-555-5555"
persistent-hint
type="tel"
:rules="entityPhoneNumberRules"
data-test="entity-phone"
></v-text-field>
<div class="font-weight-bold ml-3 mb-2">or</div>
<v-text-field
v-model="entityEmail"
filled
label="Enter the Applicant Email Address"
hint="Example: name@email.com"
persistent-hint
:rules="entityEmailRules"
data-test="entity-email"
>
</v-text-field>
</v-form>
</template>

<script lang="ts">
// Libraries
import { Component, Prop, Watch, Emit, Mixins } from 'vue-property-decorator'
import { Action } from 'vuex-class'
// Mixins
import { NameRequestMixin } from '@/mixins'
// Interfaces
import { NrCorrectionIF } from '@/interfaces/correction-interfaces'
import { ActionBindingIF } from '@/interfaces'
@Component({})
export default class CorrectNameRequest extends Mixins(NameRequestMixin) {
/** Form Submission Prop */
@Prop({ default: false }) submit: boolean
@Action setNameRequest!: ActionBindingIF
private valid = false
private nameRequestNumber: string = ''
private entityPhone: string = ''
private entityEmail: string = ''
// Form Ref
$refs: { correctNrForm: HTMLFormElement }
// Rules
private entityNumRules = [
v => !!v || 'Name Request Number is required',
v => this.validateNameRequestNumber(v) || 'Name Request Number is invalid'
]
private entityPhoneNumberRules = [
v => this.isInputEntered(v, 'phone') || 'Phone number is required',
v => !(v.length > 12) || 'Phone number is invalid'
]
private entityEmailRules = [
v => this.isInputEntered(v, 'email') || 'Email is required',
v => this.isValidateEmail(v) || 'Email is Invalid'
]
// Validations
private get isFormValid (): boolean {
return this.valid && !!this.nameRequestNumber &&
(!!this.entityPhone || !!this.entityEmail)
}
private isInputEntered (value: any, inputType: string) {
return (!!((inputType === 'email') ? this.entityPhone : this.entityEmail) || !!value)
}
private isValidateEmail (value: any) {
return ((!!this.entityPhone && !!value) || !!this.validateEmailFormat(value))
}
private validateNameRequestNumber (value: string): boolean {
const VALID_FORMAT = new RegExp(/^(NR )?\d+$/)
return VALID_FORMAT.test(value.toUpperCase())
}
private validateEmailFormat (value: string): boolean {
const VALID_FORMAT = new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)
return VALID_FORMAT.test(value)
}
private resetForm () {
this.nameRequestNumber = ''
this.entityPhone = ''
this.entityEmail = ''
this.$refs.correctNrForm.resetValidation()
}
/** Watch for form submission and emit results. */
@Watch('submit')
private async onSubmit (): Promise<any> {
await this.validateNameRequest(this.nameRequestNumber, this.entityPhone, this.entityEmail)
.then(response => {
const nrCorrection: NrCorrectionIF = {
nrNumber: this.nameRequestNumber,
legalName: this.getApprovedName(response)
}
this.setNameRequest(nrCorrection)
this.emitDone(true)
}).catch(() => {
this.emitDone()
})
}
/** Inform parent the process is complete. */
@Emit('done')
private emitDone (isSaved: boolean = false): void {
if (!isSaved) this.resetForm()
}
/** Inform parent when form is valid and ready for submission. */
@Watch('valid')
@Emit('isValid')
private emitValid (): boolean {
return this.isFormValid
}
}
</script>

<style lang="scss" scoped>
</style>
1 change: 1 addition & 0 deletions src/components/Company/CompanyName/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as CorrectNameOptions } from './CorrectNameOptions.vue'
export { default as CorrectNameRequest } from './CorrectNameRequest.vue'
Loading

0 comments on commit 4cee36c

Please sign in to comment.