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): [#175515542,#175266771] Add entrypoint for draft Transactions screen #2330

Merged
merged 51 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ddcdcbb
[#175266374] add navigation and bpddetail screen
fabriziofff Oct 29, 2020
701eea7
[#175266374] stub for BpdPeriodSelector and BpdPeriodDetails
fabriziofff Oct 29, 2020
ae34d0c
[#175266374] add different periods component and current period selector
fabriziofff Oct 29, 2020
5063f98
[#175266374] Merge remote-tracking branch 'origin/master' into 175266…
fabriziofff Oct 29, 2020
869a0a8
[#175266374] convert AwardPeriodId to number
fabriziofff Oct 29, 2020
152547d
[#175266374] wip
fabriziofff Oct 29, 2020
de90854
[#175266374] add periods navigation
fabriziofff Oct 29, 2020
0c0bc63
[#175266374] add draft selector
fabriziofff Oct 29, 2020
e3a640a
[#175266374] Merge remote-tracking branch 'origin/master' into 175266…
fabriziofff Oct 29, 2020
fc3eff8
[#175266374] add placeholder string
fabriziofff Oct 29, 2020
4f14e6d
[#175266374] simplify code
fabriziofff Oct 30, 2020
3cffb83
[#174848741] add IbanComponent logic
fabriziofff Oct 30, 2020
0382e94
[#174848741] Merge remote-tracking branch 'origin/master' into 174848…
fabriziofff Oct 30, 2020
6bea7d4
[#174848741] fix
fabriziofff Oct 30, 2020
ae1aafb
[#174848741] clean comments
fabriziofff Oct 30, 2020
b5ae6d4
Merge branch 'master' into 175266374-bpd-details-organization
Undermaken Oct 30, 2020
ca6ce69
[#175515542] Stub for bpdtransactionScreen
fabriziofff Oct 30, 2020
6b10d6e
[#175515542] GoToTransactionsButton
fabriziofff Oct 30, 2020
dd2465d
[#175515542] clean
fabriziofff Oct 30, 2020
b0840e0
[#175515542] documentation
fabriziofff Oct 30, 2020
82f60a3
[#175515542] rename
fabriziofff Oct 30, 2020
8469ece
[#175515542] fix import
fabriziofff Oct 30, 2020
eaef183
[#175266374] added comment
fabriziofff Oct 30, 2020
c787e49
[#174848741] Merge branch '175266374-bpd-details-organization' into 1…
fabriziofff Oct 30, 2020
237d66a
[#175515542] Merge branch '174848741-iban-component' into 175515542-t…
fabriziofff Oct 30, 2020
3345282
Merge branch 'master' into 175266374-bpd-details-organization
fabriziofff Nov 2, 2020
53c78c0
[#174848741] add IbanComponent logic
fabriziofff Oct 30, 2020
bfa0886
[#174848741] fix
fabriziofff Oct 30, 2020
d43655f
[#174848741] clean comments
fabriziofff Oct 30, 2020
a472bfb
[#174848741] Merge remote-tracking branch 'origin/174848741-iban-comp…
fabriziofff Nov 2, 2020
30a7110
[#175515542] Stub for bpdtransactionScreen
fabriziofff Oct 30, 2020
32d345b
[#175515542] GoToTransactionsButton
fabriziofff Oct 30, 2020
1a5557e
[#175515542] clean
fabriziofff Oct 30, 2020
adb979e
[#175515542] documentation
fabriziofff Oct 30, 2020
c221331
[#175515542] rename
fabriziofff Oct 30, 2020
33091b0
[#175515542] fix import
fabriziofff Oct 30, 2020
24797ec
[#175515542] Merge remote-tracking branch 'origin/175515542-transacti…
fabriziofff Nov 2, 2020
6c42e70
Merge branch 'master' into 175266374-bpd-details-organization
fabriziofff Nov 3, 2020
47fc120
Merge branch 'master' into 175266374-bpd-details-organization
fabriziofff Nov 3, 2020
3da3a00
Merge branch 'master' into 175266374-bpd-details-organization
fabriziofff Nov 3, 2020
21ebe15
[#174848741] Merge branch '175266374-bpd-details-organization' into 1…
fabriziofff Nov 3, 2020
558a926
[#175515542] Merge branch '174848741-iban-component' into 175515542-t…
fabriziofff Nov 3, 2020
0bb3cf7
Merge branch 'master' into 175266374-bpd-details-organization
Undermaken Nov 4, 2020
2217540
[#175266374] Merge branch 'master' of github.com:pagopa/io-app into 1…
Undermaken Nov 4, 2020
267aab3
[#174848741] Merge branch '175266374-bpd-details-organization' of git…
Undermaken Nov 4, 2020
3f3f414
[#174848741] Merge branch 'master' of github.com:pagopa/io-app into 1…
Undermaken Nov 4, 2020
df65b31
[#175515542] Merge branch '174848741-iban-component' of github.com:pa…
Undermaken Nov 4, 2020
41e5e5e
Update ts/features/bonus/bpd/store/reducers/details/transactions.ts
fabriziofff Nov 4, 2020
993de17
[#175515542] remove useLoadPotValue
fabriziofff Nov 4, 2020
862494c
[#175515542] Merge remote-tracking branch 'origin/175515542-transacti…
fabriziofff Nov 4, 2020
bed6138
[#175515542] fix ts
fabriziofff Nov 4, 2020
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
3 changes: 3 additions & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,9 @@ bonus:
title: "IBAN for accreditation"
noIbanBody: "Set your IBAN in order to receive the accumulated cashback"
button: "Set IBAN"
transaction:
title: "Your transactions"
goToButton: "Transactions detail"
webView:
error:
missingParams: Not all information necessary to access this page are available
Expand Down
3 changes: 3 additions & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,9 @@ bonus:
title: "IBAN per l’accredito"
noIbanBody: "Imposta il tuo IBAN per poter ricevere il cashback accumulato"
button: "Imposta IBAN"
transaction:
title: "Le tue transazioni"
goToButton: "Dettaglio transazioni"
webView:
error:
missingParams: Non sono presenti le informazioni necessarie per accedere a questa pagina
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const styles = StyleSheet.create({
const retryTimeout = 5000 as Millisecond;
/**
* This custom hook handles the load of the initial state and the retry in case of error.
* TODO: refactor with {@link useLoadPotValue}
* @deprecated
* @param props
*/
const useInitialValue = (props: Props) => {
Expand Down Expand Up @@ -151,10 +153,8 @@ const PaymentMethodActivationToggle: React.FunctionComponent<Props> = props => {
<>
<View style={styles.row}>
<View style={styles.leftSection}>
{/* TODO: The image will be received by props / redux state */}
<Image source={props.icon} style={styles.cardIcon} />
<View hspacer={true} />
{/* TODO: The Text will be received by props / redux state */}
<Body>{props.caption}</Body>
</View>
<BpdToggle
Expand Down
6 changes: 6 additions & 0 deletions ts/features/bonus/bpd/navigation/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ export const navigateToBpdDetails = (specificPeriod?: BpdPeriod) =>
routeName: BPD_ROUTES.DETAILS,
params: { specificPeriod }
});

// Transactions
export const navigateToBpdTransactions = () =>
NavigationActions.navigate({
routeName: BPD_ROUTES.TRANSACTIONS
});
4 changes: 4 additions & 0 deletions ts/features/bonus/bpd/navigation/navigator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createStackNavigator } from "react-navigation";
import BpdDetailsScreen from "../screens/details/BpdDetailsScreen";
import BpdTransactionsScreen from "../screens/details/transaction/BpdTransactionsScreen";
import MainIbanScreen from "../screens/iban/MainIbanScreen";
import BpdInformationScreen from "../screens/onboarding/BpdInformationScreen";
import DeclarationScreen from "../screens/onboarding/declaration/DeclarationScreen";
Expand Down Expand Up @@ -36,6 +37,9 @@ const BpdNavigator = createStackNavigator(
[BPD_ROUTES.DETAILS]: {
screen: BpdDetailsScreen
},
[BPD_ROUTES.TRANSACTIONS]: {
screen: BpdTransactionsScreen
},
// TODO: remove after the introduction of the bpd detail screen
[BPD_ROUTES.TEST]: {
screen: TMPBpdScreen
Expand Down
1 change: 1 addition & 0 deletions ts/features/bonus/bpd/navigation/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const BPD_ROUTES = {
},
IBAN: "BPD_IBAN",
DETAILS: "BPD_DETAILS",
TRANSACTIONS: "BPD_TRANSACTIONS",
// TODO: remove after the introduction of the bpd detail screen
TEST: "BPD_TEST"
};
Expand Down
3 changes: 3 additions & 0 deletions ts/features/bonus/bpd/screens/details/BpdDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import I18n from "../../../../../i18n";
import { GlobalState } from "../../../../../store/reducers/types";
import BpdPeriodSelector from "./BpdPeriodSelector";
import BpdPeriodDetail from "./periods/BpdPeriodDetail";
import GoToTransactions from "./transaction/GoToTransactions";

export type Props = ReturnType<typeof mapDispatchToProps> &
ReturnType<typeof mapStateToProps>;
Expand All @@ -28,6 +29,7 @@ const styles = StyleSheet.create({
height: 60
}
});

/**
* The screen that allows the user to see all the details related to the bpd.
* @constructor
Expand All @@ -41,6 +43,7 @@ const BpdDetailsScreen: React.FunctionComponent<Props> = () => (
topContent={<View style={styles.headerSpacer} />}
gradientHeader={true}
hideHeader={true}
footerContent={<GoToTransactions />}
>
<View style={styles.selector}>
<BpdPeriodSelector />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from "react";
import { SafeAreaView } from "react-native";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import { View } from "native-base";
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";

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

/**
* Display all the transactions for a specific period
* @constructor
*/
const BpdTransactionsScreen: React.FunctionComponent<Props> = () => (
<BaseScreenComponent goBack={true} headerTitle={I18n.t("bonus.bpd.title")}>
<SafeAreaView style={IOStyles.flex}>
<View style={IOStyles.horizontalContentPadding}>
<View spacer={true} large={true} />
<H1>{I18n.t("bonus.bpd.details.transaction.title")}</H1>
</View>
</SafeAreaView>
</BaseScreenComponent>
);

const mapDispatchToProps = (_: Dispatch) => ({});

const mapStateToProps = (_: GlobalState) => ({});

export default connect(
mapStateToProps,
mapDispatchToProps
)(BpdTransactionsScreen);
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as pot from "italia-ts-commons/lib/pot";
import * as React from "react";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import ButtonDefaultOpacity from "../../../../../../components/ButtonDefaultOpacity";
import { Label } from "../../../../../../components/core/typography/Label";
import IconFont from "../../../../../../components/ui/IconFont";
import I18n from "../../../../../../i18n";
import { GlobalState } from "../../../../../../store/reducers/types";
import { navigateToBpdTransactions } from "../../../navigation/actions";
import { AwardPeriodId } from "../../../store/actions/periods";
import { bpdTransactionsLoad } from "../../../store/actions/transactions";
import { bpdSelectedPeriodSelector } from "../../../store/reducers/details/selectedPeriod";
import { bpdTransactionsForSelectedPeriod } from "../../../store/reducers/details/transactions";

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

/**
* Display the transactions button only if the transactions number are > 0 for the selected period
* (never displayed for inactive period)
* @param props
* @constructor
*/
const GoToTransactions: React.FunctionComponent<Props> = props => {
const canRenderButton = pot.getOrElse(
pot.map(props.transactions, val => val.length > 0),
false
);

return canRenderButton ? (
<ButtonDefaultOpacity
block={true}
onPress={props.goToTransactions}
activeOpacity={1}
>
<IconFont name="io-receipt" style={{ color: "white" }} />
<Label color={"white"}>
{I18n.t("bonus.bpd.details.transaction.goToButton")}
</Label>
</ButtonDefaultOpacity>
) : null;
};

const mapDispatchToProps = (dispatch: Dispatch) => ({
goToTransactions: () => dispatch(navigateToBpdTransactions()),
loadTransactionsByPeriod: (periodId: AwardPeriodId) =>
dispatch(bpdTransactionsLoad.request(periodId))
});

const mapStateToProps = (state: GlobalState) => ({
transactions: bpdTransactionsForSelectedPeriod(state),
selectedPeriod: bpdSelectedPeriodSelector(state)
});

export default connect(mapStateToProps, mapDispatchToProps)(GoToTransactions);
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ export const bpdTransactionsForSelectedPeriod = createSelector(
],
(transactions, period) =>
fromNullable(period)
.map(p => transactions[p.awardPeriodId])
.chain(p => fromNullable(transactions[p.awardPeriodId]))
.getOrElse(pot.none)
);
64 changes: 64 additions & 0 deletions ts/utils/hooks/useLoadPotValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable functional/immutable-data */
import * as pot from "italia-ts-commons/lib/pot";
import { Millisecond } from "italia-ts-commons/lib/units";
import { useContext, useEffect, useRef, useState } from "react";
import { NavigationContext } from "react-navigation";

const retryTimeout = 5000 as Millisecond;

/**
* Load the pot value using the loadAction until is some. Automatically retry using the {@link retryTimeout}
* @param id - the loadRequestId. Should be always the same for the same pot and different, for different pots.
* @param potValue - the value that we would ensure that should be loaded
* @param loadAction - the action that trigger the load of the pot
* @deprecated
*/
export const useLoadPotValue = <T, E>(
id: string,
potValue: pot.Pot<T, E>,
loadAction: () => void
) => {
const [idState, setId] = useState("");
const timerRetry = useRef<number | undefined>(undefined);
const navigation = useContext(NavigationContext);
const retry = () => {
timerRetry.current = undefined;
loadAction();
};

/**
* When the focus change or the idRequest changes, clear the timer (if any)
* and reset the value to undefined.
* focus: true -> a new schedule is allowed
* focus: false -> clear all the pending schedule
*/
useEffect(() => {
clearTimeout(timerRetry.current);
timerRetry.current = undefined;
}, [navigation.isFocused(), idState]);

useEffect(() => {
setId(id);
// Initial state, request the state
if (potValue === pot.none) {
loadAction();
} else if (
pot.isNone(potValue) &&
pot.isError(potValue) &&
timerRetry.current === undefined &&
navigation.isFocused()
) {
// If the pot is NoneError, the navigation focus is on the element
// and no other retry are scheduled
timerRetry.current = setTimeout(retry, retryTimeout);
}
}, [potValue, timerRetry.current, navigation.isFocused(), idState]);

// Component unmount, clear scheduled
useEffect(
() => () => {
clearTimeout(timerRetry.current);
},
[]
);
};