@@ -7,6 +7,9 @@ import { colors } from "../constants";
7
7
import { SessionStore } from "../library/session-store" ;
8
8
import dayjs from "dayjs" ;
9
9
10
+ import { UserState , useUserState } from '../library/user-state-context'
11
+ import { UserStateActions , useUserStateActions } from '../library/user-state-actions-context'
12
+
10
13
import {
11
14
TextBlock ,
12
15
SEO ,
@@ -31,26 +34,25 @@ const H4 = styled.h4`
31
34
margin: 5px 0;
32
35
`
33
36
34
- export default class Prescreen1c extends React . Component {
37
+ interface Prescreen1aProps {
38
+ userState : UserState
39
+ userStateActions : UserStateActions
40
+ }
41
+
42
+ interface Prescreen1aState {
43
+ retireAge : number | null
44
+ }
45
+
46
+ class Prescreen1a extends React . Component < Prescreen1aProps , Prescreen1aState > {
47
+ public state : Prescreen1aState = {
48
+ retireAge : null ,
49
+ }
35
50
constructor ( props , context ) {
36
51
super ( props , context )
37
52
this . handleDateChange = this . handleDateChange . bind ( this ) ;
38
- this . state = {
39
- birthDate : null ,
40
- retireAge : null ,
41
- retireDate : null
42
- } ;
43
53
}
44
54
45
55
componentDidMount ( ) {
46
- if ( SessionStore . get ( "BirthDate" ) && ( this . state . birthDate === null ) ) {
47
- var birthdate = new Date ( JSON . parse ( SessionStore . get ( "BirthDate" ) ) )
48
- this . setState ( {
49
- birthDate : birthdate
50
- } )
51
-
52
- }
53
-
54
56
if ( this . state . retireAge === null ) {
55
57
if ( SessionStore . get ( "RetireAge" ) !== null ) {
56
58
var retireAge = JSON . parse ( SessionStore . get ( "RetireAge" ) )
@@ -63,25 +65,24 @@ export default class Prescreen1c extends React.Component {
63
65
}
64
66
}
65
67
66
- async handleDateChange ( name , value ) {
68
+ async handleDateChange ( name , value ) {
69
+ const { userStateActions, userState} = this . props
70
+ const { birthDate} = userState
67
71
if ( name === "birthDatePicked" ) {
68
- SessionStore . push ( "BirthDate" , JSON . stringify ( value ) )
72
+ userStateActions . setBirthDate ( value )
69
73
var year62 = new Date ( value ) . getFullYear ( ) + 62 ;
70
74
SessionStore . push ( "Year62" , year62 )
71
- var fullRetirementAge = await ObsFuncs . getFullRetirementDateSimple ( this . state . birthDate )
75
+ var fullRetirementAge = await ObsFuncs . getFullRetirementDateSimple ( birthDate )
72
76
this . setRetireDate ( value , fullRetirementAge )
73
- var state = { birthDate : value }
74
- this . setState ( state )
75
77
}
76
78
}
77
79
78
80
async setRetireDate ( dateOfBirth , retireAge ) {
81
+ const { userStateActions} = this . props
79
82
var retireDate = dayjs ( dateOfBirth ) . add ( await retireAge , 'years' ) . toDate ( )
80
- SessionStore . push ( "RetireDate" , JSON . stringify ( retireDate ) )
83
+ userStateActions . setRetireDate ( retireDate )
81
84
this . setState ( {
82
85
retireAge : JSON . stringify ( retireAge ) ,
83
- retireDate : JSON . stringify ( retireDate ) ,
84
- retireDateYear : JSON . stringify ( retireDate . getFullYear ( ) ) ,
85
86
} )
86
87
}
87
88
@@ -96,6 +97,9 @@ export default class Prescreen1c extends React.Component {
96
97
// }
97
98
98
99
render ( ) {
100
+ const { userState} = this . props
101
+ const { birthDate, retireDate} = userState
102
+ const retireDateYear = retireDate ? retireDate . getFullYear ( ) : null
99
103
return (
100
104
< div >
101
105
< SEO title = "Pre-Screen 1a" keywords = { [ `gatsby` , `application` , `react` ] } />
@@ -108,21 +112,29 @@ export default class Prescreen1c extends React.Component {
108
112
< StyledDatePicker
109
113
id = "birthDatePicked"
110
114
placeholderText = "Click to select a date"
111
- selected = { this . state . birthDate }
115
+ selected = { birthDate }
112
116
showYearDropdown
113
- openToDate = { this . state . birthDate || dayjs ( ) . subtract ( 64 , 'years' ) . toDate ( ) }
117
+ openToDate = { birthDate || dayjs ( ) . subtract ( 64 , 'years' ) . toDate ( ) }
114
118
onChange = { ( value ) => this . handleDateChange ( "birthDatePicked" , value ) }
115
119
/>
116
120
</ Card >
117
- { this . state . retireDateYear &&
121
+ { retireDateYear &&
118
122
< Card >
119
123
< H4 > Retirement Age</ H4 >
120
124
< p > Your Full Retirement Age (FRA) to collect Social Security
121
125
Benefits is { this . state . retireAge } years old, which is in
122
- year { this . state . retireDateYear } .</ p >
126
+ year { retireDateYear } .</ p >
123
127
</ Card >
124
128
}
125
129
</ div >
126
130
)
127
131
}
128
132
}
133
+
134
+ export default function Prescreen1aWrapper ( ) {
135
+ const userStateActions = useUserStateActions ( )
136
+ const userState = useUserState ( )
137
+ return (
138
+ < Prescreen1a userState = { userState } userStateActions = { userStateActions } />
139
+ )
140
+ }
0 commit comments