Переглянути джерело

refactor practice

tags/0.0.3^2
toj 3 роки тому
джерело
коміт
21ead4d949

+ 10
- 28
frontend/src/components/onboarding/FormInput.vue Переглянути файл

@@ -1,26 +1,8 @@
1 1
 <template lang="pug">
2 2
 .form-input
3
-    h3(v-if='question.response_key_prompt == "name"') Welcome to Siimee Onboarding! Let's get started!
4
-    span(v-if='question.response_key_prompt == "name"') What's your name?: 
5
-    input(v-if='question.response_key_prompt == "name"' placeholder='Jon Doe' type='text' v-model='input')
6
-    span(v-if='question.response_key_prompt == "email"') In order for you to reach out to others on siimee, we'll need an email address. Where can we best reach you?: 
7
-    input(v-if='question.response_key_prompt == "email"' placeholder='                @     .   ' type='text' v-model='input')
8
-    span(v-if='question.response_key_prompt == "password"') Next we'll need you to establish a super secret password. 
9
-        div Your password should be at least 10 characters long and have at
10
-        least 2 special characters. 
11
-        div Please enter your:
12
-    input(v-if='question.response_key_prompt == "password"' placeholder='supersEcre+passw0rd' type='text' v-model='input')
13
-    span(v-if='question.response_key_prompt == "zipcode"') Password looks good! You're doing great. 
14
-        div The next piece of info we'll need is your zip code. That way we can be sure to only show you other people in your area. 
15
-        div What's your zip code?: 
16
-    input(v-if='question.response_key_prompt == "zipcode"' placeholder='99999' type='text' v-model='input')
17
-    span(v-if='question.response_key_prompt == "blurb"')
18
-        div Please provide us with a short blurb about yourself. What's your backstory?:
19
-    textarea(v-if='question.response_key_prompt == "blurb"' placeholder='My Origin Story starts off like this...' type='text' v-model='input' rows='4' cols='50')
20
-    p(v-if='question.response_key_prompt == "image"') Hey, you're almost done!
21
-        p Please provide an image of yourself so others can recognize you if you ever meet up IRL:
22
-        w-button.ma1.grow(@click='submitImage') Upload Image
23
-    w-button.ma1.grow(@click='handleSubmit') NEXT
3
+    span {{ question.response_key_prompt }}
4
+    input(:placeholder='question.placeholder' type='text' v-model='input')
5
+    w-button.ma1.grow(@click="this.$emit('update-answers', { question, input })") NEXT
24 6
 </template>
25 7
 <script>
26 8
 export default {
@@ -51,24 +33,24 @@ export default {
51 33
         submitImage() {
52 34
             let payload = {
53 35
                 question: this.question,
54
-                answer: 'placeholder for image'
36
+                answer: 'placeholder for image',
55 37
             }
56 38
             this.$emit('update-answers', payload)
57
-        }
39
+        },
58 40
     },
59 41
 }
60 42
 </script>
61 43
 
62 44
 <style>
63 45
 .form-input,
64
-input[placeholder], 
46
+input[placeholder],
65 47
 textarea[placeholder] {
66 48
     text-align: center;
67 49
 }
68 50
 input {
69
-  border: 0;
70
-  outline: 0;
71
-  background: transparent;
72
-  border-bottom: 1px solid black;
51
+    border: 0;
52
+    outline: 0;
53
+    background: transparent;
54
+    border-bottom: 1px solid black;
73 55
 }
74 56
 </style>

+ 30
- 4
frontend/src/utils/lang.js Переглянути файл

@@ -17,9 +17,9 @@ const allSteps = {
17 17
         // language: 'language',
18 18
         zipcode: 'zipcode',
19 19
         // distance: 'distance',
20
-        blurb: 'blurb',
21
-        image: 'image',
22
-        aspects: 'aspects'
20
+        // blurb: 'blurb',
21
+        // image: 'image',
22
+        aspects: 'aspects',
23 23
     },
24 24
 }
25 25
 
@@ -81,4 +81,30 @@ possible.usa = {
81 81
     blurb: [],
82 82
 }
83 83
 
84
-export { allSteps, aspectResponses, possible, DELIMITER }
84
+const promptOverrides = {
85
+    name: "What's your name?:",
86
+    email: "In order for you to reach out to others on siimee, we'll need an email address. Where can we best reach you?:",
87
+    password:
88
+        "Next we'll need you to establish a super secret password. Your password should be at least 10 characters long and have at least 2 special characters. Please enter your:",
89
+    zipcode:
90
+        "Password looks good! You're doing great. The next piece of info we'll need is your zip code. That way we can be sure to only show you other people in your area. What's your zip code?:",
91
+    blurb: "Please provide us with a short blurb about yourself. What's your backstory?:",
92
+    image: "Hey, you're almost done! Please provide an image of yourself so others can recognize you if you ever meet up IRL:",
93
+}
94
+
95
+const inputPlaceholders = {
96
+    name: 'Joe Doe',
97
+    email: 'Joe@mailme.com',
98
+    zipcode: '90012',
99
+    blurb: '',
100
+    image: '',
101
+}
102
+
103
+export {
104
+    promptOverrides,
105
+    inputPlaceholders,
106
+    allSteps,
107
+    aspectResponses,
108
+    possible,
109
+    DELIMITER,
110
+}

