refactor
This commit is contained in:
parent
a4efd1fd93
commit
99b7066b83
1 changed files with 20 additions and 12 deletions
|
|
@ -11,40 +11,48 @@ const LoanPanel = () => {
|
|||
const [loanDuration, setLoanDuration] = useState(12);
|
||||
const [loanInterest, setLoanInterest] = useState(5);
|
||||
|
||||
const sanitizeInputToIntWithinRange = ({ value, min, max }) => {
|
||||
const onlyDigitsValue = sanitizeInputAsOnlyDigits({ value });
|
||||
const inRangeValue = sanitizeInputIntoRange({
|
||||
value: onlyDigitsValue,
|
||||
min: min,
|
||||
max: max,
|
||||
});
|
||||
|
||||
return inRangeValue;
|
||||
};
|
||||
|
||||
const handleLoanPrincipalChange = (event) => {
|
||||
setHasBeenInteracted(1);
|
||||
const inputValue = event.target.value;
|
||||
const onlyDigitsValue = sanitizeInputAsOnlyDigits({ value: inputValue });
|
||||
const inRangeValue = sanitizeInputIntoRange({
|
||||
value: onlyDigitsValue,
|
||||
const sanitizedInputValue = sanitizeInputToIntWithinRange({
|
||||
value: inputValue,
|
||||
min: 0,
|
||||
max: 1_000_000,
|
||||
});
|
||||
setLoanPrincipal(inRangeValue);
|
||||
setLoanPrincipal(sanitizedInputValue);
|
||||
};
|
||||
|
||||
const handleLoanDurationChange = (event) => {
|
||||
setHasBeenInteracted(1);
|
||||
const inputValue = event.target.value;
|
||||
const onlyDigitsValue = sanitizeInputAsOnlyDigits({ value: inputValue });
|
||||
const inRangeValue = sanitizeInputIntoRange({
|
||||
value: onlyDigitsValue,
|
||||
const sanitizedInputValue = sanitizeInputToIntWithinRange({
|
||||
value: inputValue,
|
||||
min: 1,
|
||||
max: 360,
|
||||
});
|
||||
setLoanDuration(inRangeValue);
|
||||
setLoanDuration(sanitizedInputValue);
|
||||
};
|
||||
|
||||
const handleLoanInterestChange = (event) => {
|
||||
setHasBeenInteracted(1);
|
||||
const inputValue = event.target.value;
|
||||
const onlyDigitsValue = sanitizeInputAsOnlyDigits({ value: inputValue });
|
||||
const inRangeValue = sanitizeInputIntoRange({
|
||||
value: onlyDigitsValue,
|
||||
const sanitizedInputValue = sanitizeInputToIntWithinRange({
|
||||
value: inputValue,
|
||||
min: 0,
|
||||
max: 50,
|
||||
});
|
||||
setLoanInterest(inRangeValue);
|
||||
setLoanInterest(sanitizedInputValue);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue