Skip to content

Commit

Permalink
Merge pull request #1031 from knod/code-style-9
Browse files Browse the repository at this point in the history
Cleans through 'src/forms/CurrentExpenses.js'. #1018
  • Loading branch information
knod committed Dec 2, 2018
2 parents 8083aca + 9334953 commit 91a1908
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 162 deletions.
6 changes: 4 additions & 2 deletions src/forms/ButtonReset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import React from 'react';
import { BigButton } from './inputs';


const BLANK_CALLBACK = function () {};

const ButtonReset = function ({ children, onClick, overrides }) {

if (!overrides) {
Expand All @@ -15,7 +17,7 @@ const ButtonReset = function ({ children, onClick, overrides }) {
header: ``,
message: `default`,
leaveText: `Start New Client`,
callback: () => {},
callback: { BLANK_CALLBACK },
});
};

Expand All @@ -28,7 +30,7 @@ const ButtonReset = function ({ children, onClick, overrides }) {
</BigButton>
);

}; // End <ButtonReset>
}; // Ends <ButtonReset>


export { ButtonReset };
73 changes: 38 additions & 35 deletions src/forms/CurrentBenefits.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import cloneDeep from 'lodash/cloneDeep';
// PROJECT COMPONENTS
import { FormPartsContainer } from './FormPartsContainer';
import { ControlledRadioYesNo } from './inputs';

// DATA
import { allBenefitOrders } from '../programs/allBenefitOrders';


Expand All @@ -23,45 +25,48 @@ import { allBenefitOrders } from '../programs/allBenefitOrders';
*/
class CurrentBenefitsContent extends React.Component {
handleRadioChange = (event, inputProps) => {
const benefitName = inputProps.name;

const route = 'benefits';

const value = cloneDeep(this.props.current.benefits);
const benefitName = inputProps.name,
route = `benefits`,
value = cloneDeep(this.props.current.benefits);

if (inputProps.value) {
value.push(benefitName);
value.sort(
// Make sure benefits are in the correct order
(a, b) => {
const aIndex = this.props.benefits.indexOf(a);
const bIndex = this.props.benefits.indexOf(b);
// `props.benefits` is list of available benefits
const aIndex = this.props.benefits.indexOf(a),
bIndex = this.props.benefits.indexOf(b);

return aIndex - bIndex;
}
);
}
else {
} else {
const index = value.indexOf(benefitName);

if (index >= 0) {
value.splice(index, 1);
}
}
} // ends if input value

this.props.updateClientValue(event, { route, value, time: 'current' });
};
this.props.updateClientValue(event, { route, value, time: `current` });
}; // Ends handleRadioChange()

render() {
const { current, translations, benefits } = this.props;
const {
current,
translations,
benefits,
} = this.props;

const components = [];

for (let benefitIndex = 0; benefitIndex < benefits.length; benefitIndex++) {
const benefit = benefits[ benefitIndex ];

const translationKey = `i_has_${benefit}_label`;
const benefit = benefits[ benefitIndex ],
translationKey = `i_has_${benefit}_label`;

// @todo This would have to be handled in every translation situation.
// @todo Also, is there a way we can include this in the translation report?
if (!(translationKey in translations)) {
throw new Error(`No translation found as label for benefit radio buttons; expected key "${translationKey}"`);
}
Expand All @@ -70,26 +75,22 @@ class CurrentBenefitsContent extends React.Component {

components.push(
<ControlledRadioYesNo
key={ benefit }
translations={ translations }
labelText={ labelText }
onChange={ this.handleRadioChange }
checked = { current.benefits.includes(benefit) }
name = { benefit } />
key = { benefit }
translations = { translations }
labelText = { labelText }
onChange = { this.handleRadioChange }
checked = { current.benefits.includes(benefit) }
name = { benefit } />
);
}
} // ends for every benefit

return (
<div>
{components}
</div>
<div>{ components }</div>
);
}
} // End CurrentBenefitsContent()
}; // Ends render()
}; // Ends <CurrentBenefitsContent>

/**
* @todo Combine with related components?
*
/**
* @function
* @param {object} props
* @property {function} props.updateClientValue Updates state upstream.
Expand All @@ -101,6 +102,7 @@ class CurrentBenefitsContent extends React.Component {
* @returns {object} Component
*/
const CurrentBenefitsStep = ({ updateClientValue, navData, client, translations }) => {
// @todo Combine with related components since there are so few?

return (
<FormPartsContainer
Expand All @@ -111,12 +113,13 @@ const CurrentBenefitsStep = ({ updateClientValue, navData, client, translations
formSize = { `massive` }>
<CurrentBenefitsContent
updateClientValue = { updateClientValue }
current = { client.current }
translations = { translations }
benefits = { allBenefitOrders[ client.USState ] } />
current = { client.current }
translations = { translations }
benefits = { allBenefitOrders[ client.USState ] } />
</FormPartsContainer>
);

}; // End CurrentBenefitsStep()
}; // Ends <CurrentBenefitsStep>


export { CurrentBenefitsStep };
Loading

0 comments on commit 91a1908

Please sign in to comment.