+ 15
- 5
frontend/src/utils/survey.js Переглянути файл

@@ -1,6 +1,6 @@
1 1
 import { Survey } from '../entities/index.js'
2 2
 import { fetchQuestions } from '../services/index.js'
3
-import { possible } from './lang.js'
3
+import { promptOverrides, inputPlaceholders, possible } from './lang.js'
4 4
 
5 5
 const promptToComponent = {
6 6
     splash: 'Splash',
@@ -18,7 +18,7 @@ const promptToComponent = {
18 18
     image: 'FormInput',
19 19
     // distance: 'FormInput',
20 20
     blurb: 'FormInput',
21
-    aspects: 'Aspects'
21
+    aspects: 'Aspects',
22 22
 }
23 23
 /**
24 24
  * Make a step from match or step information
@@ -63,12 +63,22 @@ class SurveyFactory {
63 63
             }
64 64
             const responseKeyLike = formatStep(match, step)
65 65
             const withComponent = associateWithComponent(responseKeyLike)
66
-            console.log('withComponent :>> ', withComponent)
66
+
67
+            // Mutate the object with extra stuff
68
+            if (promptOverrides[responseKeyLike.response_key_prompt]) {
69
+                const langStub = responseKeyLike.response_key_prompt
70
+                withComponent.response_key_prompt = promptOverrides[langStub]
71
+                withComponent.placeholder = inputPlaceholders[langStub]
72
+                withComponent.charzard = langStub
73
+            }
74
+
67 75
             return withComponent
68 76
         })
69
-        // temporary extra condition in filter 
77
+        // temporary extra condition in filter
70 78
         let unseen = this.questionsFromDb.filter(
71
-            q => !seenIds.includes(q.response_key_id) && [1,2,3,4,5,6].includes(q.response_key_id),
79
+            q =>
80
+                !seenIds.includes(q.response_key_id) &&
81
+                [1, 2, 3, 4, 5, 6].includes(q.response_key_id),
72 82
         )
73 83
         return [...stepsInCommon, ...unseen]
74 84
     }

+ 18
- 9
frontend/src/views/OnboardingView.vue Переглянути файл

@@ -4,21 +4,25 @@ main.view--onboarding
4 4
         style='display: flex; flex-direction: column; align-items: center'
5 5
         v-if='incomplete'
6 6
     )
7
-        p(v-if='currentStep != 0') You have completed: {{ currentStep - 1 }} / 7 survey steps
8 7
         .answers(v-for='(value, key) in answered')
9 8
             span(v-if='key == "name" && value && currentStep == 2') Hi {{ value }}!
10 9
             span(v-if='key == "email" && value && currentStep == 3') Thanks for the contact info, {{ answered.name }}!
11 10
             span(v-if='key == "zipcode" && value && currentStep == 5') Very cool, {{ answered.name }}, we'll be sure only to show you results in your area. Now let's get to know more about you!
12 11
 
12
+        h3(v-if="currentStep == 1") Welcome to Siimee Onboarding! Let's get started!
13
+        
13 14
         .step(v-for='(step, i) in survey.steps')
14 15
             component(
15 16
                 :aspect-questions='step.component == "Aspects" ? survey.aspectQuestions : null'
16 17
                 :is='step.component'
17 18
                 :question='step'
18
-                @handle-submit='onSubmit'
19 19
                 @update-answers='updateAnswers'
20 20
                 v-if='step && currentStep == i'
21 21
             )
22
+            
23
+        footer
24
+            p(v-if='currentStep != 0') You have completed: {{ currentStep - 1 }} / {{ survey.steps.length }} survey steps
25
+    
22 26
     article(v-else)
23 27
         SurveyCompleteView(:answers='answered' :surveySteps='survey.steps')
24 28
 </template>
@@ -35,7 +39,7 @@ export default {
35 39
     name: 'OnboardingView',
36 40
     components: {
37 41
         ...stepViews,
38
-        SurveyCompleteView
42
+        SurveyCompleteView,
39 43
     },
40 44
     data: () => ({
41 45
         answered: {},
@@ -58,13 +62,18 @@ export default {
58 62
         updateAnswers(payload) {
59 63
             // null payload is passed on splash page
60 64
             if (payload) {
61
-                const k = payload.question.response_key_prompt
62
-                this.answered[k] = payload.answer
63
-                console.log(`${k}:`, this.answered[k])
64
-                console.log(`Updated answers: ${JSON.stringify(this.answered)}`)
65
-                if (k === 'aspects') return
65
+                // const k = payload.question.response_key_prompt
66
+                this.answered[payload.question.charzard] = payload.input
67
+                // console.log(`${k}:`, this.answered[k])
68
+                // console.log(`Updated answers: ${JSON.stringify(this.answered)}`)
69
+                // if (k === 'aspects') return
70
+            }
71
+            console.log('this.answered :>> ', this.answered)
72
+            if (this.currentStep > this.survey.steps.length) {
73
+                this.onSubmit(this.answered)
74
+            } else {
75
+                this.goToStep(this.currentStep + 1)
66 76
             }
67
-            this.goToStep(this.currentStep + 1)
68 77
         },
69 78
     },
70 79
 }

Завантаження…
Відмінити
Зберегти