|
| 1 | +import React from 'react'; |
| 2 | +import createScreenWithDefaults from '@components/MultifactorAuthentication/components/OutcomeScreen/createScreenWithDefaults'; |
| 3 | +import {DefaultClientFailureScreen} from '@components/MultifactorAuthentication/components/OutcomeScreen/FailureScreen/defaultScreens'; |
| 4 | +import type { |
| 5 | + MultifactorAuthenticationScenario, |
| 6 | + MultifactorAuthenticationScenarioAdditionalParams, |
| 7 | + MultifactorAuthenticationScenarioCustomConfig, |
| 8 | +} from '@components/MultifactorAuthentication/config/types'; |
| 9 | +import {clearDraftValues} from '@libs/actions/FormActions'; |
| 10 | +import {setPersonalDetailsAndShipExpensifyCardsWithPIN} from '@libs/actions/MultifactorAuthentication'; |
| 11 | +import Navigation from '@libs/Navigation/Navigation'; |
| 12 | +import CONST from '@src/CONST'; |
| 13 | +import ONYXKEYS from '@src/ONYXKEYS'; |
| 14 | +import ROUTES from '@src/ROUTES'; |
| 15 | + |
| 16 | +/** |
| 17 | + * Payload type for the SET_PIN_ORDER_CARD scenario. |
| 18 | + * Contains personal details and PIN required for UK/EU card ordering. |
| 19 | + */ |
| 20 | +type Payload = { |
| 21 | + legalFirstName: string; |
| 22 | + legalLastName: string; |
| 23 | + phoneNumber: string; |
| 24 | + addressCity: string; |
| 25 | + addressStreet: string; |
| 26 | + addressStreet2: string; |
| 27 | + addressZip: string; |
| 28 | + addressCountry: string; |
| 29 | + addressState: string; |
| 30 | + dob: string; |
| 31 | + pin: string; |
| 32 | + cardID: string; |
| 33 | +}; |
| 34 | + |
| 35 | +/** |
| 36 | + * Type guard to verify the payload is a SetPinOrderCard payload. |
| 37 | + */ |
| 38 | +function isSetPinOrderCardPayload(payload: MultifactorAuthenticationScenarioAdditionalParams<MultifactorAuthenticationScenario> | undefined): payload is Payload { |
| 39 | + return !!payload && 'cardID' in payload && 'pin' in payload; |
| 40 | +} |
| 41 | + |
| 42 | +const AuthenticationCanceledFailureScreen = createScreenWithDefaults( |
| 43 | + DefaultClientFailureScreen, |
| 44 | + { |
| 45 | + subtitle: 'multifactorAuthentication.setPin.didNotShipCard', |
| 46 | + }, |
| 47 | + 'AuthenticationCanceledFailureScreen', |
| 48 | +); |
| 49 | + |
| 50 | +/** |
| 51 | + * Configuration for the SET_PIN_ORDER_CARD multifactor authentication scenario. |
| 52 | + * This scenario is used when a UK/EU cardholder sets their PIN during the card ordering process. |
| 53 | + * |
| 54 | + * Callback behavior per design doc: |
| 55 | + * - Success: Navigate to ExpensifyCardPage and return SKIP_OUTCOME_SCREEN |
| 56 | + * - Invalid PIN/personal details error: Display error in UI and return SKIP_OUTCOME_SCREEN |
| 57 | + * - Authentication failure: Return SHOW_OUTCOME_SCREEN to show failure screen |
| 58 | + */ |
| 59 | +export default { |
| 60 | + allowedAuthenticationMethods: [CONST.MULTIFACTOR_AUTHENTICATION.TYPE.BIOMETRICS], |
| 61 | + action: setPersonalDetailsAndShipExpensifyCardsWithPIN, |
| 62 | + |
| 63 | + callback: async (isSuccessful, _callbackInput, payload) => { |
| 64 | + if (isSuccessful && isSetPinOrderCardPayload(payload)) { |
| 65 | + clearDraftValues(ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM); |
| 66 | + Navigation.closeRHPFlow(); |
| 67 | + Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(String(payload.cardID))); |
| 68 | + return CONST.MULTIFACTOR_AUTHENTICATION.CALLBACK_RESPONSE.SKIP_OUTCOME_SCREEN; |
| 69 | + } |
| 70 | + |
| 71 | + return CONST.MULTIFACTOR_AUTHENTICATION.CALLBACK_RESPONSE.SHOW_OUTCOME_SCREEN; |
| 72 | + }, |
| 73 | + |
| 74 | + failureScreens: { |
| 75 | + [CONST.MULTIFACTOR_AUTHENTICATION.REASON.EXPO.CANCELED]: <AuthenticationCanceledFailureScreen />, |
| 76 | + }, |
| 77 | +} as const satisfies MultifactorAuthenticationScenarioCustomConfig<Payload>; |
| 78 | + |
| 79 | +export type {Payload}; |
0 commit comments