Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook refactor prescreen-1d #251

Merged
merged 2 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 24 additions & 42 deletions src/pages/prescreen-1d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,24 @@ const Link = styled.a`
overflow-wrap: break-word;
`;

///////
///////

interface Prescreen1dProps {
userState: UserState
userStateActions: UserStateActions
}

class Prescreen1d extends React.Component<Prescreen1dProps> {
handleSelection = (e: React.ChangeEvent<HTMLInputElement>) => {
const {
userStateActions: {
setExpectedLastEarningYear,
const Prescreen1d = ({ userState, userStateActions }) => {
const { setExpectedLastEarningYear,
setAwiTrendOrManualPrediction,
setAwiTrendSelection,
setExpectedPercentageWageIncrease
}
} = this.props
const selectValueString = e.target.value;
setExpectedPercentageWageIncrease } = userStateActions;

// why was isManual here??
const {
pensionDateAwarded,
pensionAmount,
expectedLastEarningYear,
awiTrendOrManualPrediction,
awiTrendSelection,
expectedPercentageWageIncrease
} = userState;

const handleSelection = (e: React.ChangeEvent<HTMLInputElement>) => {
const selectValueString = e.target.value;
switch (e.target.name) {
case "expectedLastEarningYear":
setExpectedLastEarningYear(parseInt(selectValueString, 10))
Expand All @@ -99,19 +98,7 @@ class Prescreen1d extends React.Component<Prescreen1dProps> {
}
}

render() {
const {
userState: {
pensionDateAwarded,
pensionAmount,
expectedLastEarningYear,
awiTrendOrManualPrediction,
awiTrendSelection,
expectedPercentageWageIncrease,
isManual
}
} = this.props
return (
return (
<React.Fragment>
<SEO
title="Prescreen 1D"
Expand All @@ -129,7 +116,7 @@ class Prescreen1d extends React.Component<Prescreen1dProps> {
name="expectedLastEarningYear"
defaultValue={expectedLastEarningYear ?? undefined}
placeholder={'2020'}
onChange={this.handleSelection}
onChange={handleSelection}
></AnswerInputDiscouragePlaceholder>
</label>
<WarningBox>
Expand All @@ -145,7 +132,7 @@ class Prescreen1d extends React.Component<Prescreen1dProps> {
type="radio"
name="awiTrendOrManualPrediction"
value={FutureAwiPredictionEnum.PERCENTAGE}
onChange={this.handleSelection}
onChange={handleSelection}
checked={awiTrendOrManualPrediction === FutureAwiPredictionEnum.PERCENTAGE}
/>
<LabelText>Use Percentage Only</LabelText>
Expand All @@ -155,7 +142,7 @@ class Prescreen1d extends React.Component<Prescreen1dProps> {
type="radio"
name="awiTrendOrManualPrediction"
value={FutureAwiPredictionEnum.TREND}
onChange={this.handleSelection}
onChange={handleSelection}
checked={awiTrendOrManualPrediction === FutureAwiPredictionEnum.TREND}
/>
<LabelText>Use Percentage plus<br /> Economic Trends</LabelText>
Expand All @@ -165,7 +152,7 @@ class Prescreen1d extends React.Component<Prescreen1dProps> {
type="radio"
name="awiTrendOrManualPrediction"
value={FutureAwiPredictionEnum.MANUAL}
onChange={this.handleSelection}
onChange={handleSelection}
checked={awiTrendOrManualPrediction === FutureAwiPredictionEnum.MANUAL}
/>
<LabelText>Predict it myself</LabelText>
Expand Down Expand Up @@ -193,7 +180,7 @@ class Prescreen1d extends React.Component<Prescreen1dProps> {
name="expectedPercentageWageIncrease"
defaultValue={expectedPercentageWageIncrease ?? undefined}
placeholder={'0.01'}
onChange={this.handleSelection}
onChange={handleSelection}
>
</AnswerInputDiscouragePlaceholder>
</Card>
Expand Down Expand Up @@ -250,11 +237,6 @@ class Prescreen1d extends React.Component<Prescreen1dProps> {
</ContentContainer>
</React.Fragment>
);
}
}
};

export default function Prescreen1dWrapper(): JSX.Element {
const userState = useUserState()
const userStateActions = useUserStateActions()
return <Prescreen1d userState={userState} userStateActions={userStateActions} />
}
export default Prescreen1d;
Loading