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

[#172992641] Check bonus eligibility #1841

Merged
merged 7 commits into from
May 26, 2020
Merged
4 changes: 4 additions & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,7 @@ faq:
57:
title: "Did you have problems during a payment?"
content: !include faq/faq57.md
bonus:
bonusVacanza:
checkBonusEligibility:
loading: Checking bonus eligibility
4 changes: 4 additions & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1268,3 +1268,7 @@ faq:
57:
title: "Hai avuto problemi durante un pagamento?"
content: !include faq/faq57.md
bonus:
bonusVacanza:
checkBonusEligibility:
loading: Verifico l'idoneità per l'accesso al bonus
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { View } from "native-base";
import * as React from "react";
import { StyleSheet } from "react-native";
import { withLoadingSpinner } from "../../../components/helpers/withLoadingSpinner";
import GenericErrorComponent from "../../../components/screens/GenericErrorComponent";
import customVariables from "../../../theme/variables";

type Props = {
isLoading: boolean;
loadingCaption?: string;
loadingOpacity?: number;
errorText?: string;
onRetry: () => void;
onCancel?: () => void;
};

const styles = StyleSheet.create({
main: {
backgroundColor: customVariables.colorWhite,
flex: 1,
position: "absolute",
top: 0,
bottom: 0,
left: 0,
right: 0
}
});
/**
* This component is a generic error component composed with a loading.
* In this way it is testable regardless of how it will be connected to the application flow.
* This component, when {@link Props.isLoading} display a loading overlay, hiding the background, using
* {@link withLoadingSpinner}.
* When {@link Props.isLoading} is false, display a {@link GenericErrorComponent} displaying the reasons of the error
* and two buttons to cancel the operation or retry.
* @param props
* @constructor
*/
const InnerGenericLoadingErrorScreen: React.FunctionComponent<
Props
> = props => {
return (
<View style={styles.main}>
<GenericErrorComponent
onRetry={props.onRetry}
onCancel={props.onCancel}
text={props.errorText}
/>
</View>
);
};

export const GenericLoadingErrorScreen = withLoadingSpinner(
InnerGenericLoadingErrorScreen
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from "react";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import { RTron } from "../../../boot/configureStoreAndPersistor";
import I18n from "../../../i18n";
import { GlobalState } from "../../../store/reducers/types";
import { GenericLoadingErrorScreen } from "../components/GenericLoadingErrorScreen";

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

const loadingCaption = I18n.t(
"bonus.bonusVacanza.checkBonusEligibility.loading"
);
/**
* This component link the generic {@link GenericLoadingErrorScreen} with the application flow using the {@link connect}
* of redux.
* @param props
* @constructor
*/
const CheckBonusEligibilityScreen: React.FunctionComponent<Props> = props => {
return (
<GenericLoadingErrorScreen
{...props}
loadingCaption={loadingCaption}
loadingOpacity={1}
/>
);
};

const mapDispatchToProps = (_: Dispatch) => ({
// TODO: link with the right dispatch action
onCancel: () => {
RTron.log("CANCEL");
},
// TODO: link with the right dispatch action
onRetry: () => {
RTron.log("RETRY");
}
});

const mapStateToProps = (_: GlobalState) => ({
// TODO: link with the right reducer
isLoading: true,
// TODO: link with the right reducer
errorText: "A text that explains why the operation failed"
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the error could be a network error, otherwise we should receive a response from our backend.
Could it be a solution to show an error toast informing the user that something went wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we want to have a generic error, I can remove the errorText and use the default message used within the GenericErrorComponent ("Ooops, qualcosa è andato storto! Probabilmente è un errore momentaneo, riprova per piacere!"). In this case we can also avoid a toast that which would repeat the error information. What you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good!

});

export default connect(
mapStateToProps,
mapDispatchToProps
)(CheckBonusEligibilityScreen);