/
DashboardArea.vue
894 lines (764 loc) · 30.3 KB
/
DashboardArea.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<div class="dashboard">
<BrandedLoader v-if="isLoading" />
<div v-else class="dashboard__wrap">
<div class="dashboard__wrap__main-area">
<NavigationArea v-if="!isNavigationHidden" class="dashboard__wrap__main-area__navigation" />
<MobileNavigation v-if="!isNavigationHidden" class="dashboard__wrap__main-area__mobile-navigation" />
<div
class="dashboard__wrap__main-area__content-wrap"
:class="{ 'no-nav': isNavigationHidden }"
>
<div ref="dashboardContent" class="dashboard__wrap__main-area__content-wrap__container">
<BetaSatBar v-if="isBetaSatellite" />
<MFARecoveryCodeBar v-if="showMFARecoveryCodeBar" :open-generate-modal="generateNewMFARecoveryCodes" />
<div class="banner-container dashboard__wrap__main-area__content-wrap__container__content">
<UpgradeNotification
v-if="isPaidTierBannerShown"
:open-add-p-m-modal="togglePMModal"
/>
<ProjectLimitBanner
v-if="isProjectLimitBannerShown"
:dashboard-ref="dashboardContent"
:on-upgrade-clicked="togglePMModal"
/>
<v-banner
v-if="isAccountFrozen && !isLoading && dashboardContent"
severity="critical"
:dashboard-ref="dashboardContent"
>
<template #text>
<p class="medium">Your account was frozen due to billing issues. Please update your payment information.</p>
<p class="link" @click.stop.self="redirectToBillingPage">To Billing Page</p>
</template>
</v-banner>
<v-banner
v-if="isAccountWarned && !isLoading && dashboardContent"
severity="warning"
:dashboard-ref="dashboardContent"
>
<template #text>
<p class="medium">Your account will be frozen soon due to billing issues. Please update your payment information.</p>
<p class="link" @click.stop.self="redirectToBillingPage">To Billing Page</p>
</template>
</v-banner>
<v-banner
v-if="limitState.hundredIsShown && !isLoading && dashboardContent"
severity="critical"
:on-click="() => setIsHundredLimitModalShown(true)"
:dashboard-ref="dashboardContent"
>
<template #text>
<p class="medium">{{ limitState.hundredLabel }}</p>
<p class="link" @click.stop.self="togglePMModal">Upgrade now</p>
</template>
</v-banner>
<v-banner
v-if="limitState.eightyIsShown && !isLoading && dashboardContent"
severity="warning"
:on-click="() => setIsEightyLimitModalShown(true)"
:dashboard-ref="dashboardContent"
>
<template #text>
<p class="medium">{{ limitState.eightyLabel }}</p>
<p class="link" @click.stop.self="togglePMModal">Upgrade now</p>
</template>
</v-banner>
</div>
<router-view class="dashboard__wrap__main-area__content-wrap__container__content" />
<div class="banner-container__bottom dashboard__wrap__main-area__content-wrap__container__content">
<UploadNotification
v-if="isLargeUploadNotificationShown && !isLargeUploadWarningNotificationShown && isBucketsView"
wording-bold="The web browser is best for uploads up to 1GB."
wording="To upload larger files, check our recommendations"
:notification-icon="CloudIcon"
:warning-notification="false"
:on-close-click="onNotificationCloseClick"
/>
<UploadNotification
v-if="isLargeUploadWarningNotificationShown"
wording-bold="Trying to upload a large file?"
wording="Check the recommendations for your use case"
:notification-icon="WarningIcon"
:warning-notification="true"
:on-close-click="onWarningNotificationCloseClick"
/>
</div>
</div>
</div>
</div>
</div>
<div v-if="debugTimerShown && !isLoading" class="dashboard__debug-timer">
<p>Remaining session time: <b class="dashboard__debug-timer__bold">{{ debugTimerText }}</b></p>
</div>
<limit-warning-modal
v-if="isHundredLimitModalShown && !isLoading"
severity="critical"
:on-close="() => setIsHundredLimitModalShown(false)"
:title="limitState.hundredModalTitle"
:limit-type="limitState.hundredModalLimitType"
:on-upgrade="togglePMModal"
/>
<limit-warning-modal
v-if="isEightyLimitModalShown && !isLoading"
severity="warning"
:on-close="() => setIsEightyLimitModalShown(false)"
:title="limitState.eightyModalTitle"
:limit-type="limitState.eightyModalLimitType"
:on-upgrade="togglePMModal"
/>
<AllModals />
<!-- IMPORTANT! Make sure this modal is positioned as the last element here so that it is shown on top of everything else -->
<InactivityModal
v-if="inactivityModalShown"
:on-continue="refreshSession"
:on-logout="handleInactive"
:on-close="closeInactivityModal"
:initial-seconds="inactivityModalTime / 1000"
/>
</div>
</template>
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue';
import { ErrorUnauthorized } from '@/api/errors/ErrorUnauthorized';
import { RouteConfig } from '@/router';
import { CouponType } from '@/types/coupons';
import { Project } from '@/types/projects';
import { FetchState } from '@/utils/constants/fetchStateEnum';
import { LocalData } from '@/utils/localData';
import { User } from '@/types/users';
import { AuthHttpApi } from '@/api/auth';
import { AnalyticsHttpApi } from '@/api/analytics';
import { AnalyticsErrorEventSource } from '@/utils/constants/analyticsEventNames';
import { useNotify, useRouter } from '@/utils/hooks';
import { MODALS } from '@/utils/constants/appStatePopUps';
import { useABTestingStore } from '@/store/modules/abTestingStore';
import { useUsersStore } from '@/store/modules/usersStore';
import { useProjectMembersStore } from '@/store/modules/projectMembersStore';
import { useBillingStore } from '@/store/modules/billingStore';
import { useAppStore } from '@/store/modules/appStore';
import { useAccessGrantsStore } from '@/store/modules/accessGrantsStore';
import { useBucketsStore } from '@/store/modules/bucketsStore';
import { useProjectsStore } from '@/store/modules/projectsStore';
import { useNotificationsStore } from '@/store/modules/notificationsStore';
import { useObjectBrowserStore } from '@/store/modules/objectBrowserStore';
import UploadNotification from '@/components/notifications/UploadNotification.vue';
import NavigationArea from '@/components/navigation/NavigationArea.vue';
import InactivityModal from '@/components/modals/InactivityModal.vue';
import BetaSatBar from '@/components/infoBars/BetaSatBar.vue';
import MFARecoveryCodeBar from '@/components/infoBars/MFARecoveryCodeBar.vue';
import AllModals from '@/components/modals/AllModals.vue';
import MobileNavigation from '@/components/navigation/MobileNavigation.vue';
import LimitWarningModal from '@/components/modals/LimitWarningModal.vue';
import VBanner from '@/components/common/VBanner.vue';
import UpgradeNotification from '@/components/notifications/UpgradeNotification.vue';
import ProjectLimitBanner from '@/components/notifications/ProjectLimitBanner.vue';
import BrandedLoader from '@/components/common/BrandedLoader.vue';
import CloudIcon from '@/../static/images/notifications/cloudAlert.svg';
import WarningIcon from '@/../static/images/notifications/circleWarning.svg';
const bucketsStore = useBucketsStore();
const appStore = useAppStore();
const agStore = useAccessGrantsStore();
const billingStore = useBillingStore();
const pmStore = useProjectMembersStore();
const usersStore = useUsersStore();
const abTestingStore = useABTestingStore();
const projectsStore = useProjectsStore();
const notificationsStore = useNotificationsStore();
const obStore = useObjectBrowserStore();
const notify = useNotify();
const nativeRouter = useRouter();
const router = reactive(nativeRouter);
const auth: AuthHttpApi = new AuthHttpApi();
const analytics: AnalyticsHttpApi = new AnalyticsHttpApi();
const resetActivityEvents: string[] = ['keypress', 'mousemove', 'mousedown', 'touchmove'];
const inactivityModalTime = 60000;
// Minimum number of recovery codes before the recovery code warning bar is shown.
const recoveryCodeWarningThreshold = 4;
const inactivityTimerId = ref<ReturnType<typeof setTimeout> | null>();
const sessionRefreshTimerId = ref<ReturnType<typeof setTimeout> | null>();
const debugTimerId = ref<ReturnType<typeof setTimeout> | null>();
const inactivityModalShown = ref<boolean>(false);
const isSessionActive = ref<boolean>(false);
const isSessionRefreshing = ref<boolean>(false);
const isHundredLimitModalShown = ref<boolean>(false);
const isEightyLimitModalShown = ref<boolean>(false);
const debugTimerText = ref<string>('');
const dashboardContent = ref<HTMLElement | null>(null);
/**
* Returns the session duration from the store.
*/
const sessionDuration = computed((): number => {
return appStore.state.config.inactivityTimerDuration * 1000;
});
/**
* Returns the session refresh interval from the store.
*/
const sessionRefreshInterval = computed((): number => {
return sessionDuration.value / 2;
});
/**
* Indicates whether to display the session timer for debugging.
*/
const debugTimerShown = computed((): boolean => {
return appStore.state.config.inactivityTimerViewerEnabled;
});
/**
* Indicates if account was frozen due to billing issues.
*/
const isAccountFrozen = computed((): boolean => {
return usersStore.state.user.freezeStatus.frozen;
});
/**
* Indicates if account was warned due to billing issues.
*/
const isAccountWarned = computed((): boolean => {
return usersStore.state.user.freezeStatus.warned;
});
/**
* Returns all needed information for limit banner and modal when bandwidth or storage close to limits.
*/
type LimitedState = {
eightyIsShown: boolean;
hundredIsShown: boolean;
eightyLabel: string;
eightyModalLimitType: string;
eightyModalTitle: string;
hundredLabel: string;
hundredModalTitle: string;
hundredModalLimitType: string;
}
const limitState = computed((): LimitedState => {
const result: LimitedState = {
eightyIsShown: false,
hundredIsShown: false,
eightyLabel: '',
eightyModalLimitType: '',
eightyModalTitle: '',
hundredLabel: '',
hundredModalTitle: '',
hundredModalLimitType: '',
};
if (usersStore.state.user.paidTier || isAccountFrozen.value) {
return result;
}
const currentLimits = projectsStore.state.currentLimits;
const limitTypeArr = [
{ name: 'bandwidth', usedPercent: Math.round(currentLimits.bandwidthUsed * 100 / currentLimits.bandwidthLimit) },
{ name: 'storage', usedPercent: Math.round(currentLimits.storageUsed * 100 / currentLimits.storageLimit) },
{ name: 'segment', usedPercent: Math.round(currentLimits.segmentUsed * 100 / currentLimits.segmentLimit) },
];
const hundredPercent = [] as string[];
const eightyPercent = [] as string[];
limitTypeArr.forEach((limitType) => {
if (limitType.usedPercent >= 80) {
if (limitType.usedPercent >= 100) {
hundredPercent.push(limitType.name);
} else {
eightyPercent.push(limitType.name);
}
}
});
if (eightyPercent.length !== 0) {
result.eightyIsShown = true;
const eightyPercentString = eightyPercent.join(' and ');
result.eightyLabel = `You've used 80% of your ${eightyPercentString} limit. Avoid interrupting your usage by upgrading your account.`;
result.eightyModalTitle = `80% ${eightyPercentString} limit used`;
result.eightyModalLimitType = eightyPercentString;
}
if (hundredPercent.length !== 0) {
result.hundredIsShown = true;
const hundredPercentString = hundredPercent.join(' and ');
result.hundredLabel = `URGENT: You’ve reached the ${hundredPercentString} limit for your project. Upgrade to avoid any service interruptions.`;
result.hundredModalTitle = `URGENT: You’ve reached the ${hundredPercentString} limit for your project.`;
result.hundredModalLimitType = hundredPercentString;
}
return result;
});
/**
* Indicates if navigation sidebar is hidden.
*/
const isNavigationHidden = computed((): boolean => {
return (!isAllProjectsDashboard.value && isOnboardingTour.value)
|| isCreateProjectPage.value;
});
/* whether all projects dashboard should be used */
const isAllProjectsDashboard = computed((): boolean => {
return appStore.state.config.allProjectsDashboard;
});
/* whether the project limit banner should be shown. */
const isProjectLimitBannerShown = computed((): boolean => {
return !LocalData.getProjectLimitBannerHidden()
&& isProjectListPage.value
&& (hasReachedProjectLimit.value || !usersStore.state.user.paidTier);
});
/**
* Returns whether the user has reached project limits.
*/
const hasReachedProjectLimit = computed((): boolean => {
const projectLimit: number = usersStore.state.user.projectLimit;
const projectsCount: number = projectsStore.projectsCount(usersStore.state.user.id);
return projectsCount === projectLimit;
});
/* whether the paid tier banner should be shown */
const isPaidTierBannerShown = computed((): boolean => {
return !usersStore.state.user.paidTier
&& !isOnboardingTour.value
&& joinedWhileAgo.value
&& isDashboardPage.value;
});
/* whether the user joined more than 7 days ago */
const joinedWhileAgo = computed((): boolean => {
const createdAt = usersStore.state.user.createdAt as Date | null;
if (!createdAt) return true; // true so we can show the banner regardless
const millisPerDay = 24 * 60 * 60 * 1000;
return ((Date.now() - createdAt.getTime()) / millisPerDay) > 7;
});
/**
* Indicates if current route is projects list page.
*/
const isProjectListPage = computed((): boolean => {
return router.currentRoute.name === RouteConfig.ProjectsList.name;
});
/**
* Indicates if current route is onboarding tour.
*/
const isOnboardingTour = computed((): boolean => {
return router.currentRoute.path.includes(RouteConfig.OnboardingTour.path);
});
/**
* Indicates if satellite is in beta.
*/
const isBetaSatellite = computed((): boolean => {
return appStore.state.config.isBetaSatellite;
});
/**
* Indicates if loading screen is active.
*/
const isLoading = computed((): boolean => {
return appStore.state.viewsState.fetchState === FetchState.LOADING;
});
/**
* Indicates whether the MFA recovery code warning bar should be shown.
*/
const showMFARecoveryCodeBar = computed((): boolean => {
const user: User = usersStore.state.user;
return user.isMFAEnabled && user.mfaRecoveryCodeCount < recoveryCodeWarningThreshold;
});
/**
* Indicates whether the large upload notification should be shown.
*/
const isLargeUploadNotificationShown = computed((): boolean => {
return appStore.state.viewsState.isLargeUploadNotificationShown;
});
/**
* Indicates whether the large upload warning notification should be shown (file uploading exceeds 1GB).
*/
const isLargeUploadWarningNotificationShown = computed((): boolean => {
return appStore.state.viewsState.isLargeUploadWarningNotificationShown;
});
/**
* Indicates if current route is create project page.
*/
const isCreateProjectPage = computed((): boolean => {
return router.currentRoute.name === RouteConfig.CreateProject.name;
});
/**
* Indicates if current route is the dashboard page.
*/
const isDashboardPage = computed((): boolean => {
return router.currentRoute.name === RouteConfig.ProjectDashboard.name;
});
/**
* Indicates if current route is the bucketsView page.
*/
const isBucketsView = computed((): boolean => {
return router.currentRoute.name === RouteConfig.BucketsManagement.name;
});
/**
* Closes upload notification and persists state in local storage.
*/
function onNotificationCloseClick(): void {
appStore.setLargeUploadNotification(false);
LocalData.setLargeUploadNotificationDismissed();
}
/**
* Closes upload large files warning notification.
*/
function onWarningNotificationCloseClick(): void {
appStore.setLargeUploadWarningNotification(false);
}
/**
* Stores project to vuex store and browser's local storage.
* @param projectID - project id string
*/
function storeProject(projectID: string): void {
projectsStore.selectProject(projectID);
LocalData.setSelectedProjectId(projectID);
}
/**
* Clears timers associated with session refreshing and inactivity.
*/
function clearSessionTimers(): void {
[inactivityTimerId.value, sessionRefreshTimerId.value, debugTimerId.value].forEach(id => {
if (id !== null) clearTimeout(id);
});
}
/**
* Adds DOM event listeners and starts session timers.
*/
function setupSessionTimers(): void {
if (!appStore.state.config.inactivityTimerEnabled) return;
const expiresAt = LocalData.getSessionExpirationDate();
if (expiresAt) {
resetActivityEvents.forEach((eventName: string) => {
document.addEventListener(eventName, onSessionActivity, false);
});
if (expiresAt.getTime() - sessionDuration.value + sessionRefreshInterval.value < Date.now()) {
refreshSession();
}
restartSessionTimers();
}
}
/**
* Restarts timers associated with session refreshing and inactivity.
*/
function restartSessionTimers(): void {
sessionRefreshTimerId.value = setTimeout(async () => {
sessionRefreshTimerId.value = null;
if (isSessionActive.value) {
await refreshSession();
}
}, sessionRefreshInterval.value);
inactivityTimerId.value = setTimeout(async () => {
if (obStore.uploadingLength) {
await refreshSession();
return;
}
if (isSessionActive.value) return;
inactivityModalShown.value = true;
inactivityTimerId.value = setTimeout(async () => {
await handleInactive();
await notify.notify('Your session was timed out.');
}, inactivityModalTime);
}, sessionDuration.value - inactivityModalTime);
if (!debugTimerShown) return;
const debugTimer = () => {
const expiresAt = LocalData.getSessionExpirationDate();
if (expiresAt) {
const ms = Math.max(0, expiresAt.getTime() - Date.now());
const secs = Math.floor(ms/1000)%60;
debugTimerText.value = `${Math.floor(ms/60000)}:${(secs<10 ? '0' : '')+secs}`;
if (ms > 1000) {
debugTimerId.value = setTimeout(debugTimer, 1000);
}
}
};
debugTimer();
}
/**
* Checks if stored project is in fetched projects array and selects it.
* Selects first fetched project if check is not successful.
* @param fetchedProjects - fetched projects array
*/
function selectProject(fetchedProjects: Project[]): void {
const storedProjectID = LocalData.getSelectedProjectId();
const isProjectInFetchedProjects = fetchedProjects.some(project => project.id === storedProjectID);
if (storedProjectID && isProjectInFetchedProjects) {
storeProject(storedProjectID);
return;
}
// Length of fetchedProjects array is checked before selectProject() function call.
storeProject(fetchedProjects[0].id);
}
/**
* Refreshes session and resets session timers.
*/
async function refreshSession(): Promise<void> {
isSessionRefreshing.value = true;
try {
LocalData.setSessionExpirationDate(await auth.refreshSession());
} catch (error) {
await notify.error((error instanceof ErrorUnauthorized) ? 'Your session was timed out.' : error.message, AnalyticsErrorEventSource.OVERALL_SESSION_EXPIRED_ERROR);
await handleInactive();
isSessionRefreshing.value = false;
return;
}
clearSessionTimers();
restartSessionTimers();
inactivityModalShown.value = false;
isSessionActive.value = false;
isSessionRefreshing.value = false;
}
/**
* Performs logout and cleans event listeners and session timers.
*/
async function handleInactive(): Promise<void> {
await analytics.pageVisit(RouteConfig.Login.path);
await router.push(RouteConfig.Login.path);
await Promise.all([
pmStore.clear(),
projectsStore.clear(),
usersStore.clear(),
agStore.stopWorker(),
agStore.clear(),
notificationsStore.clear(),
bucketsStore.clear(),
appStore.clear(),
billingStore.clear(),
abTestingStore.reset(),
obStore.clear(),
]);
resetActivityEvents.forEach((eventName: string) => {
document.removeEventListener(eventName, onSessionActivity);
});
clearSessionTimers();
inactivityModalShown.value = false;
try {
await auth.logout();
} catch (error) {
if (error instanceof ErrorUnauthorized) return;
await notify.error(error.message, AnalyticsErrorEventSource.OVERALL_SESSION_EXPIRED_ERROR);
}
}
function setIsEightyLimitModalShown(value: boolean): void {
isEightyLimitModalShown.value = value;
}
function setIsHundredLimitModalShown(value: boolean): void {
isHundredLimitModalShown.value = value;
}
/**
* Toggles MFA recovery modal visibility.
*/
function toggleMFARecoveryModal(): void {
appStore.updateActiveModal(MODALS.mfaRecovery);
}
/**
* Generates new MFA recovery codes and toggles popup visibility.
*/
async function generateNewMFARecoveryCodes(): Promise<void> {
try {
await usersStore.generateUserMFARecoveryCodes();
toggleMFARecoveryModal();
} catch (error) {
await notify.error(error.message, AnalyticsErrorEventSource.OVERALL_APP_WRAPPER_ERROR);
}
}
/**
* Opens add payment method modal.
*/
function togglePMModal(): void {
isHundredLimitModalShown.value = false;
isEightyLimitModalShown.value = false;
appStore.updateActiveModal(MODALS.addPaymentMethod);
}
/**
* Disables session inactivity modal visibility.
*/
function closeInactivityModal(): void {
inactivityModalShown.value = false;
}
/**
* Redirects to Billing Page.
*/
async function redirectToBillingPage(): Promise<void> {
await router.push(RouteConfig.Account.with(RouteConfig.Billing.with(RouteConfig.BillingPaymentMethods)).path);
}
/**
* Resets inactivity timer and refreshes session if necessary.
*/
async function onSessionActivity(): Promise<void> {
if (inactivityModalShown.value || isSessionActive.value) return;
if (sessionRefreshTimerId.value === null && !isSessionRefreshing.value) {
await refreshSession();
}
isSessionActive.value = true;
}
/**
* Lifecycle hook after initial render.
* Pre fetches user`s and project information.
*/
onMounted(async () => {
usersStore.$onAction((action) => {
if (action.name === 'clear') clearSessionTimers();
});
if (LocalData.getLargeUploadNotificationDismissed()) {
appStore.setLargeUploadNotification(false);
}
try {
await usersStore.getUser();
await usersStore.getFrozenStatus();
await abTestingStore.fetchValues();
await usersStore.getSettings();
setupSessionTimers();
} catch (error) {
if (!(error instanceof ErrorUnauthorized)) {
appStore.changeState(FetchState.ERROR);
await notify.error(error.message, AnalyticsErrorEventSource.OVERALL_APP_WRAPPER_ERROR);
}
setTimeout(async () => await router.push(RouteConfig.Login.path), 1000);
return;
}
try {
agStore.stopWorker();
await agStore.startWorker();
} catch (error) {
await notify.error(`Unable to set access grants wizard. ${error.message}`, AnalyticsErrorEventSource.OVERALL_APP_WRAPPER_ERROR);
}
try {
const couponType = await billingStore.setupAccount();
if (couponType === CouponType.NoCoupon) {
await notify.error(`The coupon code was invalid, and could not be applied to your account`, AnalyticsErrorEventSource.OVERALL_APP_WRAPPER_ERROR);
}
if (couponType === CouponType.SignupCoupon) {
await notify.success(`The coupon code was added successfully`);
}
} catch (error) {
await notify.error(`Unable to setup account. ${error.message}`, AnalyticsErrorEventSource.OVERALL_APP_WRAPPER_ERROR);
}
try {
await billingStore.getCreditCards();
} catch (error) {
await notify.error(`Unable to get credit cards. ${error.message}`, AnalyticsErrorEventSource.OVERALL_APP_WRAPPER_ERROR);
}
let projects: Project[] = [];
try {
projects = await projectsStore.getProjects();
} catch (error) {
return;
}
if (!appStore.state.config.allProjectsDashboard) {
try {
if (!projects.length) {
await projectsStore.createDefaultProject(usersStore.state.user.id);
} else {
selectProject(projects);
}
const onboardingPath = RouteConfig.OnboardingTour.with(appStore.firstOnboardingStep).path;
if (usersStore.shouldOnboard && router.currentRoute.path !== onboardingPath) {
await analytics.pageVisit(onboardingPath);
await router.push(onboardingPath);
}
} catch (error) {
notify.error(error.message, AnalyticsErrorEventSource.OVERALL_APP_WRAPPER_ERROR);
return;
}
}
appStore.changeState(FetchState.LOADED);
});
onBeforeUnmount(() => {
clearSessionTimers();
resetActivityEvents.forEach((eventName: string) => {
document.removeEventListener(eventName, onSessionActivity);
});
});
</script>
<style scoped lang="scss">
:deep(.notification-wrap) {
margin-top: 1rem;
}
.banner-container {
padding-top: 0 !important;
&:empty {
display: none;
}
&__bottom {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
}
.dashboard {
height: 100%;
background-color: #f5f6fa;
display: flex;
flex-direction: column;
&__wrap {
display: flex;
flex-direction: column;
height: 100%;
&__main-area {
position: fixed;
display: flex;
width: 100%;
height: 100%;
&__mobile-navigation {
display: none;
}
&__content-wrap {
width: 100%;
height: 100%;
min-width: 0;
&__container {
height: 100%;
overflow-y: auto;
display: flex;
flex-direction: column;
align-items: center;
&__content {
max-width: 1200px;
padding: 48px 48px 0;
box-sizing: border-box;
width: 100%;
}
}
}
}
}
&__debug-timer {
display: flex;
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
padding: 16px;
z-index: 10000;
background-color: #fec;
font-family: 'font_regular', sans-serif;
font-size: 14px;
border: 1px solid var(--c-yellow-2);
border-radius: 10px;
box-shadow: 0 7px 20px rgba(0 0 0 / 15%);
&__bold {
font-family: 'font_medium', sans-serif;
}
}
}
.no-nav {
width: 100%;
}
@media screen and (max-width: 1280px) {
.regular-navigation {
display: none;
}
.no-nav {
width: 100%;
}
}
@media screen and (max-width: 800px) {
.dashboard__wrap__main-area__content-wrap__container__content {
padding: 32px 24px 50px;
}
}
@media screen and (max-width: 500px) {
.dashboard__wrap__main-area {
flex-direction: column;
&__content-wrap {
height: calc(100% - 4rem);
&__container {
height: 100%;
margin-bottom: 0;
}
}
&__navigation {
display: none;
}
&__mobile-navigation {
display: block;
}
}
}
</style>