Procházet zdrojové kódy

:recycle: Further refactor, separating concerns

tags/0.0.3^2
tomit4 před 3 roky
rodič
revize
e28b580318

+ 31
- 65
backend/db/data-generator/mock.js Zobrazit soubor

@@ -426,246 +426,212 @@ module.exports = {
426 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 429
     response_keys: [
433 430
         {
434 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 432
             response_key_category: 'visionary_vs_implementer',
448 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 434
             response_key_description: 'first round draft scoring question',
450 435
             aspect: 'visionary_vs_implementer',
451 436
             category: 'aspect',
452
-            component: 'QuestionResponse',
453 437
             survey_stage: 'aspect-1',
454 438
             placeholder: null,
455 439
             invalidInputPrompt: null,
456 440
         },
457 441
         {
458
-            response_key_id: 3,
442
+            response_key_id: 2,
459 443
             response_key_category: 'creative_vs_methodical',
460 444
             response_key_prompt: 'Have you found more success working with employees that are more Creative or those that are more Methodical?',
461 445
             response_key_description: 'first round draft scoring question',
462 446
             aspect: 'creative_vs_methodical',
463 447
             category: 'aspect',
464
-            component: 'QuestionResponse',
465 448
             survey_stage: 'aspect-2',
466 449
             placeholder: null,
467 450
             invalidInputPrompt: null,
468 451
         },
469 452
         {
470
-            response_key_id: 4,
453
+            response_key_id: 3,
471 454
             response_key_category: 'dynamic_vs_ordered',
472 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 456
             response_key_description: 'first round draft scoring question',
474 457
             aspect: 'dynamic_vs_ordered',
475 458
             category: 'aspect',
476
-            component: 'QuestionResponse',
477 459
             survey_stage: 'aspect-3',
478 460
             placeholder: null,
479 461
             invalidInputPrompt: null,
480 462
         },
481 463
         {
482
-            response_key_id: 5,
464
+            response_key_id: 4,
483 465
             response_key_category: 'precise_vs_resourceful',
484 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 467
             response_key_description: 'first round draft scoring question',
486 468
             aspect: 'precise_vs_resourceful',
487 469
             category: 'aspect',
488
-            component: 'QuestionResponse',
489 470
             survey_stage: 'aspect-4',
490 471
             placeholder: null,
491 472
             invalidInputPrompt: null,
492 473
         },
493 474
         {
494
-            response_key_id: 6,
475
+            response_key_id: 5,
495 476
             response_key_category: 'big_Picture_vs_focused',
496 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 478
             response_key_description: 'first round draft scoring question',
498 479
             aspect: 'big_Picture_vs_focused',
499 480
             category: 'aspect',
500
-            component: 'QuestionResponse',
501 481
             survey_stage: 'aspect-5',
502 482
             placeholder: null,
503 483
             invalidInputPrompt: null,
504 484
         },
505 485
         {
506
-            response_key_id: 7,
486
+            response_key_id: 6,
507 487
             response_key_category: 'guided_vs_self-managed',
508 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 489
             response_key_description: 'first round draft scoring question',
510 490
             aspect: 'guided_vs_self-managed',
511 491
             category: 'aspect',
512
-            component: 'QuestionResponse',
513 492
             survey_stage: 'aspect-6',
514 493
             placeholder: null,
515 494
             invalidInputPrompt: null,
516 495
         },
517 496
         {
518
-            response_key_id: 8,
497
+            response_key_id: 7,
519 498
             response_key_category: 'profile',
520 499
             response_key_prompt: 'First things first, could you provide us with your name? [break] I am called [break] when others address me.',
521 500
             response_key_description: 'required for profile creation',
522 501
             aspect: null,
523
-            category: null,
524
-            component: 'FormInput',
502
+            category: 'input',
525 503
             survey_stage: 'name',
526 504
             placeholder: 'Joe Doe',
527 505
             invalidInputPrompt: 'So sorry, but what is your name?',
528 506
         },
529 507
         {
530
-            response_key_id: 9,
508
+            response_key_id: 8,
531 509
             response_key_category: 'profile',
532 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 511
             response_key_description: 'required for profile creation',
534 512
             aspect: null,
535
-            category: null,
536
-            component: 'FormInput',
513
+            category: 'input',
537 514
             survey_stage: 'email',
538 515
             placeholder: 'joe@mailme.com',
539 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 520
             response_key_category: 'profile',
544 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 522
             response_key_description: 'required for profile creation',
546 523
             aspect: null,
547
-            category: null,
548
-            component: 'FormInput',
524
+            category: 'input',
549 525
             survey_stage: 'password',
550 526
             placeholder: 'supersecr3tp@ssword',
551 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 531
             response_key_category: 'profile',
556 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 533
             response_key_description: 'required for distance calculations',
558 534
             aspect: null,
559
-            category: null,
560
-            component: 'FormInput',
535
+            category: 'input',
561 536
             survey_stage: 'zipcode',
562 537
             placeholder: '90012',
563 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 542
             response_key_category: 'profile',
568 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 544
             response_key_description: 'required for profile generation',
570 545
             aspect: null,
571
-            category: null,
572
-            component: 'FormDropdown',
546
+            category: 'choice',
573 547
             survey_stage: 'seeking',
574 548
             placeholder: null,
575 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 553
             response_key_category: 'profile',
580 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 555
             response_key_description: 'required for profile pictures',
582 556
             aspect: null,
583
-            category: null,
584
-            component: 'FormInput',
557
+            category: 'input',
585 558
             survey_stage: 'image',
586 559
             placeholder: null,
587 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 564
             response_key_category: 'profile',
592 565
             response_key_prompt: 'What language is your native language?[break] I consider [break] language as my native language.',
593 566
             response_key_description: 'programming and spoken language preference',
594 567
             aspect: null,
595
-            category: null,
596
-            component: 'FormDropdown',
568
+            category: 'choice',
597 569
             survey_stage: 'language',
598 570
             placeholder: null,
599 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 575
             response_key_category: 'profile',
604 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 577
             response_key_description: 'duration preference for hours able to dedicate to work',
606 578
             aspect: null,
607
-            category: null,
608
-            component: 'FormDropdown',
579
+            category: 'choice',
609 580
             survey_stage: 'duration',
610 581
             placeholder: null,
611 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 586
             response_key_category: 'profile',
616 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 588
             response_key_description: 'location preference for where work happens',
618 589
             aspect: null,
619
-            category: null,
620
-            component: 'FormDropdown',
590
+            category: 'choice',
621 591
             survey_stage: 'presence',
622 592
             placeholder: null,
623 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 597
             response_key_category: 'profile',
628 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 599
             response_key_description: 'required for profile description',
630 600
             aspect: null,
631
-            category: null,
632
-            component: 'FormInput',
601
+            category: 'input',
633 602
             survey_stage: 'blurb', 
634 603
             placeholder: 'my backstory starts long long ago...',
635 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 608
             response_key_category: 'profile',
640 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 610
             response_key_description: 'urgency for when work is required',
642 611
             aspect: null,
643
-            category: null,
644
-            component: 'FormDropdown',
612
+            category: 'choice',
645 613
             survey_stage: 'urgency',
646 614
             placeholder: null,
647 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 619
             response_key_category: 'profile',
652 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 621
             response_key_description: 'required for profile pronouns',
654 622
             aspect: null,
655
-            category: null,
656
-            component: 'FormDropdown',
623
+            category: 'choice',
657 624
             survey_stage: 'pronouns',
658 625
             placeholder: null,
659 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 630
             response_key_category: 'profile',
664 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 632
             response_key_description: 'preference for commuting distance cutoff',
666 633
             aspect: null,
667
-            category: null,
668
-            component: 'FormInput',
634
+            category: 'input',
669 635
             survey_stage: 'distance',
670 636
             placeholder: '5 mi',
671 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 Zobrazit soubor

@@ -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('component')
10 9
         table.string('survey_stage')
11 10
         table.string('placeholder')
12 11
         table.string('invalidInputPrompt')

+ 0
- 1
backend/lib/schemas/responses.js Zobrazit soubor

@@ -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
-    component: Joi.string(),
20 19
     survey_stage: Joi.string(),
21 20
     placeholder: Joi.string().allow(null, ''),
22 21
     invalidInputPrompt: Joi.string().allow(null, ''),

+ 18
- 0
frontend/src/utils/lang.js Zobrazit soubor

@@ -1,4 +1,21 @@
1 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 19
 const allSteps = {
3 20
     usa: {
4 21
         splash: 'splash',
@@ -87,6 +104,7 @@ possible.usa = {
87 104
 
88 105
 export {
89 106
     allSteps,
107
+    splash,
90 108
     aspectResponses,
91 109
     aspectsArr,
92 110
     possible,

+ 30
- 6
frontend/src/utils/survey.js Zobrazit soubor

@@ -1,16 +1,14 @@
1 1
 import { Survey } from '../entities/index.js'
2 2
 import { fetchQuestions } from '../services/index.js'
3
-import { possible } from './lang.js'
3
+import { splash, possible } from './lang.js'
4 4
 
5 5
 class SurveyFactory {
6 6
     constructor() {
7 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 12
                 if (key.survey_stage === k) {
15 13
                     key.responses = responsesByCategory[k]
16 14
                 }
@@ -18,6 +16,32 @@ class SurveyFactory {
18 16
         })
19 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 45
     async getQuestions() {
22 46
         try {
23 47
             this.questionsFromDb = await fetchQuestions()

Načítá se…
Zrušit
Uložit