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
2 changes: 1 addition & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_MANUAL_BILLING]: boolean;
[ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST]: OnyxTypes.WorkspaceCardsList;
[ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION]: OnyxTypes.PolicyConnectionName;
[ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION]: boolean;
[ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION]: OnyxTypes.CardContinuousReconciliation;
[ONYXKEYS.COLLECTION.LAST_SELECTED_FEED]: OnyxTypes.CompanyCardFeedWithDomainID;
[ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED]: OnyxTypes.FundID;
[ONYXKEYS.COLLECTION.NVP_EXPENSIFY_ON_CARD_WAITLIST]: OnyxTypes.CardOnWaitlist;
Expand Down
15 changes: 12 additions & 3 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,10 @@ function toggleContinuousReconciliation(workspaceAccountID: number, shouldUseCon
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${workspaceAccountID}`,
value: shouldUseContinuousReconciliation,
value: {
Comment thread
daledah marked this conversation as resolved.
value: shouldUseContinuousReconciliation,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -922,7 +925,10 @@ function toggleContinuousReconciliation(workspaceAccountID: number, shouldUseCon
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${workspaceAccountID}`,
value: shouldUseContinuousReconciliation,
value: {
value: shouldUseContinuousReconciliation,
pendingAction: null,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -935,7 +941,10 @@ function toggleContinuousReconciliation(workspaceAccountID: number, shouldUseCon
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${workspaceAccountID}`,
value: !shouldUseContinuousReconciliation,
value: {
value: !shouldUseContinuousReconciliation,
pendingAction: null,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
const domainID = fullySetUpCardSetting.key.split('_').at(-1);
const effectiveDomainID = Number(domainID ?? workspaceAccountID);

const [isContinuousReconciliationOn] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${effectiveDomainID}`, {canBeMissing: true});
const [continuousReconciliation] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${effectiveDomainID}`, {canBeMissing: true});
const [currentConnectionName] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${effectiveDomainID}`, {canBeMissing: true});
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});

Expand Down Expand Up @@ -117,11 +117,11 @@ function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
}, [policyID]);

useEffect(() => {
if (isContinuousReconciliationOn !== undefined) {
if (continuousReconciliation?.value !== undefined) {
return;
}
fetchPolicyAccountingData();
}, [isContinuousReconciliationOn, fetchPolicyAccountingData]);
}, [continuousReconciliation?.value, fetchPolicyAccountingData]);

return (
<AccessOrNotFoundWrapper
Expand All @@ -146,9 +146,10 @@ function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
shouldPlaceSubtitleBelowSwitch
switchAccessibilityLabel={translate('workspace.accounting.continuousReconciliation')}
disabled={!autoSync}
isActive={!!isContinuousReconciliationOn}
isActive={!!continuousReconciliation?.value}
onToggle={handleToggleContinuousReconciliation}
wrapperStyle={styles.ph5}
pendingAction={continuousReconciliation?.pendingAction}
/>
{!autoSync && (
<View style={[styles.renderHTML, styles.ph5, styles.mt2]}>
Expand All @@ -160,7 +161,7 @@ function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
/>
</View>
)}
{!!paymentBankAccountID && !!isContinuousReconciliationOn && (
{!!paymentBankAccountID && !!continuousReconciliation?.value && (
<MenuItemWithTopDescription
style={styles.mt5}
title={bankAccountTitle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: true});
const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${defaultFundID}`, {canBeMissing: true});
const [isUsingContinuousReconciliation] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${defaultFundID}`, {canBeMissing: true});
const [continuousReconciliation] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${defaultFundID}`, {canBeMissing: true});
const [reconciliationConnection] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${defaultFundID}`, {canBeMissing: true});
const isUkEuCurrencySupported = useExpensifyCardUkEuSupported(policyID);

Expand All @@ -85,11 +85,11 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP
}, [policyID]);

useEffect(() => {
if (!cardSettings || !hasActiveAccountingConnection || isUsingContinuousReconciliation !== undefined || reconciliationConnection !== undefined) {
if (!cardSettings || !hasActiveAccountingConnection || continuousReconciliation?.value !== undefined || reconciliationConnection !== undefined) {
return;
}
fetchPolicyAccountingData();
}, [cardSettings, hasActiveAccountingConnection, isUsingContinuousReconciliation, reconciliationConnection, fetchPolicyAccountingData]);
}, [cardSettings, hasActiveAccountingConnection, continuousReconciliation?.value, reconciliationConnection, fetchPolicyAccountingData]);

