Просмотр исходного кода

refactor practice

tabs-content
toj 3 лет назад
Родитель
Сommit
cb7d83c162

+ 10
- 28
frontend/src/components/onboarding/FormInput.vue Просмотреть файл

1
 <template lang="pug">
1
 <template lang="pug">
2
 .form-input
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
 </template>
6
 </template>
25
 <script>
7
 <script>
26
 export default {
8
 export default {
51
         submitImage() {
33
         submitImage() {
52
             let payload = {
34
             let payload = {
53
                 question: this.question,
35
                 question: this.question,
54
-                answer: 'placeholder for image'
36
+                answer: 'placeholder for image',
55
             }
37
             }
56
             this.$emit('update-answers', payload)
38
             this.$emit('update-answers', payload)
57
-        }
39
+        },
58
     },
40
     },
59
 }
41
 }
60
 </script>
42
 </script>
61
 
43
 
62
 <style>
44
 <style>
63
 .form-input,
45
 .form-input,
64
-input[placeholder], 
46
+input[placeholder],
65
 textarea[placeholder] {
47
 textarea[placeholder] {
66
     text-align: center;
48
     text-align: center;
67
 }
49
 }
68
 input {
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
 </style>
56
 </style>

+ 30
- 4
frontend/src/utils/lang.js Просмотреть файл

17
         // language: 'language',
17
         // language: 'language',
18
         zipcode: 'zipcode',
18
         zipcode: 'zipcode',
19
         // distance: 'distance',
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
     blurb: [],
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
 import { Survey } from '../entities/index.js'
1
 import { Survey } from '../entities/index.js'
2
 import { fetchQuestions } from '../services/index.js'
2
 import { fetchQuestions } from '../services/index.js'
3
-import { possible } from './lang.js'
3
+import { promptOverrides, inputPlaceholders, possible } from './lang.js'
4
 
4
 
5
 const promptToComponent = {
5
 const promptToComponent = {
6
     splash: 'Splash',
6
     splash: 'Splash',
18
     image: 'FormInput',
18
     image: 'FormInput',
19
     // distance: 'FormInput',
19
     // distance: 'FormInput',
20
     blurb: 'FormInput',
20
     blurb: 'FormInput',
21
-    aspects: 'Aspects'
21
+    aspects: 'Aspects',
22
 }
22
 }
23
 /**
23
 /**
24
  * Make a step from match or step information
24
  * Make a step from match or step information
63
             }
63
             }
64
             const responseKeyLike = formatStep(match, step)
64
             const responseKeyLike = formatStep(match, step)
65
             const withComponent = associateWithComponent(responseKeyLike)
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
             return withComponent
75
             return withComponent
68
         })
76
         })
69
-        // temporary extra condition in filter 
77
+        // temporary extra condition in filter
70
         let unseen = this.questionsFromDb.filter(
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
         return [...stepsInCommon, ...unseen]
83
         return [...stepsInCommon, ...unseen]
74
     }
84
     }

+ 18
- 9
frontend/src/views/OnboardingView.vue Просмотреть файл

4
         style='display: flex; flex-direction: column; align-items: center'
4
         style='display: flex; flex-direction: column; align-items: center'
5
         v-if='incomplete'
5
         v-if='incomplete'
6
     )
6
     )
7
-        p(v-if='currentStep != 0') You have completed: {{ currentStep - 1 }} / 7 survey steps
8
         .answers(v-for='(value, key) in answered')
7
         .answers(v-for='(value, key) in answered')
9
             span(v-if='key == "name" && value && currentStep == 2') Hi {{ value }}!
8
             span(v-if='key == "name" && value && currentStep == 2') Hi {{ value }}!
10
             span(v-if='key == "email" && value && currentStep == 3') Thanks for the contact info, {{ answered.name }}!
9
             span(v-if='key == "email" && value && currentStep == 3') Thanks for the contact info, {{ answered.name }}!
11
             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!
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
         .step(v-for='(step, i) in survey.steps')
14
         .step(v-for='(step, i) in survey.steps')
14
             component(
15
             component(
15
                 :aspect-questions='step.component == "Aspects" ? survey.aspectQuestions : null'
16
                 :aspect-questions='step.component == "Aspects" ? survey.aspectQuestions : null'
16
                 :is='step.component'
17
                 :is='step.component'
17
                 :question='step'
18
                 :question='step'
18
-                @handle-submit='onSubmit'
19
                 @update-answers='updateAnswers'
19
                 @update-answers='updateAnswers'
20
                 v-if='step && currentStep == i'
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
     article(v-else)
26
     article(v-else)
23
         SurveyCompleteView(:answers='answered' :surveySteps='survey.steps')
27
         SurveyCompleteView(:answers='answered' :surveySteps='survey.steps')
24
 </template>
28
 </template>
35
     name: 'OnboardingView',
39
     name: 'OnboardingView',
36
     components: {
40
     components: {
37
         ...stepViews,
41
         ...stepViews,
38
-        SurveyCompleteView
42
+        SurveyCompleteView,
39
     },
43
     },
40
     data: () => ({
44
     data: () => ({
41
         answered: {},
45
         answered: {},
58
         updateAnswers(payload) {
62
         updateAnswers(payload) {
59
             // null payload is passed on splash page
63
             // null payload is passed on splash page
60
             if (payload) {
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
 }

Загрузка…
Отмена
Сохранить