Skip to content

Commit

Permalink
Merge branch 'master' into IOCOM-1817_fimsTestCommonHook
Browse files Browse the repository at this point in the history
  • Loading branch information
Vangaorth authored Nov 4, 2024
2 parents 1bd1d1d + 6224619 commit 4ae5c5a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
import { Route, useNavigation, useRoute } from "@react-navigation/native";
import { pipe } from "fp-ts/lib/function";
import * as O from "fp-ts/lib/Option";
import * as React from "react";
import { useMemo } from "react";
import {
View,
LayoutChangeEvent,
RefreshControl,
Platform
} from "react-native";
import {
Divider,
H3,
Expand All @@ -19,22 +8,39 @@ import {
VSpacer,
hexToRgba
} from "@pagopa/io-app-design-system";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { Route, useNavigation, useRoute } from "@react-navigation/native";
import { pipe } from "fp-ts/lib/function";
import * as O from "fp-ts/lib/Option";
import * as React from "react";
import { useMemo } from "react";
import {
Dimensions,
LayoutChangeEvent,
Platform,
RefreshControl,
View
} from "react-native";
import Animated, {
useAnimatedScrollHandler,
useSharedValue
} from "react-native-reanimated";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { Merchant } from "../../../../../../definitions/cgn/merchants/Merchant";
import { IOStyles } from "../../../../../components/core/variables/IOStyles";
import GenericErrorComponent from "../../../../../components/screens/GenericErrorComponent";
import I18n from "../../../../../i18n";
import { IOStackNavigationProp } from "../../../../../navigation/params/AppParamsList";
import { useIODispatch, useIOSelector } from "../../../../../store/hooks";
import { ProductCategoryEnum } from "../../../../../../definitions/cgn/merchants/ProductCategory";
import {
getValueOrElse,
isError,
isLoading
} from "../../../../../common/model/RemoteValue";
import { IOStyles } from "../../../../../components/core/variables/IOStyles";
import { OperationResultScreenContent } from "../../../../../components/screens/OperationResultScreenContent";
import FocusAwareStatusBar from "../../../../../components/ui/FocusAwareStatusBar";
import { useHeaderSecondLevel } from "../../../../../hooks/useHeaderSecondLevel";
import I18n from "../../../../../i18n";
import { IOStackNavigationProp } from "../../../../../navigation/params/AppParamsList";
import { useIODispatch, useIOSelector } from "../../../../../store/hooks";
import { CgnMerchantListSkeleton } from "../../components/merchants/CgnMerchantListSkeleton";
import { CgnMerchantListViewRenderItem } from "../../components/merchants/CgnMerchantsListView";
import { CgnDetailsParamsList } from "../../navigation/params";
import CGN_ROUTES from "../../navigation/routes";
import {
Expand All @@ -47,17 +53,13 @@ import {
} from "../../store/reducers/merchants";
import { getCategorySpecs } from "../../utils/filters";
import { mixAndSortMerchants } from "../../utils/merchants";
import { ProductCategoryEnum } from "../../../../../../definitions/cgn/merchants/ProductCategory";
import { useHeaderSecondLevel } from "../../../../../hooks/useHeaderSecondLevel";
import FocusAwareStatusBar from "../../../../../components/ui/FocusAwareStatusBar";
import { CgnMerchantListViewRenderItem } from "../../components/merchants/CgnMerchantsListView";
import { CgnMerchantListSkeleton } from "../../components/merchants/CgnMerchantListSkeleton";

export type CgnMerchantListByCategoryScreenNavigationParams = Readonly<{
category: ProductCategoryEnum;
}>;

const CgnMerchantsListByCategory = () => {
const screenHeight = Dimensions.get("window").height;
const [titleHeight, setTitleHeight] = React.useState(0);
const translationY = useSharedValue(0);

Expand All @@ -72,6 +74,7 @@ const CgnMerchantsListByCategory = () => {
// eslint-disable-next-line functional/immutable-data
translationY.value = event.contentOffset.y;
});

const insets = useSafeAreaInsets();
const dispatch = useIODispatch();
const route =
Expand Down Expand Up @@ -230,14 +233,34 @@ const CgnMerchantsListByCategory = () => {
}}
/>
);

const getPaddingBottom = () => {
const ELEMENT_HEIGHT = 49;
const totalListElementsHeight = ELEMENT_HEIGHT * merchantsAll.length;
const usedVerticalSpace =
titleHeight + totalListElementsHeight + insets.bottom;
const availableVerticalSpace = screenHeight - usedVerticalSpace;

return availableVerticalSpace < titleHeight ? availableVerticalSpace : 0;
};

