|
|
@@ -15,9 +15,11 @@ main.view--onboarding
|
|
15
|
15
|
:responses='responses'
|
|
16
|
16
|
:survey='survey'
|
|
17
|
17
|
:currentStep='currentStep'
|
|
|
18
|
+ :jwt='jwt'
|
|
18
|
19
|
:surveyStepsCount='survey.steps.length'
|
|
19
|
20
|
@handle-submit='onSubmit'
|
|
20
|
21
|
@update-answers='updateAnswers'
|
|
|
22
|
+ @set-pid='setPid'
|
|
21
|
23
|
v-if='step && currentStep == i'
|
|
22
|
24
|
)
|
|
23
|
25
|
.invalidResponseMessage(
|
|
|
@@ -36,6 +38,7 @@ main.view--onboarding
|
|
36
|
38
|
<script>
|
|
37
|
39
|
import { Authenticator } from '../services/auth.service.js'
|
|
38
|
40
|
import { surveyFactory } from '@/utils'
|
|
|
41
|
+import { currentProfile } from '../services/'
|
|
39
|
42
|
import stepViews from '@/components/onboarding'
|
|
40
|
43
|
import SurveyCompleteView from './SurveyCompleteView.vue'
|
|
41
|
44
|
|
|
|
@@ -59,16 +62,38 @@ export default {
|
|
59
|
62
|
authenticator: {},
|
|
60
|
63
|
jwt: '',
|
|
61
|
64
|
}),
|
|
|
65
|
+ computed: {
|
|
|
66
|
+ // NOTE: perhaps start this off as returning nothing
|
|
|
67
|
+ // and then add currentProfile in created()?
|
|
|
68
|
+ profile: () => currentProfile,
|
|
|
69
|
+ },
|
|
62
|
70
|
async created() {
|
|
|
71
|
+ // console.log('this.profile.id :=>', this.profile.id)
|
|
63
|
72
|
if (document.cookie.length) {
|
|
64
|
|
- const siimeeToken = this.grabToken(document.cookie)
|
|
|
73
|
+ // TODO: Remove this this.answered section when:
|
|
|
74
|
+ // SurveyCompleteView calls all responses from db
|
|
|
75
|
+ const siimeeAnswers = JSON.parse(
|
|
|
76
|
+ this.grabCookie(document.cookie, 'siimee_answered'),
|
|
|
77
|
+ )
|
|
|
78
|
+ this.answered = {
|
|
|
79
|
+ name: siimeeAnswers.name,
|
|
|
80
|
+ email: siimeeAnswers.email,
|
|
|
81
|
+ seeking: siimeeAnswers.seeking,
|
|
|
82
|
+ }
|
|
|
83
|
+ // TODO: Instead, login using siimee_profile_id from cookie
|
|
|
84
|
+ const siimeeToken = this.grabCookie(document.cookie, 'siimee_jwt')
|
|
65
|
85
|
this.jwt = siimeeToken ? siimeeToken : ''
|
|
66
|
86
|
}
|
|
|
87
|
+
|
|
67
|
88
|
this.survey = await surveyFactory.createSurvey()
|
|
68
|
89
|
this.authenticator = new Authenticator()
|
|
69
|
90
|
if (this.jwt.length) {
|
|
70
|
|
- const jwtStillValid = await this.authenticator.validateJwt(this.jwt)
|
|
71
|
|
- if (jwtStillValid) {
|
|
|
91
|
+ // TODO: remove once currentProfile is established and user is logged in...
|
|
|
92
|
+ const jwt = await this.authenticator.validateJwt(this.jwt)
|
|
|
93
|
+ if (jwt.isValid) {
|
|
|
94
|
+ // grab profileId from jwt payload and login here
|
|
|
95
|
+ // use this profile to grab all responses in
|
|
|
96
|
+ // SurveyCompleteView.vue
|
|
72
|
97
|
this.goToStep(6)
|
|
73
|
98
|
} else {
|
|
74
|
99
|
this.goToStep(0)
|
|
|
@@ -83,13 +108,13 @@ export default {
|
|
83
|
108
|
goToStep(num) {
|
|
84
|
109
|
this.currentStep = num
|
|
85
|
110
|
},
|
|
86
|
|
- grabToken(cookieString) {
|
|
|
111
|
+ grabCookie(cookieString, cookieKey) {
|
|
87
|
112
|
const cookies = cookieString.split('; ').reduce((prev, current) => {
|
|
88
|
113
|
const [name, ...value] = current.split('=')
|
|
89
|
114
|
prev[name] = value.join('=')
|
|
90
|
115
|
return prev
|
|
91
|
116
|
}, {})
|
|
92
|
|
- return 'siimee_jwt' in cookies ? cookies['siimee_jwt'] : undefined
|
|
|
117
|
+ return cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
|
|
93
|
118
|
},
|
|
94
|
119
|
async updateAnswers(payload) {
|
|
95
|
120
|
// null payload is passed on splash page
|
|
|
@@ -102,7 +127,7 @@ export default {
|
|
102
|
127
|
this.invalidResponse = true
|
|
103
|
128
|
return
|
|
104
|
129
|
}
|
|
105
|
|
- //
|
|
|
130
|
+
|
|
106
|
131
|
// once validated, don't log password in answered object
|
|
107
|
132
|
// this.answered[k] = k === 'password' ? undefined : payload.input
|
|
108
|
133
|
|
|
|
@@ -128,6 +153,23 @@ export default {
|
|
128
|
153
|
this.goToStep(this.currentStep + 1)
|
|
129
|
154
|
}
|
|
130
|
155
|
},
|
|
|
156
|
+ // NOTE: Brought in from App.vue, might not be necessary...
|
|
|
157
|
+ // Allows for login after initial email sign up is set
|
|
|
158
|
+ async setPid(profileId) {
|
|
|
159
|
+ if (currentProfile.isLoggedIn) {
|
|
|
160
|
+ currentProfile.logout()
|
|
|
161
|
+ }
|
|
|
162
|
+ // ERROR: this._profile is undefinedin login service
|
|
|
163
|
+ this.profile.id = await currentProfile.login(
|
|
|
164
|
+ profileId,
|
|
|
165
|
+ this.$waveui.notify,
|
|
|
166
|
+ )
|
|
|
167
|
+ console.log('---')
|
|
|
168
|
+
|
|
|
169
|
+ // Change if survey isn't complete...
|
|
|
170
|
+ // const toRoute = { name: 'HomeView' }
|
|
|
171
|
+ // this.$router.push(toRoute)
|
|
|
172
|
+ },
|
|
131
|
173
|
},
|
|
132
|
174
|
}
|
|
133
|
175
|
</script>
|