|
|
@@ -6,8 +6,6 @@ main.view--onboarding
|
|
6
|
6
|
)
|
|
7
|
7
|
.answers(v-for='(value, key) in answered')
|
|
8
|
8
|
span(v-if='key == "name" && value && currentStep == 2') Hi {{ value }}!
|
|
9
|
|
- span(v-if='key == "email" && value && currentStep == 3') Thanks for the contact info, {{ answered.name }}!
|
|
10
|
|
-
|
|
11
|
9
|
//- h3(v-if='currentStep == 1') Welcome to Siimee Onboarding! Let's get started!
|
|
12
|
10
|
br
|
|
13
|
11
|
.step(v-for='(step, i) in survey.steps')
|
|
|
@@ -19,7 +17,7 @@ main.view--onboarding
|
|
19
|
17
|
@handle-submit='onSubmit'
|
|
20
|
18
|
@update-answers='updateAnswers'
|
|
21
|
19
|
v-if='step && currentStep == i'
|
|
22
|
|
- )
|
|
|
20
|
+ )
|
|
23
|
21
|
.invalidResponseMessage(
|
|
24
|
22
|
style='text-align: center'
|
|
25
|
23
|
v-if='invalidResponse'
|
|
|
@@ -34,10 +32,7 @@ main.view--onboarding
|
|
34
|
32
|
</template>
|
|
35
|
33
|
|
|
36
|
34
|
<script>
|
|
37
|
|
-// import { currentProfile } from '@/services'
|
|
38
|
|
-// import { createProfileForUserId } from '../services/profile.service'
|
|
39
|
35
|
import { surveyFactory } from '@/utils'
|
|
40
|
|
-import { signupUser, createProfileForUserId } from '@/services/'
|
|
41
|
36
|
import stepViews from '@/components/onboarding'
|
|
42
|
37
|
import SurveyCompleteView from './SurveyCompleteView.vue'
|
|
43
|
38
|
|
|
|
@@ -59,21 +54,8 @@ export default {
|
|
59
|
54
|
invalidResponse: false,
|
|
60
|
55
|
}),
|
|
61
|
56
|
async created() {
|
|
62
|
|
- // uses createSurvey/getQuestions from from utils/survey.service.js
|
|
63
|
|
- // which calls in fetchQuestions from services/survey.service.js
|
|
64
|
57
|
this.survey = await surveyFactory.createSurvey()
|
|
65
|
|
- // checks if the user has simply refreshed the page after creating a basic profile
|
|
66
|
|
- // and redirects the user to their last unanswered survey question
|
|
67
|
|
- if (localStorage['currentStep'] &&
|
|
68
|
|
- localStorage['currentProfileId'] &&
|
|
69
|
|
- localStorage['responses'] &&
|
|
70
|
|
- localStorage['answered']) {
|
|
71
|
|
- this.currentStep = Number(localStorage['currentStep'])
|
|
72
|
|
- this.currentProfileId = Number(localStorage['currentProfileId'])
|
|
73
|
|
- this.responses = JSON.parse(localStorage['responses'])
|
|
74
|
|
- this.answered = JSON.parse(localStorage['answered'])
|
|
75
|
|
- this.goToStep(this.currentStep)
|
|
76
|
|
- }
|
|
|
58
|
+ console.log('this.survey :=>', this.survey)
|
|
77
|
59
|
},
|
|
78
|
60
|
methods: {
|
|
79
|
61
|
onSubmit() {
|
|
|
@@ -85,6 +67,8 @@ export default {
|
|
85
|
67
|
async updateAnswers(payload) {
|
|
86
|
68
|
// null payload is passed on splash page
|
|
87
|
69
|
if (payload) {
|
|
|
70
|
+ // authentication achieved if payload.resume = true
|
|
|
71
|
+ if (payload.resume) this.currentStep = 3
|
|
88
|
72
|
this.invalidResponse = false
|
|
89
|
73
|
const k = payload.question.survey_stage
|
|
90
|
74
|
this.answered[k] = payload.input
|
|
|
@@ -93,36 +77,22 @@ export default {
|
|
93
|
77
|
this.invalidResponse = true
|
|
94
|
78
|
return
|
|
95
|
79
|
}
|
|
96
|
|
-
|
|
|
80
|
+ //
|
|
97
|
81
|
// once validated, don't log password in answered object
|
|
98
|
82
|
this.answered[k] = k === 'password' ? undefined : payload.input
|
|
99
|
|
- console.log('this.answered :=>', this.answered)
|
|
100
|
83
|
|
|
101
|
84
|
// formats initial responses for response table
|
|
102
|
85
|
const response = {}
|
|
103
|
86
|
response.response_key_id = payload.question.response_key_id
|
|
104
|
87
|
response.val = payload.input
|
|
105
|
88
|
this.responses.push(response)
|
|
106
|
|
- // save user's progress through survey
|
|
107
|
|
- localStorage.setItem('responses', JSON.stringify(this.responses))
|
|
108
|
|
- localStorage.setItem('answered', JSON.stringify(this.answered))
|
|
109
|
89
|
|
|
110
|
90
|
// sends latest survey response to db
|
|
111
|
91
|
if (this.currentProfileId) {
|
|
112
|
92
|
surveyFactory.addNewSurveyAnswer(
|
|
113
|
|
- this.responses[this.responses.length - 1],
|
|
114
|
|
- this.currentProfileId)
|
|
115
|
|
- }
|
|
116
|
|
-
|
|
117
|
|
- // creates a user in db as long as name, email, and seeking are defined
|
|
118
|
|
- if (!this.currentProfileId &&
|
|
119
|
|
- this.survey.hasMinResponsesToCreateProfile(this.answered)) {
|
|
120
|
|
- const newUser = await signupUser(this.answered)
|
|
121
|
|
- const newUserId = newUser.user_id
|
|
122
|
|
- const newProfile = await createProfileForUserId(newUserId, this.responses)
|
|
123
|
|
- this.currentProfileId = newProfile.profile_id
|
|
124
|
|
- // save user's progress through survey
|
|
125
|
|
- localStorage.setItem('currentProfileId', Number(newProfile.profile_id))
|
|
|
93
|
+ this.responses[this.responses.length - 1],
|
|
|
94
|
+ this.currentProfileId,
|
|
|
95
|
+ )
|
|
126
|
96
|
}
|
|
127
|
97
|
|
|
128
|
98
|
if (k === 'aspects') return
|
|
|
@@ -131,8 +101,6 @@ export default {
|
|
131
|
101
|
this.onSubmit(this.answered)
|
|
132
|
102
|
} else {
|
|
133
|
103
|
this.goToStep(this.currentStep + 1)
|
|
134
|
|
- // save user's progress through survey
|
|
135
|
|
- localStorage.setItem('currentStep', Number(this.currentStep))
|
|
136
|
104
|
}
|
|
137
|
105
|
},
|
|
138
|
106
|
},
|