-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathUserCheckView.vue
More file actions
132 lines (114 loc) · 3.88 KB
/
Copy pathUserCheckView.vue
File metadata and controls
132 lines (114 loc) · 3.88 KB
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
<template>
<CloudLoginViewSkeleton v-if="skeletonType === 'login'" />
<CloudSurveyViewSkeleton v-else-if="skeletonType === 'survey'" />
<CloudWaitlistViewSkeleton v-else-if="skeletonType === 'waitlist'" />
<div v-else-if="error" class="flex h-full items-center justify-center p-8">
<div class="max-w-[100vw] p-2 text-center lg:w-96">
<p class="mb-4 text-red-500">{{ errorMessage }}</p>
<Button :loading="isRetrying" class="w-full" @click="handleRetry">
{{
isRetrying
? $t('cloudOnboarding.retrying')
: $t('cloudOnboarding.retry')
}}
</Button>
</div>
</div>
<div v-else class="flex items-center justify-center">
<ProgressSpinner class="size-8" />
</div>
</template>
<script setup lang="ts">
import { useAsyncState } from '@vueuse/core'
import ProgressSpinner from 'primevue/progressspinner'
import { computed, nextTick, ref } from 'vue'
import { useRouter } from 'vue-router'
import Button from '@/components/ui/button/Button.vue'
import { useErrorHandling } from '@/composables/useErrorHandling'
import { useFeatureFlags } from '@/composables/useFeatureFlags'
import {
getSurveyCompletedStatus,
getUserCloudStatus
} from '@/platform/cloud/onboarding/auth'
import { isCloud } from '@/platform/distribution/types'
import { useTelemetry } from '@/platform/telemetry'
import CloudLoginViewSkeleton from './skeletons/CloudLoginViewSkeleton.vue'
import CloudSurveyViewSkeleton from './skeletons/CloudSurveyViewSkeleton.vue'
const router = useRouter()
const { wrapWithErrorHandlingAsync } = useErrorHandling()
const { flags } = useFeatureFlags()
const onboardingSurveyEnabled = computed(
() => flags.onboardingSurveyEnabled ?? true
)
const telemetry = isCloud ? useTelemetry() : undefined
const skeletonType = ref<'login' | 'survey' | 'waitlist' | 'loading'>('loading')
const {
isLoading,
error,
execute: checkUserStatus
} = useAsyncState(
wrapWithErrorHandlingAsync(async () => {
await nextTick()
if (!onboardingSurveyEnabled.value) {
telemetry?.trackOnboardingRouted({
destination: 'onboarded',
survey_completed: false,
has_cloud_status: false
})
await router.replace({ path: '/' })
return
}
const [cloudUserStats, surveyStatus] = await Promise.all([
getUserCloudStatus(),
getSurveyCompletedStatus()
])
// Navigate based on user status
if (!cloudUserStats) {
telemetry?.trackOnboardingRouted({
destination: 'waitlist',
survey_completed: !!surveyStatus,
has_cloud_status: false
})
skeletonType.value = 'login'
await router.replace({ name: 'cloud-login' })
return
}
// Survey is required for all users when feature flag is enabled
if (!surveyStatus) {
telemetry?.trackOnboardingRouted({
destination: 'survey',
survey_completed: false,
has_cloud_status: true
})
skeletonType.value = 'survey'
await router.replace({ name: 'cloud-survey' })
return
}
// User is fully onboarded (active or whitelist check disabled)
telemetry?.trackOnboardingRouted({
destination: 'onboarded',
survey_completed: true,
has_cloud_status: true
})
globalThis.location.href = '/'
}),
null,
{ resetOnExecute: false }
)
const errorMessage = computed(() => {
if (!error.value) return ''
// Provide user-friendly error messages
const errorStr = error.value.toString().toLowerCase()
if (errorStr.includes('network') || errorStr.includes('fetch')) {
return 'Connection problem. Please check your internet connection.'
}
if (errorStr.includes('timeout')) {
return 'Request timed out. Please try again.'
}
return 'Unable to check account status. Please try again.'
})
const isRetrying = computed(() => isLoading.value && !!error.value)
const handleRetry = async () => {
await checkUserStatus()
}
</script>