Skip to content

Commit fa08e61

Browse files
authored
Merge pull request Expensify#61889 from DylanDylann/dylan/fix/61605
add domain condition
2 parents d08c0a8 + d3fc929 commit fa08e61

2 files changed

Lines changed: 44 additions & 14 deletions

File tree

src/pages/workspace/accounting/PolicyAccountingPage.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Text from '@components/Text';
2121
import TextLink from '@components/TextLink';
2222
import ThreeDotsMenu from '@components/ThreeDotsMenu';
2323
import type ThreeDotsMenuProps from '@components/ThreeDotsMenu/types';
24+
import useExpensifyCardFeeds from '@hooks/useExpensifyCardFeeds';
2425
import useLocalize from '@hooks/useLocalize';
2526
import useNetwork from '@hooks/useNetwork';
2627
import usePermissions from '@hooks/usePermissions';
@@ -67,9 +68,7 @@ type RouteParams = {
6768
};
6869

6970
function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
70-
const workspaceAccountID = policy?.workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID;
7171
const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`, {canBeMissing: true});
72-
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, {canBeMissing: true});
7372
const [conciergeChatReportID] = useOnyx(ONYXKEYS.DERIVED.CONCIERGE_CHAT_REPORT_ID, {canBeMissing: true});
7473
const theme = useTheme();
7574
const styles = useThemeStyles();
@@ -89,7 +88,8 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
8988
const newConnectionName = params?.newConnectionName;
9089
const integrationToDisconnect = params?.integrationToDisconnect;
9190
const shouldDisconnectIntegrationBeforeConnecting = params?.shouldDisconnectIntegrationBeforeConnecting;
92-
91+
const policyID = policy?.id;
92+
const allCardSettings = useExpensifyCardFeeds(policyID);
9393
const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy);
9494

9595
const connectionNames = CONST.POLICY.CONNECTIONS.NAME;
@@ -99,7 +99,6 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
9999

100100
const shouldShowEnterCredentials = connectedIntegration && !!synchronizationError && isAuthenticationError(policy, connectedIntegration);
101101

102-
const policyID = policy?.id;
103102
// Get the last successful date of the integration. Then, if `connectionSyncProgress` is the same integration displayed and the state is 'jobDone', get the more recent update time of the two.
104103
const successfulDate = getIntegrationLastSuccessfulDate(
105104
connectedIntegration ? policy?.connections?.[connectedIntegration] : undefined,
@@ -113,8 +112,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
113112
const currentXeroOrganization = findCurrentXeroOrganization(tenants, policy?.connections?.xero?.config?.tenantID);
114113
const shouldShowSynchronizationError = !!synchronizationError;
115114
const shouldShowReinstallConnectorMenuItem = shouldShowSynchronizationError && connectedIntegration === CONST.POLICY.CONNECTIONS.NAME.QBD;
116-
const shouldShowCardReconciliationOption = isExpensifyCardFullySetUp(policy, cardSettings);
117-
115+
const shouldShowCardReconciliationOption = Object.values(allCardSettings ?? {})?.some((cardSetting) => isExpensifyCardFullySetUp(policy, cardSetting));
118116
const overflowMenu: ThreeDotsMenuProps['menuItems'] = useMemo(
119117
() => [
120118
...(shouldShowReinstallConnectorMenuItem

src/pages/workspace/accounting/reconciliation/CardReconciliationPage.tsx

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React, {useCallback} from 'react';
1+
import React, {useCallback, useMemo} from 'react';
22
import {useOnyx} from 'react-native-onyx';
33
import HeaderWithBackButton from '@components/HeaderWithBackButton';
44
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
55
import ScreenWrapper from '@components/ScreenWrapper';
66
import ScrollView from '@components/ScrollView';
77
import Text from '@components/Text';
88
import TextLink from '@components/TextLink';
9+
import useExpensifyCardFeeds from '@hooks/useExpensifyCardFeeds';
910
import useLocalize from '@hooks/useLocalize';
1011
import useThemeStyles from '@hooks/useThemeStyles';
1112
import {getConnectionNameFromRouteParam} from '@libs/AccountingUtils';
@@ -22,32 +23,63 @@ import CONST from '@src/CONST';
2223
import ONYXKEYS from '@src/ONYXKEYS';
2324
import ROUTES from '@src/ROUTES';
2425
import type SCREENS from '@src/SCREENS';
26+
import type ExpensifyCardSettings from '@src/types/onyx/ExpensifyCardSettings';
2527
import type {ConnectionName} from '@src/types/onyx/Policy';
2628

2729
type CardReconciliationPageProps = WithPolicyConnectionsProps & PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.ACCOUNTING.CARD_RECONCILIATION>;
2830

31+
type FullySetUpCardSetting = {
32+
key: string;
33+
cardSetting: ExpensifyCardSettings;
34+
};
35+
2936
function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
3037
const styles = useThemeStyles();
3138
const {translate} = useLocalize();
3239

3340
const workspaceAccountID = policy?.workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID;
41+
const policyID = policy?.id;
42+
const allCardSettings = useExpensifyCardFeeds(policyID);
43+
44+
const fullySetUpCardSetting = useMemo(() => {
45+
const entries = Object.entries(allCardSettings ?? {});
46+
const initialValue: FullySetUpCardSetting = {
47+
key: '',
48+
cardSetting: {
49+
monthlySettlementDate: new Date(),
50+
isMonthlySettlementAllowed: false,
51+
paymentBankAccountID: CONST.DEFAULT_NUMBER_ID,
52+
},
53+
};
3454

35-
const [isContinuousReconciliationOn] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${workspaceAccountID}`, {canBeMissing: true});
36-
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, {canBeMissing: true});
37-
const [currentConnectionName] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${workspaceAccountID}`, {canBeMissing: true});
55+
return entries.reduce<FullySetUpCardSetting>((acc, [key, cardSetting]) => {
56+
if (cardSetting && isExpensifyCardFullySetUp(policy, cardSetting)) {
57+
return {
58+
key,
59+
cardSetting,
60+
};
61+
}
62+
return acc;
63+
}, initialValue);
64+
}, [allCardSettings, policy]);
65+
66+
const domainID = fullySetUpCardSetting.key.split('_').at(-1);
67+
const effectiveDomainID = Number(domainID ?? workspaceAccountID);
68+
69+
const [isContinuousReconciliationOn] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${effectiveDomainID}`, {canBeMissing: true});
70+
const [currentConnectionName] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${effectiveDomainID}`, {canBeMissing: true});
3871
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
3972

40-
const paymentBankAccountID = cardSettings?.paymentBankAccountID ?? CONST.DEFAULT_NUMBER_ID;
73+
const paymentBankAccountID = fullySetUpCardSetting.cardSetting?.paymentBankAccountID ?? CONST.DEFAULT_NUMBER_ID;
4174
const bankAccountTitle = bankAccountList?.[paymentBankAccountID]?.title ?? '';
4275

43-
const policyID = policy?.id;
4476
const {connection} = route.params;
4577
const connectionName = getConnectionNameFromRouteParam(connection) as ConnectionName;
4678
const autoSync = !!policy?.connections?.[connectionName]?.config?.autoSync?.enabled;
47-
const shouldShow = isExpensifyCardFullySetUp(policy, cardSettings);
79+
const shouldShow = !!fullySetUpCardSetting.cardSetting?.paymentBankAccountID;
4880

4981
const handleToggleContinuousReconciliation = (value: boolean) => {
50-
toggleContinuousReconciliation(workspaceAccountID, value, connectionName, currentConnectionName);
82+
toggleContinuousReconciliation(effectiveDomainID, value, connectionName, currentConnectionName);
5183
if (value) {
5284
Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_RECONCILIATION_ACCOUNT_SETTINGS.getRoute(policyID, connection));
5385
}

0 commit comments

Comments
 (0)