Skip to content

Commit

Permalink
Merge pull request #37214 from kubabutkiewicz/ts-migration/Reimbursem…
Browse files Browse the repository at this point in the history
…entAccount/page

[TS migration] Migrate 'ReimbursementAccount' page to TypeScript
  • Loading branch information
rlinoz authored Apr 9, 2024
2 parents efa7d16 + 7023d38 commit 51704e5
Show file tree
Hide file tree
Showing 34 changed files with 421 additions and 791 deletions.
2 changes: 1 addition & 1 deletion src/components/AddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function AddressForm({
city: INPUT_IDS.CITY,
state: INPUT_IDS.STATE,
zipCode: INPUT_IDS.ZIP_POST_CODE,
country: INPUT_IDS.COUNTRY,
country: INPUT_IDS.COUNTRY as Country,
}}
maxInputLength={CONST.FORM_CHARACTER_LIMIT}
shouldSaveDraft={shouldSaveDraft}
Expand Down
5 changes: 3 additions & 2 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import type {GeolocationErrorCodeType} from '@libs/getCurrentPosition/getCurrent
import * as GooglePlacesUtils from '@libs/GooglePlacesUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {Address} from '@src/types/onyx/PrivatePersonalDetails';
import CurrentLocationButton from './CurrentLocationButton';
import isCurrentTargetInsideContainer from './isCurrentTargetInsideContainer';
import type {AddressSearchProps, RenamedInputKeysProps} from './types';
import type {AddressSearchProps} from './types';

// The error that's being thrown below will be ignored until we fork the
// react-native-google-places-autocomplete repo and replace the
Expand Down Expand Up @@ -213,7 +214,7 @@ function AddressSearch(

if (inputID) {
Object.entries(values).forEach(([key, inputValue]) => {
const inputKey = renamedInputKeys?.[key as keyof RenamedInputKeysProps] ?? key;
const inputKey = renamedInputKeys?.[key as keyof Address] ?? key;
if (!inputKey) {
return;
}
Expand Down
19 changes: 4 additions & 15 deletions src/components/AddressSearch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {NativeSyntheticEvent, StyleProp, TextInputFocusEventData, View, Vie
import type {Place} from 'react-native-google-places-autocomplete';
import type {MaybePhraseKey} from '@libs/Localize';
import type Locale from '@src/types/onyx/Locale';
import type {Address} from '@src/types/onyx/PrivatePersonalDetails';

type CurrentLocationButtonProps = {
/** Callback that is called when the button is clicked */
Expand All @@ -12,18 +13,6 @@ type CurrentLocationButtonProps = {
isDisabled?: boolean;
};

type RenamedInputKeysProps = {
street: string;
street2: string;
city: string;
state: string;
lat?: string;
lng?: string;
zipCode: string;
address?: string;
country?: string;
};

type OnPressProps = {
address: string;
lat: number;
Expand Down Expand Up @@ -61,7 +50,7 @@ type AddressSearchProps = {
defaultValue?: string;

/** A callback function when the value of this field has changed */
onInputChange?: (value: string | number | RenamedInputKeysProps | StreetValue, key?: string) => void;
onInputChange?: (value: string | number | Address | StreetValue, key?: string) => void;

/** A callback function when an address has been auto-selected */
onPress?: (props: OnPressProps) => void;
Expand All @@ -79,7 +68,7 @@ type AddressSearchProps = {
predefinedPlaces?: Place[] | null;

/** A map of inputID key names */
renamedInputKeys?: RenamedInputKeysProps;
renamedInputKeys?: Address;

/** Maximum number of characters allowed in search input */
maxInputLength?: number;
Expand All @@ -96,4 +85,4 @@ type AddressSearchProps = {

type IsCurrentTargetInsideContainerType = (event: FocusEvent | NativeSyntheticEvent<TextInputFocusEventData>, containerRef: RefObject<View | HTMLElement>) => boolean;

export type {CurrentLocationButtonProps, AddressSearchProps, RenamedInputKeysProps, IsCurrentTargetInsideContainerType, StreetValue};
export type {CurrentLocationButtonProps, AddressSearchProps, IsCurrentTargetInsideContainerType, StreetValue};
2 changes: 2 additions & 0 deletions src/components/StateSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ function StateSelector(
StateSelector.displayName = 'StateSelector';

export default React.forwardRef(StateSelector);

export type {State};
5 changes: 3 additions & 2 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,9 @@ type AddPersonalBankAccountNavigatorParamList = {

type ReimbursementAccountNavigatorParamList = {
[SCREENS.REIMBURSEMENT_ACCOUNT_ROOT]: {
stepToOpen: string;
policyID: string;
stepToOpen?: string;
backTo?: Routes;
policyID?: string;
};
};

Expand Down
7 changes: 4 additions & 3 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import type {OnfidoDataWithApplicantID} from '@components/Onfido/types';
Expand Down Expand Up @@ -70,7 +71,7 @@ function openPlaidView() {
clearPlaid().then(() => ReimbursementAccount.setBankAccountSubStep(CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID));
}

function setPlaidEvent(eventName: string) {
function setPlaidEvent(eventName: OnyxEntry<string>) {
Onyx.set(ONYXKEYS.PLAID_CURRENT_EVENT, eventName);
}

Expand Down Expand Up @@ -463,11 +464,11 @@ function connectBankAccountManually(bankAccountID: number, bankAccount: PlaidBan
/**
* Verify the user's identity via Onfido
*/
function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: OnfidoDataWithApplicantID, policyID: string) {
function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: OnfidoDataWithApplicantID, policyID?: string) {
const parameters: VerifyIdentityForBankAccountParams = {
bankAccountID,
onfidoData: JSON.stringify(onfidoData),
policyID,
policyID: policyID ?? '',
canUseNewVbbaFlow: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type * as OnyxTypes from '@src/types/onyx';
/**
* Reset user's reimbursement account. This will delete the bank account.
*/
function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry<OnyxTypes.Session>, policyID: string, user: OnyxEntry<OnyxTypes.User>) {
function resetFreePlanBankAccount(bankAccountID: number | undefined, session: OnyxEntry<OnyxTypes.Session>, policyID: string, user: OnyxEntry<OnyxTypes.User>) {
if (!bankAccountID) {
throw new Error('Missing bankAccountID when attempting to reset free plan bank account');
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/EnablePayments/AdditionalDetailsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ function AdditionalDetailsStep({walletAdditionalDetails = DEFAULT_WALLET_ADDITIO
state: 'addressState',
zipCode: 'addressZipCode',
}}
translate={translate}
streetTranslationKey={fieldNameTranslationKeys.addressStreet}
shouldSaveDraft
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import PropTypes from 'prop-types';
import React from 'react';
import CompleteVerification from './CompleteVerification/CompleteVerification';

const propTypes = {
type ACHContractStepProps = {
/** Goes to the previous step */
onBackButtonPress: PropTypes.func.isRequired,
onBackButtonPress: () => void;
};

function ACHContractStep({onBackButtonPress}) {
function ACHContractStep({onBackButtonPress}: ACHContractStepProps) {
return <CompleteVerification onBackButtonPress={onBackButtonPress} />;
}

ACHContractStep.propTypes = propTypes;
ACHContractStep.displayName = 'ACHContractStep';

export default ACHContractStep;
163 changes: 0 additions & 163 deletions src/pages/ReimbursementAccount/AddressForm.js

This file was deleted.

Loading

0 comments on commit 51704e5

Please sign in to comment.