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

fix APP 407 inputs logic #2572

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open

fix APP 407 inputs logic #2572

wants to merge 9 commits into from

Conversation

r41ph
Copy link
Contributor

@r41ph r41ph commented Dec 12, 2024

Description

https://regennetwork.atlassian.net/browse/APP-407

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • provided a link to the relevant issue or specification
  • provided instructions on how to test
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

How to test

https://deploy-preview-2572--regen-marketplace.netlify.app/project/mai-ndombe-4/buy

  1. Check the reported bug and the zero leading functionality mentioned in ticket work as expected

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items
.

I have...

  • confirmed all author checklist items have been addressed
  • reviewed code correctness and readability
  • verified React components follow DRY principles
  • reviewed documentation is accurate
  • reviewed tests
  • manually tested (if applicable)

Copy link

netlify bot commented Dec 12, 2024

Deploy Preview for terrasos ready!

Name Link
🔨 Latest commit 8cf4080
🔍 Latest deploy log https://app.netlify.com/sites/terrasos/deploys/677d186d6350ba00086d5119
😎 Deploy Preview https://deploy-preview-2572--terrasos.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 12, 2024

Deploy Preview for regen-website ready!

Name Link
🔨 Latest commit 8cf4080
🔍 Latest deploy log https://app.netlify.com/sites/regen-website/deploys/677d186d76200800084f2d9e
😎 Deploy Preview https://deploy-preview-2572--regen-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@r41ph
Copy link
Contributor Author

r41ph commented Dec 12, 2024

@erikalogie @blushi see testing instructions

Note: I've tried to mimic the behaviour in the video shared in the Jira task but since we are using an <input type="number"> there are some limitations on what we can achieve, particularly regarding cursor position.

@r41ph r41ph requested a review from blushi December 12, 2024 10:43
@r41ph r41ph mentioned this pull request Dec 12, 2024
10 tasks
@erikalogie
Copy link
Collaborator

This looks much better. One thing that is a little weird is that if I type in 0 decimals and then keep typing past 2 digits, it erases the decimals that I typed. Whereas with other numbers, the expected behavior of simply not being able to type more digits happens.

Screen.Recording.2024-12-12.at.9.22.52.AM.mov

@r41ph r41ph force-pushed the APP-407-inputs-logic branch from 5d55063 to df367f1 Compare January 6, 2025 09:54
@r41ph
Copy link
Contributor Author

r41ph commented Jan 6, 2025

@erikalogie have a look please. I have updated the code to allow typing two decimals that are zero, but in some scenarios the number may be converted to just 2, like when changing payment method or returning to step 1. This is because our input field is of type=number and JavaScript doesn’t distinguish between 2 and 2.00 because both are treated as the same number.

@erikalogie
Copy link
Collaborator

@erikalogie have a look please. I have updated the code to allow typing two decimals that are zero, but in some scenarios the number may be converted to just 2, like when changing payment method or returning to step 1. This is because our input field is of type=number and JavaScript doesn’t distinguish between 2 and 2.00 because both are treated as the same number.

This looks great now!

Copy link
Member

@blushi blushi left a comment

Choose a reason for hiding this comment

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

Looks good, just a few nits.

Just one small difference I noticed (that was already there btw) between the editable input in the order summary card and the CreditsInput and CurrencyInput is that within the editable input, I cannot use a comma as a decimal separator which is a convention that is widely used: https://en.wikipedia.org/wiki/Decimal_separator#/media/File:DecimalSeparator.svg, looks like we could update sanitizeValue function to account for that, but can be in a separate issue if you want?

Comment on lines 59 to 63
// Allow only two decimals when they are all zeros
const value = event.target.value;
const decimalPart = value.split('.')?.[1];
if (
decimalPart &&
decimalPart.length > 2 &&
decimalPart.startsWith('00') &&
paymentOption === PAYMENT_OPTIONS.CARD
) {
event.target.value = value.slice(0, -1);
}
Copy link
Member

Choose a reason for hiding this comment

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

we could refactor to use a function to get the if value, as the same check is also used in handleInput

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While they are not exactly the same, refactoring makes sense, thanks!

@r41ph r41ph force-pushed the APP-407-inputs-logic branch from df367f1 to 8cf4080 Compare January 7, 2025 12:04
@r41ph
Copy link
Contributor Author

r41ph commented Jan 7, 2025

Just one small difference I noticed (that was already there btw) between the editable input in the order summary...

After having a look, I've created a new issue for this because it'll require a bit more work than just update sanitizeValue because JS doesn't seem to recognise commas as decimal separators.

https://regennetwork.atlassian.net/browse/APP-540

@r41ph r41ph requested a review from blushi January 7, 2025 12:12
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.

3 participants