Sfoglia il codice sorgente

:recycle: Refactored Radio Questionnaire into individual questions

tags/0.0.3^2
tomit4 3 anni fa
parent
commit
dd01e0b904

+ 22
- 11
frontend/src/components/onboarding/Aspects.vue Vedi File

@@ -1,14 +1,12 @@
1 1
 <template lang="pug">
2
-w-card.aspects.w-flex.column
3
-    form.questionnaire(@submit.prevent='this.$emit("handle-submit")')
4
-        QuestionResponse(
5
-            :question='question'
6
-            @updated='updateRadio'
7
-            v-for='question in aspectQuestions'
8
-        )
9
-        w-button.ma1.grow(bg-color='success' type='submit')
10
-            w-icon.mr1 wi-check
11
-            | SUBMIT ANSWERS
2
+form.questionnaire(@submit.prevent='this.$emit("handle-submit")')
3
+p(v-for='question in aspectQuestions')
4
+    QuestionResponse(
5
+        :question='question' 
6
+        @updated='updateRadio'
7
+        @updateIsAnswered='updateIsAnswered'
8
+        v-if='question.isBeingAnswered' @update-all='updateAll'
9
+    )
12 10
 </template>
13 11
 
14 12
 <script>
@@ -30,19 +28,32 @@ export default {
30 28
     async created() {
31 29
         this.aspectQuestions.forEach((q, i) => {
32 30
             console.log(`Aspect #${i}: ${JSON.stringify(q)}`)
31
+            q.isBeingAnswered = i === 0 ? true : false
33 32
         })
34 33
     },
35 34
     methods: {
35
+        updateAll() {
36
+            this.$emit('handle-submit')
37
+        },
36 38
         updateRadio(onRadioSelect) {
37 39
             answered[onRadioSelect.id - 1] = onRadioSelect.answer
38 40
             this.$emit('update-answers', {
39 41
                 key: 'Aspects',
40 42
                 question: {
41
-                    survey_stage: 'aspects'
43
+                    survey_stage: 'aspects',
42 44
                 },
43 45
                 input: answered,
44 46
             })
45 47
         },
48
+        updateIsAnswered(id) {
49
+            this.aspectQuestions.forEach((q, i) => {
50
+                if (i === id - 1) {
51
+                    const nextQ = this.aspectQuestions[id]
52
+                    q.isBeingAnswered = false
53
+                    nextQ.isBeingAnswered = true
54
+                }
55
+            })
56
+        },
46 57
     },
47 58
 }
48 59
 </script>

+ 10
- 1
frontend/src/components/onboarding/QuestionResponse.vue Vedi File

@@ -4,6 +4,9 @@ w-card.question
4 4
     section.radio-buttons.w-flex.row.justify-space-between
5 5
         p(v-for="label in question.labels") {{label}}
6 6
     w-radios.w-flex.row.justify-space-between(@update:model-value="onUpdate" :items="radioItems" color="red")
7
+    w-button.ma1.grow(v-if='question.id !== 6' @click="updateAnswers") NEXT
8
+    w-button.ma1.grow(v-else @click="updateAll") SUBMIT ANSWERS
9
+
7 10
 </template>
8 11
 
9 12
 <script>
@@ -14,7 +17,7 @@ export default {
14 17
             required: true,
15 18
         },
16 19
     },
17
-    emits: ['updated'],
20
+    emits: ['updated', 'update-is-answered', 'update-all'],
18 21
     data: () => ({
19 22
         radioItems: [
20 23
             { answer: 1 },
@@ -28,6 +31,12 @@ export default {
28 31
         onUpdate(e) {
29 32
             this.$emit('updated', { ...this.question, answer: e + 1 })
30 33
         },
34
+        updateAnswers() {
35
+            this.$emit('update-is-answered', this.question.id)
36
+        },
37
+        updateAll() {
38
+            this.$emit('update-all')
39
+        }
31 40
     },
32 41
 }
33 42
 </script>

+ 0
- 1
frontend/src/views/OnboardingView.vue Vedi File

@@ -67,7 +67,6 @@ export default {
67 67
                 console.log(`Updated answers: ${JSON.stringify(this.answered)}`)
68 68
                 if (k === 'aspects') return
69 69
             }
70
-            console.log('this.answered :>> ', this.answered)
71 70
             if (this.currentStep > this.survey.steps.length) {
72 71
                 this.onSubmit(this.answered)
73 72
             } else {

Loading…
Annulla
Salva