-
Notifications
You must be signed in to change notification settings - Fork 25
/
dashboard.vue
175 lines (158 loc) · 4.85 KB
/
dashboard.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
<template>
<v-container fluid class="py-12">
<v-overlay v-model="loadingProducts">
<v-progress-circular color="primary" size="50" indeterminate />
</v-overlay>
<h1 class="dash-header">{{ isSbcStaff ? 'SBC Staff' : 'BC' }} Registries Dashboard</h1>
<p class="dash-header-info ma-0 pt-3">Access to your BC Registries account product and services</p>
<h3 v-if="!loadingProducts" class="dash-sub-header">
My Products and Services
<span class="font-weight-regular">({{ subscribedProducts.length }})</span>
</h3>
<v-row v-if="!loadingProducts" no-gutters>
<div class="col-md-8 col-sm-12">
<UserProduct
v-for="product in subscribedProducts"
:key="product.code"
class="mt-5"
:product="product"
/>
</div>
<div class="pl-6 col-md-4 col-sm-12">
<v-container fluid rounded class="dash-container-info mt-5 white">
<h4>Add Product and Services</h4>
<p class="ma-0 pt-3">
To request access to additional products and services, contact the account
Administrator of your BC Registries account.
</p>
</v-container>
</div>
</v-row>
</v-container>
</template>
<script lang="ts">
import Vue from 'vue'
import { SessionStorageKeys } from 'sbc-common-components/src/util/constants'
import { mapGetters } from 'vuex'
import UserProduct from '@/components/UserProduct.vue'
import { ProductCode, ProductStatus } from '@/enums'
import { fetchAccountProducts, fetchOrganization, getKeycloakRoles, getProductInfo, sleep } from '@/utils'
export default Vue.extend ({
components: {
UserProduct,
},
asyncData ({ $config, redirect, store }) {
// if user is not logged in, redirect to home page
const token = sessionStorage.getItem(SessionStorageKeys.KeyCloakToken)
if (!token) {
return redirect($config.baseURL)
}
// get roles
let roles: string[]
try {
roles = getKeycloakRoles()
} catch {
roles = []
}
store.commit('setRoles', roles)
// check if user is staff
let isStaff: boolean
try {
isStaff = roles?.includes('staff') || false
} catch {
isStaff = false
}
store.commit('setStaff', isStaff)
// if user is staff, redirect to Business Registry staff dashboard
if (isStaff) {
return redirect($config.businessRegistryStaffDashboard)
}
},
data () {
return {
getProductInfo, // for use in template
loadingProducts: false,
subscribedProducts: [],
}
},
computed: {
...mapGetters(['isSbcStaff', 'getRoles', 'getAccountId']),
},
async mounted () {
// get account id from object in session storage
// wait up to 10 sec for current account to be synced (typically by SbcHeader)
this.loadingProducts = true
let accountId: number
for (let i = 0; i < 100; i++) {
const currentAccount = sessionStorage.getItem(SessionStorageKeys.CurrentAccount)
const account = JSON.parse(currentAccount)
accountId = account?.id as number
if (accountId) break
await sleep(100)
}
this.$store.commit('setAccountId', accountId)
// check if user is SBC staff
let isSbcStaff: boolean
if (this.getRoles?.includes('gov_account_user')) {
try {
const org = await fetchOrganization(accountId)
isSbcStaff = org?.branchName?.includes('Service BC') || false
} catch {
isSbcStaff = false
}
}
this.$store.commit('setSbcStaff', isSbcStaff)
let products = []
if (this.isSbcStaff) {
// static products list for SBC staff
products = [
{
code: ProductCode.BUSINESS,
subscriptionStatus: ProductStatus.ACTIVE
},
{
code: ProductCode.PPR,
subscriptionStatus: ProductStatus.ACTIVE
},
]
} else {
// get products list from API
products = await fetchAccountProducts(this.getAccountId)
}
const currentProducts = products.filter(
product => product.subscriptionStatus === ProductStatus.ACTIVE)
// only show products with no placeholder
for (let i = 0; i < currentProducts.length; i++) {
const thisProduct = getProductInfo(this.$config, currentProducts[i].code)
if (thisProduct.title !== 'placeholder_title') {
this.subscribedProducts.push(thisProduct)
}
}
// wait a short amount so it doesn't look glitchy when products come back immediately
setTimeout(() => { this.loadingProducts = false }, 250)
}
})
</script>
<style lang="scss" scoped>
@import '@/assets/scss/theme.scss';
.dash-container-info {
padding: 30px;
p {
color: $gray7;
font-size: $px-14;
line-height: 1.375rem;
}
}
.dash-header {
color: $gray9;
}
.dash-header-info {
color: $gray7;
font-size: $px-16;
}
.dash-sub-header {
color: $gray9;
font-size: $px-18;
padding-top: 50px;
}
</style>