-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [IOBP-511] New Wallet payment playground refinement (#5406)
## 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
Showing
5 changed files
with
158 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
ts/screens/profile/playgrounds/WalletPaymentPlayground.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters