Parcourir la source

:recycle: Refactored survey stages as part of front end mutations

tags/0.0.3^2
tomit4 il y a 3 ans
Parent
révision
3ba236b4f8

+ 0
- 19
backend/db/data-generator/mock.js Voir le fichier

@@ -434,7 +434,6 @@ module.exports = {
434 434
             response_key_description: 'first round draft scoring question',
435 435
             aspect: 'visionary_vs_implementer',
436 436
             category: 'aspect',
437
-            survey_stage: 'aspect-1',
438 437
             placeholder: null,
439 438
             invalidInputPrompt: null,
440 439
         },
@@ -445,7 +444,6 @@ module.exports = {
445 444
             response_key_description: 'first round draft scoring question',
446 445
             aspect: 'creative_vs_methodical',
447 446
             category: 'aspect',
448
-            survey_stage: 'aspect-2',
449 447
             placeholder: null,
450 448
             invalidInputPrompt: null,
451 449
         },
@@ -456,7 +454,6 @@ module.exports = {
456 454
             response_key_description: 'first round draft scoring question',
457 455
             aspect: 'dynamic_vs_ordered',
458 456
             category: 'aspect',
459
-            survey_stage: 'aspect-3',
460 457
             placeholder: null,
461 458
             invalidInputPrompt: null,
462 459
         },
@@ -467,7 +464,6 @@ module.exports = {
467 464
             response_key_description: 'first round draft scoring question',
468 465
             aspect: 'precise_vs_resourceful',
469 466
             category: 'aspect',
470
-            survey_stage: 'aspect-4',
471 467
             placeholder: null,
472 468
             invalidInputPrompt: null,
473 469
         },
@@ -478,7 +474,6 @@ module.exports = {
478 474
             response_key_description: 'first round draft scoring question',
479 475
             aspect: 'big_Picture_vs_focused',
480 476
             category: 'aspect',
481
-            survey_stage: 'aspect-5',
482 477
             placeholder: null,
483 478
             invalidInputPrompt: null,
484 479
         },
@@ -489,7 +484,6 @@ module.exports = {
489 484
             response_key_description: 'first round draft scoring question',
490 485
             aspect: 'guided_vs_self-managed',
491 486
             category: 'aspect',
492
-            survey_stage: 'aspect-6',
493 487
             placeholder: null,
494 488
             invalidInputPrompt: null,
495 489
         },
@@ -500,7 +494,6 @@ module.exports = {
500 494
             response_key_description: 'required for profile creation',
501 495
             aspect: null,
502 496
             category: 'input',
503
-            survey_stage: 'name',
504 497
             placeholder: 'Joe Doe',
505 498
             invalidInputPrompt: 'So sorry, but what is your name?',
506 499
         },
@@ -511,7 +504,6 @@ module.exports = {
511 504
             response_key_description: 'required for profile creation',
512 505
             aspect: null,
513 506
             category: 'input',
514
-            survey_stage: 'email',
515 507
             placeholder: 'joe@mailme.com',
516 508
             invalidInputPrompt: 'It looks like that email is not valid, try en email that is formatted like so: joe@joe.com',
517 509
         },
@@ -522,7 +514,6 @@ module.exports = {
522 514
             response_key_description: 'required for profile creation',
523 515
             aspect: null,
524 516
             category: 'input',
525
-            survey_stage: 'password',
526 517
             placeholder: 'supersecr3tp@ssword',
527 518
             invalidInputPrompt: 'That password does not fit our requirements, please follow the above instructions to generate a secure password.',
528 519
         },
@@ -533,7 +524,6 @@ module.exports = {
533 524
             response_key_description: 'required for distance calculations',
534 525
             aspect: null,
535 526
             category: 'input',
536
-            survey_stage: 'zipcode',
537 527
             placeholder: '90012',
538 528
             invalidInputPrompt: 'Oops! That is not a recognized zipcode, please enter a 5 digit zipcode like: 97869',
539 529
         },
@@ -544,7 +534,6 @@ module.exports = {
544 534
             response_key_description: 'required for profile generation',
545 535
             aspect: null,
546 536
             category: 'choice',
547
-            survey_stage: 'seeking',
548 537
             placeholder: null,
549 538
             invalidInputPrompt: 'In order to provide you with the best results, Siimee will need to know whether you are an employer looking to fill a position, or a candidate looking for an employment. Please take a look at our above options and choose one.',
550 539
         },
@@ -555,7 +544,6 @@ module.exports = {
555 544
             response_key_description: 'required for profile pictures',
556 545
             aspect: null,
557 546
             category: 'input',
558
-            survey_stage: 'image',
559 547
             placeholder: null,
560 548
             invalidInputPrompt: 'It appears you have yet to upload an image. Please provide Siimee with an image in case you want to show others what you look like.',
561 549
         },
@@ -566,7 +554,6 @@ module.exports = {
566 554
             response_key_description: 'programming and spoken language preference',
567 555
             aspect: null,
568 556
             category: 'choice',
569
-            survey_stage: 'language',
570 557
             placeholder: null,
571 558
             invalidInputPrompt: 'We try our best to provide results in the language of your choosing. ¿Prefieres ver resultados en español? Or would you prefer to see results in english?',
572 559
         },
@@ -577,7 +564,6 @@ module.exports = {
577 564
             response_key_description: 'duration preference for hours able to dedicate to work',
578 565
             aspect: null,
579 566
             category: 'choice',
580
-            survey_stage: 'duration',
581 567
             placeholder: null,
582 568
             invalidInputPrompt: 'Looks like you have yet to  fill out what kind of work you are most interested in. As in, part-time, full-time. Take a look at our above options and choose whatever feels right for you right now. You can always edit them later!',
583 569
         },
