ソースを参照

:recycle: Refactored Radio Questionnaire into individual questions

tags/0.0.3^2
tomit4 3年前
コミット
dd01e0b904

+ 22
- 11
frontend/src/components/onboarding/Aspects.vue ファイルの表示

1
 <template lang="pug">
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
 </template>
10
 </template>
13
 
11
 
14
 <script>
12
 <script>
30
     async created() {
28
     async created() {
31
         this.aspectQuestions.forEach((q, i) => {
29
         this.aspectQuestions.forEach((q, i) => {
32
             console.log(`Aspect #${i}: ${JSON.stringify(q)}`)
30
             console.log(`Aspect #${i}: ${JSON.stringify(q)}`)
31
+            q.isBeingAnswered = i === 0 ? true : false
33
         })
32
         })
34
     },
33
     },
35
     methods: {
34
     methods: {
35
+        updateAll() {
36
+            this.$emit('handle-submit')
37
+        },
36
         updateRadio(onRadioSelect) {
38
         updateRadio(onRadioSelect) {
37
             answered[onRadioSelect.id - 1] = onRadioSelect.answer
39
             answered[onRadioSelect.id - 1] = onRadioSelect.answer
38
             this.$emit('update-answers', {
40
             this.$emit('update-answers', {
39
                 key: 'Aspects',
41
                 key: 'Aspects',
40
                 question: {
42
                 question: {
41
-                    survey_stage: 'aspects'
43
+                    survey_stage: 'aspects',
42
                 },
44
                 },
43
                 input: answered,
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
 </script>
59
 </script>

+ 10
- 1
frontend/src/components/onboarding/QuestionResponse.vue ファイルの表示

4
     section.radio-buttons.w-flex.row.justify-space-between
4
     section.radio-buttons.w-flex.row.justify-space-between
5
         p(v-for="label in question.labels") {{label}}
5
         p(v-for="label in question.labels") {{label}}
6
     w-radios.w-flex.row.justify-space-between(@update:model-value="onUpdate" :items="radioItems" color="red")
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
 </template>
10
 </template>
8
 
11
 
9
 <script>
12
 <script>
14
             required: true,
17
             required: true,
15
         },
18
         },
16
     },
19
     },
17
-    emits: ['updated'],
20
+    emits: ['updated', 'update-is-answered', 'update-all'],
18
     data: () => ({
21
     data: () => ({
19
         radioItems: [
22
         radioItems: [
20
             { answer: 1 },
23
             { answer: 1 },
28
         onUpdate(e) {
31
         onUpdate(e) {
29
             this.$emit('updated', { ...this.question, answer: e + 1 })
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
 </script>
42
 </script>

+ 0
- 1
frontend/src/views/OnboardingView.vue ファイルの表示

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

読み込み中…
キャンセル
保存