Parcourir la source

:recycle: Refactor of survey steps logic with J

tabs-content
tomit4 il y a 3 ans
Parent
révision
a17bdfd7d2

+ 0
- 68
frontend/src/components/onboarding/Aspects.vue Voir le fichier

@@ -1,68 +0,0 @@
1
-<template lang="pug">
2
-p {{ aspectQuestions }}
3
-//- form.questionnaire(@submit.prevent='this.$emit("handle-submit")')
4
-
5
-//- p(v-for='question in aspectQuestions')
6
-//-     QuestionResponse(
7
-//-         :question='question'
8
-//-         @updated='updateRadio'
9
-//-         @updateIsAnswered='updateIsAnswered'
10
-//-         @update-all='updateAll'
11
-//-         v-if='question.isBeingAnswered'
12
-//-     )
13
-</template>
14
-
15
-<script>
16
-import QuestionResponse from './QuestionResponse.vue'
17
-import { aspectsArr } from '../../utils/lang.js'
18
-
19
-export default {
20
-    name: 'Aspects',
21
-    components: {
22
-        QuestionResponse,
23
-    },
24
-    props: {
25
-        aspectQuestions: {
26
-            required: true,
27
-            type: Array,
28
-        },
29
-    },
30
-    emits: ['handle-submit', 'update-answers'],
31
-    data: () => ({
32
-        answered: [],
33
-    }),
34
-    async created() {
35
-        this.aspectQuestions.forEach((q, i) => {
36
-            console.log(`Aspect #${i}: ${JSON.stringify(q)}`)
37
-            q.isBeingAnswered = i === 0 ? true : false
38
-        })
39
-        aspectsArr.forEach(() => {
40
-            this.answered.push(null)
41
-        })
42
-    },
43
-    methods: {
44
-        updateAll() {
45
-            this.$emit('handle-submit')
46
-        },
47
-        updateRadio(onRadioSelect) {
48
-            this.answered[onRadioSelect.id - 1] = onRadioSelect.answer
49
-            this.$emit('update-answers', {
50
-                key: 'Aspects',
51
-                question: {
52
-                    survey_stage: 'aspects',
53
-                },
54
-                input: this.answered,
55
-            })
56
-        },
57
-        updateIsAnswered(id) {
58
-            this.aspectQuestions.forEach((q, i) => {
59
-                if (i === id - 1) {
60
-                    const nextQ = this.aspectQuestions[id]
61
-                    q.isBeingAnswered = false
62
-                    nextQ.isBeingAnswered = true
63
-                }
64
-            })
65
-        },
66
-    },
67
-}
68
-</script>

+ 0
- 2
frontend/src/components/onboarding/index.js Voir le fichier

@@ -6,7 +6,6 @@ import Skills from './Skills.vue'
6 6
 import Location from './Location.vue'
7 7
 import Interests from './Interests.vue'
8 8
 import LicensesAndCertifications from './LicensesAndCertifications.vue'
9
-import Aspects from './Aspects.vue'
10 9
 import FormInput from './FormInput.vue'
11 10
 import FormTags from './FormTags.vue'
12 11
 import FormDropdown from './FormDropdown.vue'
