Skip to content

Commit

Permalink
chore: [IOBP-511] New Wallet payment playground refinement (#5406)
Browse files Browse the repository at this point in the history
## Short description
This PR refines the Wallet Payment Playground and introduces the ability
to input a payment notice number and an organization fiscal code, along
with the option to generate a random payment notice to pay (works with
[io-dev-api-server](https://github.com/pagopa/io-dev-api-server))

## List of changes proposed in this pull request
- Added `WalletPaymentPlayground` screen

## How to test
Within the profile screen, navigate to **Playgrounds > New Wallet >
Payment**.

## Preview



https://github.com/pagopa/io-app/assets/6160324/34cc2f85-8b3f-4839-8265-8c3775274640
  • Loading branch information
mastro993 authored Jan 17, 2024
1 parent b33bafb commit 599a037
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 13 deletions.
5 changes: 5 additions & 0 deletions ts/navigation/ProfileNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import MarkdownPlayground from "../screens/profile/playgrounds/MarkdownPlaygroun
import WalletPlayground from "../screens/profile/playgrounds/WalletPlayground";
import { useIOSelector } from "../store/hooks";
import { isGestureEnabled } from "../utils/navigation";
import { WalletPaymentPlayground } from "../screens/profile/playgrounds/WalletPaymentPlayground";
import { ProfileParamsList } from "./params/ProfileParamsList";
import ROUTES from "./routes";

Expand Down Expand Up @@ -194,6 +195,10 @@ const ProfileStackNavigator = () => {
name={ROUTES.WALLET_PLAYGROUND}
component={WalletPlayground}
/>
<Stack.Screen
name={ROUTES.WALLET_PAYMENT_PLAYGROUND}
component={WalletPaymentPlayground}
/>
<Stack.Screen
name={ROUTES.PROFILE_REMOVE_ACCOUNT_INFO}
component={RemoveAccountInfo}
Expand Down
1 change: 1 addition & 0 deletions ts/navigation/params/ProfileParamsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export type ProfileParamsList = {
[ROUTES.IDPAY_ONBOARDING_PLAYGROUND]: undefined;
[ROUTES.IDPAY_CODE_PLAYGROUND]: undefined;
[ROUTES.WALLET_PLAYGROUND]: undefined;
[ROUTES.WALLET_PAYMENT_PLAYGROUND]: undefined;
};
1 change: 1 addition & 0 deletions ts/navigation/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const ROUTES = {
IDPAY_ONBOARDING_PLAYGROUND: "IDPAY_ONBOARDING_PLAYGROUND",
LOLLIPOP_PLAYGROUND: "LOLLIPOP_PLAYGROUND",
WALLET_PLAYGROUND: "WALLET_PLAYGROUND",
WALLET_PAYMENT_PLAYGROUND: "WALLET_PAYMENT_PLAYGROUND",
IDPAY_CODE_PLAYGROUND: "IDPAY_CODE_PLAYGROUND",

// Preferences
Expand Down
146 changes: 146 additions & 0 deletions ts/screens/profile/playgrounds/WalletPaymentPlayground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import {
GradientScrollView,
TextInputValidation,
VSpacer
} from "@pagopa/io-app-design-system";
import {
RptId as PagoPaRptId,
PaymentNoticeNumberFromString,
RptIdFromString as PagoPaRptIdFromString
} from "@pagopa/io-pagopa-commons/lib/pagopa";
import { useNavigation } from "@react-navigation/native";
import { sequenceS } from "fp-ts/lib/Apply";
import * as E from "fp-ts/lib/Either";
import * as O from "fp-ts/lib/Option";
import { pipe } from "fp-ts/lib/function";
import React from "react";
import { RptId } from "../../../../definitions/pagopa/ecommerce/RptId";
import {
validateOrganizationFiscalCode,
validatePaymentNoticeNumber
} from "../../../features/walletV3/common/utils/validation";
import { WalletPaymentRoutes } from "../../../features/walletV3/payment/navigation/routes";
import { walletPaymentInitState } from "../../../features/walletV3/payment/store/actions/orchestration";
import { useHeaderSecondLevel } from "../../../hooks/useHeaderSecondLevel";
import I18n from "../../../i18n";
import {
AppParamsList,
IOStackNavigationProp
} from "../../../navigation/params/AppParamsList";
import { useIODispatch } from "../../../store/hooks";

const WalletPaymentPlayground = () => {
const dispatch = useIODispatch();
const navigation = useNavigation<IOStackNavigationProp<AppParamsList>>();

const [rptId, setRptId] = React.useState<PagoPaRptId>();
const [paymentNoticeNumber, setPaymentNoticeNumber] =
React.useState<string>("");
const [organizationFiscalCode, setOrganizationFiscalCode] =
React.useState<string>("");

React.useEffect(() => {
pipe(
rptId,
PagoPaRptIdFromString.decode,
E.map(rptId => {
setPaymentNoticeNumber(
PaymentNoticeNumberFromString.encode(rptId.paymentNoticeNumber)
);
setOrganizationFiscalCode(rptId.organizationFiscalCode);
})
);
}, [rptId]);

React.useEffect(() => {
pipe(
sequenceS(E.Monad)({
paymentNoticeNumber: E.right(paymentNoticeNumber),
organizationFiscalCode: E.right(organizationFiscalCode)
}),
E.chain(PagoPaRptId.decode),
E.map(setRptId),
E.getOrElse(() => setRptId(undefined))
);
}, [paymentNoticeNumber, organizationFiscalCode]);

const navigateToWalletPayment = () => {
pipe(
rptId,
O.fromNullable,
O.map(PagoPaRptIdFromString.encode),
O.map(rptId => {
dispatch(walletPaymentInitState());
navigation.navigate(WalletPaymentRoutes.WALLET_PAYMENT_MAIN, {
screen: WalletPaymentRoutes.WALLET_PAYMENT_DETAIL,
params: {
rptId: rptId as RptId
}
});
})
);
};

const generateValidRandomRptId = () => {
pipe(
"00000123456002160020399398578",
PagoPaRptIdFromString.decode,
E.map(setRptId)
);
};

useHeaderSecondLevel({ title: "Payment playground" });

return (
<GradientScrollView
primaryActionProps={{
label: "Continua",
accessibilityLabel: "Continue",
onPress: navigateToWalletPayment,
disabled: rptId === undefined
}}
secondaryActionProps={{
label: "RptId casuale",
accessibilityLabel: "RptIt casuale",
onPress: generateValidRandomRptId
}}
>
<VSpacer size={24} />
<TextInputValidation
placeholder={I18n.t("wallet.payment.manual.noticeNumber.placeholder")}
accessibilityLabel={I18n.t(
"wallet.payment.manual.noticeNumber.placeholder"
)}
value={paymentNoticeNumber}
icon="docPaymentCode"
onChangeText={setPaymentNoticeNumber}
onValidate={validatePaymentNoticeNumber}
counterLimit={18}
textInputProps={{
keyboardType: "number-pad",
inputMode: "numeric",
returnKeyType: "done"
}}
/>
<VSpacer size={8} />
<TextInputValidation
placeholder={I18n.t("wallet.payment.manual.fiscalCode.placeholder")}
accessibilityLabel={I18n.t(
"wallet.payment.manual.fiscalCode.placeholder"
)}
value={organizationFiscalCode}
icon="fiscalCodeIndividual"
onChangeText={setOrganizationFiscalCode}
onValidate={validateOrganizationFiscalCode}
counterLimit={11}
textInputProps={{
keyboardType: "number-pad",
inputMode: "numeric",
returnKeyType: "done"
}}
/>
</GradientScrollView>
);
};

export { WalletPaymentPlayground };
18 changes: 5 additions & 13 deletions ts/screens/profile/playgrounds/WalletPlayground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ import { Divider, ListItemNav, VSpacer } from "@pagopa/io-app-design-system";
import { useNavigation } from "@react-navigation/native";
import React from "react";
import { ScrollView } from "react-native";
import { RptId } from "../../../../definitions/pagopa/ecommerce/RptId";
import { Body } from "../../../components/core/typography/Body";
import { H2 } from "../../../components/core/typography/H2";
import { IOStyles } from "../../../components/core/variables/IOStyles";
import BaseScreenComponent from "../../../components/screens/BaseScreenComponent";
import { WalletOnboardingRoutes } from "../../../features/walletV3/onboarding/navigation/navigator";
import { WalletPaymentRoutes } from "../../../features/walletV3/payment/navigation/routes";
import { walletPaymentInitState } from "../../../features/walletV3/payment/store/actions/orchestration";
import {
AppParamsList,
IOStackNavigationProp
} from "../../../navigation/params/AppParamsList";
import { useIODispatch } from "../../../store/hooks";
import ROUTES from "../../../navigation/routes";

const WalletPlayground = () => {
const dispatch = useIODispatch();
const navigation = useNavigation<IOStackNavigationProp<AppParamsList>>();

const navigateToWalletOnboarding = () => {
Expand All @@ -27,13 +23,9 @@ const WalletPlayground = () => {
});
};

const navigateToWalletPayment = () => {
dispatch(walletPaymentInitState());
navigation.navigate(WalletPaymentRoutes.WALLET_PAYMENT_MAIN, {
screen: WalletPaymentRoutes.WALLET_PAYMENT_DETAIL,
params: {
rptId: "00000123456002160020399398578" as RptId
}
const navigateToWalletPaymentPlayground = () => {
navigation.navigate(ROUTES.PROFILE_NAVIGATOR, {
screen: ROUTES.WALLET_PAYMENT_PLAYGROUND
});
};

Expand All @@ -56,7 +48,7 @@ const WalletPlayground = () => {
value="Payment"
accessibilityLabel={"Onboarding Playground"}
description="Start the payment flow to pay with a method of payment"
onPress={navigateToWalletPayment}
onPress={navigateToWalletPaymentPlayground}
/>
</ScrollView>
</BaseScreenComponent>
Expand Down

0 comments on commit 599a037

Please sign in to comment.