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: [#176175845] removes transactions list from the transactions screen #2628

Merged
merged 6 commits into from
Jan 22, 2021
Merged
Changes from all commits
Commits
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
120 changes: 13 additions & 107 deletions ts/screens/wallet/TransactionsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,38 @@
* from a specific credit card
*/
import * as pot from "italia-ts-commons/lib/pot";
import { Content, Text, View } from "native-base";
import { View } from "native-base";
import * as React from "react";
import { RefreshControl, StyleSheet } from "react-native";
import { NavigationInjectedProps } from "react-navigation";
import { connect } from "react-redux";
import { IOStyles } from "../../components/core/variables/IOStyles";
import ItemSeparatorComponent from "../../components/ItemSeparatorComponent";

import { ContextualHelpPropsMarkdown } from "../../components/screens/BaseScreenComponent";
import { EdgeBorderComponent } from "../../components/screens/EdgeBorderComponent";
import H5 from "../../components/ui/H5";
import CardComponent from "../../components/wallet/card/CardComponent";
import TransactionsList from "../../components/wallet/TransactionsList";
import WalletLayout from "../../components/wallet/WalletLayout";
import PaymentMethodCapabilities from "../../features/wallet/component/PaymentMethodCapabilities";
import I18n from "../../i18n";
import {
navigateToTransactionDetailsScreen,
navigateToWalletHome,
navigateToWalletList
} from "../../store/actions/navigation";
import { Dispatch } from "../../store/actions/types";
import {
fetchTransactionsRequest,
readTransaction
} from "../../store/actions/wallet/transactions";
import {
deleteWalletRequest,
setFavouriteWalletRequest
} from "../../store/actions/wallet/wallets";
import { paymentsHistorySelector } from "../../store/reducers/payments/history";
import { GlobalState } from "../../store/reducers/types";
import {
areMoreTransactionsAvailable,
getTransactions,
getTransactionsLoadedLength
} from "../../store/reducers/wallet/transactions";
import {
getFavoriteWalletId,
paymentMethodsSelector
} from "../../store/reducers/wallet/wallets";
import variables from "../../theme/variables";
import { Transaction, Wallet } from "../../types/pagopa";
import { Wallet } from "../../types/pagopa";
import { showToast } from "../../utils/showToast";
import { handleSetFavourite } from "../../utils/wallet";


type NavigationParams = Readonly<{
selectedWallet: Wallet;
}>;
Expand All @@ -59,44 +45,11 @@ type Props = OwnProps &
ReturnType<typeof mapStateToProps> &
ReturnType<typeof mapDispatchToProps>;

const styles = StyleSheet.create({
walletBannerText: {
alignItems: "flex-end",
flexDirection: "row"
},

noBottomPadding: {
padding: variables.contentPadding,
paddingBottom: 0
},

whiteBg: {
backgroundColor: variables.colorWhite
},

brandDarkGray: {
color: variables.brandDarkGray
}
});

const contextualHelpMarkdown: ContextualHelpPropsMarkdown = {
title: "wallet.walletCardTransaction.contextualHelpTitle",
body: "wallet.walletCardTransaction.contextualHelpContent"
};

const ListEmptyComponent = (
<Content
scrollEnabled={false}
style={[styles.noBottomPadding, styles.whiteBg]}
>
<H5 style={styles.brandDarkGray}>{I18n.t("wallet.noneTransactions")}</H5>
<View spacer={true} />
<Text>{I18n.t("wallet.noTransactionsInTransactionsScreen")}</Text>
<View spacer={true} large={true} />
<EdgeBorderComponent />
</Content>
);

const HEADER_HEIGHT = 250;

class TransactionsScreen extends React.Component<Props> {
Expand All @@ -123,17 +76,8 @@ class TransactionsScreen extends React.Component<Props> {
);
}

private handleLoadMoreTransactions = () => {
this.props.loadTransactions(this.props.transactionsLoadedLength);
};

public render(): React.ReactNode {
const selectedWallet = this.props.navigation.getParam("selectedWallet");
const transactions = pot.map(this.props.transactions, tsx =>
tsx
.filter(t => t.idWallet === selectedWallet.idWallet)
.sort((a, b) => b.created.getTime() - a.created.getTime())
);

const isFavorite = pot.map(
this.props.favoriteWallet,
Expand All @@ -148,19 +92,6 @@ class TransactionsScreen extends React.Component<Props> {
undefined
);

const transactionsRefreshControl = (
<RefreshControl
onRefresh={() => {
this.props.loadTransactions(this.props.transactionsLoadedLength);
}}
// The refresh control spinner is displayed only at pull-to-refresh
// while, during the transactions reload, it is displayed the custom transaction
// list spinner
refreshing={false}
tintColor={"transparent"}
/>
);

return (
<WalletLayout
title={I18n.t("wallet.paymentMethod")}
Expand All @@ -169,57 +100,32 @@ class TransactionsScreen extends React.Component<Props> {
hideHeader={true}
hasDynamicSubHeader={true}
topContentHeight={HEADER_HEIGHT}
refreshControl={transactionsRefreshControl}
contextualHelpMarkdown={contextualHelpMarkdown}
faqCategories={["wallet_transaction"]}
>
{pm && (
<View style={IOStyles.horizontalContentPadding}>
<View spacer={true} extralarge={true} />
<PaymentMethodCapabilities paymentMethod={pm} />
<View spacer={true} />
<ItemSeparatorComponent noPadded={true} />
</View>
<>
<View style={IOStyles.horizontalContentPadding}>
<View spacer={true} extralarge={true} />
<PaymentMethodCapabilities paymentMethod={pm} />
<View spacer={true} />
<ItemSeparatorComponent noPadded={true} />
</View>
<EdgeBorderComponent />
</>

)}
<TransactionsList
title={I18n.t("wallet.transactions")}
amount={I18n.t("wallet.amount")}
transactions={transactions}
areMoreTransactionsAvailable={this.props.areMoreTransactionsAvailable}
onLoadMoreTransactions={this.handleLoadMoreTransactions}
navigateToTransactionDetails={
this.props.navigateToTransactionDetailsScreen
}
readTransactions={this.props.readTransactions}
ListEmptyComponent={ListEmptyComponent}
/>
</WalletLayout>
);
}
}

const mapStateToProps = (state: GlobalState) => ({
transactions: getTransactions(state),
potPayments: paymentsHistorySelector(state),
transactionsLoadedLength: getTransactionsLoadedLength(state),
favoriteWallet: getFavoriteWalletId(state),
readTransactions: state.entities.transactionsRead,
areMoreTransactionsAvailable: areMoreTransactionsAvailable(state),
paymentMethods: paymentMethodsSelector(state)
});

const mapDispatchToProps = (dispatch: Dispatch) => ({
loadTransactions: (start: number) =>
dispatch(fetchTransactionsRequest({ start })),
navigateToTransactionDetailsScreen: (transaction: Transaction) => {
dispatch(readTransaction(transaction));
dispatch(
navigateToTransactionDetailsScreen({
transaction,
isPaymentCompletedTransaction: false
})
);
},
setFavoriteWallet: (walletId?: number) =>
dispatch(setFavouriteWalletRequest(walletId)),
deleteWallet: (walletId: number) =>
Expand Down