This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter Products By Price block: don't allow to insert negative values…
… on inputs (#5123) * Don't allow to insert negative values on input for Filter Products By Price block #2695 Don't allow to insert negative values on input for Filter Products By Price block * renaming util functions and add comments
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { NumberFormatValues } from 'react-number-format'; | ||
|
||
/** | ||
Check if that the value is minor than the max price and greater than 0. | ||
*/ | ||
export const isValidMaxValue = ( { | ||
maxConstraint, | ||
minorUnit, | ||
}: { | ||
maxConstraint: number; | ||
minorUnit: number; | ||
} ) => ( { floatValue }: NumberFormatValues ): boolean => { | ||
const maxPrice = maxConstraint / 10 ** minorUnit; | ||
|
||
return floatValue !== undefined && floatValue <= maxPrice && floatValue > 0; | ||
}; | ||
|
||
/** | ||
Check if that the value is minor than the max price and greater than 0. | ||
*/ | ||
export const isValidMinValue = ( { | ||
minConstraint, | ||
currentMaxValue, | ||
minorUnit, | ||
}: { | ||
minConstraint: number; | ||
currentMaxValue: number; | ||
minorUnit: number; | ||
} ) => ( { floatValue }: NumberFormatValues ): boolean => { | ||
const minPrice = minConstraint / 10 ** minorUnit; | ||
const currentMaxPrice = currentMaxValue / 10 ** minorUnit; | ||
|
||
return ( | ||
floatValue !== undefined && | ||
floatValue >= minPrice && | ||
floatValue < currentMaxPrice | ||
); | ||
}; |