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
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
180dfb2
Merge remote-tracking branch 'origin/master' into IOBP-316-resume-sta…
Hantex9 Jan 12, 2024
083a3e8
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 15, 2024
3cc0b68
feat: Add return to origin page after payment flow completion
Hantex9 Jan 15, 2024
4f90967
chore: added popToTop before to navigate
Hantex9 Jan 15, 2024
f9f8912
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 15, 2024
2102d66
chore: added sub-route handling navigation
Hantex9 Jan 15, 2024
3bfd87d
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 15, 2024
832a611
chore: changed orchestration to get current route when starting payme…
Hantex9 Jan 15, 2024
7a0f24a
typo: route name
Hantex9 Jan 15, 2024
29e02b6
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 16, 2024
34fbc2b
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 17, 2024
0c4e545
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 17, 2024
8890b61
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 19, 2024
46229af
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 22, 2024
1c7a0e3
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 22, 2024
1e9b038
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 23, 2024
9db9856
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
mastro993 Jan 23, 2024
5ca24f7
chore: addressed review feedback
Hantex9 Jan 23, 2024
e963a35
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 24, 2024
eea52e1
Merge branch 'master' into IOBP-316-resume-start-point-after-payment
Hantex9 Jan 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as pot from "@pagopa/ts-commons/lib/pot";
import { RouteProp, useNavigation, useRoute } from "@react-navigation/native";
import {
NavigatorScreenParams,
RouteProp,
useNavigation,
useRoute
} from "@react-navigation/native";
import * as O from "fp-ts/lib/Option";
import { pipe } from "fp-ts/lib/function";
import React from "react";
Expand All @@ -17,7 +22,10 @@ import { formatNumberCentsToAmount } from "../../../../utils/stringBuilder";
import { WalletPaymentFeebackBanner } from "../components/WalletPaymentFeedbackBanner";
import { usePaymentFailureSupportModal } from "../hooks/usePaymentFailureSupportModal";
import { WalletPaymentParamsList } from "../navigation/params";
import { walletPaymentDetailsSelector } from "../store/selectors";
import {
walletPaymentDetailsSelector,
walletPaymentStartRouteSelector
} from "../store/selectors";
import {
WalletPaymentOutcome,
WalletPaymentOutcomeEnum
Expand All @@ -38,6 +46,7 @@ const WalletPaymentOutcomeScreen = () => {

const navigation = useNavigation<IOStackNavigationProp<AppParamsList>>();
const paymentDetailsPot = useIOSelector(walletPaymentDetailsSelector);
const paymentStartRoute = useIOSelector(walletPaymentStartRouteSelector);

const supportModal = usePaymentFailureSupportModal({
outcome
Expand All @@ -55,6 +64,13 @@ const WalletPaymentOutcomeScreen = () => {
};

const handleClose = () => {
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

});
return;
}
navigation.popToTop();
navigation.pop();
};
Expand Down
4 changes: 4 additions & 0 deletions ts/features/walletV3/payment/store/actions/orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { ActionType, createStandardAction } from "typesafe-actions";
import { Bundle } from "../../../../../../definitions/pagopa/ecommerce/Bundle";
import { WalletInfo } from "../../../../../../definitions/pagopa/walletv3/WalletInfo";

/**
* Action to initialize the state of a payment, optionally you can specify the route to go back to
* after the payment is completed or cancelled (default is the popToTop route)
*/
export const walletPaymentInitState = createStandardAction(
"WALLET_PAYMENT_INIT_STATE"
)();
Expand Down
19 changes: 18 additions & 1 deletion ts/features/walletV3/payment/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { WalletInfo } from "../../../../../../definitions/pagopa/walletv3/WalletInfo";
import { WalletPaymentFailure } from "../../types/failure";
import { RptId } from "../../../../../../definitions/pagopa/ecommerce/RptId";
import NavigationService from "../../../../../navigation/NavigationService";

export type WalletPaymentState = {
rptId?: RptId;
Expand All @@ -44,6 +45,10 @@ export type WalletPaymentState = {
NetworkError | WalletPaymentFailure
>;
authorizationUrl: pot.Pot<string, NetworkError>;
startRoute?: {
routeName: string;
routeKey: string;
};
};

const INITIAL_STATE: WalletPaymentState = {
Expand All @@ -64,7 +69,19 @@ const reducer = (
): WalletPaymentState => {
switch (action.type) {
case getType(walletPaymentInitState):
return INITIAL_STATE;
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

return {
...INITIAL_STATE,
startRoute
};

// Payment verification and details
case getType(walletPaymentGetDetails.request):
Expand Down
5 changes: 5 additions & 0 deletions ts/features/walletV3/payment/store/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ export const walletPaymentAuthorizationUrlSelector = createSelector(
selectWalletPayment,
state => state.authorizationUrl
);

export const walletPaymentStartRouteSelector = createSelector(
selectWalletPayment,
state => state.startRoute
);
Loading