11import { useSessionStorage } from '@vueuse/core' ;
22import { defineStore } from 'pinia' ;
33import { computed , ref } from 'vue' ;
4+ import { captureError , captureStep } from '../api' ;
45
5- export const enum SignUpSteps {
6+ export const enum SIGN_UP_STEPS {
67 INVALID = 0 ,
78 USERNAME = 10 ,
89 PASSWORD = 20 ,
910 VERIFY = 30 ,
10- DONE = 100 ,
11+ DONE = 100 , // Not currently used
12+ }
13+
14+ export const SIGN_UP_STEPS_TO_STR = {
15+ [ SIGN_UP_STEPS . INVALID ] : 'INVALID' ,
16+ [ SIGN_UP_STEPS . USERNAME ] : 'USERNAME' ,
17+ [ SIGN_UP_STEPS . PASSWORD ] : 'PASSWORD' ,
18+ [ SIGN_UP_STEPS . VERIFY ] : 'VERIFY' ,
19+ [ SIGN_UP_STEPS . DONE ] : 'DONE'
1120}
1221
1322export const useSignUpFlowStore = defineStore ( 'signUpFlow' , ( ) => {
@@ -20,7 +29,7 @@ export const useSignUpFlowStore = defineStore('signUpFlow', () => {
2029 const timezone = useSessionStorage ( `${ sessionStorageKeyPrefix } /timezone` , null ) ;
2130 const lang = useSessionStorage ( `${ sessionStorageKeyPrefix } /lang` , null ) ;
2231 // In-memory only!
23- const step = ref ( SignUpSteps . USERNAME ) ;
32+ const step = ref ( SIGN_UP_STEPS . USERNAME ) ;
2433 const password = ref ( null ) ;
2534 const confirmPassword = ref ( null ) ;
2635
@@ -71,8 +80,8 @@ export const useSignUpFlowStore = defineStore('signUpFlow', () => {
7180 if ( ! error ) {
7281 return false ;
7382 }
83+
7484 errorMessage . value = error [ 'error' ] ?? 'Unknown Error' ;
75-
7685 const type : string = error [ 'type' ] ?? 'unknown-error' ;
7786 if ( type === 'go-to-wait-list' ) {
7887 // Don't show this error, just redirect!
@@ -83,15 +92,20 @@ export const useSignUpFlowStore = defineStore('signUpFlow', () => {
8392
8493 // What step are we moving the user back to?
8594 if ( type . indexOf ( 'invalidPassword' ) === 0 ) {
86- step . value = SignUpSteps . PASSWORD ;
95+ step . value = SIGN_UP_STEPS . PASSWORD ;
8796 } else if ( type === 'status-409' ) { // User already exists error (this comes from keycloak)
88- step . value = SignUpSteps . VERIFY ;
97+ step . value = SIGN_UP_STEPS . VERIFY ;
8998 } else {
90- step . value = SignUpSteps . USERNAME ;
99+ step . value = SIGN_UP_STEPS . USERNAME ;
91100 }
101+
102+ // Capture the step we send them back to
103+ captureStep ( step . value ) ;
92104 } catch {
93105 errorMessage . value = 'Unknown error' ;
94106 }
107+
108+ captureError ( errorMessage . value ) ;
95109 return false ;
96110 } ;
97111
@@ -101,17 +115,18 @@ export const useSignUpFlowStore = defineStore('signUpFlow', () => {
101115 * Note: There's no previousStep because we intentionally do not have a back button.
102116 */
103117 const nextStep = ( ) => {
104- let nextStepValue = SignUpSteps . INVALID ;
118+ let nextStepValue = SIGN_UP_STEPS . INVALID ;
105119 switch ( step . value ) {
106- case SignUpSteps . USERNAME :
107- nextStepValue = SignUpSteps . PASSWORD ;
120+ case SIGN_UP_STEPS . USERNAME :
121+ nextStepValue = SIGN_UP_STEPS . PASSWORD ;
108122 break ;
109- case SignUpSteps . PASSWORD :
110- nextStepValue = SignUpSteps . VERIFY ;
123+ case SIGN_UP_STEPS . PASSWORD :
124+ nextStepValue = SIGN_UP_STEPS . VERIFY ;
111125 break ;
112- case SignUpSteps . VERIFY :
126+ case SIGN_UP_STEPS . VERIFY :
113127 return ;
114128 }
129+ captureStep ( nextStepValue ) ;
115130 step . value = nextStepValue ;
116131 }
117132
@@ -129,7 +144,7 @@ export const useSignUpFlowStore = defineStore('signUpFlow', () => {
129144 lang . value = null ;
130145 errorMessage . value = null ;
131146 if ( resetStep ) {
132- step . value = SignUpSteps . USERNAME ;
147+ step . value = SIGN_UP_STEPS . USERNAME ;
133148 }
134149 } ;
135150
0 commit comments