Explorar el Código

:construction: Started to finalize Survey Complete Page

brian_dev_survey_complete
tomit4 hace 2 años
padre
commit
ad48c4a80f

+ 1
- 0
frontend/src/router/guards.js Ver fichero

@@ -47,6 +47,7 @@ const loginIfToken = async () => {
47 47
     ) {
48 48
         await currentProfile.login(
49 49
             sessionData.profileId,
50
+            // NOTE: probably not correct...
50 51
             WaveUI.notify,
51 52
             sessionData.accessToken,
52 53
         )

+ 4
- 3
frontend/src/views/OnboardingView.vue Ver fichero

@@ -30,8 +30,7 @@ main.view--onboarding
30 30
             p(v-if='currentStep != 0') You have completed: {{ currentStep }} / {{ survey?.steps?.length }} survey steps
31 31
 
32 32
     article(v-else)
33
-        // TODO: format answers and surveySteps on created based off of existing responses
34
-        SurveyCompleteView(:answers='answered' :surveySteps='survey.steps' :responses='responses')
33
+        SurveyCompleteView(:surveySteps='survey.steps' :responses='responses')
35 34
 </template>
36 35
 
37 36
 <script>
@@ -56,9 +55,10 @@ export default {
56 55
         invalidResponse: false,
57 56
     }),