@@ -588,7 +574,6 @@ module.exports = {
588 574
             response_key_description: 'location preference for where work happens',
589 575
             aspect: null,
590 576
             category: 'choice',
591
-            survey_stage: 'presence',
592 577
             placeholder: null,
593 578
             invalidInputPrompt: 'Hold up! So sorry to put a pause here, but it looks like you have not chosen whether to work remotely or in person. No worries, if you are unsure, just choose the flexible option.',
594 579
         },
@@ -599,7 +584,6 @@ module.exports = {
599 584
             response_key_description: 'required for profile description',
600 585
             aspect: null,
601 586
             category: 'input',
602
-            survey_stage: 'blurb', 
603 587
             placeholder: 'my backstory starts long long ago...',
604 588
             invalidInputPrompt: 'Whoa! Cool story. Unfortunately your backstory is either too long or too short. Please tell us a bit about yourself between 1 and 100 characters.',
605 589
         },
@@ -610,7 +594,6 @@ module.exports = {
610 594
             response_key_description: 'urgency for when work is required',
611 595
             aspect: null,
612 596
             category: 'choice',
613
-            survey_stage: 'urgency',
614 597
             placeholder: null,
615 598
             invalidInputPrompt: 'Looks like you left this field blank. Take a look at our provided options and tell us when you would like be employed.',
616 599
         },
@@ -621,7 +604,6 @@ module.exports = {
621 604
             response_key_description: 'required for profile pronouns',
622 605
             aspect: null,
623 606
             category: 'choice',
624
-            survey_stage: 'pronouns',
625 607
             placeholder: null,
626 608
             invalidInputPrompt: 'Ensuring that others on our platform are aware of what your preferred pronouns are is important to us. Please choose from one of the above options.',
627 609
         },
@@ -632,7 +614,6 @@ module.exports = {
632 614
             response_key_description: 'preference for commuting distance cutoff',
633 615
             aspect: null,
634 616
             category: 'input',
635
-            survey_stage: 'distance',
636 617
             placeholder: '5 mi',
637 618
             invalidInputPrompt: 'Whoa! You either left this field blank or tried to input an astronomically large distance you would like to see results from. Please input a distance you would like to see results in.',
638 619
         },

+ 0
- 1
backend/db/migrations/20210527174416_create_response_keys_table.js Voir le fichier

@@ -6,7 +6,6 @@ exports.up = function (knex) {
6 6
         table.string('response_key_description')
7 7
         table.string('aspect')
8 8
         table.string('category')
9
-        table.string('survey_stage')
10 9
         table.string('placeholder')
11 10
         table.string('invalidInputPrompt')
12 11
     })

+ 0
- 1
backend/lib/schemas/responses.js Voir le fichier

@@ -16,7 +16,6 @@ const singleResponseKey = Joi.object({
16 16
     response_key_description: Joi.any(),
17 17
     aspect: Joi.string().allow(null, ''),
18 18
     category: Joi.string().allow(null, ''),
19
-    survey_stage: Joi.string(),
20 19
     placeholder: Joi.string().allow(null, ''),
21 20
     invalidInputPrompt: Joi.string().allow(null, ''),
22 21
 

+ 26
- 1
frontend/src/utils/lang.js Voir le fichier

@@ -3,7 +3,7 @@ const aspectsArr = [1, 2, 3, 4, 5, 6]
3 3
 // Splash page is unique in survey steps and therefore is simply spliced in
4 4
 // during survey generation
5 5
 const splash = {
6
-    response_key_id: 1,
6
+    response_key_id: 20,
7 7
     response_key_category: 'splash',
8 8
     response_key_prompt: 'splash page',
9 9
     response_key_description: 'required for splash page rendering',
@@ -15,6 +15,30 @@ 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
+
18 42
 // TODO: in utils/survey.js modify _setSteps() to reorder survey steps from here
19 43
 const allSteps = {
20 44
     usa: {
@@ -105,6 +129,7 @@ possible.usa = {
105 129
 export {
106 130
     allSteps,
107 131
     splash,
132
+    surveyStages,
108 133
     aspectResponses,
109 134
     aspectsArr,
110 135
     possible,

+ 10
- 4
frontend/src/utils/survey.js Voir le fichier

@@ -1,11 +1,16 @@
1 1
 import { Survey } from '../entities/index.js'
2 2
 import { fetchQuestions } from '../services/index.js'
3
-import { splash, possible } from './lang.js'
3
+import { splash, possible, surveyStages } from './lang.js'
4 4
 
5 5
 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
+    }
9 14
     _addResponses(responseKeys, responsesByCategory) {
10 15
         Object.keys(responsesByCategory).forEach(k => {
11 16
             responseKeys.forEach(key => {
@@ -36,10 +41,11 @@ class SurveyFactory {
36 41
     _setSteps() {
37 42
         const responseKeys = this.questionsFromDb
38 43
         const responsesByCategory = possible['usa']
39
-        let mutatedResponseKeys = this._addResponses(responseKeys, responsesByCategory)
44
+        let mutatedResponseKeys = this._addSurveyStages(responseKeys, surveyStages)
45
+        mutatedResponseKeys = this._addResponses(responseKeys, responsesByCategory)
40 46
         mutatedResponseKeys = this._addComponents(responseKeys)
41
-        // Splash page is spliced into first step of survey
42
-        mutatedResponseKeys.splice(0, 1, splash)
47
+        // Splash page is placed at beginning of survey
48
+        mutatedResponseKeys.unshift(splash)
43 49
         return mutatedResponseKeys
44 50
     }
45 51
     async getQuestions() {

Chargement…
Annuler
Enregistrer