|
|
@@ -62,7 +62,16 @@ export default {
|
|
62
|
62
|
// uses createSurvey/getQuestions from from utils/survey.service.js
|
|
63
|
63
|
// which calls in fetchQuestions from services/survey.service.js
|
|
64
|
64
|
this.survey = await surveyFactory.createSurvey()
|
|
65
|
|
- // TODO: create boolean value based off if a passed user_email is found in user db (i.e. login)
|
|
|
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
|
+ this.currentStep = Number(localStorage['currentStep'])
|
|
|
71
|
+ this.currentProfileId = Number(localStorage['currentProfileId'])
|
|
|
72
|
+ this.responses = JSON.parse(localStorage['responses'])
|
|
|
73
|
+ this.goToStep(this.currentStep)
|
|
|
74
|
+ }
|
|
66
|
75
|
},
|
|
67
|
76
|
methods: {
|
|
68
|
77
|
onSubmit() {
|
|
|
@@ -93,18 +102,23 @@ export default {
|
|
93
|
102
|
response.val = payload.input
|
|
94
|
103
|
this.responses.push(response)
|
|
95
|
104
|
|
|
96
|
|
- // save endpoint here
|
|
97
|
|
- // start with utils/surve.js
|
|
|
105
|
+ // sends latest survey response to db
|
|
98
|
106
|
if (this.currentProfileId) {
|
|
99
|
|
- surveyFactory.addNewSurveyAnswer(this.responses[this.responses.length - 1], this.currentProfileId)
|
|
|
107
|
+ surveyFactory.addNewSurveyAnswer(
|
|
|
108
|
+ this.responses[this.responses.length - 1],
|
|
|
109
|
+ this.currentProfileId)
|
|
100
|
110
|
}
|
|
101
|
111
|
|
|
102
|
112
|
// creates a user in db as long as name, email, and seeking are defined
|
|
103
|
|
- if (!this.currentProfileId && this.survey.hasMinResponsesToCreateProfile(this.answered)) {
|
|
|
113
|
+ if (!this.currentProfileId &&
|
|
|
114
|
+ this.survey.hasMinResponsesToCreateProfile(this.answered)) {
|
|
104
|
115
|
const newUser = await signupUser(this.answered)
|
|
105
|
116
|
const newUserId = newUser.user_id
|
|
106
|
117
|
const newProfile = await createProfileForUserId(newUserId, this.responses)
|
|
107
|
118
|
this.currentProfileId = newProfile.profile_id
|
|
|
119
|
+ // save user's progress through survey
|
|
|
120
|
+ localStorage.setItem('currentProfileId', Number(newProfile.profile_id))
|
|
|
121
|
+ localStorage.setItem('responses', JSON.stringify(this.responses))
|
|
108
|
122
|
}
|
|
109
|
123
|
|
|
110
|
124
|
if (k === 'aspects') return
|
|
|
@@ -113,6 +127,8 @@ export default {
|
|
113
|
127
|
this.onSubmit(this.answered)
|
|
114
|
128
|
} else {
|
|
115
|
129
|
this.goToStep(this.currentStep + 1)
|
|
|
130
|
+ // save user's progress through survey
|
|
|
131
|
+ localStorage.setItem('currentStep', Number(this.currentStep))
|
|
116
|
132
|
}
|
|
117
|
133
|
},
|
|
118
|
134
|
},
|