@@ -21,7 +20,6 @@ export default {
21 20
     Location,
22 21
     Interests,
23 22
     LicensesAndCertifications,
24
-    Aspects,
25 23
     FormDropdown,
26 24
     FormTags,
27 25
     FormInput,

+ 44
- 54
frontend/src/utils/lang.js Voir le fichier

@@ -15,30 +15,6 @@ const splash = {
15 15
     invalidInputPrompt: null,
16 16
 }
17 17
 
18
-// Order of surveyStages is strongly correlated with order of response_keys 
19
-// in backend's mock.js
20
-const surveyStages = [
21
-    'aspect-1',
22
-    'aspect-2',
23
-    'aspect-3',
24
-    'aspect-4',
25
-    'aspect-5',
26
-    'aspect-6',
27
-    'name',
28
-    'email',
29
-    'password',
30
-    'zipcode',
31
-    'seeking',
32
-    'image',
33
-    'language',
34
-    'duration',
35
-    'presence',
36
-    'blurb',
37
-    'urgency',
38
-    'pronouns',
39
-    'distance'
40
-]
41
-
42 18
 // Easily reorder steps of survey here:
43 19
 const allSteps = {
44 20
     usa: {
@@ -65,6 +41,27 @@ const allSteps = {
65 41
         // roles: 'role',
66 42
     },
67 43
 }
44
+const surveyStages = {
45
+    7: allSteps.usa.name,
46
+    8: allSteps.usa.email,
47
+    9: allSteps.usa.password,
48
+    10: allSteps.usa.zipcode,
49
+    11: allSteps.usa.seeking,
50
+    12: allSteps.usa.image,
51
+    13: allSteps.usa.language,
52
+    14: allSteps.usa.duration,
53
+    15: allSteps.usa.presence,
54
+    16: allSteps.usa.blurb,
55
+    17: allSteps.usa.urgency,
56
+    18: allSteps.usa.pronouns,
57
+    19: allSteps.usa.distance,
58
+    1: allSteps.usa.aspect01,
59
+    2: allSteps.usa.aspect02,
60
+    3: allSteps.usa.aspect03,
61
+    4: allSteps.usa.aspect04,
62
+    5: allSteps.usa.aspect05,
63
+    6: allSteps.usa.aspect06,
64
+}
68 65
 
69 66
 const aspectResponses = {
70 67
     usa: {
@@ -95,41 +92,34 @@ possible.usa = {
95 92
     // key 10
96 93
     duration: ['full-time', 'part-time', 'contract', 'flexible'],
97 94
     // Experience and roles concat, key: 14
98
-//     experience: ['associate', 'junior', 'mid-level', 'senior', 'staff'],
95
+    //     experience: ['associate', 'junior', 'mid-level', 'senior', 'staff'],
99 96
     // roles: {
100
-        // type: [
101
-            // 'back-end',
102
-            // 'database',
103
-            // 'front-end',
104
-            // 'full-stack',
105
-            // 'qa',
106
-            // 'security',
107
-            // 'system',
108
-            // 'test',
109
-        // ],
110
-        // position: [
111
-            // 'administrator',
112
-            // 'analyst',
113
-            // 'architect',
114
-            // 'developer',
115
-            // 'engineer',
116
-            // 'manager',
117
-            // 'technician',
118
-        // ],
119
-        // candidate: ['hiring_manager', 'recruiter'],
97
+    // type: [
98
+    // 'back-end',
99
+    // 'database',
100
+    // 'front-end',
101
+    // 'full-stack',
102
+    // 'qa',
103
+    // 'security',
104
+    // 'system',
105
+    // 'test',
106
+    // ],
107
+    // position: [
108
+    // 'administrator',
109
+    // 'analyst',
110
+    // 'architect',
111
+    // 'developer',
112
+    // 'engineer',
113
+    // 'manager',
114
+    // 'technician',
115
+    // ],
116
+    // candidate: ['hiring_manager', 'recruiter'],
120 117
     // },
121 118
     pronouns: ['she/her', 'she/they', 'he/him', 'he/they', 'they/them'],
122
-//    role: ['role1', 'role2'],
119
+    //    role: ['role1', 'role2'],
123 120
     image: [],
124 121
     zipcode: [],
125 122
     blurb: [],
126 123
 }
127 124
 
128
-export {
129
-    allSteps,
130
-    splash,
131
-    surveyStages,
132
-    aspectResponses,
133
-    aspectsArr,
134
-    possible,
135
-}
125
+export { allSteps, splash, surveyStages, aspectResponses, aspectsArr, possible }

+ 14
- 16
frontend/src/utils/survey.js Voir le fichier

@@ -6,17 +6,13 @@ class SurveyFactory {
6 6
     constructor() {
7 7
         this.questionsFromDb = []
8 8
     }
9
-    _addSurveyStages(responseKeys, surveyStages) {
10
-        responseKeys.forEach((key, i) => {
11
-            key.survey_stage = surveyStages[i]
12
-        })
13
-        return responseKeys
14
-    }
15
-    _addResponses(responseKeys, responsesByCategory) {
16
-        Object.keys(responsesByCategory).forEach(k => {
17
-            responseKeys.forEach(key => {
18
-                if (key.survey_stage === k) {
19
-                    key.responses = responsesByCategory[k]
9
+    _addResponses(responseKeys, possibleResponsesByCategory) {
10
+        console.log('possibleResponsesByCategory >>', possibleResponsesByCategory)
11
+        Object.keys(possibleResponsesByCategory).forEach(categoryKey => {
12
+            console.log('categoryKey >>', categoryKey)
13
+            responseKeys.forEach(responseKey => {
14
+                if (possibleResponsesByCategory[categoryKey].length) {
15
+                    responseKey.responses = possibleResponsesByCategory[categoryKey]
20 16
                 }
21 17
             })
22 18
         })
@@ -38,12 +34,14 @@ class SurveyFactory {
38 34
         })
39 35
         return responseKeys
40 36
     }
37
+    // TODO: Don't nest the for loop...
41 38
     _sortSurveySteps(mutatedResponseKeys, allSteps) {
42 39
         const reordered = [] 
43
-        Object.values(allSteps).forEach((step, i) => {
40
+        Object.values(allSteps).forEach(step => {
44 41
             Object.values(mutatedResponseKeys).forEach(val => {
45
-                if (val.survey_stage === step) {
46
-                    reordered[i] = val
42
+                if (surveyStages[val.response_key_id] === step)  {
43
+                    val.survey_stage = step
44
+                    reordered.push(val)
47 45
                 }
48 46
             })
49 47
         })
@@ -52,12 +50,12 @@ class SurveyFactory {
52 50
     _setSteps() {
53 51
         const responseKeys = this.questionsFromDb
54 52
         const responsesByCategory = possible['usa']
55
-        let mutatedResponseKeys = this._addSurveyStages(responseKeys, surveyStages)
56
-        mutatedResponseKeys = this._addResponses(responseKeys, responsesByCategory)
53
+        let mutatedResponseKeys = this._addResponses(responseKeys, responsesByCategory)
57 54
         mutatedResponseKeys = this._addComponents(responseKeys)
58 55
         mutatedResponseKeys = this._sortSurveySteps(mutatedResponseKeys, allSteps['usa'])
59 56
         // Splash page is placed at beginning of survey
60 57
         mutatedResponseKeys.unshift(splash)
58
+        console.log('mutatedResponseKeys >>', mutatedResponseKeys)
61 59
         return mutatedResponseKeys
62 60
     }
63 61
     async getQuestions() {

Chargement…
Annuler
Enregistrer