Sfoglia il codice sorgente

:recycle: Further refactor, separating concerns

tags/0.0.3^2
tomit4 3 anni fa
parent
commit
e28b580318

+ 31
- 65
backend/db/data-generator/mock.js Vedi File

426
             is_deleted: false,
426
             is_deleted: false,
427
         },
427
         },
428
     ],
428
     ],
429
-    // need to add responses? table to join to here... use json capability? OR
430
-    // use simplified association logic on front end that is already sort of
431
-    // present
432
     response_keys: [
429
     response_keys: [
433
         {
430
         {
434
             response_key_id: 1,
431
             response_key_id: 1,
435
-            response_key_category: 'splash',
436
-            response_key_prompt: 'splash page',
437
-            response_key_description: 'required for splash page rendering',
438
-            aspect: null,
439
-            category: 'splash',
440
-            component: 'Splash',
441
-            survey_stage: 'splash',
442
-            placeholder: null,
443
-            invalidInputPrompt: null,
444
-        },
445
-        {
446
-            response_key_id: 2,
447
             response_key_category: 'visionary_vs_implementer',
432
             response_key_category: 'visionary_vs_implementer',
448
             response_key_prompt: 'Do you prefer to work with those who are driven by their Visionary insights, or those who are driven more by their Implementation?',
433
             response_key_prompt: 'Do you prefer to work with those who are driven by their Visionary insights, or those who are driven more by their Implementation?',
449
             response_key_description: 'first round draft scoring question',
434
             response_key_description: 'first round draft scoring question',
450
             aspect: 'visionary_vs_implementer',
435
             aspect: 'visionary_vs_implementer',
451
             category: 'aspect',
436
             category: 'aspect',
452
-            component: 'QuestionResponse',
453
             survey_stage: 'aspect-1',
437
             survey_stage: 'aspect-1',
454
             placeholder: null,
438
             placeholder: null,
455
             invalidInputPrompt: null,
439
             invalidInputPrompt: null,
456
         },
440
         },
457
         {
441
         {
458
-            response_key_id: 3,
442
+            response_key_id: 2,
459
             response_key_category: 'creative_vs_methodical',
443
             response_key_category: 'creative_vs_methodical',
460
             response_key_prompt: 'Have you found more success working with employees that are more Creative or those that are more Methodical?',
444
             response_key_prompt: 'Have you found more success working with employees that are more Creative or those that are more Methodical?',
461
             response_key_description: 'first round draft scoring question',
445
             response_key_description: 'first round draft scoring question',
462
             aspect: 'creative_vs_methodical',
446
             aspect: 'creative_vs_methodical',
463
             category: 'aspect',
447
             category: 'aspect',
464
-            component: 'QuestionResponse',
465
             survey_stage: 'aspect-2',
448
             survey_stage: 'aspect-2',
466
             placeholder: null,
449
             placeholder: null,
467
             invalidInputPrompt: null,
450
             invalidInputPrompt: null,
468
         },
451
         },
469
         {
452
         {
470
-            response_key_id: 4,
453
+            response_key_id: 3,
471
             response_key_category: 'dynamic_vs_ordered',
454
             response_key_category: 'dynamic_vs_ordered',
472
             response_key_prompt: 'Which do you find to be the ideal working environment, one that is more Collaborative or one that is more Independent?',
455
             response_key_prompt: 'Which do you find to be the ideal working environment, one that is more Collaborative or one that is more Independent?',
473
             response_key_description: 'first round draft scoring question',
456
             response_key_description: 'first round draft scoring question',
474
             aspect: 'dynamic_vs_ordered',
457
             aspect: 'dynamic_vs_ordered',
475
             category: 'aspect',
458
             category: 'aspect',
476
-            component: 'QuestionResponse',
477
             survey_stage: 'aspect-3',
459
             survey_stage: 'aspect-3',
478
             placeholder: null,
460
             placeholder: null,
479
             invalidInputPrompt: null,
461
             invalidInputPrompt: null,
480
         },
462
         },
481
         {
463
         {
482
-            response_key_id: 5,
464
+            response_key_id: 4,
483
             response_key_category: 'precise_vs_resourceful',
465
             response_key_category: 'precise_vs_resourceful',
484
             response_key_prompt: 'Is the success of your team more likely if it includes individuals who are more Innovative, or those that are more Conventional when fulfilling their job duties?',
466
             response_key_prompt: 'Is the success of your team more likely if it includes individuals who are more Innovative, or those that are more Conventional when fulfilling their job duties?',
485
             response_key_description: 'first round draft scoring question',
467
             response_key_description: 'first round draft scoring question',
486
             aspect: 'precise_vs_resourceful',
468
             aspect: 'precise_vs_resourceful',
487
             category: 'aspect',
469
             category: 'aspect',
488
-            component: 'QuestionResponse',
489
             survey_stage: 'aspect-4',
470
             survey_stage: 'aspect-4',
490
             placeholder: null,
471
             placeholder: null,
491
             invalidInputPrompt: null,
472
             invalidInputPrompt: null,
492
         },
473
         },
493
         {
474
         {
494
-            response_key_id: 6,
475
+            response_key_id: 5,
495
             response_key_category: 'big_Picture_vs_focused',
476
             response_key_category: 'big_Picture_vs_focused',
496
             response_key_prompt: 'When fulfilling the role of the hiring leader, do you find yourself focusing more on the Big Picture or The Task At Hand?',
477
             response_key_prompt: 'When fulfilling the role of the hiring leader, do you find yourself focusing more on the Big Picture or The Task At Hand?',
497
             response_key_description: 'first round draft scoring question',
478
             response_key_description: 'first round draft scoring question',
498
             aspect: 'big_Picture_vs_focused',
479
             aspect: 'big_Picture_vs_focused',
499
             category: 'aspect',
480
             category: 'aspect',
500
-            component: 'QuestionResponse',
501
             survey_stage: 'aspect-5',
481
             survey_stage: 'aspect-5',
502
             placeholder: null,
482
             placeholder: null,
503
             invalidInputPrompt: null,
483
             invalidInputPrompt: null,
504
         },
484
         },
505
         {
485
         {
506
-            response_key_id: 7,
486
+            response_key_id: 6,
507
             response_key_category: 'guided_vs_self-managed',
487
             response_key_category: 'guided_vs_self-managed',
508
             response_key_prompt: 'Do you prefer to Guide your employees towards achieving the team goals, or do you prefer your employees to be Self-Managed?',
488
             response_key_prompt: 'Do you prefer to Guide your employees towards achieving the team goals, or do you prefer your employees to be Self-Managed?',
509
             response_key_description: 'first round draft scoring question',
489
             response_key_description: 'first round draft scoring question',
510
             aspect: 'guided_vs_self-managed',
490
             aspect: 'guided_vs_self-managed',
511
             category: 'aspect',
491
             category: 'aspect',
512
-            component: 'QuestionResponse',
513
             survey_stage: 'aspect-6',
492
             survey_stage: 'aspect-6',
514
             placeholder: null,
493
             placeholder: null,
515
             invalidInputPrompt: null,
494
             invalidInputPrompt: null,
516
         },
495
         },
517
         {
496
         {
518
-            response_key_id: 8,
497
+            response_key_id: 7,
519
             response_key_category: 'profile',
498
             response_key_category: 'profile',
520
             response_key_prompt: 'First things first, could you provide us with your name? [break] I am called [break] when others address me.',
499
             response_key_prompt: 'First things first, could you provide us with your name? [break] I am called [break] when others address me.',
521
             response_key_description: 'required for profile creation',
500
             response_key_description: 'required for profile creation',
522
             aspect: null,
501
             aspect: null,
523
-            category: null,
524
-            component: 'FormInput',
502
+            category: 'input',
525
             survey_stage: 'name',
503
             survey_stage: 'name',
526
             placeholder: 'Joe Doe',
504
             placeholder: 'Joe Doe',
527
             invalidInputPrompt: 'So sorry, but what is your name?',
505
             invalidInputPrompt: 'So sorry, but what is your name?',
528
         },
506
         },
529
         {
507
         {
530
-            response_key_id: 9,
508
+            response_key_id: 8,
531
             response_key_category: 'profile',
509
             response_key_category: 'profile',
532
             response_key_prompt: 'In order for others to reach out to you on Siimee, we will need you to provide your email address.[break]When reaching out to me, [break] is my preferred email.',
510
             response_key_prompt: 'In order for others to reach out to you on Siimee, we will need you to provide your email address.[break]When reaching out to me, [break] is my preferred email.',
533
             response_key_description: 'required for profile creation',
511
             response_key_description: 'required for profile creation',
534
             aspect: null,
512
             aspect: null,
535
-            category: null,
536
-            component: 'FormInput',
513
+            category: 'input',
537
             survey_stage: 'email',
514
             survey_stage: 'email',
538
             placeholder: 'joe@mailme.com',
515
             placeholder: 'joe@mailme.com',
539
             invalidInputPrompt: 'It looks like that email is not valid, try en email that is formatted like so: joe@joe.com',
516
             invalidInputPrompt: 'It looks like that email is not valid, try en email that is formatted like so: joe@joe.com',
540
         },
517
         },
541
         {
518
         {
542
-            response_key_id: 10,
519
+            response_key_id: 9,
543
             response_key_category: 'profile',
520
             response_key_category: 'profile',
544
             response_key_prompt: 'So far so good! Next we will need you to establish a super secret password. Your password should be at least 10 characters long and have at least 2 special characters.[break]My [break] is a very secure passcode that only I will have access to!',
521
             response_key_prompt: 'So far so good! Next we will need you to establish a super secret password. Your password should be at least 10 characters long and have at least 2 special characters.[break]My [break] is a very secure passcode that only I will have access to!',
545
             response_key_description: 'required for profile creation',
522
             response_key_description: 'required for profile creation',
546
             aspect: null,
523
             aspect: null,
547
-            category: null,
548
-            component: 'FormInput',
524
+            category: 'input',
549
             survey_stage: 'password',
525
             survey_stage: 'password',
550
             placeholder: 'supersecr3tp@ssword',
526
             placeholder: 'supersecr3tp@ssword',
551
             invalidInputPrompt: 'That password does not fit our requirements, please follow the above instructions to generate a secure password.',
527
             invalidInputPrompt: 'That password does not fit our requirements, please follow the above instructions to generate a secure password.',
552
         },
528
         },
553
         {
529
         {
554
-            response_key_id: 11,
530
+            response_key_id: 10,
555
             response_key_category: 'profile',
531
             response_key_category: 'profile',
556
             response_key_prompt: 'Looking good! Doing great. The next piece of info needed is your zip code. That way we can be sure to only show you other people in your area.[break]My zip code, [break] is the general area where I wish to see results in.',
532
             response_key_prompt: 'Looking good! Doing great. The next piece of info needed is your zip code. That way we can be sure to only show you other people in your area.[break]My zip code, [break] is the general area where I wish to see results in.',
557
             response_key_description: 'required for distance calculations',
533
             response_key_description: 'required for distance calculations',
558
             aspect: null,
534
             aspect: null,
559
-            category: null,
560
-            component: 'FormInput',
535
+            category: 'input',
561
             survey_stage: 'zipcode',
536
             survey_stage: 'zipcode',
562
             placeholder: '90012',
537
             placeholder: '90012',
563
             invalidInputPrompt: 'Oops! That is not a recognized zipcode, please enter a 5 digit zipcode like: 97869',
538
             invalidInputPrompt: 'Oops! That is not a recognized zipcode, please enter a 5 digit zipcode like: 97869',
564
         },
539
         },
565
         {
540
         {
566
-            response_key_id: 12,
541
+            response_key_id: 11,
567
             response_key_category: 'profile',
542
             response_key_category: 'profile',
568
             response_key_prompt: 'What are you seeking? Are you looking to find a position to be employed in, or are you looking to employ a candidate?[break] I am a [break] seeking an employer/employee.',
543
             response_key_prompt: 'What are you seeking? Are you looking to find a position to be employed in, or are you looking to employ a candidate?[break] I am a [break] seeking an employer/employee.',
569
             response_key_description: 'required for profile generation',
544
             response_key_description: 'required for profile generation',
570
             aspect: null,
545
             aspect: null,
571
-            category: null,
572
-            component: 'FormDropdown',
546
+            category: 'choice',
573
             survey_stage: 'seeking',
547
             survey_stage: 'seeking',
574
             placeholder: null,
548
             placeholder: null,
575
             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.',
549
             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.',
576
         },
550
         },
577
         {
551
         {
578
-            response_key_id: 13,
552
+            response_key_id: 12,
579
             response_key_category: 'profile',
553
             response_key_category: 'profile',
580
             response_key_prompt: 'Hey, you are almost done! Please provide an image of yourself so others can recognize you if you ever meet up IRL:',
554
             response_key_prompt: 'Hey, you are almost done! Please provide an image of yourself so others can recognize you if you ever meet up IRL:',
581
             response_key_description: 'required for profile pictures',
555
             response_key_description: 'required for profile pictures',
582
             aspect: null,
556
             aspect: null,
583
-            category: null,
584
-            component: 'FormInput',
557
+            category: 'input',
585
             survey_stage: 'image',
558
             survey_stage: 'image',
586
             placeholder: null,
559
             placeholder: null,
587
             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.',
560
             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.',
588
         },
561
         },
589
         {
562
         {
590
-            response_key_id: 14,
563
+            response_key_id: 13,
591
             response_key_category: 'profile',
564
             response_key_category: 'profile',
592
             response_key_prompt: 'What language is your native language?[break] I consider [break] language as my native language.',
565
             response_key_prompt: 'What language is your native language?[break] I consider [break] language as my native language.',
593
             response_key_description: 'programming and spoken language preference',
566
             response_key_description: 'programming and spoken language preference',
594
             aspect: null,
567
             aspect: null,
595
-            category: null,
596
-            component: 'FormDropdown',
568
+            category: 'choice',
597
             survey_stage: 'language',
569
             survey_stage: 'language',
598
             placeholder: null,
570
             placeholder: null,
599
             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?',
571
             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?',
600
         },
572
         },
601
         {
573
         {
602
-            response_key_id: 15,
574
+            response_key_id: 14,
603
             response_key_category: 'profile',
575
             response_key_category: 'profile',
604
             response_key_prompt: 'What kind of duration would you prefer? Are you looking for part-time, full-time, other?[break] Currently, I am looking for a [break] job at this time.',
576
             response_key_prompt: 'What kind of duration would you prefer? Are you looking for part-time, full-time, other?[break] Currently, I am looking for a [break] job at this time.',
605
             response_key_description: 'duration preference for hours able to dedicate to work',
577
             response_key_description: 'duration preference for hours able to dedicate to work',
606
             aspect: null,
578
             aspect: null,
607
-            category: null,
608
-            component: 'FormDropdown',
579
+            category: 'choice',
609
             survey_stage: 'duration',
580
             survey_stage: 'duration',
610
             placeholder: null,
581
             placeholder: null,
611
             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!',
582
             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!',
612
         },
583
         },
613
         {
584
         {
614
-            response_key_id: 16,
585
+            response_key_id: 15,
615
             response_key_category: 'profile',
586
             response_key_category: 'profile',
616
             response_key_prompt: 'Would you prefer remote, hybrid, in-person work?[break] Personally I would prefer a [break] job right now. It is just what works best for me.',
587
             response_key_prompt: 'Would you prefer remote, hybrid, in-person work?[break] Personally I would prefer a [break] job right now. It is just what works best for me.',
617
             response_key_description: 'location preference for where work happens',
588
             response_key_description: 'location preference for where work happens',
618
             aspect: null,
589
             aspect: null,
619
-            category: null,
620
-            component: 'FormDropdown',
590
+            category: 'choice',
621
             survey_stage: 'presence',
591
             survey_stage: 'presence',
622
             placeholder: null,
592
             placeholder: null,
623
             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.',
593
             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.',
624
         },
594
         },
625
         {
595
         {
626
-            response_key_id: 17,
596
+            response_key_id: 16,
627
             response_key_category: 'profile',
597
             response_key_category: 'profile',
628
             response_key_prompt: 'Please provide us with a short blurb about yourself. What is your backstory?[break] My origin story starts like this:[break]',
598
             response_key_prompt: 'Please provide us with a short blurb about yourself. What is your backstory?[break] My origin story starts like this:[break]',
629
             response_key_description: 'required for profile description',
599
             response_key_description: 'required for profile description',
630
             aspect: null,
600
             aspect: null,
631
-            category: null,
632
-            component: 'FormInput',
601
+            category: 'input',
633
             survey_stage: 'blurb', 
602
             survey_stage: 'blurb', 
634
             placeholder: 'my backstory starts long long ago...',
603
             placeholder: 'my backstory starts long long ago...',
635
             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.',
604
             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.',
636
         },
605
         },
637
         {
606
         {
638
-            response_key_id: 18,
607
+            response_key_id: 17,
639
             response_key_category: 'profile',
608
             response_key_category: 'profile',
640
             response_key_prompt: 'How soon do you need the position filled or you need to be employed? [break]I am currently [break] when it comes to employment opportunities right now.',
609
             response_key_prompt: 'How soon do you need the position filled or you need to be employed? [break]I am currently [break] when it comes to employment opportunities right now.',
641
             response_key_description: 'urgency for when work is required',
610
             response_key_description: 'urgency for when work is required',
642
             aspect: null,
611
             aspect: null,
643
-            category: null,
644
-            component: 'FormDropdown',
612
+            category: 'choice',
645
             survey_stage: 'urgency',
613
             survey_stage: 'urgency',
646
             placeholder: null,
614
             placeholder: null,
647
             invalidInputPrompt: 'Looks like you left this field blank. Take a look at our provided options and tell us when you would like be employed.',
615
             invalidInputPrompt: 'Looks like you left this field blank. Take a look at our provided options and tell us when you would like be employed.',
648
         },
616
         },
649
         {
617
         {
650
-            response_key_id: 19,
618
+            response_key_id: 18,
651
             response_key_category: 'profile',
619
             response_key_category: 'profile',
652
             response_key_prompt: 'When others refer to you, what pronouns do you prefer they use?[break]I prefer to be called [break] when others refer to me.',
620
             response_key_prompt: 'When others refer to you, what pronouns do you prefer they use?[break]I prefer to be called [break] when others refer to me.',
653
             response_key_description: 'required for profile pronouns',
621
             response_key_description: 'required for profile pronouns',
654
             aspect: null,
622
             aspect: null,
655
-            category: null,
656
-            component: 'FormDropdown',
623
+            category: 'choice',
657
             survey_stage: 'pronouns',
624
             survey_stage: 'pronouns',
658
             placeholder: null,
625
             placeholder: null,
659
             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.',
626
             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.',
660
         },
627
         },
661
         {
628
         {
662
-            response_key_id: 20,
629
+            response_key_id: 19,
663
             response_key_category: 'profile',
630
             response_key_category: 'profile',
664
             response_key_prompt: 'What distance from your home are you looking to work in?[break] Preferably, I would like to work [break] from my place of residence.',
631
             response_key_prompt: 'What distance from your home are you looking to work in?[break] Preferably, I would like to work [break] from my place of residence.',
665
             response_key_description: 'preference for commuting distance cutoff',
632
             response_key_description: 'preference for commuting distance cutoff',
666
             aspect: null,
633
             aspect: null,
667
-            category: null,
668
-            component: 'FormInput',
634
+            category: 'input',
669
             survey_stage: 'distance',
635
             survey_stage: 'distance',
670
             placeholder: '5 mi',
636
             placeholder: '5 mi',
671
             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.',
637
             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.',

+ 0
- 1
backend/db/migrations/20210527174416_create_response_keys_table.js Vedi File

6
         table.string('response_key_description')
6
         table.string('response_key_description')
7
         table.string('aspect')
7
         table.string('aspect')
8
         table.string('category')
8
         table.string('category')
9
-        table.string('component')
10
         table.string('survey_stage')
9
         table.string('survey_stage')
11
         table.string('placeholder')
10
         table.string('placeholder')
12
         table.string('invalidInputPrompt')
11
         table.string('invalidInputPrompt')

+ 0
- 1
backend/lib/schemas/responses.js Vedi File

16
     response_key_description: Joi.any(),
16
     response_key_description: Joi.any(),
17
     aspect: Joi.string().allow(null, ''),
17
     aspect: Joi.string().allow(null, ''),
18
     category: Joi.string().allow(null, ''),
18
     category: Joi.string().allow(null, ''),
19
-    component: Joi.string(),
20
     survey_stage: Joi.string(),
19
     survey_stage: Joi.string(),
21
     placeholder: Joi.string().allow(null, ''),
20
     placeholder: Joi.string().allow(null, ''),
22
     invalidInputPrompt: Joi.string().allow(null, ''),
21
     invalidInputPrompt: Joi.string().allow(null, ''),

+ 18
- 0
frontend/src/utils/lang.js Vedi File

1
 const aspectsArr = [1, 2, 3, 4, 5, 6]
1
 const aspectsArr = [1, 2, 3, 4, 5, 6]
2
+
3
+// Splash page is unique in survey steps and therefore is simply spliced in
4
+// during survey generation
5
+const splash = {
6
+    response_key_id: 1,
7
+    response_key_category: 'splash',
8
+    response_key_prompt: 'splash page',
9
+    response_key_description: 'required for splash page rendering',
10
+    aspect: null,
11
+    category: 'splash',
12
+    component: 'Splash',
13
+    survey_stage: 'splash',
14
+    placeholder: null,
15
+    invalidInputPrompt: null,
16
+}
17
+
18
+// TODO: in utils/survey.js modify _setSteps() to reorder survey steps from here
2
 const allSteps = {
19
 const allSteps = {
3
     usa: {
20
     usa: {
4
         splash: 'splash',
21
         splash: 'splash',
87
 
104
 
88
 export {
105
 export {
89
     allSteps,
106
     allSteps,
107
+    splash,
90
     aspectResponses,
108
     aspectResponses,
91
     aspectsArr,
109
     aspectsArr,
92
     possible,
110
     possible,

+ 30
- 6
frontend/src/utils/survey.js Vedi File

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 { splash, possible } from './lang.js'
4
 
4
 
5
 class SurveyFactory {
5
 class SurveyFactory {
6
     constructor() {
6
     constructor() {
7
         this.questionsFromDb = []
7
         this.questionsFromDb = []
8
     }
8
     }
9
-    _setSteps() {
10
-        const responseKeys = this.questionsFromDb
11
-        const responsesByCategory = possible['usa']
12
-        Object.keys(responsesByCategory).forEach((k) => {
13
-            responseKeys.forEach((key) => {
9
+    _addResponses(responseKeys, responsesByCategory) {
10
+        Object.keys(responsesByCategory).forEach(k => {
11
+            responseKeys.forEach(key => {
14
                 if (key.survey_stage === k) {
12
                 if (key.survey_stage === k) {
15
                     key.responses = responsesByCategory[k]
13
                     key.responses = responsesByCategory[k]
16
                 }
14
                 }
18
         })
16
         })
19
         return responseKeys
17
         return responseKeys
20
     }
18
     }
19
+    _addComponents(responseKeys) {
20
+        responseKeys.forEach(key => {
21
+            switch (key.category) {
22
+                case 'input':
23
+                    key.component = 'FormInput'
24
+                    break
25
+                case 'choice':
26
+                    key.component = 'FormDropdown'
27
+                    break
28
+                case 'aspect':
29
+                    key.component = 'QuestionResponse'
30
+                    break
31
+            }
32
+        })
33
+        return responseKeys
34
+    }
35
+    // TODO: in _setSteps(), reorder survey steps based off of allSteps in lang.js
36
+    _setSteps() {
37
+        const responseKeys = this.questionsFromDb
38
+        const responsesByCategory = possible['usa']
39
+        let mutatedResponseKeys = this._addResponses(responseKeys, responsesByCategory)
40
+        mutatedResponseKeys = this._addComponents(responseKeys)
41
+        // Splash page is spliced into first step of survey
42
+        mutatedResponseKeys.splice(0, 1, splash)
43
+        return mutatedResponseKeys
44
+    }
21
     async getQuestions() {
45
     async getQuestions() {
22
         try {
46
         try {
23
             this.questionsFromDb = await fetchQuestions()
47
             this.questionsFromDb = await fetchQuestions()

Loading…
Annulla
Salva