瀏覽代碼

:construction: Set up new Auth component to survey

tags/0.0.3^2
tomit4 3 年之前
父節點
當前提交
a5485454e9

+ 47
- 0
frontend/src/components/onboarding/Auth.vue 查看文件

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
 </template>
27
 </template>
28
 
28
 
29
 <script>
29
 <script>
30
-
31
 export default {
30
 export default {
32
     name: 'Splash',
31
     name: 'Splash',
33
     props: {
32
     props: {
42
         handleSubmit() {
41
         handleSubmit() {
43
             this.$emit('update-answers', null)
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
 </script>
46
 </script>

+ 2
- 0
frontend/src/components/onboarding/index.js 查看文件

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

+ 2
- 0
frontend/src/entities/survey/survey.answer.validator.js 查看文件

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

+ 23
- 1
frontend/src/utils/lang.js 查看文件

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

+ 8
- 40
frontend/src/views/OnboardingView.vue 查看文件

6
     )
6
     )
7
         .answers(v-for='(value, key) in answered')
7
         .answers(v-for='(value, key) in answered')
8
             span(v-if='key == "name" && value && currentStep == 2') Hi {{ value }}!
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
         //- h3(v-if='currentStep == 1') Welcome to Siimee Onboarding! Let's get started!
9
         //- h3(v-if='currentStep == 1') Welcome to Siimee Onboarding! Let's get started!
12
         br
10
         br
13
         .step(v-for='(step, i) in survey.steps')
11
         .step(v-for='(step, i) in survey.steps')
19
                 @handle-submit='onSubmit'
17
                 @handle-submit='onSubmit'
20
                 @update-answers='updateAnswers'
18
                 @update-answers='updateAnswers'
21
                 v-if='step && currentStep == i'
19
                 v-if='step && currentStep == i'
22
-            )
20
+            ) 
23
         .invalidResponseMessage(
21
         .invalidResponseMessage(
24
             style='text-align: center'
22
             style='text-align: center'
25
             v-if='invalidResponse'
23
             v-if='invalidResponse'
34
 </template>
32
 </template>
35
 
33
 
36
 <script>
34
 <script>
37
-// import { currentProfile } from '@/services'
38
-// import { createProfileForUserId } from '../services/profile.service'
39
 import { surveyFactory } from '@/utils'
35
 import { surveyFactory } from '@/utils'
40
-import { signupUser, createProfileForUserId } from '@/services/'
41
 import stepViews from '@/components/onboarding'
36
 import stepViews from '@/components/onboarding'
42
 import SurveyCompleteView from './SurveyCompleteView.vue'
37
 import SurveyCompleteView from './SurveyCompleteView.vue'
43
 
38
 
59
         invalidResponse: false,
54
         invalidResponse: false,
60
     }),
55
     }),
61
     async created() {
56
     async created() {
62
-        // uses createSurvey/getQuestions from from utils/survey.service.js 
63
-        // which calls in fetchQuestions from services/survey.service.js
64
         this.survey = await surveyFactory.createSurvey()
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
     methods: {
60
     methods: {
79
         onSubmit() {
61
         onSubmit() {
85
         async updateAnswers(payload) {
67
         async updateAnswers(payload) {
86
             // null payload is passed on splash page
68
             // null payload is passed on splash page
87
             if (payload) {
69
             if (payload) {
70
+                // authentication achieved if payload.resume = true
71
+                if (payload.resume) this.currentStep = 3
88
                 this.invalidResponse = false
72
                 this.invalidResponse = false
89
                 const k = payload.question.survey_stage
73
                 const k = payload.question.survey_stage
90
                 this.answered[k] = payload.input
74
                 this.answered[k] = payload.input
93
                     this.invalidResponse = true
77
                     this.invalidResponse = true
94
                     return
78
                     return
95
                 }
79
                 }
96
-
80
+                //
97
                 // once validated, don't log password in answered object
81
                 // once validated, don't log password in answered object
98
                 this.answered[k] = k === 'password' ? undefined : payload.input
82
                 this.answered[k] = k === 'password' ? undefined : payload.input
99
-                console.log('this.answered :=>', this.answered)
100
 
83
 
101
                 // formats initial responses for response table
84
                 // formats initial responses for response table
102
                 const response = {}
85
                 const response = {}
103
                 response.response_key_id = payload.question.response_key_id
86
                 response.response_key_id = payload.question.response_key_id
104
                 response.val = payload.input
87
                 response.val = payload.input
105
                 this.responses.push(response)
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
                 // sends latest survey response to db
90
                 // sends latest survey response to db
111
                 if (this.currentProfileId) {
91
                 if (this.currentProfileId) {
112
                     surveyFactory.addNewSurveyAnswer(
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
                 if (k === 'aspects') return
98
                 if (k === 'aspects') return
131
                 this.onSubmit(this.answered)
101
                 this.onSubmit(this.answered)
132
             } else {
102
             } else {
133
                 this.goToStep(this.currentStep + 1)
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
     },

Loading…
取消
儲存