Skip to content

Commit

Permalink
Use policy achAccount instead of reimbursementAccount in WorkspaceWor…
Browse files Browse the repository at this point in the history
…kflow
  • Loading branch information
nkuoch committed Mar 15, 2024
1 parent b1e607d commit 65fe96b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 50 deletions.
35 changes: 1 addition & 34 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2013,42 +2013,9 @@ function openPolicyWorkflowsPage(policyID: string) {
return;
}

const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM
key: `${ONYXKEYS.REIMBURSEMENT_ACCOUNT}${policyID}`,
value: {
isLoading: true,
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM
key: `${ONYXKEYS.REIMBURSEMENT_ACCOUNT}${policyID}`,
value: {
isLoading: false,
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM
key: `${ONYXKEYS.REIMBURSEMENT_ACCOUNT}${policyID}`,
value: {
isLoading: false,
},
},
],
};

const params: OpenPolicyWorkflowsPageParams = {policyID};

API.read(READ_COMMANDS.OPEN_POLICY_WORKFLOWS_PAGE, params, onyxData);
API.read(READ_COMMANDS.OPEN_POLICY_WORKFLOWS_PAGE, params);
}

function setPolicyIDForReimburseView(policyID: string) {
Expand Down
25 changes: 9 additions & 16 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as ErrorUtils from '@libs/ErrorUtils';
import BankAccount from '@libs/models/BankAccount';
import Navigation from '@libs/Navigation/Navigation';
import Permissions from '@libs/Permissions';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
Expand All @@ -28,7 +27,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Beta, ReimbursementAccount, Session} from '@src/types/onyx';
import type {Beta, Session} from '@src/types/onyx';
import ToggleSettingOptionRow from './ToggleSettingsOptionRow';
import type {ToggleSettingOptionRowProps} from './ToggleSettingsOptionRow';
import {getAutoReportingFrequencyDisplayNames} from './WorkspaceAutoReportingFrequencyPage';
Expand All @@ -37,14 +36,12 @@ import type {AutoReportingFrequencyKey} from './WorkspaceAutoReportingFrequencyP
type WorkspaceWorkflowsPageOnyxProps = {
/** Beta features list */
betas: OnyxEntry<Beta[]>;
/** Reimbursement account details */
reimbursementAccount: OnyxEntry<ReimbursementAccount>;
/** Policy details */
session: OnyxEntry<Session>;
};
type WorkspaceWorkflowsPageProps = WithPolicyProps & WorkspaceWorkflowsPageOnyxProps & StackScreenProps<WorkspacesCentralPaneNavigatorParamList, typeof SCREENS.WORKSPACE.WORKFLOWS>;

function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, session}: WorkspaceWorkflowsPageProps) {
function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkflowsPageProps) {
const {translate, preferredLocale} = useLocalize();
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();
Expand Down Expand Up @@ -74,9 +71,12 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
}, []);

const optionItems: ToggleSettingOptionRowProps[] = useMemo(() => {
const {accountNumber, state, bankName} = reimbursementAccount?.achData ?? {};
const hasVBA = state === BankAccount.STATE.OPEN;
const bankDisplayName = bankName ? `${bankName} ${accountNumber ? `${accountNumber.slice(-5)}` : ''}` : '';
const {accountNumber, addressName} = policy?.achAccount ?? {};
const hasVBA = !!policy?.achAccount;
let bankDisplayName = addressName;
if (accountNumber && bankDisplayName !== accountNumber) {
bankDisplayName += accountNumber.slice(-5);
}
const hasReimburserEmailError = !!policy?.errorFields?.reimburserEmail;

return [
Expand Down Expand Up @@ -156,7 +156,7 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
titleStyle={styles.textLabelSupportingNormal}
descriptionTextStyle={styles.textNormalThemeText}
title={hasVBA ? translate('common.bankAccount') : translate('workflowsPage.connectBankAccount')}
description={state === BankAccount.STATE.OPEN ? bankDisplayName : undefined}
description={bankDisplayName}
onPress={() => navigateToBankAccountRoute(route.params.policyID, ROUTES.WORKSPACE_WORKFLOWS.getRoute(route.params.policyID))}
shouldShowRightIcon
wrapperStyle={containerStyle}
Expand Down Expand Up @@ -201,7 +201,6 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
onPressAutoReportingFrequency,
preferredLocale,
canUseDelayedSubmission,
reimbursementAccount?.achData,
displayNameForAuthorizedPayer,
session?.accountID,
]);
Expand All @@ -224,7 +223,6 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses

const isPaidGroupPolicy = PolicyUtils.isPaidGroupPolicy(policy);
const isPolicyAdmin = PolicyUtils.isPolicyAdmin(policy);
const isLoading = reimbursementAccount?.isLoading ?? true;

return (
<WorkspacePageWithSections
Expand All @@ -235,7 +233,6 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
shouldShowOfflineIndicatorInWideScreen
shouldShowNotFoundPage={!isPaidGroupPolicy || !isPolicyAdmin}
shouldSkipVBBACall
isLoading={isLoading}
>
<View style={[styles.mt3, styles.textStrong, isSmallScreenWidth ? styles.workspaceSectionMobile : styles.workspaceSection]}>
<Section
Expand Down Expand Up @@ -264,10 +261,6 @@ export default withPolicy(
betas: {
key: ONYXKEYS.BETAS,
},
reimbursementAccount: {
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM
key: ({route}) => `${ONYXKEYS.REIMBURSEMENT_ACCOUNT}${route.params.policyID}`,
},
session: {
key: ONYXKEYS.SESSION,
},
Expand Down
9 changes: 9 additions & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ type Connections = {
quickbooksOnline: Connection<QBOConnectionData, QBOConnectionConfig>;
};

type ACHAccount = {
bankAccountID: number;
accountNumber: string;
routingNumber: string;
addressName: string;
};

type AutoReportingOffset = number | ValueOf<typeof CONST.POLICY.AUTO_REPORTING_OFFSET>;

type PendingJoinRequestPolicy = {
Expand Down Expand Up @@ -351,6 +358,8 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<

/** Whether the Connections feature is enabled */
areConnectionsEnabled?: boolean;

achAccount?: ACHAccount;
} & Partial<PendingJoinRequestPolicy>,
'generalSettings' | 'addWorkspaceRoom'
>;
Expand Down

0 comments on commit 65fe96b

Please sign in to comment.