generated from bcgov/bcrs-template-ui
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathApp.vue
920 lines (812 loc) · 28.8 KB
/
App.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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
<template>
<v-app
id="app"
class="app-container theme--light"
>
<!-- Dialogs -->
<DashboardUnavailableDialog
:dialog="dashboardUnavailableDialog"
attach="#app"
@exit="onClickExit()"
@retry="onClickRetry()"
/>
<DownloadErrorDialog
:dialog="downloadErrorDialog"
attach="#app"
@close="downloadErrorDialog=false"
/>
<BusinessAuthErrorDialog
:dialog="businessAuthErrorDialog"
attach="#app"
@exit="onClickExit()"
@retry="onClickRetry(true)"
/>
<NameRequestAuthErrorDialog
:dialog="nameRequestAuthErrorDialog"
attach="#app"
@exit="onClickExit()"
@retry="onClickRetry(true)"
/>
<NameRequestInvalidDialog
:dialog="nameRequestInvalidDialog"
:type="nameRequestInvalidType"
attach="#app"
@exit="onClickExit()"
@retry="onClickRetry()"
/>
<ConfirmDissolutionDialog
:dialog="confirmDissolutionDialog"
attach="#app"
@close="confirmDissolutionDialog = false"
@proceed="dissolveCompany()"
/>
<NotInGoodStandingDialog
:dialog="notInGoodStandingDialog"
:message="nigsMessage"
attach="#app"
@close="notInGoodStandingDialog = false"
/>
<!-- Loading Dashboard spinner -->
<v-fade-transition>
<div
v-show="showLoadingDashboardSpinner"
class="loading-container"
>
<div class="loading__content">
<v-progress-circular
color="primary"
size="50"
indeterminate
/>
<div
v-if="!isSignoutRoute"
class="loading-msg"
>
Loading Dashboard
</div>
</div>
</div>
</v-fade-transition>
<!-- Fetching Data/Starting Amalgamation spinner -->
<v-fade-transition>
<div
v-show="spinnerText"
class="loading-container grayed-out"
>
<div class="loading__content">
<v-progress-circular
color="primary"
size="50"
indeterminate
/>
<div class="loading-msg white--text">
{{ spinnerText }}
</div>
</div>
</div>
</v-fade-transition>
<SbcHeader />
<!-- Alert banner -->
<v-alert
v-if="bannerText"
tile
dense
type="warning"
>
<div
class="mb-0 text-center color-dk-text"
v-html="bannerText"
/>
</v-alert>
<div class="app-body">
<!-- only show pages while signing in or once the data is loaded -->
<main v-if="isSigninRoute || dataLoaded">
<Breadcrumb :breadcrumbs="breadcrumbs" />
<EntityInfo
v-if="!isAmalgamationSelectionRoute"
@confirmDissolution="confirmDissolutionDialog = true"
@notInGoodStanding="nigsMessage = $event; notInGoodStandingDialog = true"
@downloadBusinessSummary="downloadBusinessSummary()"
@viewAddDigitalCredentials="viewAddDigitalCredentials()"
/>
<router-view />
</main>
</div>
<SbcFooter :aboutText="aboutText" />
</v-app>
</template>
<script lang="ts">
import { mapActions, mapState } from 'pinia'
import * as Sentry from '@sentry/browser'
import { GetFeatureFlag, navigate, UpdateLdUser } from '@/utils'
import SbcHeader from 'sbc-common-components/src/components/SbcHeader.vue'
import SbcFooter from 'sbc-common-components/src/components/SbcFooter.vue'
import { Breadcrumb } from '@/components/common'
import EntityInfo from '@/components/EntityInfo.vue'
import {
BusinessAuthErrorDialog,
ConfirmDissolutionDialog,
DashboardUnavailableDialog,
DownloadErrorDialog,
NameRequestAuthErrorDialog,
NameRequestInvalidDialog,
NotInGoodStandingDialog
} from '@/components/dialogs'
import {
ConfigJson,
getMyBusinessRegistryBreadcrumb,
getRegistryDashboardBreadcrumb,
getStaffDashboardBreadcrumb
} from '@/resources'
import { CommonMixin, DateMixin, DirectorMixin, EnumMixin, FilingMixin, NameRequestMixin } from '@/mixins'
import { AuthServices, EnumUtilities, LegalServices } from '@/services/'
import {
ApiFilingIF,
ApiTaskIF,
BreadcrumbIF,
DocumentIF,
NameRequestIF,
PartyIF,
TaskTodoIF
} from '@/interfaces'
import {
EntityStatus,
FilingStatus,
FilingTypes,
NameRequestStates,
NigsMessage,
Routes
} from '@/enums'
import { CorpTypeCd, GetCorpFullDescription } from '@bcrs-shared-components/corp-type-module'
import { SessionStorageKeys } from 'sbc-common-components/src/util/constants'
import { useBusinessStore, useConfigurationStore, useFilingHistoryListStore, useRootStore } from './stores'
export default {
name: 'App',
components: {
Breadcrumb,
ConfirmDissolutionDialog,
DashboardUnavailableDialog,
DownloadErrorDialog,
BusinessAuthErrorDialog,
NameRequestAuthErrorDialog,
NameRequestInvalidDialog,
NotInGoodStandingDialog,
SbcHeader,
SbcFooter,
EntityInfo
},
mixins: [
CommonMixin,
DateMixin,
DirectorMixin,
EnumMixin,
FilingMixin,
NameRequestMixin
],
data () {
return {
confirmDissolutionDialog: false,
downloadErrorDialog: false,
dataLoaded: false,
dashboardUnavailableDialog: false,
businessAuthErrorDialog: false,
nameRequestAuthErrorDialog: false,
nameRequestInvalidDialog: false,
nameRequestInvalidType: null as NameRequestStates,
notInGoodStandingDialog: false,
nigsMessage: null as NigsMessage,
localNrNumber: null as string,
/** Currently supported entity types in Filings UI. */
supportedEntityTypes: [
CorpTypeCd.BENEFIT_COMPANY,
CorpTypeCd.BC_CCC,
CorpTypeCd.BC_COMPANY,
CorpTypeCd.BC_ULC_COMPANY,
CorpTypeCd.COOP,
CorpTypeCd.PARTNERSHIP,
CorpTypeCd.SOLE_PROP
]
}
},
computed: {
...mapState(useConfigurationStore,
[
'getAuthApiUrl',
'getBusinessUrl',
'getCreateUrl',
'getRegHomeUrl'
]),
...mapState(useBusinessStore,
[
'getEntityName',
'getLegalType',
'getIdentifier',
'isSoleProp'
]),
...mapState(useRootStore,
[
'getKeycloakRoles',
'isAppFiling',
'isAppTask',
'isRoleStaff',
'showFetchingDataSpinner',
'showStartingAmalgamationSpinner'
]),
/** The Business ID string. */
businessId (): string {
return sessionStorage.getItem('BUSINESS_ID')
},
/** The Temporary Registration Number string. */
tempRegNumber (): string {
return sessionStorage.getItem('TEMP_REG_NUMBER')
},
/** True if "Loading Dashboard" spinner should be shown. */
showLoadingDashboardSpinner (): boolean {
return (
!this.dataLoaded &&
!this.dashboardUnavailableDialog &&
!this.businessAuthErrorDialog &&
!this.nameRequestAuthErrorDialog &&
!this.nameRequestInvalidDialog
)
},
/** True if route is Signin. */
isSigninRoute (): boolean {
return (this.$route.name === Routes.SIGNIN)
},
/** True if route is Signout. */
isSignoutRoute (): boolean {
return (this.$route.name === Routes.SIGNOUT)
},
/** True if user is authenticated. */
isAuthenticated (): boolean {
const keycloakToken = sessionStorage.getItem(SessionStorageKeys.KeyCloakToken)
// FUTURE: also check that token isn't expired!
return !!keycloakToken
},
/** Is true if this is the amalgamation selection panel page. */
isAmalgamationSelectionRoute (): boolean {
return this.$route?.name === Routes.AMALGAMATION_SELECTION
},
/** The About text. */
aboutText (): string {
return import.meta.env.ABOUT_TEXT
},
/** Get banner text. */
bannerText (): string {
const bannerText: string = GetFeatureFlag('banner-text')
// remove spaces so that " " becomes falsy
return bannerText?.trim() || null
},
/** Spinner text. */
spinnerText (): string {
if (this.showFetchingDataSpinner) return 'Fetching Data'
if (this.showStartingAmalgamationSpinner) return 'Starting Amalgamation'
return null
},
/** The route breadcrumbs list. */
breadcrumbs (): Array<BreadcrumbIF> {
const breadcrumbs = this.$route?.meta?.breadcrumb
const crumbs: Array<BreadcrumbIF> = [
{
text: this.getEntityName || 'Unknown Name',
to: { name: Routes.DASHBOARD }
},
...(breadcrumbs || [])
]
// Set base crumbs based on user role
// Staff don't want the home landing page and they can't access the Manage Business Dashboard
if (this.isRoleStaff) {
// If staff, set StaffDashboard as home crumb
crumbs.unshift(getStaffDashboardBreadcrumb(this.getBusinessUrl))
} else {
// For non-staff, set Home and Dashboard crumbs
crumbs.unshift(
getRegistryDashboardBreadcrumb(this.getRegHomeUrl),
getMyBusinessRegistryBreadcrumb(this.getBusinessUrl))
}
return crumbs
}
},
watch: {
async '$route' (): Promise<void> {
// re-fetch all data when we (re)route to the dashboard
// (does not fire on initial dashboard load)
if (this.$route.name === Routes.DASHBOARD) {
await this.fetchData()
}
}
},
/** Called when component is created. */
created (): void {
// listen for reload data events
this.$root.$on('reloadData', () => this.fetchData())
},
/** Called when component is mounted. */
async mounted (): Promise<void> {
// do not fetch data if we need to authenticate
// just let signin page do its thing
if (!this.isAuthenticated) return
// ...otherwise proceed
await this.fetchData()
},
/** Called just before this component is destroyed. */
beforeUnmount (): void {
// stop listening for reload data events
this.$root.$off('reloadData')
},
methods: {
...mapActions(useBusinessStore,
[
'loadBusinessInfo',
'setGoodStanding',
'setLegalName',
'setLegalType',
'setIdentifier'
]),
...mapActions(useFilingHistoryListStore,
[
'loadFilings',
'setFilings'
]),
...mapActions(useRootStore,
[
'loadStateFiling',
'setAuthRoles',
'setBusinessAddress',
'setBusinessEmail',
'setBusinessPhone',
'setBusinessPhoneExtension',
'setConfigObject',
'setCorpTypeCd',
'setCurrentDate',
'setCurrentJsDate',
'setEntityStatus',
'setFetchingDataSpinner',
'setKeycloakRoles',
'setNameRequest',
'setParties',
'setRecordsAddress',
'setRegisteredAddress',
'setTasks',
'setUserInfo',
'setUserKeycloakGuid'
]),
/** Fetches business data / incorp app data. */
async fetchData (): Promise<void> {
this.dataLoaded = false
// store today's date every time the dashboard is loaded
const jsDate: Date = await this.getServerDate()
if (!this.isVitestRunning) {
// eslint-disable-next-line no-console
console.info(`It is currently ${this.dateToPacificDateTime(jsDate)}.`)
}
this.setCurrentJsDate(jsDate)
this.setCurrentDate(this.dateToYyyyMmDd(jsDate))
// check authorizations
try {
// get Keycloak roles
const jwt = this.getJWT()
const keycloakRoles = this.fetchKeycloakRoles(jwt)
this.setKeycloakRoles(keycloakRoles)
// safety check
if (!this.businessId && !this.tempRegNumber) {
throw new Error('Missing Business ID or Temporary Registration Number')
}
// check if current user is authorized
const response = await AuthServices.fetchAuthorizations(
this.getAuthApiUrl, this.businessId || this.tempRegNumber
)
this.storeAuthorizations(response) // throws if no role
} catch (error) {
console.log(error) // eslint-disable-line no-console
if (this.businessId) this.businessAuthErrorDialog = true
if (this.tempRegNumber) this.nameRequestAuthErrorDialog = true
return // do not execute remaining code
}
// fetch user info and update Launch Darkly
// and save user's Keycloak GUID
try {
const userInfo = await AuthServices.fetchUserInfo(this.getAuthApiUrl)
this.setUserInfo(userInfo)
await this.updateLaunchDarkly(userInfo)
this.setUserKeycloakGuid(userInfo.keycloakGuid)
} catch (error) {
// just log the error -- no need to halt app
// eslint-disable-next-line no-console
console.log('Error fetching user info or updating Launch Darkly =', error)
}
// is this a business entity?
if (this.businessId) {
try {
await this.fetchBusinessData() // throws on error
await this.fetchStoreAddressData() // business address
this.dataLoaded = true
} catch (error) {
console.log(error) // eslint-disable-line no-console
this.dashboardUnavailableDialog = true
// Log exception to Sentry due to incomplete business data.
// At this point the system doesn't know why it's incomplete.
// Since this is not an expected behaviour, report this.
Sentry.captureException(error)
}
}
// is this a draft app entity (incorporation/registration/amalgamation)?
if (this.tempRegNumber) {
try {
await this.fetchDraftAppData() // throws on error
this.dataLoaded = true
} catch (error) {
console.log(error) // eslint-disable-line no-console
this.nameRequestInvalidDialog = true
}
}
},
/** Fetches and stores the business data. */
async fetchBusinessData (): Promise<void> {
const data = await Promise.all([
// FUTURE: all of these should be store actions
AuthServices.fetchEntityInfo(this.getAuthApiUrl, this.businessId),
this.loadBusinessInfo(),
LegalServices.fetchTasks(this.businessId),
this.loadFilings(this.businessId || this.tempRegNumber),
LegalServices.fetchParties(this.businessId)
])
if (!data || data.length !== 5) throw new Error('Incomplete business data')
// store data from calls above
this.storeEntityInfo(data[0])
this.storeTasks(data[2])
this.storeParties(data[4])
// now that we have business info, load state filing
await this.loadStateFiling()
// now that we know entity type, store config object
this.storeConfigObject()
},
async fetchStoreAddressData ():Promise<void> {
let hasBAError = false
const data = await Promise.resolve(
LegalServices.fetchAddresses(this.businessId)
).catch(error => {
if (error.response.status === 404 &&
error.response.config.url.includes('addresses') &&
error.response.data.message.includes('address not found')) hasBAError = true
})
if (data) {
this.storeAddresses(data)
} else if (hasBAError) { // if 404 and business address not found
this.storeAddresses({ data: { businessOffice: null } })
} else {
throw new Error('Incomplete business data')
}
},
/** Fetches and stores the draft application data. */
async fetchDraftAppData (): Promise<void> {
this.nameRequestInvalidType = null // reset for new fetches
const application = await LegalServices.fetchDraftApp(this.tempRegNumber)
// handle draft application
this.storeDraftApp(application)
// if this app is a task (not a filing), and it has a NR, load it
if (this.isAppTask && this.localNrNumber) {
const nr = await LegalServices.fetchNameRequest(this.localNrNumber)
this.storeNrData(nr, application)
}
},
/** Gets Keycloak JWT and parses it. */
getJWT (): any {
const keycloakToken = sessionStorage.getItem(SessionStorageKeys.KeyCloakToken)
if (keycloakToken) {
return this.parseKcToken(keycloakToken)
}
throw new Error('Error getting Keycloak token')
},
/** Decodes and parses Keycloak token. */
parseKcToken (token: string): any {
try {
const base64Url = token.split('.')[1]
const base64 = decodeURIComponent(window.atob(base64Url).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
}).join(''))
return JSON.parse(base64)
} catch (error) {
throw new Error('Error parsing token - ' + error)
}
},
/** Fetches Keycloak roles from JWT. */
fetchKeycloakRoles (jwt: any): Array<string> {
const keycloakRoles = jwt.roles
if (keycloakRoles && keycloakRoles.length > 0) {
return keycloakRoles
}
throw new Error('Error getting Keycloak roles')
},
storeAuthorizations (response: any): void {
// NB: roles array may contain 'view', 'edit' or nothing
const authRoles = response?.data?.roles
if (authRoles && authRoles.length > 0) {
this.setAuthRoles(authRoles)
} else {
throw new Error('Invalid auth roles')
}
},
/** Updates Launch Darkly with current user info. */
async updateLaunchDarkly (userInfo: any): Promise<void> {
// since username is unique, use it as the user key
const key: string = userInfo.username
const email: string = userInfo.contacts[0]?.email || userInfo.email
const firstName: string = userInfo?.firstname
const lastName: string = userInfo?.lastname
// store Keycloak roles in custom object
const custom = { roles: this.getKeycloakRoles } as any
await UpdateLdUser(key, email, firstName, lastName, custom)
},
/** Stores entity info from Auth API. */
storeEntityInfo (response: any): void {
const contacts = response?.data?.contacts
// ensure we received the right looking object
// but allow empty contacts array
if (contacts) {
// at this time there is at most 1 contact
const contact = contacts.length > 0 && contacts[0]
if (contact) {
this.setBusinessEmail(contact.email)
this.setBusinessPhone(contact.phone)
this.setBusinessPhoneExtension(contact.phoneExtension)
}
// store Corp Type Code to compare with Legal Type in business info
const corpTypeCd = response?.data?.corpType?.code
if (corpTypeCd) this.setCorpTypeCd(corpTypeCd)
} else {
throw new Error('Invalid entity contact info')
}
},
/** Verifies and stores a draft application's data. */
storeDraftApp (application: any): void {
const filing = application?.filing
const filingName = filing.header?.name as FilingTypes
if (!filing || !filing.header || !filingName) {
throw new Error(`Invalid ${filingName} filing`)
}
const status = filing.header.status as FilingStatus
if (!status) {
throw new Error(`Invalid ${filingName} filing - filing status`)
}
const isAmalgamation = (filingName === FilingTypes.AMALGAMATION_APPLICATION)
const isIncorporationApplication = (filingName === FilingTypes.INCORPORATION_APPLICATION)
const isRegistration = (filingName === FilingTypes.REGISTRATION)
let entityStatus: EntityStatus
switch (status) {
case FilingStatus.DRAFT:
case FilingStatus.PENDING:
// this is a draft application
if (isAmalgamation) entityStatus = EntityStatus.DRAFT_AMALGAMATION
else if (isIncorporationApplication) entityStatus = EntityStatus.DRAFT_INCORP_APP
else if (isRegistration) entityStatus = EntityStatus.DRAFT_REGISTRATION
else throw new Error(`Invalid ${filingName} filing - filing name`)
break
case FilingStatus.COMPLETED:
case FilingStatus.PAID:
// this is a filed application
if (isAmalgamation) entityStatus = EntityStatus.FILED_AMALGAMATION
else if (isIncorporationApplication) entityStatus = EntityStatus.FILED_INCORP_APP
else if (isRegistration) entityStatus = EntityStatus.FILED_REGISTRATION
else throw new Error(`Invalid ${filingName} filing - filing name`)
break
default:
throw new Error(`Invalid ${filingName} filing - filing status`)
}
// special check for amalgamation application
if (isAmalgamation && !filing.amalgamationApplication.type) {
throw new Error('Missing amalgamation type')
}
// NB: different object from actual NR
const nameRequest = filing[filingName].nameRequest as {
legalName?: string
legalType: CorpTypeCd
nrNumber: string
}
if (!nameRequest) {
throw new Error(`Invalid ${filingName} filing - Name Request object`)
}
// verify that this is a supported entity type
const legalType = nameRequest.legalType
if (!legalType || !this.supportedEntityTypes.includes(legalType)) {
throw new Error(`Invalid ${filingName} filing - legal type`)
}
// store business info
this.setEntityStatus(entityStatus)
this.setIdentifier(this.tempRegNumber)
this.setLegalType(legalType)
this.setGoodStanding(true) // draft apps are always in good standing
// save local NR Number if present
this.localNrNumber = nameRequest.nrNumber || null
// store Legal Name if present
if (nameRequest.legalName) this.setLegalName(nameRequest.legalName)
// store the application in the right list
if (this.isAppTask) this.storeDraftAppTask(application)
else if (this.isAppFiling) this.storeDraftAppFiling(application)
else throw new Error(`Invalid ${filingName} filing - filing status`)
},
/** Stores draft application as a task in the Todo List. */
storeDraftAppTask (application: any): void {
const filing = application.filing as TaskTodoIF
// NB: these were already validated in storeDraftApp()
const header = filing.header
const data = filing[header.name]
const description = GetCorpFullDescription(data.nameRequest.legalType)
const dba = this.isSoleProp ? ' / Doing Business As (DBA) ' : ' '
const filingName = EnumUtilities.filingTypeToName(header.name, null, data.type)
// save display name for later
filing.displayName = `${description}${dba}${filingName}`
// add this as a task item
const taskItem: ApiTaskIF = {
enabled: true,
order: 1,
task: { filing }
}
this.setTasks([taskItem])
},
/** Stores filed application as a filing in the Filing History List. */
storeDraftAppFiling (application: any): void {
const filing = application.filing as TaskTodoIF
// NB: these were already validated in storeDraftApp()
const header = filing.header
const data = filing[header.name]
// set addresses
this.storeAddresses({ data: data.offices || [] })
// set parties
this.storeParties({ data: { parties: data.parties || [] } })
const description = GetCorpFullDescription(data.nameRequest.legalType)
const filingName = EnumUtilities.filingTypeToName(header.name, null, data.type)
// add this as a filing item
const filingItem = {
availableOnPaperOnly: header.availableOnPaperOnly,
businessIdentifier: this.getIdentifier,
commentsCount: application.commentsCount,
commentsLink: application.commentsLink,
displayLedger: application.displayLedger,
displayName: `${description} ${filingName}`,
documentsLink: application.documentsLink,
effectiveDate: this.apiToUtcString(header.effectiveDate),
filingId: header.filingId,
filingLink: application.filingLink,
filingSubType: data.type,
isFutureEffective: header.isFutureEffective,
name: header.name,
status: header.status,
submittedDate: this.apiToUtcString(header.date),
submitter: header.submitter,
data: {
applicationDate: this.dateToYyyyMmDd(this.apiToDate(header.date)),
legalFilings: [header.name]
}
} as ApiFilingIF
this.setFilings([filingItem])
},
storeNrData (nr: NameRequestIF, app: any): void {
// verify that NR is valid
const error = this.isNrInvalid(nr)
if (error) {
this.nameRequestInvalidDialog = true
throw new Error(error)
}
// verify that NR type matches entity type from application
if (nr.legalType !== this.getLegalType) {
this.nameRequestInvalidDialog = true
throw new Error('Invalid NR request type')
}
// if IA is not yet completed, check if NR is consumable
// (once IA is completed, NR state will be CONSUMED)
if (app.filing.header.status !== FilingStatus.COMPLETED) {
const nrState = this.getNrState(nr) as NameRequestStates
if (nrState !== NameRequestStates.APPROVED && nrState !== NameRequestStates.CONDITIONAL) {
this.nameRequestInvalidDialog = true
this.nameRequestInvalidType = nrState
throw new Error('NR not consumable')
}
}
// save the NR
this.setNameRequest(nr)
// save the approved name
const entityName = this.getNrApprovedName(nr) || ''
this.setLegalName(entityName || 'Unknown Name')
},
storeTasks (response: any): void {
const tasks = response?.data?.tasks as ApiTaskIF[]
if (tasks) {
this.setTasks(tasks)
} else {
throw new Error('Invalid tasks')
}
},
storeAddresses (response: any): void {
if (response?.data) {
if (response.data.registeredOffice) {
this.setRegisteredAddress(this.omitProps(response.data.registeredOffice,
['deliveryAddress', 'mailingAddress'], ['addressType']))
}
if (response.data.recordsOffice) {
this.setRecordsAddress(this.omitProps(response.data.recordsOffice,
['deliveryAddress', 'mailingAddress'], ['addressType']))
}
if (response.data.businessOffice) {
this.setBusinessAddress(this.omitProps(response.data.businessOffice,
['deliveryAddress', 'mailingAddress'], ['addressType']))
}
} else {
throw new Error('invalid office addresses')
}
},
storeParties (response: any): void {
const parties = response?.data?.parties as PartyIF[]
if (parties) {
this.setParties(parties)
} else {
throw new Error('Invalid parties')
}
},
/** Stores config object matching the specified entity type. */
storeConfigObject (): void {
const configObject = ConfigJson.find(x => x.entityType === this.getLegalType)
this.setConfigObject(configObject)
},
/** Creates a draft filing and navigates to the Create UI to file a company dissolution filing. */
async dissolveCompany (): Promise<void> {
const dissolutionFiling = this.buildDissolutionFiling()
const draftDissolution = await LegalServices.createFiling(this.getIdentifier, dissolutionFiling, true)
const draftDissolutionId = +draftDissolution?.header?.filingId
if (!draftDissolution || isNaN(draftDissolutionId)) {
throw new Error('Invalid API response')
}
const url = `${this.getCreateUrl}define-dissolution?id=${this.getIdentifier}`
navigate(url)
},
/** Handles Exit click event from dialogs. */
onClickExit (): void {
navigate(this.getBusinessUrl)
},
/** Handles Retry click event from dialogs. */
onClickRetry (hard = false): void {
if (hard) {
// clear session variables and hard-reload the page
// to force new login and try again
sessionStorage.clear()
location.reload()
} else {
// try to fetch the data again
this.dashboardUnavailableDialog = false
this.businessAuthErrorDialog = false
this.nameRequestAuthErrorDialog = false
this.nameRequestInvalidDialog = false
this.fetchData()
}
},
/** Request and Download Business Summary Document. */
async downloadBusinessSummary (): Promise<void> {
this.setFetchingDataSpinner(true)
const summaryDocument: DocumentIF = {
title: 'Summary',
filename: `${this.businessId} Summary - ${this.getCurrentDate}.pdf`,
link: `businesses/${this.businessId}/documents/summary`
}
await LegalServices.fetchDocument(summaryDocument).catch(error => {
// eslint-disable-next-line no-console
console.log('fetchDocument() error =', error)
this.downloadErrorDialog = true
})
this.setFetchingDataSpinner(false)
},
/** Direct to Digital Credentials. **/
viewAddDigitalCredentials (): void {
this.$router.push({ name: Routes.DIGITAL_CREDENTIALS })
}
}
}
</script>
<style lang="scss">
.loading-container.grayed-out {
// these are the same styles as dialog overlay:
opacity: 0.46;
background-color: rgb(33, 33, 33); // grey darken-4
border-color: rgb(33, 33, 33); // grey darken-4
}
</style>