generated from bcgov/bcrs-template-ui
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathAgmExtension.vue
590 lines (524 loc) · 17.5 KB
/
AgmExtension.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
<template>
<div id="agm-extension">
<ConfirmDialog
ref="confirm"
attach="#agm-extension"
/>
<PaymentErrorDialog
attach="#agm-extension"
filingName="AGM Extension"
:dialog="paymentErrorDialog"
:errors="saveErrors"
:warnings="saveWarnings"
@exit="onPaymentErrorDialogExit()"
/>
<NotEligibleExtensionDialog
attach="#agm-extension"
:dialog="notEligibleExtensionDialog"
@okay="notEligibleExtensionDialog = false"
/>
<!-- Main Body -->
<v-container class="view-container">
<v-row>
<v-col
cols="12"
lg="9"
>
<article id="main-article">
<!-- Page Title -->
<h1>AGM Extension</h1>
<ExpandableHelp helpLabel="Help with Annual General Meeting Extension">
<template #content>
<AgmExtensionHelp />
</template>
</ExpandableHelp>
<header>
<h2>Extension Detail</h2>
<p class="grey-text">
Enter the details about the extension request to evaluate the eligibility.
</p>
</header>
<!-- About the Business -->
<AboutTheBusiness
class="mt-6"
:data.sync="data"
/>
<!-- Extension Request -->
<ExtensionRequest
class="mt-8"
:data.sync="data"
:showErrors="showErrors"
@valid="extensionRequestValid=$event"
/>
<!-- AGM Extension Evaluation -->
<AgmExtensionEvaluation
class="mt-8"
:data.sync="data"
/>
<!-- delete this debugging code -->
<pre class="mt-8">data: {{ data }}</pre>
<!-- Certify -->
<section class="mt-8">
<header>
<h2>Certify</h2>
<p class="grey-text">
Enter the legal name of the person authorized to complete and submit this filing.
</p>
</header>
<div
id="certify-form-section"
:class="{ 'invalid-section': !certifyFormValid && showErrors }"
>
<Certify
ref="certifyRef"
:isCertified.sync="isCertified"
:certifiedBy.sync="certifiedBy"
:class="{ 'invalid-certify': !certifyFormValid && showErrors }"
:disableEdit="!isRoleStaff"
:entityDisplay="displayName()"
:message="certifyText(FilingCodes.AGM_EXTENSION)"
@valid="certifyFormValid=$event"
/>
</div>
</section>
</article>
</v-col>
<v-col
cols="12"
lg="3"
style="position: relative"
>
<aside>
<affix
relative-element-selector="#main-article"
:offset="{ top: 120, bottom: 40 }"
>
<SbcFeeSummary
:filingData="filingData"
:payURL="getPayApiUrl"
@total-fee="totalFee=$event"
/>
</affix>
</aside>
</v-col>
</v-row>
</v-container>
<!-- Buttons -->
<v-container
id="buttons-container"
class="list-item"
>
<div class="buttons-right">
<v-tooltip
top
color="tooltipColor"
content-class="top-tooltip"
>
<template #activator="{ on }">
<div
class="d-inline"
v-on="on"
>
<v-btn
id="file-pay-btn"
color="primary"
large
:disabled="busySaving"
:loading="filingPaying"
@click="onClickFilePay()"
>
<span>{{ isPayRequired ? "File and Pay" : "File Now (no fee)" }}</span>
</v-btn>
</div>
</template>
Ensure all of your information is entered correctly before you File.<br>
There is no opportunity to change information beyond this point.
</v-tooltip>
<v-btn
id="cancel-btn"
class="ml-2"
large
:disabled="busySaving"
@click="goToDashboard()"
>
<span>Cancel</span>
</v-btn>
</div>
</v-container>
</div>
</template>
<script lang="ts">
import { Component, Mixins, Watch } from 'vue-property-decorator'
import { Getter } from 'pinia-class'
import { StatusCodes } from 'http-status-codes'
import { navigate } from '@/utils'
import SbcFeeSummary from 'sbc-common-components/src/components/SbcFeeSummary.vue'
import { ExpandableHelp } from '@bcrs-shared-components/expandable-help'
import { Certify } from '@/components/common'
import { ConfirmDialog, NotEligibleExtensionDialog, PaymentErrorDialog } from '@/components/dialogs'
import AboutTheBusiness from '@/components/AgmExtension/AboutTheBusiness.vue'
import AgmExtensionEvaluation from '@/components/AgmExtension/AgmExtensionEvaluation.vue'
import AgmExtensionHelp from '@/components/AgmExtension/AgmExtensionHelp.vue'
import ExtensionRequest from '@/components/AgmExtension/ExtensionRequest.vue'
import { CommonMixin, DateMixin, EnumMixin, FilingMixin, ResourceLookupMixin } from '@/mixins'
import { LegalServices } from '@/services/'
import { FilingCodes, FilingTypes, Routes, SaveErrorReasons } from '@/enums'
import { AgmExtEvalIF, ConfirmDialogType, EmptyAgmExtEval } from '@/interfaces'
import { useBusinessStore, useConfigurationStore, useRootStore } from '@/stores'
@Component({
components: {
AboutTheBusiness,
AgmExtensionEvaluation,
AgmExtensionHelp,
Certify,
ConfirmDialog,
ExpandableHelp,
ExtensionRequest,
NotEligibleExtensionDialog,
PaymentErrorDialog,
SbcFeeSummary
}
})
export default class AgmExtension extends Mixins(CommonMixin, DateMixin,
EnumMixin, FilingMixin, ResourceLookupMixin) {
// Refs
$refs!: {
confirm: ConfirmDialogType,
certifyRef: Certify
}
@Getter(useConfigurationStore) getAuthWebUrl!: string
@Getter(useBusinessStore) getLegalName!: string
@Getter(useConfigurationStore) getPayApiUrl!: string
@Getter(useRootStore) getUserInfo!: any
@Getter(useBusinessStore) isGoodStanding!: boolean
@Getter(useRootStore) isRoleStaff!: boolean
// enum for template
readonly FilingCodes = FilingCodes
// evaluation object
data = { ...EmptyAgmExtEval } as AgmExtEvalIF
// variables for Certify component
certifiedBy = ''
isCertified = false
certifyFormValid = false
// variables for Extension Request section
extensionRequestValid = false
// variables for displaying dialogs
saveErrorReason: SaveErrorReasons = null
paymentErrorDialog = false
// other variables
totalFee = 0
filingId = 0 // id of this agm extension filing
savedFiling: any = null // filing during save
showErrors = false // true when we press on File and Pay (trigger validation)
filingPaying = false // true only when filing and paying
haveChanges = false
saveErrors = []
saveWarnings = []
notEligibleExtensionDialog = false
/** The Base URL string. */
get baseUrl (): string {
return sessionStorage.getItem('BASE_URL')
}
/** True if page is valid, else False. */
get isPageValid (): boolean {
return (this.extensionRequestValid && this.certifyFormValid)
}
/** True when filing and paying. */
get busySaving (): boolean {
return (this.filingPaying)
}
/** True if payment is required, else False. */
get isPayRequired (): boolean {
// FUTURE: modify rule here as needed
return (this.totalFee > 0)
}
/** Called when component is created. */
created (): void {
// init
this.setFilingData([])
// before unloading this page, if there are changes then prompt user
window.onbeforeunload = (event) => {
if (this.haveChanges) {
event.preventDefault()
// NB: custom text is not supported in all browsers
event.returnValue = 'You have unsaved changes. Are you sure you want to leave?'
}
}
// this is the id of THIS filing
// it must be 0 (meaning new filing) -- we do not support resuming a draft filing
this.filingId = +this.$route.params.filingId // number or NaN
// if required data isn't set, go back to dashboard
if (!this.getIdentifier || this.filingId !== 0) {
this.$router.push({ name: Routes.DASHBOARD })
}
}
/** Called when component is mounted. */
mounted (): void {
this.data.currentDate = this.getCurrentDate
this.data.isGoodStanding = this.isGoodStanding
this.data.incorporationDate = this.getFoundingDate
// Pre-populate the certified block with the logged in user's name (if not staff)
if (!this.isRoleStaff && this.getUserInfo) {
this.certifiedBy = this.getUserInfo.firstname + ' ' + this.getUserInfo.lastname
}
// always include agm extension code
// (no Priority flag and no Waive Fees flag)
this.updateFilingData('add', FilingCodes.AGM_EXTENSION, undefined, undefined)
}
/**
* Called when user clicks File and Pay button
* or when user retries from Save Error dialog.
*/
async onClickFilePay (): Promise<void> {
// if there is an invalid component, scroll to it
if (!this.isPageValid) {
this.showErrors = true
//
// FUTURE: check for section errors here
//
if (!this.extensionRequestValid) {
// nothing to do here -- "showErrors" will do it all
}
if (!this.certifyFormValid) {
// Show error message of legal name text field if invalid
this.$refs.certifyRef.$refs.certifyTextfieldRef.error = true
}
await this.validateAndScroll(this.validFlags, this.validComponents)
return
}
// if not eligible, display dialog
if (!this.data.isEligible) {
this.notEligibleExtensionDialog = true
return
}
// prevent double saving
if (this.busySaving) return
this.filingPaying = true
// save final filing (not draft)
this.savedFiling = await this.saveFiling(false).catch(error => {
if (error?.response?.status === StatusCodes.PAYMENT_REQUIRED) {
// changes were saved if a 402 is received, so clear flag
this.haveChanges = false
// display payment error dialog
this.paymentErrorDialog = true
// try to return filing (which should exist in this case)
return error?.response?.data?.filing || null
} else {
this.saveErrorReason = SaveErrorReasons.FILE_PAY
// try to return filing (which may exist depending on save error)
return error?.response?.data?.filing || null
}
})
const filingId = +this.savedFiling?.header?.filingId || 0
if (filingId > 0) {
// save filing ID for possible future updates
this.filingId = filingId
}
// if there were no errors, finish file-pay process now
// otherwise, dialogs may finish this later
if (!this.paymentErrorDialog && !this.saveErrorReason) this.onClickFilePayFinish()
this.filingPaying = false
}
onClickFilePayFinish (): void {
// safety check
if (this.filingId > 0) {
// changes were saved, so clear flag
this.haveChanges = false
const isPaymentActionRequired = Boolean(this.savedFiling.header.isPaymentActionRequired)
// if payment action is required, navigate to Pay URL
if (isPaymentActionRequired) {
const paymentToken = this.savedFiling.header.paymentToken
const returnUrl = encodeURIComponent(this.baseUrl + '?filing_id=' + this.filingId)
const payUrl = this.getAuthWebUrl + 'makepayment/' + paymentToken + '/' + returnUrl
// assume Pay URL is always reachable
// otherwise, user will have to retry payment later
navigate(payUrl)
} else {
// route to dashboard with filing id parameter
this.$router.push({ name: Routes.DASHBOARD, query: { filing_id: this.filingId.toString() } })
}
} else {
// eslint-disable-next-line no-console
console.log('onClickFilePayFinish(): invalid filing ID, filing =', null)
}
}
/** Builds and saves the filing. NB: Caller needs to catch exceptions. */
async saveFiling (isDraft): Promise<any> {
this.saveErrors = []
this.saveWarnings = []
// if this is a new filing, ensure there are no pending tasks
if (this.filingId === 0) {
const hasPendingTasks = await LegalServices.hasPendingTasks(this.getIdentifier)
.catch(() => {
this.saveErrors = [{ error: 'Unable to check server for pending tasks.' }]
throw new Error()
})
if (hasPendingTasks) {
this.saveErrors = [
{ error: 'Another draft filing already exists. Please complete it before creating a new filing.' }
]
throw new Error()
}
}
const header: any = {
header: {
name: FilingTypes.AGM_EXTENSION,
certifiedBy: this.certifiedBy || '',
date: this.getCurrentDate // NB: API will reassign this date according to its clock
}
}
const business: any = {
business: {
foundingDate: this.dateToApi(this.getFoundingDate),
identifier: this.getIdentifier,
legalName: this.getLegalName,
legalType: this.getLegalType
}
}
const data: any = {
[FilingTypes.AGM_EXTENSION]: {
// convert local properties into API/schema properties
year: this.data.agmYear,
isFirstAgm: this.data.isFirstAgm,
prevAgmRefDate: this.data.prevAgmDate,
extReqForAgmYear: this.data.isPrevExtension,
expireDateCurrExt: this.data.prevExpiryDate,
intendedAgmDate: this.data.intendedAgmDate,
totalApprovedExt: this.data.extensionDuration,
expireDateApprovedExt: this.data.agmDueDate,
// add in remaining local properties for future auditing
...this.data
}
}
// build filing
const filing = Object.assign({}, header, business, data)
try {
let ret
if (this.filingId > 0) {
// we have a filing id, so update an existing filing
ret = await LegalServices.updateFiling(this.getIdentifier, filing, this.filingId, isDraft)
} else {
// filing id is 0, so create a new filing
ret = await LegalServices.createFiling(this.getIdentifier, filing, isDraft)
}
return ret
} catch (error) {
// save errors or warnings, if any
this.saveErrors = error?.response?.data?.errors || []
this.saveWarnings = error?.response?.data?.warnings || []
throw error
}
}
/**
* Routes to dashboard if there are no outstanding changes,
* else prompts user before routing.
*/
goToDashboard (force = false): void {
// check if there are no data changes
if (!this.haveChanges || force) {
// route to dashboard
this.$router.push({ name: Routes.DASHBOARD })
.catch(() => {}) // ignore error in case navigation was aborted
return
}
// open confirmation dialog and wait for response
this.$refs.confirm.open(
'Unsaved Changes',
'You have unsaved changes in your AGM Extension. Do you want to exit your filing?',
{
width: '45rem',
persistent: true,
yes: 'Return to my filing',
no: null,
cancel: 'Exit without saving'
}
).then(() => {
// if we get here, Yes was clicked
// nothing to do
}).catch(() => {
// if we get here, Cancel was clicked
// ignore changes
this.haveChanges = false
// route to dashboard
this.$router.push({ name: Routes.DASHBOARD })
.catch(() => {}) // ignore error in case navigation was aborted
})
}
/** Handles Exit event from Payment Error dialog. */
onPaymentErrorDialogExit (): void {
if (this.isRoleStaff) {
// close Payment Error dialog -- this
// leaves user on Staff Payment dialog
this.paymentErrorDialog = false
} else {
// close the dialog and go to dashboard --
// user will have to retry payment from there
this.paymentErrorDialog = false
this.goToDashboard(true)
}
}
/** Array of valid components. Must match validFlags. */
readonly validComponents = [
'extension-request',
'certify-form-section'
]
/** Object of valid flags. Must match validComponents. */
get validFlags (): object {
return {
extensionEligibility: this.extensionRequestValid,
certifyForm: this.certifyFormValid
}
}
/** Watches all data properties to keep track of changes. */
@Watch('data.isFirstAgm')
@Watch('data.agmYear')
@Watch('data.prevAgmDate')
@Watch('data.isPrevExtension')
@Watch('data.prevExpiryDate')
@Watch('data.intendedAgmDate')
private onHaveChanges (): void {
this.haveChanges = true
}
}
</script>
<style lang="scss" scoped>
@import '@/assets/styles/theme.scss';
#agm-extension {
/* Set "header-counter" to 0 */
counter-reset: header-counter;
}
h2::before {
/* Increment "header-counter" by 1 */
counter-increment: header-counter;
content: counter(header-counter) '. ';
}
h1 {
margin-bottom: 1.25rem;
line-height: 2rem;
letter-spacing: -0.01rem;
}
h2 {
margin-bottom: 0.25rem;
margin-top: 3rem;
font-size: 1.125rem;
}
// Save & Filing Buttons
#buttons-container {
padding-top: 2rem;
border-top: 1px solid $gray5;
.buttons-right {
margin-left: auto;
}
}
// Fix font size and color to stay consistent.
:deep() {
.certify-clause, .certify-stmt, .grey-text {
color: $gray7;
}
.invalid-certify {
.certify-stmt, .title-label {
color: $app-red;
}
}
}
</style>