Skip to content
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

FirstStep.tsx: Improve otherAmount input field #1478

Merged

Conversation

sashko9807
Copy link
Member

-Added an upper donation limit of BGN 1.500.000(Stripe allows up to $1M for a single transaction, so we are close enough); -
-Fixed conflicting labels with input borders;
-Fixed Firefox incompatibility, which caused the input field to accept letters and symbols

Closes: Reported in discord

Testing

Steps to test

  1. Find out a browser which doesn't completely support type="number" for inputs(such as Firefox).
  2. Input field should accept only numbers or decimal points as input.

-Added an upper donation limit of BGN 1.500.000(Stripe allows up to $1M for a single transaction, so we are close enough);
-Fixed conflicting labels with input borders;
-Fixed Firefox incompatibility, which caused the input field to accept letters and symbols
@github-actions
Copy link

github-actions bot commented Jul 10, 2023

✅ Tests will run for this PR. Once they succeed it can be merged.

@ani-kalpachka ani-kalpachka added the run tests Allows running the tests workflows for forked repos label Jul 11, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jul 11, 2023
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Jul 11, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jul 11, 2023
@sashko9807 sashko9807 force-pushed the donation-otherAmount-improvement branch from 3c33c04 to 6297fe8 Compare July 11, 2023 09:41
Copy link
Contributor

@igoychev igoychev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great improvement, just please extract the onKeyDown code as a reusable function

Comment on lines 265 to 276
onKeyDown={(e) => {
if (
formik.errors.otherAmount &&
e.key !== 'Backspace' &&
e.key !== 'Delete' &&
!isInteger(formik.values.otherAmount)
) {
e.preventDefault()
return
}
if (decimalSeparator !== e.key && (e.key === '.' || e.key === ',')) {
e.preventDefault()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks the onKeyDown is quite long and deserves to be a separate function, to keep the main code readable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that the onChange and onPaste behaviors are also changed, should I just extract the whole input field to its own component?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great suggestion, however I was thinking we should not spend much time on something that the browser should support out-of-the-box. So let's leave the extraction for a later stage unless you want to do it now :)

Comment on lines 431 to 447
onKeyDown={(e) => {
if (
formik.errors.otherAmount &&
e.key !== 'Backspace' &&
e.key !== 'Delete' &&
!isInteger(formik.values.otherAmount)
) {
e.preventDefault()
return
}
if (decimalSeparator !== e.key && (e.key === '.' || e.key === ',')) {
e.preventDefault()
return
}

if (
(e.key.charCodeAt(0) >= 48 && e.key.charCodeAt(0) <= 57) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like repeated code from the onKeyDown above, so definitely needs to be a reusable function

@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Jul 14, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jul 14, 2023
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Jul 15, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jul 15, 2023
(e.ctrlKey && e.key === 'c') ||
e.key === 'Backspace' ||
e.key === 'Delete' ||
(e.ctrlKey && e.key === 'a') ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested after the last changes and noticed that on Mac the Copy/Paste/SelectAll combinations are not working. The ctrlKey on Mac is e.metaKey - could you include in the logic too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but I am unable to test it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works now!

Copy link
Contributor

@igoychev igoychev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great for adding the mac keys

@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Jul 18, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jul 18, 2023
@igoychev igoychev merged commit 15063a0 into podkrepi-bg:master Jul 18, 2023
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants