Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

OnboardingView.vue 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template lang="pug">
  2. main.view--onboarding
  3. article(style='display: flex; flex-direction: column; align-items: center')
  4. component(
  5. :aspectQuestions='onboardingStep.component == "Aspects" ? aspectQuestions : null'
  6. :currentStep='currentStep'
  7. :is='onboardingStep.component'
  8. @go-to-step='goToStep'
  9. @handle-submit="onSubmit"
  10. @update-answers="updateAnswers"
  11. )
  12. </template>
  13. <script>
  14. import { surveyFactory } from '@/utils'
  15. import { allSteps, possible } from '@/utils/lang'
  16. import stepViews from '@/components/onboarding'
  17. import OnboardingStepComponents from '../utils/onboardingStepComponents'
  18. const SCORED = [1, 2, 3, 4, 5, 6]
  19. const _isScored = id => SCORED.includes(id)
  20. const _makeCategoryFriendly = responseCategory => {
  21. const labels = responseCategory.split('_vs_')
  22. labels.forEach((a, i) => {
  23. if (a.indexOf('_') == -1) return
  24. labels[i] = a.split('_').join(' ')
  25. })
  26. return labels
  27. }
  28. const _formatAspectQuestions = steps => {
  29. return steps
  30. .map(q => {
  31. if (!_isScored(q.response_key_id)) return null
  32. return {
  33. id: q.response_key_id,
  34. question: q.response_key_prompt,
  35. labels: _makeCategoryFriendly(q.response_key_category),
  36. answer: null,
  37. }
  38. })
  39. .filter(step => step != null)
  40. }
  41. // import savesurveybyprfileid - call it on submit
  42. // paginate to save every steps answers
  43. export default {
  44. name: 'OnboardingView',
  45. components: {
  46. ...stepViews,
  47. },
  48. data: () => ({
  49. answered: {},
  50. aspectQuestions: [],
  51. currentStep: 0,
  52. onboardingStepComponents: [],
  53. validSurvey: null,
  54. }),
  55. computed: {
  56. onboardingStep() {
  57. if (!this.onboardingStepComponents.length) return []
  58. return this.onboardingStepComponents[this.currentStep]
  59. },
  60. },
  61. async created() {
  62. const survey = await surveyFactory.createSurvey(
  63. allSteps['usa'],
  64. possible['usa']['roles'],
  65. )
  66. this.aspectQuestions = _formatAspectQuestions(survey.steps)
  67. this.onboardingStepComponents = OnboardingStepComponents
  68. },
  69. methods: {
  70. onSubmit() {
  71. console.log(JSON.stringify(this.answered))
  72. // Object.values(this.answered).forEach(ans =>
  73. // console.log(ans.question, ans.answer),
  74. // )
  75. },
  76. goToStep(num) {
  77. this.currentStep = num
  78. },
  79. updateAnswers(payload){
  80. this.answered[payload.key] = payload.answer
  81. console.log(`Updated answers: ${JSON.stringify(this.answered)}`);
  82. }
  83. },
  84. }
  85. </script>