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 26, 2024
1 parent a51e60e commit 9af39f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 51 deletions.
35 changes: 1 addition & 34 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2048,42 +2048,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
26 changes: 9 additions & 17 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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 @@ -30,7 +29,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 @@ -39,14 +38,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 @@ -86,9 +83,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;
const hasApprovalError = !!policy?.errorFields?.approvalMode;
const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting;
Expand Down Expand Up @@ -187,7 +187,7 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
? translate('common.bankAccount')
: translate('workflowsPage.connectBankAccount')
}
description={state === BankAccount.STATE.OPEN ? bankDisplayName : undefined}
description={bankDisplayName}
onPress={() => {
if (!Policy.isCurrencySupportedForDirectReimbursement(policy?.outputCurrency ?? '')) {
setIsCurrencyModalOpen(true);
Expand Down Expand Up @@ -238,7 +238,6 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
onPressAutoReportingFrequency,
preferredLocale,
canUseDelayedSubmission,
reimbursementAccount?.achData,
displayNameForAuthorizedPayer,
session?.accountID,
]);
Expand All @@ -264,7 +263,6 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses

const isPaidGroupPolicy = PolicyUtils.isPaidGroupPolicy(policy);
const isPolicyAdmin = PolicyUtils.isPolicyAdmin(policy);
const isLoading = reimbursementAccount?.isLoading && policy?.reimbursementChoice === undefined;

return (
<FeatureEnabledAccessOrNotFoundWrapper
Expand All @@ -279,8 +277,6 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
shouldShowOfflineIndicatorInWideScreen
shouldShowNotFoundPage={!isPaidGroupPolicy || !isPolicyAdmin}
shouldSkipVBBACall
isLoading={isLoading}
shouldShowLoading={isLoading}
shouldUseScrollView
>
<View style={[styles.mt3, styles.textStrong, isSmallScreenWidth ? styles.workspaceSectionMobile : styles.workspaceSection]}>
Expand Down Expand Up @@ -317,10 +313,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 @@ -183,6 +183,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 PolicyReportFieldType = 'text' | 'date' | 'dropdown' | 'formula';
Expand Down Expand Up @@ -417,6 +424,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 9af39f6

Please sign in to comment.