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

feat(Bonus Pagamenti Digitali): [#175783832] Alerts when BPD is already active #2420

Merged
merged 11 commits into from
Nov 27, 2020
Merged
5 changes: 5 additions & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,11 @@ bonus:
failure: "We were unable to remove, please try again"
earned: Collected Cashback
onboarding:
alert:
title: Cashback is aleady active
body: You can find more details in your Wallet.
cancel: Close
confirm: Back to Wallet
loadingActivationStatus:
title: Loading activation status
declaration:
Expand Down
5 changes: 5 additions & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,11 @@ bonus:
success: "La tua iscrizione al cashback è stata cancellata"
failure: "Non siamo riusciti a cancellare la tua iscrizione, riprova per favore"
onboarding:
alert:
title: Il cashback è già attivo
body: Puoi vedere maggiori dettagli nel tuo Portafoglio.
cancel: Chiudi
confirm: Torna al Portaoglio
CrisTofani marked this conversation as resolved.
Show resolved Hide resolved
loadingActivationStatus:
title: Verifico lo stato di attivazione
declaration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from "redux-saga/effects";
import { CitizenResource } from "../../../../../../../definitions/bpd/citizen/CitizenResource";
import ROUTES from "../../../../../../navigation/routes";
import { navigateToWalletHome } from "../../../../../../store/actions/navigation";
import { navigationHistoryPop } from "../../../../../../store/actions/navigationHistory";
import { navigationCurrentRouteSelector } from "../../../../../../store/reducers/navigation";
import { SagaCallReturnType } from "../../../../../../types/utils";
Expand Down Expand Up @@ -77,30 +76,16 @@ export function* bpdStartOnboardingWorker() {
}
}

// read if the bpd is active for the user
const isBpdActive: SagaCallReturnType<typeof isBpdEnabled> = yield call(
isBpdEnabled
);
yield put(navigateToBpdOnboardingInformationTos());
yield put(navigationHistoryPop(1));

if (isBpdActive.isRight()) {
if (isBpdActive.value) {
// The bpd is already active, go directly to the bpd details screen
// TODO: navigate to bpd details
yield put(navigateToWalletHome());
yield put(navigationHistoryPop(1));
} else {
// The bpd is not active, continue with the onboarding
yield put(navigateToBpdOnboardingInformationTos());
yield put(navigationHistoryPop(1));
// wait for the user that choose to continue
yield take(bpdUserActivate);

// wait for the user that choose to continue
yield take(bpdUserActivate);
// Navigate to the Onboarding Declaration and wait for the action that complete the saga
yield put(navigateToBpdOnboardingDeclaration());
yield put(navigationHistoryPop(1));

// Navigate to the Onboarding Declaration and wait for the action that complete the saga
yield put(navigateToBpdOnboardingDeclaration());
yield put(navigationHistoryPop(1));
}
}
// The saga ends when the user accepts the declaration
yield take(bpdOnboardingAcceptDeclaration);
}
Expand Down
42 changes: 30 additions & 12 deletions ts/features/bonus/bpd/screens/onboarding/BpdInformationScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import * as React from "react";
import { connect } from "react-redux";
import I18n from "../../../../../i18n";
import { Dispatch } from "../../../../../store/actions/types";
import { GlobalState } from "../../../../../store/reducers/types";
import { actionWithAlert } from "../../../bonusVacanze/components/alert/ActionWithAlert";
import { availableBonusTypesSelectorFromId } from "../../../bonusVacanze/store/reducers/availableBonusesTypes";
import { ID_BPD_TYPE } from "../../../bonusVacanze/utils/bonus";
import BonusInformationComponent from "../../../common/components/BonusInformationComponent";
import { getValue } from "../../model/RemoteValue";
import {
bpdOnboardingCancel,
bpdUserActivate
} from "../../store/actions/onboarding";
import { bpdEnabledSelector } from "../../store/reducers/details/activation";

export type Props = ReturnType<typeof mapDispatchToProps> &
ReturnType<typeof mapStateToProps>;
Expand All @@ -17,21 +21,35 @@ export type Props = ReturnType<typeof mapDispatchToProps> &
* This Screen shows all the information about the bpd program, with the rules and t&c.
*/

const BpdInformationScreen: React.FunctionComponent<Props> = (props: Props) => (
<>
{props.bonus ? (
<BonusInformationComponent
bonus={props.bonus}
onConfirm={props.userActivateBpd}
onCancel={props.onCancel}
/>
) : null}
</>
);
const BpdInformationScreen: React.FunctionComponent<Props> = (props: Props) => {
const onConfirm = () =>
getValue(props.bpdActiveBonus) === true
Copy link
Contributor

Choose a reason for hiding this comment

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

The bpd activation is prefetched in the wallet, but we should also handle the case if it is still RemoteLoading or RemoteError, we no longer have the guarantee that the data will be loaded when we arrive on this page, having removed the check that guaranteed it in the saga.

One solution could be restore the saga part:

  // read if the bpd is active for the user
  const isBpdActive: SagaCallReturnType<typeof isBpdEnabled> = yield call(
    isBpdEnabled
  );

in order to have the error /retry logic, and after that check we can continue to the InformationScreen with the safeness to have the data loaded.
Otherwise we have to handel the loading and the error inside the BpdInformationScreen.
We could see together tomorrow!

? actionWithAlert({
title: I18n.t("bonus.bpd.onboarding.alert.title"),
body: I18n.t("bonus.bpd.onboarding.alert.body"),
cancelText: I18n.t("bonus.bpd.onboarding.alert.cancel"),
confirmText: I18n.t("bonus.bpd.onboarding.alert.confirm"),
onConfirmAction: props.onCancel
})
: props.userActivateBpd;
CrisTofani marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
{props.bonus ? (
<BonusInformationComponent
bonus={props.bonus}
onConfirm={onConfirm}
onCancel={props.onCancel}
/>
) : null}
</>
);
};

const mapStateToProps = (state: GlobalState) => ({
// display the error with the retry only in case of networking errors
bonus: availableBonusTypesSelectorFromId(ID_BPD_TYPE)(state)
bonus: availableBonusTypesSelectorFromId(ID_BPD_TYPE)(state),
bpdActiveBonus: bpdEnabledSelector(state)
});

const mapDispatchToProps = (dispatch: Dispatch) => ({
Expand Down