Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ const ONYXKEYS = {
/** The value that indicates whether Continuous Reconciliation should be used on the domain */
EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION: 'expensifyCard_useContinuousReconciliation_',

/** Pending action for continuous reconciliation enabled status */
EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION_PENDING_ACTION: 'expensifyCard_useContinuousReconciliationPendingAction_',

/** The selected accounting integration bank account ID for card reconciliation */
EXPENSIFY_CARD_RECONCILIATION_BANK_ACCOUNT_ID: 'expensifyCard_bankAccount_',

Expand Down Expand Up @@ -1319,7 +1322,8 @@ 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]: OnyxTypes.CardContinuousReconciliation;
[ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION]: boolean;
[ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION_PENDING_ACTION]: OnyxTypes.CardContinuousReconciliation;
[ONYXKEYS.COLLECTION.EXPENSIFY_CARD_RECONCILIATION_BANK_ACCOUNT_ID]: string;
[ONYXKEYS.COLLECTION.LAST_SELECTED_FEED]: OnyxTypes.CompanyCardFeedWithDomainID;
[ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED]: OnyxTypes.FundID;
Expand Down
48 changes: 27 additions & 21 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,12 @@ function openCardDetailsPage(cardID: number) {
API.read(READ_COMMANDS.OPEN_CARD_DETAILS_PAGE, parameters);
}

type ContinuousReconciliationUpdate = OnyxUpdate<
| typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION
| typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION_PENDING_ACTION
| typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION
>;

function toggleContinuousReconciliation(workspaceAccountID: number, shouldUseContinuousReconciliation: boolean, connectionName: ConnectionName, oldConnectionName?: ConnectionName) {
const parameters = shouldUseContinuousReconciliation
? {
Expand All @@ -1511,16 +1517,16 @@ function toggleContinuousReconciliation(workspaceAccountID: number, shouldUseCon
shouldUseContinuousReconciliation,
};

const optimisticData: Array<
OnyxUpdate<typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION | typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION>
> = [
const optimisticData: ContinuousReconciliationUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${workspaceAccountID}`,
value: {
value: shouldUseContinuousReconciliation,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
value: shouldUseContinuousReconciliation,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION_PENDING_ACTION}${workspaceAccountID}`,
value: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -1529,16 +1535,16 @@ function toggleContinuousReconciliation(workspaceAccountID: number, shouldUseCon
},
];

const successData: Array<
OnyxUpdate<typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION | typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION>
> = [
const successData: ContinuousReconciliationUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${workspaceAccountID}`,
value: {
value: shouldUseContinuousReconciliation,
pendingAction: null,
},
value: shouldUseContinuousReconciliation,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION_PENDING_ACTION}${workspaceAccountID}`,
value: null,
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -1547,16 +1553,16 @@ function toggleContinuousReconciliation(workspaceAccountID: number, shouldUseCon
},
];

const failureData: Array<
OnyxUpdate<typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION | typeof ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION>
> = [
const failureData: ContinuousReconciliationUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${workspaceAccountID}`,
value: {
value: !shouldUseContinuousReconciliation,
pendingAction: null,
},
value: !shouldUseContinuousReconciliation,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION_PENDING_ACTION}${workspaceAccountID}`,
value: null,
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
const effectiveDomainID = Number(domainID ?? workspaceAccountID);

const [continuousReconciliation] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${effectiveDomainID}`);
const [continuousReconciliationPendingAction] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION_PENDING_ACTION}${effectiveDomainID}`);
const [currentConnectionName] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${effectiveDomainID}`);
const [reconciliationBankAccountID] = useOnyx(`${ONYXKEYS.COLLECTION.EXPENSIFY_CARD_RECONCILIATION_BANK_ACCOUNT_ID}${effectiveDomainID}`);

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

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

return (
<AccessOrNotFoundWrapper
Expand All @@ -153,10 +154,10 @@ function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
shouldPlaceSubtitleBelowSwitch
switchAccessibilityLabel={translate('workspace.accounting.continuousReconciliation')}
disabled={!autoSync}
isActive={!!continuousReconciliation?.value}
isActive={!!continuousReconciliation}
onToggle={handleToggleContinuousReconciliation}
wrapperStyle={styles.ph5}
pendingAction={continuousReconciliation?.pendingAction}
pendingAction={continuousReconciliationPendingAction}
/>
{!autoSync && (
<View style={[styles.renderHTML, styles.ph5, styles.mt2]}>
Expand All @@ -169,8 +170,8 @@ function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
/>
</View>
)}
<OfflineWithFeedback pendingAction={continuousReconciliation?.pendingAction}>
{!!paymentBankAccountID && !!continuousReconciliation?.value && (
<OfflineWithFeedback pendingAction={continuousReconciliationPendingAction}>
{!!paymentBankAccountID && !!continuousReconciliation && (
<MenuItemWithTopDescription
style={styles.mt5}
title={bankAccountTitle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP
}, [policyID]);

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

const eligibleBankAccountsOptions: BankAccountListItem[] = eligibleBankAccounts.map((bankAccount) => {
const bankName = (bankAccount.accountData?.addressName ?? '') as BankName;
Expand Down Expand Up @@ -124,7 +124,7 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP
return (
<>
<Text style={[styles.mh5, styles.mv4]}>{translate('workspace.expensifyCard.settlementAccountDescription')}</Text>
{!!continuousReconciliation?.value && !!connectionParam && hasActiveAccountingConnection && (
{!!continuousReconciliation && !!connectionParam && hasActiveAccountingConnection && (
<View style={[styles.renderHTML, styles.mh5, styles.mb6]}>
<RenderHTML
html={translate(
Expand Down
10 changes: 2 additions & 8 deletions src/types/onyx/CardContinuousReconciliation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
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;
};
/** Pending action of continuous reconciliation status for a card. */
type CardContinuousReconciliation = PendingAction | null;

export default CardContinuousReconciliation;
Loading