From 0aab9154934e7e746fddd2470d642f253a99ccef Mon Sep 17 00:00:00 2001 From: Thad Kerosky Date: Wed, 14 Jul 2021 02:54:13 -0400 Subject: [PATCH] merge function component fixes --- src/pages/prescreen-1a.tsx | 22 ++++++++++------------ src/pages/prescreen-1b.tsx | 18 ++++-------------- src/pages/prescreen-1c.tsx | 34 +++++++++++++--------------------- 3 files changed, 27 insertions(+), 47 deletions(-) diff --git a/src/pages/prescreen-1a.tsx b/src/pages/prescreen-1a.tsx index 68871b11..9df08c8a 100644 --- a/src/pages/prescreen-1a.tsx +++ b/src/pages/prescreen-1a.tsx @@ -6,7 +6,7 @@ import * as ObsFuncs from "../library/observable-functions"; import { colors } from "../constants"; import dayjs from "dayjs"; -import { UserState, useUserState } from "../library/user-state-context"; +import { useUserState } from "../library/user-state-context"; import { useUserStateActions } from "../library/user-state-actions-context"; import { TextBlock, SEO, Card, WarningBox, H2 } from "../components"; @@ -28,11 +28,6 @@ const H4 = styled.h4` margin: 5px 0; `; -interface Prescreen1aProps { - userState: UserState; - userStateActions: UserStateActions; -} - const Prescreen1a = () => { const userState = useUserState(); const userStateActions = useUserStateActions(); @@ -51,6 +46,11 @@ const Prescreen1a = () => { userStateActions.setYear62(year62); let fullRetirementAge = 0; + /* + TODO: use the getFullRetirementAge from whichever calculator is picked + so we dont need to update the tables by hand + use the raw value because of the delay in setting local/session storage. + */ fullRetirementAge = await ObsFuncs.getFullRetirementDateSimple(value); setRetireDate(value, fullRetirementAge); } else if (value === null) { @@ -60,6 +60,8 @@ const Prescreen1a = () => { }; const setRetireDate = async (dateOfBirth: Date, retireAge: number) => { + /* dayjs cannot .add() fractional years that we put into the tables + but only months, so let us use rounded months. */ const retireAgeInRoundedMonths = Math.round((await retireAge) * 12); const retireDate = dayjs(dateOfBirth).add(retireAgeInRoundedMonths, "month").toDate(); userStateActions.setRetireDate(retireDate); @@ -69,7 +71,7 @@ const Prescreen1a = () => {

Step 1: Background Information

- To calculate your Social Security benefit, please input the following dates. + To calculate your Social Security benefit, please provide your birthdate.

Birthdate

{ ); }; -export default function Prescreen1aWrapper() { - const userStateActions = useUserStateActions(); - const userState = useUserState(); - return ; -} +export default Prescreen1a; \ No newline at end of file diff --git a/src/pages/prescreen-1b.tsx b/src/pages/prescreen-1b.tsx index 8673835f..9a3e3477 100644 --- a/src/pages/prescreen-1b.tsx +++ b/src/pages/prescreen-1b.tsx @@ -43,20 +43,14 @@ const Link = styled.a` overflow-wrap: break-word; `; -interface Prescreen1bProps { - userState: UserState; - userStateActions: UserStateActions; -} -function Prescreen1b() { +const Prescreen1b = () => { const earningsSelectRef = React.createRef(); const howToRef = React.createRef(); const earningsRecordRef = React.createRef(); - const { - userState: { birthDate, haveEarnings, haveSSAAccount, earningsFormat }, - userStateActions: { setHaveEarnings, setHaveSSAAccount, setEarningsFormat }, - } = {userState: useUserState(), userStateActions: useUserStateActions()} ; + const { birthDate, haveEarnings, haveSSAAccount, earningsFormat } = useUserState(); + const { setHaveEarnings, setHaveSSAAccount, setEarningsFormat } = useUserStateActions(); function scrollToElement(ref: React.RefObject) { if (gatsbyScrollWhenFinish) { @@ -322,8 +316,4 @@ function Prescreen1b() { ); } -export default function Prescreen1bWrapper(): JSX.Element { - const userState = useUserState(); - const userStateActions = useUserStateActions(); - return ; -} +export default Prescreen1b; \ No newline at end of file diff --git a/src/pages/prescreen-1c.tsx b/src/pages/prescreen-1c.tsx index 8657918e..1a2f12cf 100644 --- a/src/pages/prescreen-1c.tsx +++ b/src/pages/prescreen-1c.tsx @@ -16,8 +16,8 @@ import { ContentContainer, AnswerInputDiscouragePlaceholder, } from "../components"; -import { PensionEnum, useUserState, UserState } from "../library/user-state-context"; -import { useUserStateActions, UserStateActions } from "../library/user-state-actions-context"; +import { PensionEnum, useUserState } from "../library/user-state-context"; +import { useUserStateActions } from "../library/user-state-actions-context"; import { gatsbyScrollWhenFinish } from "../constants/config"; const StyledDatePicker = styled(DatePicker)` @@ -41,24 +41,20 @@ const TopQuestionAndTitle = styled.div` } `; -interface Prescreen1cProps { - userState: UserState; - userStateActions: UserStateActions; -} - -const Prescreen1c = (props: Prescreen1cProps) => { +const Prescreen1c = () => { const pensionTypeRef = React.createRef(); const pensionAmountRef = React.createRef(); + const { isEmploymentCovered, + pensionDateAwarded, + pensionAmount, + pensionOrRetirementAccount } = useUserState(); const { - userState: { isEmploymentCovered, pensionDateAwarded, pensionAmount, pensionOrRetirementAccount }, - userStateActions: { - setPensionDateAwarded, - setIsEmploymentCovered, - setPensionOrRetirementAccount, - setPensionAmount, - }, - } = props; + setPensionDateAwarded, + setIsEmploymentCovered, + setPensionOrRetirementAccount, + setPensionAmount, + } = useUserStateActions(); function scrollToElement(ref: React.RefObject) { if (gatsbyScrollWhenFinish) { @@ -220,8 +216,4 @@ const Prescreen1c = (props: Prescreen1cProps) => { ); }; -export default function Prescreen1cWrapper(): JSX.Element { - const userState = useUserState(); - const userStateActions = useUserStateActions(); - return ; -} +export default Prescreen1c;