58 57
     async created() {
58
+        // TODO: Troubleshoot bug where not all responses are returned at SurveyCompleteView
59
+        console.log('currentProfile :=>', currentProfile)
59 60
         this.survey = await surveyFactory.createSurvey()
60 61
         hashedAccessToken = this.grabStoredCookie('siimee_access')
61
-        console.log('currentProfile.isLoggedIn :=>', currentProfile.isLoggedIn)
62 62
         try {
63 63
             const sessionData = await this.verifySession(hashedAccessToken)
64 64
             await currentProfile.login(
@@ -116,6 +116,7 @@ export default {
116 116
             })
117 117
         },
118 118
         async updateAnswers(payload) {
119
+            console.log('this.survey.steps :=>', this.survey.steps)
119 120
             if (payload) {
120 121
                 const k = payload.question.survey_stage
121 122
                 this.answered[k] = payload.input

+ 88
- 39
frontend/src/views/SurveyCompleteView.vue Ver fichero

@@ -3,60 +3,109 @@ main.view--surveycomplete
3 3
     article(style='display: flex; flex-direction: column; align-items: center; text-align: center;')
4 4
         h2 Thanks for Completing Our Survey!!
5 5
         h1 Please review your answers and let us know if you need to change anything.
6
+        div(v-for='response in responses')
7
+            p Your {{ response.stage }}: 
8
+            p {{ response.val }}
9
+            br
10
+        div.survey-spacer
11
+        div(v-for='aspectResponse in aspectResponses')
12
+            p {{ aspectResponse.question }} :
13
+            br
14
+            p {{ aspectResponse.response }}
15
+            br
6 16
         br
7
-        p(v-for='input in formInputs')
8
-            p(v-for='(value, key) in answers')
9
-                p(v-if='input.survey_stage == key && key !== "password"')
10
-                    p Your {{ key }}: {{ value }}
11
-        br
12
-        p(v-for='input in formDropdowns')
13
-            p(v-for='(value, key) in answers')
14
-                p(v-if='input.survey_stage == key')
15
-                    p Your {{ key }}: {{ value }}
16
-        br
17
-        p(v-for='(response, responseIndex) in questionResponses')
18
-            p(v-for='(value, key) in answers')
19
-                p(v-if='response.survey_stage == key') 
20
-                    p Survey Question {{ responseIndex + 1 }}: 
21
-                    p {{ response.response_key_prompt }}
22
-                    p You Answered: {{ value }}
23
-                    br
24 17
         w-button.ma1(@click="changeAnswers") Change Answers
25
-        w-button.ma1(@click="finalSubmit") Submit Answers
26 18
 </template>
27 19
 
28 20
 <script>
21
+import { currentProfile } from '../services'
29 22
 export default {
30 23
     props: {
31
-        answers: {
32
-            type: Object,
33
-            default: () => ({}),
34
-        },
35 24
         surveySteps: {
36 25
             type: Array,
37 26
             default: () => [],
38 27
         },
39 28
     },
40 29
     data: () => ({
41
-        surveyObjects: [],
42
-        formInputs: [],
43
-        questionResponses: [],
44
-        formDropdowns: [],
30
+        responses: {},
31
+        aspectQuestions: {},
32
+        surveyStages: {},
33
+        aspectResponses: [],
45 34
     }),
46 35
     created() {
47
-        this.surveySteps.forEach((step) => {
48
-            switch (step.component) {
49
-                case 'FormInput':
50
-                    this.formInputs.push(step)
51
-                    break
52
-                case 'FormDropdown':
53
-                    this.formDropdowns.push(step)
54
-                    break
55
-                case 'QuestionResponse':
56
-                    this.questionResponses.push(step)
57
-                    break
58
-            }
59
-        })
36
+        // TODO: Troubleshoot bug where not all responses are returned
37
+        console.log('currentProfile :=>', currentProfile)
38
+        this.aspectQuestions = this.parseSurvey(this.surveySteps, false)
39
+        this.surveyStages = this.parseSurvey(this.surveySteps, true)
40
+        this.aspectResponses = this.grabAspectResponses(
41
+            currentProfile._profile.responses,
42
+            this.aspectQuestions,
43
+        )
44
+        const responses = this.grabResponsesFromProfile(this.aspectQuestions)
45
+        this.responses = this.appendStagesToResponses(
46
+            responses,
47
+            this.surveyStages,
48
+        )
49
+    },
50
+    methods: {
51
+        parseSurvey(surveySteps, isStage) {
52
+            const parsedAspects = {}
53
+            const parsedStages = {}
54
+            surveySteps.forEach(step => {
55
+                const isAspect = step.category === 'aspect'
56
+                if (isAspect) {
57
+                    parsedAspects[`${step.response_key_id}`] =
58
+                        step.response_key_prompt
59
+                } else {
60
+                    parsedStages[`${step.response_key_id}`] = step.survey_stage
61
+                }
62
+            })
63
+            return isStage ? parsedStages : parsedAspects
64
+        },
65
+        grabResponsesFromProfile(aspectQuestions) {
66
+            const aspectQuestionsKeys = Object.keys(aspectQuestions).map(Number)
67
+            const responses = currentProfile._profile.responses
68
+                .map(response => {
69
+                    if (
70
+                        !aspectQuestionsKeys.includes(response.response_key_id)
71
+                    ) {
72
+                        return response
73
+                    }
74
+                })
75
+                .filter(res => {
76
+                    return typeof res === 'object'
77
+                })
78
+            return responses
79
+        },
80
+        appendStagesToResponses(responses, surveyStages) {
81
+            const responsesWithStages = responses.map(response => {
82
+                return {
83
+                    ...response,
84
+                    stage: surveyStages[`${response.response_key_id}`],
85
+                }
86
+            })
87
+            return responsesWithStages
88
+        },
89
+        grabAspectResponses(responses, questions) {
90
+            return responses
91
+                .map(response => {
92
+                    const prompt = questions[`${response.response_key_id}`]
93
+                    if (prompt) {
94
+                        return {
95
+                            question: questions[`${response.response_key_id}`],
96
+                            response: response.val,
97
+                        }
98
+                    }
99
+                })
100
+                .filter(res => {
101
+                    return typeof res === 'object'
102
+                })
103
+        },
60 104
     },
61 105
 }
62 106
 </script>
107
+<style>
108
+.survey-spacer {
109
+    height: 1.25rem;
110
+}
111
+</style>

Loading…
Cancelar
Guardar