Skip to content

Commit

Permalink
UISACQCOMP-216: Extend 'TypeToggle' component's functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrHladchenko1 committed Sep 10, 2024
1 parent 0862151 commit 8565c5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* ECS - Display all consortium tenants in the affiliation selection of the location lookup. Refs UISACQCOMP-202.
* Add isMultiSelect prop to DonorsLookup component. Refs UISACQCOMP-212.
* ECS - Add `isLoading` prop for `ConsortiumFieldInventory` component. Refs UISACQCOMP-215.
* Allow TypeToggle component to accept values in format `'\"Value\"'`. Refs UISACQCOMP-216.

## [5.1.1](https://github.com/folio-org/stripes-acq-components/tree/v5.1.1) (2024-04-22)
[Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v5.1.0...v5.1.1)
Expand Down
14 changes: 8 additions & 6 deletions lib/TypeToggle/TypeToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ const TypeToggle = ({
onChangeToAmount,
onChangeToPercent,
}) => {
const normalizedValue = value.replace(/"/g, '').toLowerCase();

const switchToAmount = useCallback(() => {
if (value !== FUND_DISTR_TYPE.amount) {
if (normalizedValue !== FUND_DISTR_TYPE.amount) {
onChange(FUND_DISTR_TYPE.amount);
if (onChangeToAmount) onChangeToAmount(name);
}
}, [name, onChange, onChangeToAmount, value]);
}, [name, onChange, onChangeToAmount, normalizedValue]);

const switchToPercent = useCallback(() => {
if (value !== FUND_DISTR_TYPE.percent) {
if (normalizedValue !== FUND_DISTR_TYPE.percent) {
onChange(FUND_DISTR_TYPE.percent);
if (onChangeToPercent) onChangeToPercent(name);
}
}, [name, onChange, onChangeToPercent, value]);
}, [name, onChange, onChangeToPercent, normalizedValue]);

return (
<KeyValue label={label}>
Expand All @@ -41,15 +43,15 @@ const TypeToggle = ({
>
<Button
onClick={switchToPercent}
buttonStyle={value === FUND_DISTR_TYPE.percent ? 'primary' : 'default'}
buttonStyle={normalizedValue === FUND_DISTR_TYPE.percent ? 'primary' : 'default'}
data-test-fund-distr-type-percent
disabled={disabled}
>
<FormattedMessage id="stripes-acq-components.fundDistribution.type.sign.percent" />
</Button>
<Button
onClick={switchToAmount}
buttonStyle={value === FUND_DISTR_TYPE.amount ? 'primary' : 'default'}
buttonStyle={normalizedValue === FUND_DISTR_TYPE.amount ? 'primary' : 'default'}
data-test-fund-distr-type-amount
disabled={disabled}
>
Expand Down

0 comments on commit 8565c5a

Please sign in to comment.