You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OnboardingView.vue 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template lang="pug">
  2. main.view--onboarding
  3. article(
  4. style='display: flex; flex-direction: column; align-items: center'
  5. <<<<<<< HEAD
  6. v-if='currentStep !== survey.steps.length'
  7. )
  8. .answers(v-for='(value, key) in answered')
  9. span(v-if='key == "name" && value && currentStep == 2') Hi {{ value }}!
  10. br
  11. .step(v-for='(step, i) in survey.steps')
  12. component(
  13. :is='step.component'
  14. :question='step'
  15. :answered='answered'
  16. :responses='responses'
  17. :survey='survey'
  18. :currentStep='currentStep'
  19. :surveyStepsCount='survey.steps.length'
  20. @handle-submit='onSubmit'
  21. @update-answers='updateAnswers'
  22. v-if='step && currentStep == i'
  23. )
  24. .invalidResponseMessage(
  25. style='text-align: center'
  26. v-if='invalidResponse'
  27. )
  28. p {{ survey.steps[currentStep].invalidInputPrompt }}
  29. footer
  30. p(v-if='currentStep != 0') You have completed: {{ currentStep }} / {{ survey.steps.length }} survey steps
  31. article(v-else)
  32. SurveyCompleteView(:answers='answered' :surveySteps='survey.steps')
  33. =======
  34. v-if='survey'
  35. )
  36. .step(v-for='(step, i) in survey.steps')
  37. component(
  38. :aspect-questions='step.component == "Aspects" ? survey.aspectQuestions : null'
  39. :is='step.component'
  40. :question='step'
  41. @handle-submit='onSubmit'
  42. @update-answers='updateAnswers'
  43. v-if='step && currentStep == i'
  44. )
  45. >>>>>>> b0c2120 (another pre-release (#53))
  46. </template>
  47. <script>
  48. import { Authenticator } from '../services/auth.service.js'
  49. import { surveyFactory } from '@/utils'
  50. <<<<<<< HEAD
  51. import stepViews from '@/components/onboarding'
  52. import SurveyCompleteView from './SurveyCompleteView.vue'
  53. let hashedAccessToken = null
  54. let currentProfileId = null
  55. =======
  56. import { allSteps } from '@/utils/lang'
  57. import stepViews from '@/components/onboarding'
  58. >>>>>>> b0c2120 (another pre-release (#53))
  59. // import savesurveybyprfileid - call it on submit
  60. // paginate to save every steps answers
  61. export default {
  62. name: 'OnboardingView',
  63. components: {
  64. ...stepViews,
  65. <<<<<<< HEAD
  66. SurveyCompleteView,
  67. },
  68. data: () => ({
  69. answered: {},
  70. aspectQuestions: [],
  71. responses: [],
  72. currentStep: 0,
  73. survey: null,
  74. invalidResponse: false,
  75. authenticator: {},
  76. }),
  77. async created() {
  78. this.survey = await surveyFactory.createSurvey()
  79. this.authenticator = new Authenticator()
  80. hashedAccessToken = this.grabStoredCookie('siimee_access')
  81. try {
  82. const sessionData = await this.verifySession(hashedAccessToken)
  83. currentProfileId = sessionData.profileId
  84. this.responses = sessionData.responses
  85. this.currentStep = this.responses.length + 3
  86. this.goToStep(this.currentStep)
  87. } catch (err) {
  88. console.error('ERROR :=>', err)
  89. this.goToStep(0)
  90. }
  91. },
  92. =======
  93. },
  94. data: () => ({
  95. answered: {},
  96. aspectQuestions: [],
  97. currentStep: 0,
  98. survey: null,
  99. }),
  100. async created() {
  101. this.survey = await surveyFactory.createSurvey(allSteps['usa'])
  102. },
  103. >>>>>>> b0c2120 (another pre-release (#53))
  104. methods: {
  105. onSubmit() {
  106. console.log(JSON.stringify(this.answered))
  107. },
  108. <<<<<<< HEAD
  109. async goToStep(num) {
  110. this.currentStep = num
  111. },
  112. grabStoredCookie(cookieKey) {
  113. const cookies = document.cookie
  114. .split('; ')
  115. .reduce((prev, current) => {
  116. const [name, ...value] = current.split('=')
  117. prev[name] = value.join('=')
  118. return prev
  119. }, {})
  120. const cookieVal =
  121. cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
  122. return cookieVal
  123. },
  124. async verifySession(hashedAccessToken) {
  125. if (!hashedAccessToken)
  126. return console.warn('WARNING :=> accessToken is not defined')
  127. const validatedToken = await this.authenticator.validateSession(
  128. hashedAccessToken,
  129. )
  130. if (validatedToken.error) {
  131. throw new Error(validatedToken.error)
  132. } else {
  133. return validatedToken
  134. }
  135. },
  136. async updateAnswers(payload) {
  137. if (payload) {
  138. const k = payload.question.survey_stage
  139. this.answered[k] = payload.input
  140. // Once validated, don't log password in answered object
  141. this.answered[k] = k === 'password' ? undefined : payload.input
  142. // Hacky WorkAround for Validating Answers
  143. if (!this.survey.validateAnswer(payload)) {
  144. this.invalidResponse = true
  145. return
  146. }
  147. // Formats initial responses for response table
  148. const response = {}
  149. response.response_key_id = payload.question.response_key_id
  150. response.val = payload.input
  151. this.responses.push(response)
  152. if (k === 'aspects') return
  153. }
  154. // NOTE: If user has finished minimum profile creation,
  155. // Adds survey answers to responses table and verifies tokens on each step
  156. if (currentProfileId) {
  157. await surveyFactory.addNewSurveyAnswer(
  158. this.responses[this.responses.length - 1],
  159. currentProfileId,
  160. )
  161. try {
  162. await this.verifySession(hashedAccessToken)
  163. } catch (err) {
  164. this.currentStep = 0
  165. this.goToStep(this.currentStep)
  166. throw new Error(err)
  167. }
  168. }
  169. if (this.currentStep > this.survey.steps.length) {
  170. this.onSubmit(this.answered)
  171. } else {
  172. this.goToStep(this.currentStep + 1)
  173. }
  174. =======
  175. goToStep(num) {
  176. this.currentStep = num
  177. },
  178. updateAnswers(payload) {
  179. // null payload is passed on splash page
  180. if (payload) {
  181. const k = payload.question.response_key_prompt
  182. this.answered[k] = payload.answer
  183. console.log(`${k}:`, this.answered[k])
  184. console.log(`Updated answers: ${JSON.stringify(this.answered)}`)
  185. if (k === 'aspects') return
  186. }
  187. this.goToStep(this.currentStep + 1)
  188. >>>>>>> b0c2120 (another pre-release (#53))
  189. },
  190. },
  191. }
  192. </script>
  193. <style lang="sass">
  194. .view--onboarding
  195. width: 100%
  196. max-width: 428px
  197. background-color: #fff
  198. color: #1F2024
  199. font-family: Century Gothic,CenturyGothic,AppleGothic,sans-serif
  200. margin: 0 auto
  201. article
  202. height: 100vh
  203. <<<<<<< HEAD
  204. .answers
  205. text-align: center
  206. =======
  207. >>>>>>> b0c2120 (another pre-release (#53))
  208. .w-button
  209. display: flex
  210. width: 315px
  211. height: 60px
  212. border-radius: 6
  213. background-color: #D5D5D5
  214. color: #1F2024
  215. margin: 11px auto
  216. font-weight: bold
  217. font-size: 16px
  218. text-transform: uppercase
  219. &.next-btn
  220. border-radius: 6px
  221. background-color: #5BA626
  222. color: #1F2024
  223. height: 50px
  224. width: 315px
  225. font-size: 18px
  226. padding: 7px
  227. .w-card
  228. background-color: #1F2024
  229. justify-content: center
  230. align-items: center
  231. width: 100%
  232. h3
  233. text-transform: uppercase
  234. text-align: center
  235. font-size: 28px
  236. font-weight: bold
  237. color: white
  238. margin-top: 88px
  239. p
  240. color: white
  241. font-size: 18px
  242. padding: 11px
  243. text-align: center
  244. margin: 22px auto
  245. font-weight: bold
  246. input
  247. display: flex
  248. width: 315px
  249. height: 60px
  250. padding: 11px
  251. border-radius: 6
  252. background-color: #D5D5D5
  253. color: #1F2024
  254. margin: 11px auto
  255. font-weight: bold
  256. font-size: 16px
  257. .w-select
  258. padding: 11px
  259. color: #1F2024
  260. .search-type
  261. color: #1F2024
  262. height: 50px
  263. &.question
  264. p
  265. font-size: 18px
  266. text-align: left
  267. margin: 7px auto
  268. font-weight: normal
  269. section
  270. p
  271. margin: 0
  272. font-weight: bold
  273. text-transform: capitalize
  274. .w-radio__input
  275. &.primary
  276. background-color: #FFFFFF
  277. border: #BCC5D3 1px solid
  278. .w-card__content
  279. .w-button
  280. height: 50px
  281. background-color: #5BA626
  282. </style>