const eligibleBankAccountsOptions: BankAccountListItem[] = eligibleBankAccounts.map((bankAccount) => {
const bankName = (bankAccount.accountData?.addressName ?? '') as BankName;
Expand Down Expand Up @@ -129,7 +129,7 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP
return (
<>
<Text style={[styles.mh5, styles.mv4]}>{translate('workspace.expensifyCard.settlementAccountDescription')}</Text>
{!!isUsingContinuousReconciliation && !!connectionParam && hasActiveAccountingConnection && (
{!!continuousReconciliation?.value && !!connectionParam && hasActiveAccountingConnection && (
<View style={[styles.renderHTML, styles.mh5, styles.mb6]}>
<RenderHTML
html={translate('workspace.expensifyCard.settlementAccountInfo', {
Expand All @@ -141,7 +141,7 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP
)}
</>
);
}, [isUsingContinuousReconciliation, reconciliationConnection, environmentURL, paymentBankAccountNumber, translate, hasActiveAccountingConnection, policyID, styles]);
}, [continuousReconciliation?.value, reconciliationConnection, environmentURL, paymentBankAccountNumber, translate, hasActiveAccountingConnection, policyID, styles]);

return (
<AccessOrNotFoundWrapper
Expand Down
5 changes: 4 additions & 1 deletion src/pages/workspace/withPolicyConnections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ type WithPolicyConnectionsProps = WithPolicyProps & {
function withPolicyConnections<TProps extends WithPolicyConnectionsProps>(WrappedComponent: ComponentType<TProps>, shouldBlockView = true) {
function WithPolicyConnections(props: TProps) {
const {isOffline} = useNetwork();
const [hasConnectionsDataBeenFetched, hasConnectionsDataBeenFetchedResult] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${props.policy?.id ?? '-1'}`);
const [hasConnectionsDataBeenFetched, hasConnectionsDataBeenFetchedResult] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${props.policy?.id}`, {
canBeMissing: true,
});
const isOnyxDataLoading = isLoadingOnyxValue(hasConnectionsDataBeenFetchedResult);
const isConnectionDataFetchNeeded =
!isOnyxDataLoading && !isOffline && !!props.policy && (!!props.policy.areConnectionsEnabled || !isEmptyObject(props.policy.connections)) && !hasConnectionsDataBeenFetched;
Expand All @@ -49,6 +51,7 @@ function withPolicyConnections<TProps extends WithPolicyConnectionsProps>(Wrappe
// When the accounting feature is not enabled, or if the connections data already exists,
// there is no need to fetch the connections data.
if (!isConnectionDataFetchNeeded || !props.policy?.id) {
setIsFetchingData(false);
Comment thread
daledah marked this conversation as resolved.
return;
}
setIsFetchingData(true);
Expand Down
12 changes: 12 additions & 0 deletions src/types/onyx/CardContinuousReconciliation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type {PendingAction} from './OnyxCommon';

/** Represents the continuous reconciliation status for a card. */
type CardContinuousReconciliation = {
/** The boolean value indicating if continuous reconciliation is enabled */
value: boolean;

/** Pending action for optimistic UI updates */
pendingAction?: PendingAction;
};

export default CardContinuousReconciliation;
2 changes: 2 additions & 0 deletions src/types/onyx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type BlockedFromConcierge from './BlockedFromConcierge';
import type CancellationDetails from './CancellationDetails';
import type Card from './Card';
import type {CardList, IssueNewCard, ProvisioningCardData, WorkspaceCardsList} from './Card';
import type CardContinuousReconciliation from './CardContinuousReconciliation';
import type CardFeeds from './CardFeeds';
import type {AddNewCompanyCardFeed, CompanyCardFeed, CompanyCardFeedWithDomainID, DomainSettings, FundID} from './CardFeeds';
import type CardOnWaitlist from './CardOnWaitlist';
Expand Down Expand Up @@ -167,6 +168,7 @@ export type {
IssueNewCard,
AddNewCompanyCardFeed,
CompanyCardFeed,
Comment thread
daledah marked this conversation as resolved.
CardContinuousReconciliation,
CompanyCardFeedWithDomainID,
LastExportMethod,
Locale,
Expand Down
Loading