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

chore: [IOBP-316] Add return to origin page after payment flow completion #5399

Merged
merged 20 commits into from
Jan 24, 2024

Conversation

Hantex9
Copy link
Contributor

@Hantex9 Hantex9 commented Jan 15, 2024

Short description

This PR implements a new feature that allows users to automatically navigate back to their origin page once they have completed (successfully or not) the payment process. This enhancement improves user experience by providing a seamless transition back to their initial context after finishing a transaction.

List of changes proposed in this pull request

  • Added an additional argument into walletPaymentInitState action that expects an optional route name to go back to after the payment is completed/canceled.

How to test

  • Start a new payment flow until you reach the end of it;
  • When you close the outcome message, you should be able to go back to the origin point that started the flow

Preview

origin-back.mov

@Hantex9 Hantex9 added the IO-Bonus e pagamenti IO - Bonus e pagamenti label Jan 15, 2024
@Hantex9 Hantex9 requested a review from a team as a code owner January 15, 2024 13:19
@pagopa-github-bot pagopa-github-bot changed the title feat: [IOBP-316] Add return to origin page after payment flow completion chore: [IOBP-316] Add return to origin page after payment flow completion Jan 15, 2024
@pagopa-github-bot
Copy link
Collaborator

pagopa-github-bot commented Jan 15, 2024

Affected stories

  • ⚙️ IOBP-316: Come CIT voglio poter tornare alla pagina di origine dopo aver completato il flusso di pagamento
    subtask of
    • IOBP-197: [MVP] Integrazione IO-ecommerce PagoPA (Flusso pagamento)

Generated by 🚫 dangerJS against eea52e1

Copy link

codecov bot commented Jan 15, 2024

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (71d6507) 47.46% compared to head (eea52e1) 47.44%.
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5399      +/-   ##
==========================================
- Coverage   47.46%   47.44%   -0.02%     
==========================================
  Files        1604     1604              
  Lines       33600    33613      +13     
  Branches     8204     8205       +1     
==========================================
+ Hits        15948    15949       +1     
- Misses      17594    17606      +12     
  Partials       58       58              
Files Coverage Δ
...es/walletV3/payment/store/actions/orchestration.ts 100.00% <ø> (ø)
...features/walletV3/payment/store/selectors/index.ts 43.75% <50.00%> (+0.41%) ⬆️
.../features/walletV3/payment/store/reducers/index.ts 10.52% <0.00%> (-0.19%) ⬇️
...tV3/payment/screens/WalletPaymentOutcomeScreen.tsx 2.04% <0.00%> (-0.19%) ⬇️
...s/walletV3/details/screens/WalletDetailsScreen.tsx 7.89% <0.00%> (-1.49%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 893d6e4...eea52e1. Read the comment docs.

@@ -56,6 +60,10 @@ const WalletPaymentOutcomeScreen = () => {

const handleClose = () => {
navigation.popToTop();
if (paymentStartRoute) {
navigation.navigate(paymentStartRoute);
Copy link
Contributor

Choose a reason for hiding this comment

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

What if I need to navigate to a sub-route?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, in this way, we cannot handle a sub-route. I changed the implementation and now the action walletPaymentInitState accepts an object with the root navigator and screen param. In this way, it's possible to navigate anywhere after the payment flow closes.

What do you think? 2102d66

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the best way is to save all the current route info, like we are currently doing in the payment sagas:

    const currentRouteName = NavigationService.getCurrentRouteName();
    const currentRouteKey = NavigationService.getCurrentRouteKey();
    if (currentRouteName !== undefined && currentRouteKey !== undefined) {
      yield* put(
        paymentInitializeEntrypointRoute({
          name: currentRouteName,
          key: currentRouteKey
        })
      );
    }

In this way we will be able to save the information on the route directly within the saga and not from the component that starts the payment flow.

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 like it, this is way better! Addressed into 832a611

Comment on lines 72 to 80
const currentRouteName = NavigationService.getCurrentRouteName();
const currentRouteKey = NavigationService.getCurrentRouteKey();
const startRoute =
currentRouteKey && currentRouteName
? {
routeName: currentRouteName,
routeKey: currentRouteKey
}
: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about using fp-ts here?

Suggested change
const currentRouteName = NavigationService.getCurrentRouteName();
const currentRouteKey = NavigationService.getCurrentRouteKey();
const startRoute =
currentRouteKey && currentRouteName
? {
routeName: currentRouteName,
routeKey: currentRouteKey
}
: undefined;
const startRoute = pipe(
sequenceS(O.Monad)({
routeName: O.fromNullable(NavigationService.getCurrentRouteName()),
routeKey: O.fromNullable(NavigationService.getCurrentRouteKey())
}),
O.toUndefined
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's cool! Addressed into 5ca24f7

Comment on lines 67 to 70
if (paymentStartRoute) {
navigation.navigate(paymentStartRoute.routeName as keyof AppParamsList, {
screen:
paymentStartRoute.routeKey as keyof NavigatorScreenParams<AppParamsList>["screen"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this type casting is better done inside the store; what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, maybe it could be more type-safe. Addressed into 5ca24f7

Copy link
Contributor

@mastro993 mastro993 left a comment

Choose a reason for hiding this comment

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

LGTM!

@Hantex9 Hantex9 merged commit 3e0f184 into master Jan 24, 2024
8 checks passed
@Hantex9 Hantex9 deleted the IOBP-316-resume-start-point-after-payment branch January 24, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO-Bonus e pagamenti IO - Bonus e pagamenti
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants