|
|
@@ -70,27 +70,17 @@ export default {
|
|
70
|
70
|
this.authenticator = new Authenticator()
|
|
71
|
71
|
|
|
72
|
72
|
if (document.cookie.length) {
|
|
73
|
|
- // TODO: Remove this this.answered section when:
|
|
74
|
|
- // SurveyCompleteView calls all responses from db
|
|
|
73
|
+ // TODO: Heavy Refactor needed, obvious code smells
|
|
75
|
74
|
// BUG: NEEDS BROWSER REFRESH TO SEE UPDATED COOKIES
|
|
76
|
|
- const siimeeAnswered = this.grabCookie(
|
|
77
|
|
- document.cookie,
|
|
78
|
|
- 'siimee_answered',
|
|
79
|
|
- )
|
|
|
75
|
+ const siimeeAnswered = this.grabCookie('siimee_answered')
|
|
|
76
|
+ const myCurrentStep = this.grabCookie('siimee_current_step')
|
|
|
77
|
+ console.log('myCurrentStep :=>', myCurrentStep)
|
|
80
|
78
|
if (siimeeAnswered) {
|
|
81
|
|
- const siimeeAnswers = JSON.parse(
|
|
82
|
|
- this.grabCookie(document.cookie, 'siimee_answered'),
|
|
83
|
|
- )
|
|
84
|
|
- this.sessionToken = this.grabCookie(
|
|
85
|
|
- document.cookie,
|
|
86
|
|
- 'siimee_session',
|
|
87
|
|
- )
|
|
|
79
|
+ const siimeeAnswers = JSON.parse(siimeeAnswered)
|
|
|
80
|
+ this.sessionToken = this.grabCookie('siimee_session')
|
|
88
|
81
|
const sessionTokenIsValid =
|
|
89
|
82
|
await this.authenticator.validateJwt(this.sessionToken)
|
|
90
|
|
- this.accessToken = this.grabCookie(
|
|
91
|
|
- document.cookie,
|
|
92
|
|
- 'siimee_access',
|
|
93
|
|
- )
|
|
|
83
|
+ this.accessToken = this.grabCookie('siimee_access')
|
|
94
|
84
|
if (sessionTokenIsValid.isValid) {
|
|
95
|
85
|
this.answered = {
|
|
96
|
86
|
name: siimeeAnswers.name,
|
|
|
@@ -98,9 +88,36 @@ export default {
|
|
98
|
88
|
seeking: siimeeAnswers.seeking,
|
|
99
|
89
|
}
|
|
100
|
90
|
this.currentProfileId = siimeeAnswers.profile_id
|
|
101
|
|
- this.goToStep(6)
|
|
|
91
|
+ this.currentStep = 6
|
|
|
92
|
+ this.responses = [
|
|
|
93
|
+ { response_key_id: 8, val: siimeeAnswers.email },
|
|
|
94
|
+ { response_key_id: 7, val: siimeeAnswers.name },
|
|
|
95
|
+ { response_key_id: 11, val: siimeeAnswers.seeking },
|
|
|
96
|
+ ]
|
|
|
97
|
+ document.cookie = `siimee_current_step=${this.currentStep}; max-age=600 ; path=/onboarding ; secure`
|
|
|
98
|
+ document.cookie = `siimee_cache_answered=${JSON.stringify(
|
|
|
99
|
+ this.answered,
|
|
|
100
|
+ )}; max-age=600 ; path=/onboarding ; secure`
|
|
|
101
|
+ document.cookie = `siimee_cache_responses=${JSON.stringify(
|
|
|
102
|
+ this.responses,
|
|
|
103
|
+ )}; max-age=600 ; path=/onboarding ; secure`
|
|
|
104
|
+ document.cookie = 'siimee_answered='
|
|
|
105
|
+ this.goToStep(this.currentStep)
|
|
102
|
106
|
}
|
|
103
|
|
- } else this.goToStep(0)
|
|
|
107
|
+ } else if (myCurrentStep) {
|
|
|
108
|
+ const myCurrentAnswers = this.grabCookie(
|
|
|
109
|
+ 'siimee_cache_answered',
|
|
|
110
|
+ )
|
|
|
111
|
+ const myCurrentResponses = this.grabCookie(
|
|
|
112
|
+ 'siimee_cache_responses',
|
|
|
113
|
+ )
|
|
|
114
|
+ this.answered = JSON.parse(myCurrentAnswers)
|
|
|
115
|
+ this.responses = JSON.parse(myCurrentResponses)
|
|
|
116
|
+ this.currentStep = myCurrentStep
|
|
|
117
|
+ this.goToStep(Number(myCurrentStep) + 1)
|
|
|
118
|
+ } else {
|
|
|
119
|
+ this.goToStep(0)
|
|
|
120
|
+ }
|
|
104
|
121
|
}
|
|
105
|
122
|
},
|
|
106
|
123
|
methods: {
|
|
|
@@ -108,6 +125,16 @@ export default {
|
|
108
|
125
|
console.log(JSON.stringify(this.answered))
|
|
109
|
126
|
},
|
|
110
|
127
|
async goToStep(num) {
|
|
|
128
|
+ document.cookie = `siimee_current_step=${Number(
|
|
|
129
|
+ this.currentStep,
|
|
|
130
|
+ )}; max-age=600 ; path=/onboarding ; secure`
|
|
|
131
|
+ document.cookie = `siimee_cache_answered=${JSON.stringify(
|
|
|
132
|
+ this.answered,
|
|
|
133
|
+ )}; max-age=600 ; path=/onboarding ; secure`
|
|
|
134
|
+ document.cookie = `siimee_cache_responses=${JSON.stringify(
|
|
|
135
|
+ this.responses,
|
|
|
136
|
+ )}; max-age=600 ; path=/onboarding ; secure`
|
|
|
137
|
+
|
|
111
|
138
|
if (num > 6) {
|
|
112
|
139
|
this.validateAccessToken()
|
|
113
|
140
|
}
|
|
|
@@ -137,7 +164,8 @@ export default {
|
|
137
|
164
|
return true
|
|
138
|
165
|
} else return false
|
|
139
|
166
|
},
|
|
140
|
|
- grabCookie(cookieString, cookieKey) {
|
|
|
167
|
+ grabCookie(cookieKey) {
|
|
|
168
|
+ const cookieString = document.cookie
|
|
141
|
169
|
const cookies = cookieString.split('; ').reduce((prev, current) => {
|
|
142
|
170
|
const [name, ...value] = current.split('=')
|
|
143
|
171
|
prev[name] = value.join('=')
|