Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const ONYXKEYS = {
/** The Wise onboarding page saves still running, by save ID. RAM-only, since a page with an SSN skips the queue, so its save ends when the app closes and must not keep the flow saving after a reload. */
RAM_ONLY_WISE_ONBOARDING_PENDING_SAVES: 'wiseOnboardingPendingSaves',

/** The ID of the bank account whose business details the Wise intro page has started reading. RAM-only, since a reload ends the read. */
RAM_ONLY_WISE_INTRO_READ_BANK_ACCOUNT_ID: 'wiseIntroReadBankAccountID',

/** Ordered reportIDs from the latest SearchForReports response, used to display server search results in the tier order Auth returned. */
RAM_ONLY_SEARCH_RESULT_REPORT_IDS: 'searchResultReportIDs',
/** Boolean flag set whenever we are searching for users in the server */
Expand Down Expand Up @@ -1977,6 +1980,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.RAM_ONLY_IS_SEARCHING_FOR_REPORTS]: boolean;
[ONYXKEYS.RAM_ONLY_IS_LOADING_DEPOSIT_ACCOUNT_SETUP]: boolean;
[ONYXKEYS.RAM_ONLY_WISE_ONBOARDING_PENDING_SAVES]: Record<string, boolean>;
[ONYXKEYS.RAM_ONLY_WISE_INTRO_READ_BANK_ACCOUNT_ID]: number;
[ONYXKEYS.RAM_ONLY_SEARCH_RESULT_REPORT_IDS]: string[] | null;
[ONYXKEYS.RAM_ONLY_IS_SEARCHING_FOR_USERS]: boolean;
[ONYXKEYS.RAM_ONLY_IS_AUTHENTICATING_WITH_SHORT_LIVED_TOKEN]: boolean;
Expand Down
15 changes: 15 additions & 0 deletions src/hooks/useDismissWiseGlobalReimbursementsBanners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {dismissWiseGlobalReimbursementsBanners} from '@userActions/WiseOnboarding';

import {useEffect} from 'react';

/** Dismisses the Wallet and Workspace banners that promote Wise global reimbursements once `shouldDismiss` turns true. */
function useDismissWiseGlobalReimbursementsBanners(shouldDismiss: boolean) {
useEffect(() => {
if (!shouldDismiss) {
return;
}
dismissWiseGlobalReimbursementsBanners();
}, [shouldDismiss]);
}

export default useDismissWiseGlobalReimbursementsBanners;
17 changes: 17 additions & 0 deletions src/hooks/useOpenReimbursementAccountPageForWiseIntro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {clearWiseIntroReadBankAccountID, openReimbursementAccountPageForWiseIntro} from '@userActions/WiseOnboarding';

import {useEffect} from 'react';

/** Reads the business details for the Wise onboarding form whenever `shouldRead` turns true, so the form can open without waiting for them. */
function useOpenReimbursementAccountPageForWiseIntro(bankAccountID: number, shouldRead: boolean) {
useEffect(() => {
if (!shouldRead) {
return;
}
openReimbursementAccountPageForWiseIntro(bankAccountID);
}, [bankAccountID, shouldRead]);

useEffect(() => clearWiseIntroReadBankAccountID, []);
}

