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

:construction: Set up new Auth component to survey

juan_spike
tomit4 3 лет назад
Родитель
Сommit
8410e4a835

+ 47
- 0
frontend/src/components/onboarding/Auth.vue Просмотреть файл

@@ -0,0 +1,47 @@
1
+<template lang="pug">
2
+.wait-message
3
+    p.verify-message Thanks for signing up!
4
+    p.verify-message We'll just need you to verify your email address to continue. Please check your email!
5
+    w-button.ma1.grow(
6
+        @click='handleSubmit'
7
+    ) TEST BUTTON
8
+</template>
9
+
10
+<script>
11
+// import { Authenticator } from '../services/auth.service.js'
12
+export default {
13
+    name: 'Auth',
14
+    props: {
15
+        question: {
16
+            required: true,
17
+            type: String,
18
+            default: 'authenticated question!!',
19
+        },
20
+    },
21
+    emits: ['update-answers'],
22
+    created() {
23
+        // TODO: Put front end ping here to send email via Brevo on the backend
24
+        console.log('hi from auth :=>')
25
+    },
26
+    methods: {
27
+        // TODO: remove test button above and use a watcher instead to emit this
28
+        handleSubmit() {
29
+            const payload = {
30
+                question: this.question,
31
+            }
32
+            this.$emit('update-answers', payload)
33
+        },
34
+    },
35
+}
36
+</script>
37
+
38
+<style>
39
+.wait-message {
40
+    margin: 5rem auto;
41
+    text-align: center;
42
+    width: 90%;
43
+    max-width: 35rem;
44
+    font-size: 150%;
45
+    font-weight: bold;
46
+}
47
+</style>

+ 0
- 6
frontend/src/components/onboarding/Splash.vue Просмотреть файл

@@ -27,7 +27,6 @@ w-flex.column
27 27
 </template>
28 28
 
29 29
 <script>
