@@ -3,45 +3,34 @@ import { tracked } from '@glimmer/tracking';
33import { action } from '@ember/object' ;
44import { inject as service } from '@ember/service' ;
55import { NEW_FORM_STEPS } from '../constants/new-join-form' ;
6+ import { getLocalStorageItem , setLocalStorageItem } from '../../utils/storage' ;
67
78export default class NewStepperComponent extends Component {
89 MIN_STEP = 0 ;
910 MAX_STEP = 6 ;
11+ applicationId = '4gchuf690' ;
1012
1113 @service login ;
1214 @service router ;
1315 @service onboarding ;
1416 @service applicationTerms ;
1517
16- @tracked currentStep = + (
17- localStorage . getItem ( 'currentStep' ) ??
18- this . args . step ??
19- 0
20- ) ;
18+ @tracked currentStep =
19+ Number ( getLocalStorageItem ( 'currentStep' ) ?? this . args . step ) || 0 ;
2120 @tracked preValid = false ;
2221 @tracked isValid = localStorage . getItem ( 'isValid' ) === 'true' ;
2322
2423 setIsValid = ( newVal ) => ( this . isValid = newVal ) ;
2524 setIsPreValid = ( newVal ) => ( this . preValid = newVal ) ;
2625
27- constructor ( ) {
28- super ( ...arguments ) ;
29-
30- this . handlePopState = ( ) => {
31- const step = new URLSearchParams ( window . location . search ) . get ( 'step' ) ;
32- if ( step !== null ) {
33- this . isValid = false ;
34- this . preValid = false ;
35- this . currentStep = Number ( step ) ;
36- localStorage . setItem ( 'isValid' , false ) ;
37- }
38- } ;
39- window . addEventListener ( 'popstate' , this . handlePopState ) ;
40- }
41-
42- willDestroy ( ) {
43- super . willDestroy ( ...arguments ) ;
44- window . removeEventListener ( 'popstate' , this . handlePopState ) ;
26+ updateQueryParam ( step ) {
27+ const existingQueryParams = this . router . currentRoute ?. queryParams ;
28+ this . router . transitionTo ( 'join' , {
29+ queryParams : {
30+ ...existingQueryParams ,
31+ step,
32+ } ,
33+ } ) ;
4534 }
4635
4736 get showPreviousButton ( ) {
@@ -56,38 +45,32 @@ export default class NewStepperComponent extends Component {
5645 return NEW_FORM_STEPS . subheadings [ this . currentStep - 1 ] ?? '' ;
5746 }
5847
48+ get firstName ( ) {
49+ return localStorage . getItem ( 'first_name' ) ?? '' ;
50+ }
51+
5952 @action incrementStep ( ) {
6053 if ( this . currentStep < this . MAX_STEP ) {
61- this . isValid = false ;
62- this . preValid = false ;
63- this . currentStep += 1 ;
64-
65- localStorage . setItem ( 'currentStep' , this . currentStep ) ;
66- localStorage . setItem ( 'isValid' , false ) ;
67- this . router . transitionTo ( {
68- queryParams : { dev : true , step : this . currentStep } ,
69- } ) ;
54+ const nextStep = this . currentStep + 1 ;
55+ setLocalStorageItem ( 'currentStep' , String ( nextStep ) ) ;
56+ this . currentStep = nextStep ;
57+ this . updateQueryParam ( nextStep ) ;
7058 }
7159 }
7260
7361 @action decrementStep ( ) {
7462 if ( this . currentStep > this . MIN_STEP ) {
75- this . isValid = false ;
76- this . preValid = false ;
77- this . currentStep -= 1 ;
78-
79- localStorage . setItem ( 'currentStep' , this . currentStep ) ;
80- localStorage . setItem ( 'isValid' , false ) ;
81- this . router . transitionTo ( {
82- queryParams : { dev : true , step : this . currentStep } ,
83- } ) ;
63+ const previousStep = this . currentStep - 1 ;
64+ setLocalStorageItem ( 'currentStep' , String ( previousStep ) ) ;
65+ this . currentStep = previousStep ;
66+ this . updateQueryParam ( previousStep ) ;
8467 }
8568 }
8669
8770 @action startHandler ( ) {
88- localStorage . setItem ( 'id' , this . login . userData . id ) ;
89- localStorage . setItem ( 'first_name' , this . login . userData . first_name ) ;
90- localStorage . setItem ( 'last_name' , this . login . userData . last_name ) ;
71+ sessionStorage . setItem ( 'id' , this . login . userData . id ) ;
72+ sessionStorage . setItem ( 'first_name' , this . login . userData . first_name ) ;
73+ sessionStorage . setItem ( 'last_name' , this . login . userData . last_name ) ;
9174 this . incrementStep ( ) ;
9275 }
9376
@@ -96,16 +79,17 @@ export default class NewStepperComponent extends Component {
9679 this . isValid = false ;
9780 this . preValid = false ;
9881 this . currentStep = stepNumber ;
99- localStorage . setItem ( 'currentStep' , this . currentStep ) ;
100- localStorage . setItem ( 'isValid' , false ) ;
101- this . router . transitionTo ( {
102- queryParams : { dev : true , step : this . currentStep } ,
103- } ) ;
82+ setLocalStorageItem ( 'currentStep' , String ( stepNumber ) ) ;
83+ setLocalStorageItem ( 'isValid' , 'false' ) ;
84+ this . updateQueryParam ( stepNumber ) ;
10485 }
10586 }
10687
107- // handle create application using this action
10888 @action handleSubmit ( ) {
109- console . log ( 'Submit review' ) ;
89+ // ToDo: handle create application
90+ console . log ( 'Submit application for review' ) ;
91+ this . currentStep = this . MAX_STEP + 1 ;
92+ setLocalStorageItem ( 'currentStep' , String ( this . currentStep ) ) ;
93+ this . updateQueryParam ( this . currentStep ) ;
11094 }
11195}
0 commit comments