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-410 save buy flow on last user interaction #2574

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

Conversation

r41ph
Copy link
Contributor

@r41ph r41ph commented Jan 8, 2025

Description

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

Now when users interact with the forms the information should be stored in the localstorage automatically even when the next button hasn't been clicked yet, and therefore, on navigating away and back to the same page, users should be in the same step and see the same form data as before navigating away.


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

  1. https://deploy-preview-2574--regen-marketplace.netlify.app/project/mai-ndombe-4/buy
  2. Edit the form and navigate away then come back to the same page and verify the step and the form data is the same as before navigating away.

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 Jan 8, 2025

Deploy Preview for regen-website ready!

Name Link
🔨 Latest commit 662d86f
🔍 Latest deploy log https://app.netlify.com/sites/regen-website/deploys/6788e81bd574b30008a2b58a
😎 Deploy Preview https://deploy-preview-2574--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.

Copy link

netlify bot commented Jan 8, 2025

Deploy Preview for terrasos ready!

Name Link
🔨 Latest commit 662d86f
🔍 Latest deploy log https://app.netlify.com/sites/terrasos/deploys/6788e81b81fcbe0008090066
😎 Deploy Preview https://deploy-preview-2574--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.

@r41ph r41ph requested a review from blushi January 8, 2025 12:31
@r41ph
Copy link
Contributor Author

r41ph commented Jan 8, 2025

@erikalogie see testing instructions

@erikalogie
Copy link
Collaborator

LGTM

@r41ph r41ph force-pushed the fix-APP-410-save-buy-flow-on-last-user-interaction branch from fef3652 to 0b294da Compare January 8, 2025 13:18
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.

Two additional comments:

  • We don't save values for the last step to local storage
  • When using credit card, if the user leaves the page while being on the last step, when he comes back, we should go back to step 2 (Payment info) because we need the user to re-enter credit card info since this is something we can't save to local storage of course

@r41ph r41ph requested a review from blushi January 13, 2025 13:03
@r41ph
Copy link
Contributor Author

r41ph commented Jan 13, 2025

@erikalogie can you review the changes mentioned in this comment please #2574 (review)

@erikalogie
Copy link
Collaborator

LGTM

@S4mmyb
Copy link
Member

S4mmyb commented Jan 13, 2025

LGTM !

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.

If I set credits or currency amount to 0 then leave the page, now I get this error and I need to reset my buy-credits-... local storage value to make it work again

image

name: 'postalCode',
});

const { anonymousPurchase, followProject, subscribeNewsletter, agreeErpa } =
Copy link
Member

Choose a reason for hiding this comment

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

it would be more appropriate to move that getValues() into the useEffect that uses them, looks like we don't need them at the component top level

this is also going to cause a bug when we enable anonymousPurchase checkbox (commented for now) because we use it in the checked prop and getValues does not subscribe to input change, which will cause the checkbox to be unresponsive, that's why we use useWatch instead, which you commented

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this would only cause a bug if we wouldn't update the getValues when we uncomment the anonymousPurchase field. However, it'd probably be better to use useWatch for all fields. I've made the update, please review.

@r41ph
Copy link
Contributor Author

r41ph commented Jan 15, 2025

If I set credits or currency amount to 0 then leave the page, now I get this error...

I've changed the way we handle onBlur when a user leaves the credits and currency inputs. Now if a user leaves the input with a value of 0 or empty '' I'm resetting the credits to 1 and then setting the corresponding currency amount. Also, I have updated the stripeOptions so it doesn't initialise with 0 when data.[CURRENCY_AMOUNT] is undefined.

@erikalogie @S4mmyb have a look how the currency and credits fields behave now when a user leaves the inputs with a value of zero or empty, let me know if you want to change anything.

@blushi although the CI shows some failed tests they weren't related with the code updates and a redeploy seems to have been successful: https://app.netlify.com/sites/regen-website/deploys/6788180794db4932a06dce1f

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

I've changed the way we handle onBlur when a user leaves the credits and currency inputs. Now if a user leaves the input with a value of 0 or empty '' I'm resetting the credits to 1 and then setting the corresponding currency amount.

We should also reset the SELL_ORDERS value in this case. If I set one of the field to 0, then the currency/amount fields do update but not the selected sell orders

Here's how my local storage looks like after that:

image

and then when I go through the end of the flow, I cannot purchase because I'm getting an "invalid amount" error from our server endpoint /marketplace/v1/stripe/create-payment-intent since quantity is NaN

Comment on lines 290 to 297
const stripeAmount =
data?.[CURRENCY_AMOUNT] ||
getCurrencyAmount({
currentCreditsAmount: 1,
card: paymentOption === PAYMENT_OPTIONS.CARD,
orderedSellOrders: cardSellOrders,
creditTypePrecision: creditTypeData?.creditType?.precision,
}).currencyAmount;
Copy link
Member

Choose a reason for hiding this comment

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

should we put this in a useMemo too? getCurrencyAmount is a bit computation heavy

@r41ph r41ph requested a review from blushi January 16, 2025 11:13
@erikalogie
Copy link
Collaborator

@erikalogie @S4mmyb have a look how the currency and credits fields behave now when a user leaves the inputs with a value of zero or empty, let me know if you want to change anything.

I think this is fine? @S4mmyb wdyt

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.

4 participants