return (
<>
<FocusAwareStatusBar
backgroundColor={categorySpecs?.colors}
barStyle={"dark-content"}
/>
{isError(onlineMerchants) && isError(offlineMerchants) ? (
<GenericErrorComponent onRetry={initLoadingLists} />
<OperationResultScreenContent
pictogram="umbrellaNew"
title={I18n.t("wallet.errors.GENERIC_ERROR")}
subtitle={I18n.t("wallet.errorTransaction.submitBugText")}
action={{
label: I18n.t("global.buttons.retry"),
accessibilityLabel: I18n.t("global.buttons.retry"),
onPress: initLoadingLists
}}
/>
) : (
<Animated.FlatList
style={{ flexGrow: 1, backgroundColor: IOColors.white }}
Expand All @@ -247,11 +270,11 @@ const CgnMerchantsListByCategory = () => {
snapToEnd={false}
contentContainerStyle={{
flexGrow: 1,
paddingBottom: 48,
paddingBottom: getPaddingBottom(),
backgroundColor: IOColors.white
}}
refreshControl={refreshControl}
data={isListLoading && !isPullRefresh ? [] : merchantsAll}
data={merchantsAll}
keyExtractor={item => item.id}
ListEmptyComponent={CgnMerchantListSkeleton}
renderItem={renderItem}
Expand Down
6 changes: 4 additions & 2 deletions ts/features/payments/checkout/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export const getPaymentAnalyticsEventFromFailureOutcome = (
};

export const getPaymentAnalyticsEventFromRequestFailure = (
falure: WalletPaymentFailure
failure: WalletPaymentFailure
) => {
switch (falure.faultCodeCategory) {
switch (failure.faultCodeCategory) {
case "PAYMENT_UNAVAILABLE":
return "PAYMENT_TECHNICAL_ERROR";
case "PAYMENT_DATA_ERROR":
Expand All @@ -93,6 +93,8 @@ export const getPaymentAnalyticsEventFromRequestFailure = (
return "PAYMENT_ALREADY_PAID_ERROR";
case "PAYMENT_UNKNOWN":
return "PAYMENT_NOT_FOUND_ERROR";
case "PAYMENT_GENERIC_ERROR_AFTER_USER_CANCELLATION":
return "PAYMENT_GENERIC_ERROR_AFTER_USER_CANCELLATION";
default:
return "PAYMENT_GENERIC_ERROR";
}
Expand Down
18 changes: 16 additions & 2 deletions ts/features/payments/checkout/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { PaymentMethodsResponse } from "../../../../../../definitions/pagopa/eco
import { PaymentRequestsGetResponse } from "../../../../../../definitions/pagopa/ecommerce/PaymentRequestsGetResponse";
import { RptId } from "../../../../../../definitions/pagopa/ecommerce/RptId";
import { TransactionInfo } from "../../../../../../definitions/pagopa/ecommerce/TransactionInfo";
import { UserLastPaymentMethodResponse } from "../../../../../../definitions/pagopa/ecommerce/UserLastPaymentMethodResponse";
import { WalletInfo } from "../../../../../../definitions/pagopa/ecommerce/WalletInfo";
import { Wallets } from "../../../../../../definitions/pagopa/ecommerce/Wallets";
import { Action } from "../../../../../store/actions/types";
import { NetworkError } from "../../../../../utils/errors";
import { getSortedPspList } from "../../../common/utils";
import { WalletPaymentStepEnum } from "../../types";
import { FaultCodeCategoryEnum } from "../../types/PaymentGenericErrorAfterUserCancellationProblemJson";
import { WalletPaymentFailure } from "../../types/WalletPaymentFailure";
import {
paymentsCalculatePaymentFeesAction,
Expand All @@ -34,7 +36,6 @@ import {
selectPaymentPspAction,
walletPaymentSetCurrentStep
} from "../actions/orchestration";
import { UserLastPaymentMethodResponse } from "../../../../../../definitions/pagopa/ecommerce/UserLastPaymentMethodResponse";
export const WALLET_PAYMENT_STEP_MAX = 4;

export type PaymentsCheckoutState = {
Expand Down Expand Up @@ -242,11 +243,24 @@ const reducer = (
transaction: pot.none
};
case getType(paymentsGetPaymentTransactionInfoAction.failure):
case getType(paymentsDeleteTransactionAction.failure):
return {
...state,
transaction: pot.toError(state.transaction, action.payload)
};
case getType(paymentsDeleteTransactionAction.failure):
return {
...state,
transaction: pot.toError(
state.transaction,
action.payload.kind === "generic"
? {
faultCodeCategory:
FaultCodeCategoryEnum.PAYMENT_GENERIC_ERROR_AFTER_USER_CANCELLATION,
faultCodeDetail: ""
}
: action.payload
)
};

// Authorization url
case getType(paymentsStartPaymentAuthorizationAction.request):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as t from "io-ts";
import { enumType } from "@pagopa/ts-commons/lib/types";

export enum FaultCodeCategoryEnum {
"PAYMENT_GENERIC_ERROR_AFTER_USER_CANCELLATION" = "PAYMENT_GENERIC_ERROR_AFTER_USER_CANCELLATION"
}

// required attributes
const PaymentGenericErrorAfterUserCancellationProblemJsonR = t.type({
faultCodeCategory: enumType<FaultCodeCategoryEnum>(
FaultCodeCategoryEnum,
"faultCodeCategory"
),

faultCodeDetail: t.string
});

// optional attributes
const PaymentGenericErrorAfterUserCancellationProblemJsonO = t.partial({
title: t.string
});

export const PaymentGenericErrorAfterUserCancellationProblemJson =
t.intersection(
[
PaymentGenericErrorAfterUserCancellationProblemJsonR,
PaymentGenericErrorAfterUserCancellationProblemJsonO
],
"PaymentGenericErrorAfterUserCancellationProblemJson"
);

export type PaymentGenericErrorAfterUserCancellationProblemJson = t.TypeOf<
typeof PaymentGenericErrorAfterUserCancellationProblemJson
>;
12 changes: 7 additions & 5 deletions ts/features/payments/checkout/types/WalletPaymentFailure.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as t from "io-ts";
import { GatewayFaultPaymentProblemJson } from "../../../../../definitions/pagopa/ecommerce/GatewayFaultPaymentProblemJson";
import { PartyConfigurationFaultPaymentProblemJson } from "../../../../../definitions/pagopa/ecommerce/PartyConfigurationFaultPaymentProblemJson";
import { ValidationFaultPaymentUnknownProblemJson } from "../../../../../definitions/pagopa/ecommerce/ValidationFaultPaymentUnknownProblemJson";
import { ValidationFaultPaymentDataErrorProblemJson } from "../../../../../definitions/pagopa/ecommerce/ValidationFaultPaymentDataErrorProblemJson";
import { PaymentCanceledStatusFaultPaymentProblemJson } from "../../../../../definitions/pagopa/ecommerce/PaymentCanceledStatusFaultPaymentProblemJson";
import { PaymentDuplicatedStatusFaultPaymentProblemJson } from "../../../../../definitions/pagopa/ecommerce/PaymentDuplicatedStatusFaultPaymentProblemJson";
import { PaymentExpiredStatusFaultPaymentProblemJson } from "../../../../../definitions/pagopa/ecommerce/PaymentExpiredStatusFaultPaymentProblemJson";
import { PaymentOngoingStatusFaultPaymentProblemJson } from "../../../../../definitions/pagopa/ecommerce/PaymentOngoingStatusFaultPaymentProblemJson";
import { PaymentCanceledStatusFaultPaymentProblemJson } from "../../../../../definitions/pagopa/ecommerce/PaymentCanceledStatusFaultPaymentProblemJson";
import { ValidationFaultPaymentDataErrorProblemJson } from "../../../../../definitions/pagopa/ecommerce/ValidationFaultPaymentDataErrorProblemJson";
import { ValidationFaultPaymentUnavailableProblemJson } from "../../../../../definitions/pagopa/ecommerce/ValidationFaultPaymentUnavailableProblemJson";
import { PaymentDuplicatedStatusFaultPaymentProblemJson } from "../../../../../definitions/pagopa/ecommerce/PaymentDuplicatedStatusFaultPaymentProblemJson";
import { ValidationFaultPaymentUnknownProblemJson } from "../../../../../definitions/pagopa/ecommerce/ValidationFaultPaymentUnknownProblemJson";
import { PaymentGenericErrorAfterUserCancellationProblemJson } from "./PaymentGenericErrorAfterUserCancellationProblemJson";

export type WalletPaymentFailure = t.TypeOf<typeof WalletPaymentFailure>;
export const WalletPaymentFailure = t.union([
Expand All @@ -19,5 +20,6 @@ export const WalletPaymentFailure = t.union([
PaymentOngoingStatusFaultPaymentProblemJson,
PaymentCanceledStatusFaultPaymentProblemJson,
ValidationFaultPaymentUnavailableProblemJson,
PaymentDuplicatedStatusFaultPaymentProblemJson
PaymentDuplicatedStatusFaultPaymentProblemJson,
PaymentGenericErrorAfterUserCancellationProblemJson
]);

0 comments on commit 4ae5c5a

Please sign in to comment.