export default useOpenReimbursementAccountPageForWiseIntro;
1 change: 1 addition & 0 deletions src/libs/ExportOnyxState/masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ const safeOnyxKeys = new Set<string>([
ONYXKEYS.RAM_ONLY_SEARCH_RESULT_REPORT_IDS,
ONYXKEYS.RAM_ONLY_UPDATE_REQUIRED,
ONYXKEYS.RAM_ONLY_WISE_BANK_ACCOUNT_FIELDS,
ONYXKEYS.RAM_ONLY_WISE_INTRO_READ_BANK_ACCOUNT_ID,
ONYXKEYS.RAM_ONLY_WISE_ONBOARDING_PENDING_SAVES,
ONYXKEYS.REIMBURSEMENT_ACCOUNT_OPTION_PRESSED,
ONYXKEYS.REIMBURSEMENT_ACCOUNT_WORKSPACE_ID,
Expand Down
28 changes: 27 additions & 1 deletion src/libs/actions/WiseOnboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import getWiseOnboardingPageParams from '@libs/getWiseOnboardingPageParams';
import {rand64} from '@libs/NumberUtils';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {DynamicFormPage} from '@src/types/onyx';
import type {OnyxData} from '@src/types/onyx/Request';

import Onyx from 'react-native-onyx';

import {openReimbursementAccountPage} from './BankAccounts';
import {dismissProductTraining} from './Welcome';

/**
* Marks the page as unsaved until its own save succeeds, since `errors` is shared by every page and the next page's save clears it. It also covers a save
* whose answer never comes, as when the app closes during a request that is not queued, since the running saves are kept only in memory. A failed save marks the page again, so when the same page is
Expand Down Expand Up @@ -104,6 +108,21 @@ function clearWiseOnboardingUnsavedPages() {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {wiseOnboardingUnsavedPages: null});
}

/** Reads the business details the Wise onboarding form prefills from, and records which bank account the read is for so the form does not read them again. */
function openReimbursementAccountPageForWiseIntro(bankAccountID: number) {
Onyx.set(ONYXKEYS.RAM_ONLY_WISE_INTRO_READ_BANK_ACCOUNT_ID, bankAccountID);
openReimbursementAccountPage({bankAccountID, shouldPreserveDraft: true});
}

function clearWiseIntroReadBankAccountID() {
Onyx.set(ONYXKEYS.RAM_ONLY_WISE_INTRO_READ_BANK_ACCOUNT_ID, null);
}

function dismissWiseGlobalReimbursementsBanners() {
dismissProductTraining(CONST.WISE_GLOBAL_REIMBURSEMENTS_WALLET_BANNER);
dismissProductTraining(CONST.WISE_GLOBAL_REIMBURSEMENTS_WORKSPACE_BANNER);
}

/** Submits the business to Wise with the answers its pages saved. Auth creates the Wise profile and opens Wise's review in the same request. */
function submitWiseBusinessOnboarding(params: SubmitWiseBusinessOnboardingParams) {
const onyxData: OnyxData<typeof ONYXKEYS.REIMBURSEMENT_ACCOUNT> = {
Expand Down Expand Up @@ -146,4 +165,11 @@ function clearWiseBusinessOnboardingSubmission() {
}

export default saveWiseOnboardingPage;
export {clearWiseBusinessOnboardingSubmission, clearWiseOnboardingUnsavedPages, submitWiseBusinessOnboarding};
export {
clearWiseIntroReadBankAccountID,
clearWiseBusinessOnboardingSubmission,
clearWiseOnboardingUnsavedPages,
dismissWiseGlobalReimbursementsBanners,
openReimbursementAccountPageForWiseIntro,
submitWiseBusinessOnboarding,
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Header from '@components/Header';
import ScreenWrapper from '@components/ScreenWrapper';

import useDismissWiseGlobalReimbursementsBanners from '@hooks/useDismissWiseGlobalReimbursementsBanners';
import useDynamicBackPath from '@hooks/useDynamicBackPath';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -102,7 +103,10 @@ function WiseBusinessOnboardingPage({route}: WiseBusinessOnboardingPageProps) {
// device holds.
const [isNewVisit] = useState(!route.params.subPage);
const shouldReadBusinessAccount = isNewVisit && !isOffline && !isOnboardingSubmitted;
const [hasBusinessAccountReadStarted, setHasBusinessAccountReadStarted] = useState(false);
const [introReadBankAccountID] = useOnyx(ONYXKEYS.RAM_ONLY_WISE_INTRO_READ_BANK_ACCOUNT_ID);
const [hasBusinessAccountReadStarted, setHasBusinessAccountReadStarted] = useState(
introReadBankAccountID === bankAccountID && (!!businessAccount?.isLoading || businessAccount?.data?.bankAccountID === bankAccountID),
);

// The reimbursement account's errors are shared with the other bank account flows, so a new visit drops any left from them or from an earlier visit
useEffect(() => {
Expand All @@ -118,7 +122,7 @@ function WiseBusinessOnboardingPage({route}: WiseBusinessOnboardingPageProps) {
if (!shouldReadBusinessAccount || hasBusinessAccountReadStarted || isPrefillDone) {
return;
}
openReimbursementAccountPage({bankAccountID});
openReimbursementAccountPage({bankAccountID, shouldPreserveDraft: true});
}, [bankAccountID, shouldReadBusinessAccount, hasBusinessAccountReadStarted, isPrefillDone]);
const isWaitingForBusinessAccount = shouldReadBusinessAccount && (!hasBusinessAccountReadStarted || !!businessAccount?.isLoading);

Expand Down Expand Up @@ -183,6 +187,10 @@ function WiseBusinessOnboardingPage({route}: WiseBusinessOnboardingPageProps) {
setIsPrefillDone(true);
}

// Starting onboarding for any account retires both banners for good, and the writes wait for the form so the read is not queued behind them
const isEligible = isBankAccountEligibleForGlobalReimbursements(bankAccount?.accountData, bankAccount?.bankCurrency);
useDismissWiseGlobalReimbursementsBanners(isNewVisit && isPrefillDone && isEligible);
Comment thread
grgia marked this conversation as resolved.
Resolved

useEffect(() => {
if (!isPrefillPending) {
return;
Expand All @@ -206,7 +214,7 @@ function WiseBusinessOnboardingPage({route}: WiseBusinessOnboardingPageProps) {
return <FullScreenLoadingIndicator shouldUseGoBackButton />;
}

if (!isBankAccountEligibleForGlobalReimbursements(bankAccount?.accountData, bankAccount?.bankCurrency)) {
if (!isEligible) {
return <NotFoundPage onBackButtonPress={goBackToIntro} />;
}

Expand Down
28 changes: 19 additions & 9 deletions src/pages/settings/Wallet/WiseGlobalReimbursementsIntroPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import ScreenWrapper from '@components/ScreenWrapper';
import useDynamicBackPath from '@hooks/useDynamicBackPath';
import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useOpenReimbursementAccountPageForWiseIntro from '@hooks/useOpenReimbursementAccountPageForWiseIntro';
import usePermissions from '@hooks/usePermissions';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';

import {dismissProductTraining} from '@libs/actions/Welcome';
import {isBankAccountEligibleForGlobalReimbursements, isWiseOnboardingPendingSubmit, isWiseOnboardingSubmitted} from '@libs/BankAccountUtils';
import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute';
import {isWiseGlobalReimbursementsIntroOverPayReportScreen} from '@libs/Navigation/helpers/enableGlobalReimbursementsNavigationUtils';
Expand All @@ -24,12 +25,15 @@ import type {SettingsNavigatorParamList} from '@navigation/types';

import variables from '@styles/variables';

import {dismissWiseGlobalReimbursementsBanners} from '@userActions/WiseOnboarding';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

import {useIsFocused} from '@react-navigation/native';
import React, {useEffect} from 'react';

type WiseGlobalReimbursementsIntroPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.WALLET.DYNAMIC_WISE_GLOBAL_REIMBURSEMENTS_INTRO>;
Expand All @@ -52,6 +56,12 @@ function WiseGlobalReimbursementsIntroPage({route}: WiseGlobalReimbursementsIntr

const goBackToEntryPoint = () => Navigation.goBack(backPath);

const {isOffline} = useNetwork();
const isEligible = isBankAccountEligibleForGlobalReimbursements(bankAccount?.accountData, bankAccount?.bankCurrency);
// The intro stays mounted under the form on a direct link to the form, which reads for itself
const isFocused = useIsFocused();
useOpenReimbursementAccountPageForWiseIntro(bankAccountID, isFocused && isEligible && !isOffline && !isOnboardingSubmitted && !!isWiseReimbursementsBetaEnabled);

// Close the page instead of showing "not found" when the user lacks the beta. Wait for betas to load first
useEffect(() => {
if (isWiseReimbursementsBetaEnabled !== false) {
Expand All @@ -70,7 +80,7 @@ function WiseGlobalReimbursementsIntroPage({route}: WiseGlobalReimbursementsIntr
return (
<ScreenWrapper testID="WiseGlobalReimbursementsIntroPage">
<FullPageNotFoundView
shouldShow={!isBankAccountEligibleForGlobalReimbursements(bankAccount?.accountData, bankAccount?.bankCurrency)}
shouldShow={!isEligible}
onBackButtonPress={goBackToEntryPoint}
>
<Header>
Expand Down Expand Up @@ -102,13 +112,13 @@ function WiseGlobalReimbursementsIntroPage({route}: WiseGlobalReimbursementsIntr
}
text={translate(isOnboardingSubmitted || isWiseOnboardingPendingSubmit(bankAccount) ? 'common.continue' : 'walletPage.wiseGlobalReimbursementsIntro.getStarted')}
onPress={() => {
// Starting onboarding for any account retires both banners for good
dismissProductTraining(CONST.WISE_GLOBAL_REIMBURSEMENTS_WALLET_BANNER);
dismissProductTraining(CONST.WISE_GLOBAL_REIMBURSEMENTS_WORKSPACE_BANNER);
// A submitted business has nothing left to submit, so it sees where its onboarding stands instead of ending on the terms
Navigation.navigate(
createDynamicRoute(isOnboardingSubmitted ? DYNAMIC_ROUTES.WISE_ONBOARDING_STATUS.path : DYNAMIC_ROUTES.WISE_BUSINESS_ONBOARDING.getRoute()),
);
// A submitted business goes to its status page, which leaves the banners alone, so they are dismissed here. The form dismisses them itself
if (isOnboardingSubmitted) {
dismissWiseGlobalReimbursementsBanners();
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.WISE_ONBOARDING_STATUS.path));
return;
}
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.WISE_BUSINESS_ONBOARDING.getRoute()));
}}
/>
</FixedFooter>
Expand Down
1 change: 1 addition & 0 deletions src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export default function () {
ONYXKEYS.RAM_ONLY_ENABLE_GLOBAL_REIMBURSEMENTS_MODAL,
ONYXKEYS.RAM_ONLY_MEMBERS_NEED_CATEGORY_MODAL,
ONYXKEYS.RAM_ONLY_WISE_ONBOARDING_PENDING_SAVES,
ONYXKEYS.RAM_ONLY_WISE_INTRO_READ_BANK_ACCOUNT_ID,
ONYXKEYS.RAM_ONLY_DYNAMIC_FORM_SENSITIVE_ANSWERS,
],
});
Expand Down
Loading
Loading