-
Notifications
You must be signed in to change notification settings - Fork 193
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
Fix: disable currency abbreviations in custom amounts #7625
Open
JoshuaHungDinh
wants to merge
12
commits into
develop
Choose a base branch
from
fix/abbreviated-language-support
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+15
−1
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a6dab4c
fix: disable abbreviations
JoshuaHungDinh 5da7ac6
Merge branch 'develop' into fix/abbreviated-language-support
JoshuaHungDinh 9c75977
Merge branch 'develop' into fix/abbreviated-language-support
JoshuaHungDinh 6251549
feature: use currency separators
JoshuaHungDinh 4e7513b
Merge branch 'develop' into fix/abbreviated-language-support
JoshuaHungDinh 5980e72
Merge branch 'develop' into fix/abbreviated-language-support
JoshuaHungDinh ba16e61
Merge branch 'develop' into fix/abbreviated-language-support
kjohnson 7819877
Merge github.com:impress-org/give into fix/abbreviated-language-support
kjohnson efa12c8
Merge branch 'fix/abbreviated-language-support' of github.com:impress…
kjohnson 73f413b
Refactor: Replace separator hook
kjohnson 096c0b6
Fix: Prevent conflict with suffix separator
kjohnson 60b6d5d
Merge branch 'develop' into fix/abbreviated-language-support
kjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions
26
src/DonationForms/resources/registrars/templates/fields/Amount/useCurrencySeparators.tsx
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,26 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
/** | ||
* Custom hook to determine the group and decimal separators based on locale. | ||
*/ | ||
export default function useCurrencySeparator(){ | ||
const [groupSeparator, setGroupSeparator] = useState(','); | ||
const [decimalSeparator, setDecimalSeparator] = useState('.'); | ||
|
||
useEffect(() => { | ||
const formatter = new Intl.NumberFormat(); | ||
const getGroupSeparator = formatter.format(1000).replace(/[0-9]/g, ''); | ||
const getDecimalSeparator = formatter.format(1.1).replace(/[0-9]/g, ''); | ||
|
||
// Ensure separators are not the same. | ||
if (getGroupSeparator === getDecimalSeparator) { | ||
setDecimalSeparator(getDecimalSeparator === '.' ? ',' : '.'); | ||
} else { | ||
setGroupSeparator(getGroupSeparator); | ||
setDecimalSeparator(getDecimalSeparator); | ||
} | ||
}, []); | ||
|
||
return { groupSeparator, decimalSeparator }; | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will override the browser's locale and assume a US locale for separators.
While is does prevent the
NaN
issue, we shouldn't do so by locking the local config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I don't think we need a hook for this, since the value shouldn't change after page load. Instead, we could initialize these variables at the top of the component file,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoshuaHungDinh I updated this to use the browser locale configuration and replaced the non-breaking space on the group separator to avoid any conflicts with the suffix separator used by the
<CurrencyInput />
component.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, these changes make sense.
Thanks for helping me move this forward. I'll send it to QA.