Skip to content

Commit

Permalink
feat(Bonus Pagamenti Digitali): [#175683801] When credit card has bee…
Browse files Browse the repository at this point in the history
…n added, join BPD or enroll the new method to BPD (#2399)

* [#175683801] wip

* [#175683801] refactoring
when new credit card has been added navigate to join bpd / enroll the new method on bpd

* [#175683801] add comment

* [#175683801] refactoring

* [#175683801] restore code

* [#175683801] fix typo

* [#175683801] log the AuthorizationCode

* [#175683801] revert

Co-authored-by: fabriziofff <[email protected]>
  • Loading branch information
Undermaken and fabriziofff authored Nov 19, 2020
1 parent 114b511 commit 86fb44c
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 64 deletions.
10 changes: 10 additions & 0 deletions ts/features/wallet/onboarding/bancomat/navigation/action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { NavigationActions } from "react-navigation";
import { InferNavigationParams } from "../../../../../types/react";
import { ActivateBpdOnNewCreditCardScreen } from "../screens/bpd/ActivateBpdOnNewCreditCardScreen";
import WALLET_ONBOARDING_BANCOMAT_ROUTES from "./routes";

export const navigateToOnboardingBancomatChooseBank = () =>
Expand All @@ -25,3 +27,11 @@ export const navigateToActivateBpdOnNewBancomat = () =>
NavigationActions.navigate({
routeName: WALLET_ONBOARDING_BANCOMAT_ROUTES.ACTIVATE_BPD_NEW_BANCOMAT
});

export const navigateToActivateBpdOnNewCreditCard = (
params: InferNavigationParams<typeof ActivateBpdOnNewCreditCardScreen>
) =>
NavigationActions.navigate({
routeName: WALLET_ONBOARDING_BANCOMAT_ROUTES.ACTIVATE_BPD_NEW_CREDIT_CARD,
params
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createStackNavigator } from "react-navigation";
import ActivateBpdOnNewBancomatScreen from "../screens/bpd/ActivateBpdOnNewBancomatScreen";
import SuggestBpdActivationScreen from "../screens/bpd/SuggestBpdActivationScreen";
import SearchBankScreen from "../screens/search/SearchBankScreen";
import SearchAvailableUserBancomatScreen from "../screens/searchBancomat/SearchAvailableUserBancomatScreen";
import { ActivateBpdOnNewCreditCardScreen } from "../screens/bpd/ActivateBpdOnNewCreditCardScreen";
import ActivateBpdOnNewBancomatScreen from "../screens/bpd/ActivateBpdOnNewBancomatScreen";
import WALLET_ONBOARDING_BANCOMAT_ROUTES from "./routes";

const PaymentMethodOnboardingBancomatNavigator = createStackNavigator(
Expand All @@ -18,6 +19,9 @@ const PaymentMethodOnboardingBancomatNavigator = createStackNavigator(
},
[WALLET_ONBOARDING_BANCOMAT_ROUTES.ACTIVATE_BPD_NEW_BANCOMAT]: {
screen: ActivateBpdOnNewBancomatScreen
},
[WALLET_ONBOARDING_BANCOMAT_ROUTES.ACTIVATE_BPD_NEW_CREDIT_CARD]: {
screen: ActivateBpdOnNewCreditCardScreen
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion ts/features/wallet/onboarding/bancomat/navigation/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const WALLET_ONBOARDING_BANCOMAT_ROUTES = {

ADD_BANCOMAT: "WALLET_ONBOARDING_BANCOMAT_ADD",
SUGGEST_BPD_ACTIVATION: "WALLET_ONBOARDING_BANCOMAT_SUGGEST_BPD_ACTIVATION",
ACTIVATE_BPD_NEW_BANCOMAT: "WALLET_ONBOARDING_BANCOMAT_ACTIVATE_BPD_NEW"
ACTIVATE_BPD_NEW_BANCOMAT: "WALLET_ONBOARDING_BANCOMAT_ACTIVATE_BPD_NEW",
ACTIVATE_BPD_NEW_CREDIT_CARD: "WALLET_ONBOARDING_CREDIT_CARD_ACTIVATE_BPD_NEW"
};

export default WALLET_ONBOARDING_BANCOMAT_ROUTES;
Original file line number Diff line number Diff line change
@@ -1,70 +1,15 @@
import { View } from "native-base";
import * as React from "react";
import { SafeAreaView, ScrollView } from "react-native";
import { NavigationActions } from "react-navigation";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import { Body } from "../../../../../../components/core/typography/Body";
import { H1 } from "../../../../../../components/core/typography/H1";
import { IOStyles } from "../../../../../../components/core/variables/IOStyles";
import BaseScreenComponent from "../../../../../../components/screens/BaseScreenComponent";
import I18n from "../../../../../../i18n";
import { GlobalState } from "../../../../../../store/reducers/types";
import { FooterTwoButtons } from "../../../../../bonus/bonusVacanze/components/markdown/FooterTwoButtons";
import { PaymentMethodRawList } from "../../../../../bonus/bpd/components/paymentMethodActivationToggle/list/PaymentMethodRawList";
import { onboardingBancomatAddedPansSelector } from "../../store/reducers/addedPans";
import { GlobalState } from "../../../../../../store/reducers/types";
import ActivateBpdOnNewPaymentMethodScreen from "./ActivateBpdOnNewPaymentMethodScreen";
export type Props = ReturnType<typeof mapStateToProps>;

export type Props = ReturnType<typeof mapDispatchToProps> &
ReturnType<typeof mapStateToProps>;

const loadLocales = () => ({
headerTitle: I18n.t("wallet.onboarding.bancomat.headerTitle"),
title: I18n.t("wallet.onboarding.bancomat.bpd.activateNew.title"),
body1: I18n.t("wallet.onboarding.bancomat.bpd.activateNew.body1"),
body2: I18n.t("wallet.onboarding.bancomat.bpd.activateNew.body2"),
skip: I18n.t("wallet.onboarding.bancomat.bpd.activateNew.skip"),
continueStr: I18n.t("global.buttons.continue")
});

const ActivateBpdOnNewBancomatScreen: React.FunctionComponent<Props> = props => {
const { headerTitle, title, body1, body2, skip, continueStr } = loadLocales();
return (
<BaseScreenComponent headerTitle={headerTitle}>
<SafeAreaView style={IOStyles.flex}>
<ScrollView>
<View style={IOStyles.horizontalContentPadding}>
<View spacer={true} large={true} />
<H1>{title}</H1>
<View spacer={true} large={true} />
<Body>{body1}</Body>
<View spacer={true} large={true} />
<PaymentMethodRawList paymentList={props.newBancomat} />
<View spacer={true} large={true} />
<Body>{body2}</Body>
</View>
</ScrollView>

<FooterTwoButtons
type={"TwoButtonsInlineHalf"}
onCancel={props.skip}
onRight={props.skip}
rightText={continueStr}
leftText={skip}
/>
</SafeAreaView>
</BaseScreenComponent>
);
};

const mapDispatchToProps = (dispatch: Dispatch) => ({
skip: () => dispatch(NavigationActions.back())
});
const ActivateBpdOnNewBancomatScreen: React.FC<Props> = (props: Props) => (
<ActivateBpdOnNewPaymentMethodScreen paymentMethods={props.newBancomat} />
);

const mapStateToProps = (state: GlobalState) => ({
newBancomat: onboardingBancomatAddedPansSelector(state)
});

export default connect(
mapStateToProps,
mapDispatchToProps
)(ActivateBpdOnNewBancomatScreen);
export default connect(mapStateToProps)(ActivateBpdOnNewBancomatScreen);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from "react";
import { NavigationScreenProps } from "react-navigation";
import { PatchedWalletV2 } from "../../../../../../types/pagopa";
import ActivateBpdOnNewPaymentMethodScreen from "./ActivateBpdOnNewPaymentMethodScreen";

type ActivateBpdOnNewCreditCardScreenNavigationParams = {
creditCards: ReadonlyArray<PatchedWalletV2>;
};
type Props = NavigationScreenProps<
ActivateBpdOnNewCreditCardScreenNavigationParams
>;

export const ActivateBpdOnNewCreditCardScreen: React.FC<Props> = (
props: Props
) => (
<ActivateBpdOnNewPaymentMethodScreen
paymentMethods={props.navigation.getParam("creditCards")}
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { View } from "native-base";
import * as React from "react";
import { SafeAreaView, ScrollView } from "react-native";
import { NavigationActions } from "react-navigation";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import { Body } from "../../../../../../components/core/typography/Body";
import { H1 } from "../../../../../../components/core/typography/H1";
import { IOStyles } from "../../../../../../components/core/variables/IOStyles";
import BaseScreenComponent from "../../../../../../components/screens/BaseScreenComponent";
import I18n from "../../../../../../i18n";
import { FooterTwoButtons } from "../../../../../bonus/bonusVacanze/components/markdown/FooterTwoButtons";
import { PaymentMethodRawList } from "../../../../../bonus/bpd/components/paymentMethodActivationToggle/list/PaymentMethodRawList";
import { PatchedWalletV2 } from "../../../../../../types/pagopa";

type OwnProps = {
paymentMethods: ReadonlyArray<PatchedWalletV2>;
};

export type Props = ReturnType<typeof mapDispatchToProps> & OwnProps;

const loadLocales = () => ({
headerTitle: I18n.t("wallet.onboarding.bancomat.headerTitle"),
title: I18n.t("wallet.onboarding.bancomat.bpd.activateNew.title"),
body1: I18n.t("wallet.onboarding.bancomat.bpd.activateNew.body1"),
body2: I18n.t("wallet.onboarding.bancomat.bpd.activateNew.body2"),
skip: I18n.t("wallet.onboarding.bancomat.bpd.activateNew.skip"),
continueStr: I18n.t("global.buttons.continue")
});

const ActivateBpdOnNewPaymentMethodScreen: React.FunctionComponent<Props> = props => {
const { headerTitle, title, body1, body2, skip, continueStr } = loadLocales();
return (
<BaseScreenComponent headerTitle={headerTitle}>
<SafeAreaView style={IOStyles.flex}>
<ScrollView>
<View style={IOStyles.horizontalContentPadding}>
<View spacer={true} large={true} />
<H1>{title}</H1>
<View spacer={true} large={true} />
<Body>{body1}</Body>
<View spacer={true} large={true} />
<PaymentMethodRawList paymentList={props.paymentMethods} />
<View spacer={true} large={true} />
<Body>{body2}</Body>
</View>
</ScrollView>

<FooterTwoButtons
type={"TwoButtonsInlineHalf"}
onCancel={props.skip}
onRight={props.skip}
rightText={continueStr}
leftText={skip}
/>
</SafeAreaView>
</BaseScreenComponent>
);
};

const mapDispatchToProps = (dispatch: Dispatch) => ({
skip: () => dispatch(NavigationActions.back())
});

export default connect(
undefined,
mapDispatchToProps
)(ActivateBpdOnNewPaymentMethodScreen);
40 changes: 40 additions & 0 deletions ts/sagas/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import { isProfileEmailValidatedSelector } from "../store/reducers/profile";
import { GlobalState } from "../store/reducers/types";

import {
EnableableFunctionsTypeEnum,
NullableWallet,
PaymentManagerToken,
PayRequest
Expand Down Expand Up @@ -126,6 +127,14 @@ import {
} from "./wallet/pagopaApis";
import { getTransactionsRead } from "../store/reducers/entities/readTransactions";
import _ from "lodash";
import { hasFunctionEnabled } from "../utils/walletv2";
import { bpdEnabledSelector } from "../features/bonus/bpd/store/reducers/details/activation";
import { isReady } from "../features/bonus/bpd/model/RemoteValue";
import {
navigateToActivateBpdOnNewCreditCard,
navigateToSuggestBpdActivation
} from "../features/wallet/onboarding/bancomat/navigation/action";
import { navigationHistoryPop } from "../store/actions/navigationHistory";

/**
* Configure the max number of retries and delay between retries when polling
Expand Down Expand Up @@ -298,7 +307,38 @@ function* startOrResumeAddCreditCardSaga(
const maybeAddedWallet = updatedWallets.find(
_ => _.idWallet === idWallet
);
// if the new method has been added
if (maybeAddedWallet !== undefined) {
const bpdEnroll: ReturnType<typeof bpdEnabledSelector> = yield select(
bpdEnabledSelector
);
// check if the new method is compliant with bpd
if (bpdEnabled && maybeAddedWallet.v2) {
const hasBpdFeature = hasFunctionEnabled(
maybeAddedWallet.v2,
EnableableFunctionsTypeEnum.BPD
);
// if the method is bpd compliant check if we have info about bpd activation
if (hasBpdFeature && isReady(bpdEnroll)) {
// if bdp is active navigate to a screen where it asked to enroll that method in bpd
// otherwise navigate to a screen where is asked to join bpd
if (bpdEnroll.value) {
yield put(
navigateToActivateBpdOnNewCreditCard({
creditCards: [maybeAddedWallet.v2]
})
);
} else {
yield put(navigateToSuggestBpdActivation());
}
// remove these screens from the navigation stack: method choice, credit card form, credit card resume
// this pop could be easily break when this flow is entered by other points
// different from the current ones (i.e see https://www.pivotaltracker.com/story/show/175757212)
yield put(navigationHistoryPop(3));
return;
}
}

// dispatch the action: a new card has been added
yield put(addWalletNewCreditCardSuccess());
if (action.payload.setAsFavorite === true) {
Expand Down

0 comments on commit 86fb44c

Please sign in to comment.