30
-
31 30
 export default {
32 31
     name: 'Splash',
33 32
     props: {
@@ -42,11 +41,6 @@ export default {
42 41
         handleSubmit() {
43 42
             this.$emit('update-answers', null)
44 43
         },
45
-        handleLogin() {
46
-            console.log('hello world :=>')
47
-            // this.$emit('update-answers', null)
48
-        },
49
-
50 44
     },
51 45
 }
52 46
 </script>

+ 2
- 0
frontend/src/components/onboarding/index.js Просмотреть файл

@@ -1,4 +1,5 @@
1 1
 import Splash from './Splash.vue'
2
+import Auth from './Auth.vue'
2 3
 import AccountType from './AccountType.vue'
3 4
 import CompanyID from './CompanyID.vue'
4 5
 import Role from './Role.vue'
@@ -13,6 +14,7 @@ import QuestionResponse from './QuestionResponse.vue'
13 14
 
14 15
 export default {
15 16
     Splash,
17
+    Auth,
16 18
     AccountType,
17 19
     CompanyID,
18 20
     Role,

+ 2
- 0
frontend/src/entities/survey/survey.answer.validator.js Просмотреть файл

@@ -7,6 +7,8 @@ const answerValidator = {
7 7
         minDomainSegments: 2,
8 8
         tlds: { allow: domains },
9 9
     }),
10
+    // TODO: change to valdate against JWT??
11
+    auth: Joi.any(),
10 12
 
11 13
     password: Joi.string().min(10).max(30).pattern(new RegExp('[a-zA-Z0-9]+')),
12 14
     // TODO: Change if going international (only works in usa)

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

@@ -15,6 +15,20 @@ const splash = {
15 15
     invalidInputPrompt: null,
16 16
 }
17 17
 
18
+// Auth page is also unique in survey steps and is spliced in as well
19
+const auth = {
20
+    response_key_id: 21,
21
+    response_key_category: 'auth',
22
+    response_key_prompt: 'auth page',
23
+    response_key_description: 'required to authenticate user signup',
24
+    aspect: null,
25
+    category: 'auth',
26
+    component: 'Auth',
27
+    survey_stage: 'auth',
28
+    placeholder: null,
29
+    invalidInputPrompt: null,
30
+}
31
+
18 32
 // Easily reorder steps of survey here:
19 33
 const allSteps = {
20 34
     usa: {
@@ -122,4 +136,12 @@ possible.usa = {
122 136
     blurb: [],
123 137
 }
124 138
 
125
-export { allSteps, splash, surveyStages, aspectResponses, aspectsArr, possible }
139
+export {
140
+    allSteps,
141
+    splash,
142
+    auth,
143
+    surveyStages,
144
+    aspectResponses,
145
+    aspectsArr,
146
+    possible,
147
+}

+ 23
- 9
frontend/src/utils/survey.js Просмотреть файл

@@ -1,6 +1,6 @@
1 1
 import { Survey } from '../entities/index.js'
2 2
 import { fetchQuestions, insertNewSurveyResponse } from '../services/index.js'
3
-import { splash, possible, surveyStages, allSteps } from './lang.js'
3
+import { splash, auth, possible, surveyStages, allSteps } from './lang.js'
4 4
 
5 5
 class SurveyFactory {
6 6
     constructor() {
@@ -12,7 +12,8 @@ class SurveyFactory {
12 12
         // Removes empty form drop down options from possible['usa']
13 13
         Object.keys(responsesByCategory).forEach(categoryKey => {
14 14
             if (responsesByCategory[categoryKey].length) {
15
-                existingResponses[categoryKey] = responsesByCategory[categoryKey]
15
+                existingResponses[categoryKey] =
16
+                    responsesByCategory[categoryKey]
16 17
             }
17 18
         })
18 19
         // Adds form drop down options to each responseKey
@@ -56,7 +57,7 @@ class SurveyFactory {
56 57
         const reordered = []
57 58
         Object.values(allSteps).forEach(step => {
58 59
             Object.values(mutatedResponseKeys).forEach(response => {
59
-                if (surveyStages[response.response_key_id] === step)  {
60
+                if (surveyStages[response.response_key_id] === step) {
60 61
                     response.survey_stage = step
61 62
                     reordered.push(response)
62 63
                 }
@@ -67,12 +68,23 @@ class SurveyFactory {
67 68
     _setSteps() {
68 69
         const responseKeys = this.questionsFromDb
69 70
         const responsesByCategory = possible['usa']
70
-        let mutatedResponseKeys = this._addSurveySteps(responseKeys, surveyStages)
71
-        mutatedResponseKeys = this._addResponses(mutatedResponseKeys, responsesByCategory)
71
+        let mutatedResponseKeys = this._addSurveySteps(
72
+            responseKeys,
73
+            surveyStages,
74
+        )
75
+        mutatedResponseKeys = this._addResponses(
76
+            mutatedResponseKeys,
77
+            responsesByCategory,
78
+        )
72 79
         mutatedResponseKeys = this._addComponents(responseKeys)
73
-        mutatedResponseKeys = this._sortSurveySteps(mutatedResponseKeys, allSteps['usa'])
80
+        mutatedResponseKeys = this._sortSurveySteps(
81
+            mutatedResponseKeys,
82
+            allSteps['usa'],
83
+        )
74 84
         // Splash page is placed at beginning of survey
75 85
         mutatedResponseKeys.unshift(splash)
86
+        // Auth page is placed after email/password
87
+        mutatedResponseKeys.splice(3, 0, auth)
76 88
         return mutatedResponseKeys
77 89
     }
78 90
     async getQuestions() {
@@ -85,10 +97,12 @@ class SurveyFactory {
85 97
     }
86 98
     async addNewSurveyAnswer(responses, profileId) {
87 99
         try {
88
-            this.responsesFromDb = await insertNewSurveyResponse(responses, profileId)
100
+            this.responsesFromDb = await insertNewSurveyResponse(
101
+                responses,
102
+                profileId,
103
+            )
89 104
             return this.responsesFromDb
90
-        }
91
-        catch (err) {
105
+        } catch (err) {
92 106
             console.error(err)
93 107
         }
94 108
     }

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

@@ -6,8 +6,6 @@ main.view--onboarding
6 6
     )
7 7
         .answers(v-for='(value, key) in answered')
8 8
             span(v-if='key == "name" && value && currentStep == 2') Hi {{ value }}!
9
-            span(v-if='key == "email" && value && currentStep == 3') Thanks for the contact info, {{ answered.name }}!
10
-
11 9
         //- h3(v-if='currentStep == 1') Welcome to Siimee Onboarding! Let's get started!
12 10
         br
13 11
         .step(v-for='(step, i) in survey.steps')
@@ -19,7 +17,7 @@ main.view--onboarding
19 17
                 @handle-submit='onSubmit'
20 18
                 @update-answers='updateAnswers'
21 19
                 v-if='step && currentStep == i'
22
-            )
20
+            ) 
23 21
         .invalidResponseMessage(
24 22
             style='text-align: center'
25 23
             v-if='invalidResponse'
@@ -34,10 +32,7 @@ main.view--onboarding
34 32
 </template>
35 33
 
36 34
 <script>
37
-// import { currentProfile } from '@/services'
38
-// import { createProfileForUserId } from '../services/profile.service'
39 35
 import { surveyFactory } from '@/utils'
40
-import { signupUser, createProfileForUserId } from '@/services/'
41 36
 import stepViews from '@/components/onboarding'
42 37
 import SurveyCompleteView from './SurveyCompleteView.vue'
43 38
 
@@ -59,21 +54,8 @@ export default {
59 54
         invalidResponse: false,
60 55
     }),
61 56
     async created() {
62
-        // uses createSurvey/getQuestions from from utils/survey.service.js 
63
-        // which calls in fetchQuestions from services/survey.service.js
64 57
         this.survey = await surveyFactory.createSurvey()
65
-        // checks if the user has simply refreshed the page after creating a basic profile
66
-        // and redirects the user to their last unanswered survey question
67
-        if (localStorage['currentStep'] &&
68
-            localStorage['currentProfileId'] &&
69
-            localStorage['responses'] &&
70
-            localStorage['answered']) {
71
-            this.currentStep = Number(localStorage['currentStep'])
72
-            this.currentProfileId = Number(localStorage['currentProfileId'])
73
-            this.responses = JSON.parse(localStorage['responses'])
74
-            this.answered = JSON.parse(localStorage['answered'])
75
-            this.goToStep(this.currentStep)
76
-        }
58
+        console.log('this.survey :=>', this.survey)
77 59
     },
78 60
     methods: {
79 61
         onSubmit() {
@@ -85,6 +67,8 @@ export default {
85 67
         async updateAnswers(payload) {
86 68
             // null payload is passed on splash page
87 69
             if (payload) {
70
+                // authentication achieved if payload.resume = true
71
+                if (payload.resume) this.currentStep = 3
88 72
                 this.invalidResponse = false
89 73
                 const k = payload.question.survey_stage
90 74
                 this.answered[k] = payload.input
@@ -93,36 +77,22 @@ export default {
93 77
                     this.invalidResponse = true
94 78
                     return
95 79
                 }
96
-
80
+                //
97 81
                 // once validated, don't log password in answered object
98 82
                 this.answered[k] = k === 'password' ? undefined : payload.input
99
-                console.log('this.answered :=>', this.answered)
100 83
 
101 84
                 // formats initial responses for response table
102 85
                 const response = {}
103 86
                 response.response_key_id = payload.question.response_key_id
104 87
                 response.val = payload.input
105 88
                 this.responses.push(response)
106
-                // save user's progress through survey
107
-                localStorage.setItem('responses', JSON.stringify(this.responses))
108
-                localStorage.setItem('answered', JSON.stringify(this.answered))
109 89
 
110 90
                 // sends latest survey response to db
111 91
                 if (this.currentProfileId) {
112 92
                     surveyFactory.addNewSurveyAnswer(
113
-                        this.responses[this.responses.length - 1], 
114
-                        this.currentProfileId)
115
-                }
116
-
117
-                // creates a user in db as long as name, email, and seeking are defined
118
-                if (!this.currentProfileId && 
119
-                    this.survey.hasMinResponsesToCreateProfile(this.answered)) {
120
-                    const newUser = await signupUser(this.answered)
121
-                    const newUserId = newUser.user_id
122
-                    const newProfile = await createProfileForUserId(newUserId, this.responses)
123
-                    this.currentProfileId = newProfile.profile_id
124
-                    // save user's progress through survey
125
-                    localStorage.setItem('currentProfileId', Number(newProfile.profile_id))
93
+                        this.responses[this.responses.length - 1],
94
+                        this.currentProfileId,
95
+                    )
126 96
                 }
127 97
 
128 98
                 if (k === 'aspects') return
@@ -131,8 +101,6 @@ export default {
131 101
                 this.onSubmit(this.answered)
132 102
             } else {
133 103
                 this.goToStep(this.currentStep + 1)
134
-                // save user's progress through survey
135
-                localStorage.setItem('currentStep', Number(this.currentStep))
136 104
             }
137 105
         },
138 106
     },

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