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/libs/API/parameters/PayTravelBillingSpendParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type PayTravelBillingSpendParams = {
domainAccountID: number;
policyID: string;
};

export default PayTravelBillingSpendParams;
4 changes: 2 additions & 2 deletions src/libs/actions/TravelBilling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ function retryTravelCardsProvisioning(policyID: string, workspaceAccountID: numb
* Optimistically sets the manual billing flag to true (payment queued state).
* The backend will send updates for private_expensifyCardManualBilling_ to clear it when billing runs.
*/
function payTravelBillingSpend(workspaceAccountID: number, travelSpend: number) {
function payTravelBillingSpend(policyID: string, workspaceAccountID: number, travelSpend: number) {
const cardSettingsKey = getTravelBillingCardSettingsKey(workspaceAccountID);

const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS>> = [
Expand Down Expand Up @@ -593,7 +593,7 @@ function payTravelBillingSpend(workspaceAccountID: number, travelSpend: number)
];

const params: PayTravelBillingSpendParams = {
domainAccountID: workspaceAccountID,
policyID,
};

return API.write(WRITE_COMMANDS.PAY_TRAVEL_BILLING_SPEND, params, {optimisticData, failureData});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import Text from '@components/Text';

import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useConfirmModal from '@hooks/useConfirmModal';
import useDefaultFundID from '@hooks/useDefaultFundID';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import useWorkspaceAccountID from '@hooks/useWorkspaceAccountID';

import {updateTravelBillingMonthlyLimit} from '@libs/actions/TravelBilling';
import {getCardSettings} from '@libs/CardUtils';
Expand All @@ -36,16 +36,16 @@ function WorkspaceTravelBillingMonthlyLimitPage({route}: WorkspaceTravelBillingM
const styles = useThemeStyles();
const {translate} = useLocalize();
const policyID = route.params?.policyID;
const workspaceAccountID = useWorkspaceAccountID(policyID);
const [cardSettings] = useOnyx(getTravelBillingCardSettingsKey(workspaceAccountID));
const defaultFundID = useDefaultFundID(policyID);
const [cardSettings] = useOnyx(getTravelBillingCardSettingsKey(defaultFundID));
const travelSettings = getCardSettings(cardSettings, CONST.TRAVEL.PROGRAM_TRAVEL_US);
const currentLimit = travelSettings?.monthlySpendLimitPerUser ?? 0;
const defaultValue = convertToFrontendAmountAsString(currentLimit, CONST.DEFAULT_CURRENCY_DECIMALS);
const {inputCallbackRef} = useAutoFocusInput();
const {showConfirmModal} = useConfirmModal();

const submitLimit = (newLimitInCents: number) => {
updateTravelBillingMonthlyLimit(workspaceAccountID, newLimitInCents, currentLimit);
updateTravelBillingMonthlyLimit(defaultFundID, newLimitInCents, currentLimit);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
};

Expand Down
29 changes: 14 additions & 15 deletions src/pages/workspace/travel/WorkspaceTravelBillingSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import Text from '@components/Text';

import useConfirmModal from '@hooks/useConfirmModal';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useDefaultFundID from '@hooks/useDefaultFundID';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePolicyFeatureWriteAccess from '@hooks/usePolicyFeatureWriteAccess';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWorkspaceAccountID from '@hooks/useWorkspaceAccountID';

import {
clearTravelBillingErrors,
Expand Down Expand Up @@ -78,7 +78,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
const {isLargeScreenWidth} = useResponsiveLayout();
const {translate} = useLocalize();
const {convertToDisplayString} = useCurrencyListActions();
const workspaceAccountID = useWorkspaceAccountID(policyID);
const defaultFundID = useDefaultFundID(policyID);

const {showConfirmModal, closeModal} = useConfirmModal();
const [isDisableConfirmModalVisible, setIsDisableConfirmModalVisible] = useState(false);
Expand All @@ -90,17 +90,16 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
// Ref to track if we should auto-resume the toggle flow after returning from TravelLegalNamePage
const shouldResumeToggleRef = useRef(false);

// For Travel Billing, we use a travel-specific card settings key
// Uses the same key pattern as Expensify Card: private_expensifyCardSettings_{workspaceAccountID}
const [cardSettings] = useOnyx(getTravelBillingCardSettingsKey(workspaceAccountID));
// Read the travel feed from the resolved fund so a shared domain feed shows feed-wide spend and limit.
const [cardSettings] = useOnyx(getTravelBillingCardSettingsKey(defaultFundID));
const [cardOnWaitlist] = useOnyx(`${ONYXKEYS.COLLECTION.NVP_EXPENSIFY_ON_CARD_WAITLIST}${policyID}`);
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const {canWrite: canWriteMoreFeatures, showReadOnlyModal} = usePolicyFeatureWriteAccess(policy, CONST.POLICY.POLICY_FEATURE.MORE_FEATURES);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS);
const [domainMemberData] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`);
const [domainMemberData] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${defaultFundID}`);

// Resolve travel-specific settings from the shared card settings key
const travelSettings = getCardSettings(cardSettings, CONST.TRAVEL.PROGRAM_TRAVEL_US);
Expand Down Expand Up @@ -198,7 +197,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
* can reconcile their travel spend.
*/
const handleViewOnSpend = () => {
const travelFeedID = getTravelBillingFeedID(workspaceAccountID);
const travelFeedID = getTravelBillingFeedID(defaultFundID);
const query = buildQueryStringFromFilterFormValues({
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
feed: [travelFeedID],
Expand All @@ -212,7 +211,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
*/
const handleConfirmPayBalance = () => {
setIsPayBalanceModalVisible(false);
payTravelBillingSpend(workspaceAccountID, travelSpend);
payTravelBillingSpend(policyID, defaultFundID, travelSpend);
};

const continueToggleFlow = () => {
Expand Down Expand Up @@ -243,7 +242,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection

// Has settlement account - enable Travel Billing and navigate to settlement page to show verification state
if (settlementAccount?.bankAccountID) {
configureTravelBillingForPolicy(policyID, workspaceAccountID, settlementAccount.bankAccountID);
configureTravelBillingForPolicy(policyID, defaultFundID, settlementAccount.bankAccountID);
}
Navigation.navigate(ROUTES.WORKSPACE_TRAVEL_SETTINGS_ACCOUNT.getRoute(policyID));
};
Expand Down Expand Up @@ -308,7 +307,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection

const handleConfirmDisable = () => {
setIsDisableConfirmModalVisible(false);
deactivateTravelBilling(policyID, workspaceAccountID);
deactivateTravelBilling(policyID, defaultFundID);
};

// Dismiss the "Update to USD" modal check if the currency changes to USD externally (e.g. from another device)
Expand Down Expand Up @@ -357,7 +356,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
<FormHelpMessageRowWithRetryButton
message={translate('workspace.moreFeatures.travel.travelInvoicing.travelInvoicingSection.subsections.provisioningError')}
size={CONST.BUTTON_SIZE.SMALL}
onRetry={() => retryTravelCardsProvisioning(policyID, workspaceAccountID, travelProvisioningErrors ?? {})}
onRetry={() => retryTravelCardsProvisioning(policyID, defaultFundID, travelProvisioningErrors ?? {})}
variant={CONST.BUTTON_VARIANT.DANGER}
shouldAlignButtonToMessage
/>
Expand Down Expand Up @@ -416,7 +415,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
<OfflineWithFeedback
errors={settlementAccountErrors}
pendingAction={settlementAccountPendingAction}
onClose={() => clearTravelBillingSettlementAccountErrors(workspaceAccountID, travelSettings?.previousPaymentBankAccountID ?? null)}
onClose={() => clearTravelBillingSettlementAccountErrors(defaultFundID, travelSettings?.previousPaymentBankAccountID ?? null)}
errorRowStyles={styles.mh2half}
errorRowTextStyles={styles.mr3}
>
Expand All @@ -435,7 +434,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
<OfflineWithFeedback
errors={settlementFrequencyErrors}
pendingAction={cardSettings?.pendingFields?.monthlySettlementDate}
onClose={() => clearTravelBillingSettlementFrequencyErrors(workspaceAccountID, travelSettings?.previousMonthlySettlementDate)}
onClose={() => clearTravelBillingSettlementFrequencyErrors(defaultFundID, travelSettings?.previousMonthlySettlementDate)}
errorRowStyles={styles.mh2half}
errorRowTextStyles={styles.mr3}
>
Expand All @@ -454,7 +453,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
<OfflineWithFeedback
errors={monthlyLimitErrors}
pendingAction={cardSettings?.pendingFields?.monthlySpendLimitPerUser}
onClose={() => clearTravelBillingMonthlyLimitErrors(workspaceAccountID)}
onClose={() => clearTravelBillingMonthlyLimitErrors(defaultFundID)}
errorRowStyles={styles.mh2half}
errorRowTextStyles={styles.mr3}
>
Expand Down Expand Up @@ -488,7 +487,7 @@ function WorkspaceTravelBillingSection({policyID}: WorkspaceTravelBillingSection
showLockIcon={!canWriteMoreFeatures || isOnWaitlist || hasOutstandingBalance}
pendingAction={togglePendingAction}
errors={toggleErrors}
onCloseError={() => clearTravelBillingErrors(workspaceAccountID)}
onCloseError={() => clearTravelBillingErrors(defaultFundID)}
subMenuItems={travelBillingSubMenuItems}
/>
</Section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import SettlementAccountSelector, {BankAccountListItemLeftElement} from '@compon
import type {BankAccountListItem} from '@components/SettlementAccountSelector';
import Text from '@components/Text';

import useDefaultFundID from '@hooks/useDefaultFundID';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import useWorkspaceAccountID from '@hooks/useWorkspaceAccountID';

import {configureTravelBillingForPolicy, setTravelBillingSettlementAccount} from '@libs/actions/TravelBilling';
import {getLastFourDigits} from '@libs/BankAccountUtils';
Expand All @@ -37,10 +37,10 @@ function WorkspaceTravelBillingSettlementAccountPage({route}: WorkspaceTravelBil
const styles = useThemeStyles();
const {translate} = useLocalize();
const policyID = route.params?.policyID;
const workspaceAccountID = useWorkspaceAccountID(policyID);
const defaultFundID = useDefaultFundID(policyID);

const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [cardSettings] = useOnyx(getTravelBillingCardSettingsKey(workspaceAccountID));
const [cardSettings] = useOnyx(getTravelBillingCardSettingsKey(defaultFundID));
const [cardOnWaitlist] = useOnyx(`${ONYXKEYS.COLLECTION.NVP_EXPENSIFY_ON_CARD_WAITLIST}${policyID}`);

const travelSettings = getCardSettings(cardSettings, CONST.TRAVEL.PROGRAM_TRAVEL_US);
Expand Down Expand Up @@ -89,12 +89,12 @@ function WorkspaceTravelBillingSettlementAccountPage({route}: WorkspaceTravelBil
}

if (!isTravelBillingEnabled) {
configureTravelBillingForPolicy(policyID, workspaceAccountID, value);
configureTravelBillingForPolicy(policyID, defaultFundID, value);
return;
}

const previousPaymentBankAccountID = travelSettings?.previousPaymentBankAccountID ?? travelSettings?.paymentBankAccountID;
setTravelBillingSettlementAccount(policyID, workspaceAccountID, value, previousPaymentBankAccountID);
setTravelBillingSettlementAccount(policyID, defaultFundID, value, previousPaymentBankAccountID);
Navigation.goBack();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelec
import type {ListItem} from '@components/SelectionList/types';
import Text from '@components/Text';

import useDefaultFundID from '@hooks/useDefaultFundID';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import useWorkspaceAccountID from '@hooks/useWorkspaceAccountID';

import {updateTravelBillingSettlementFrequency} from '@libs/actions/TravelBilling';
import {getCardSettings} from '@libs/CardUtils';
Expand Down Expand Up @@ -36,8 +36,8 @@ function WorkspaceTravelBillingSettlementFrequencyPage({route}: WorkspaceTravelB
const styles = useThemeStyles();
const {translate} = useLocalize();
const policyID = route.params?.policyID;
const workspaceAccountID = useWorkspaceAccountID(policyID);
const [cardSettings] = useOnyx(getTravelBillingCardSettingsKey(workspaceAccountID));
const defaultFundID = useDefaultFundID(policyID);
const [cardSettings] = useOnyx(getTravelBillingCardSettingsKey(defaultFundID));
const travelSettings = getCardSettings(cardSettings, CONST.TRAVEL.PROGRAM_TRAVEL_US);

const currentFrequency = getTravelSettlementFrequency(travelSettings);
Expand Down Expand Up @@ -68,7 +68,7 @@ function WorkspaceTravelBillingSettlementFrequencyPage({route}: WorkspaceTravelB
const monthlySettlementDate = travelSettings?.monthlySettlementDate;
const saveAndGoBack = () => {
if (selectedFrequency && (selectedFrequency !== currentFrequency || hasFrequencyError)) {
updateTravelBillingSettlementFrequency(workspaceAccountID, selectedFrequency, monthlySettlementDate ? new Date(monthlySettlementDate) : undefined);
updateTravelBillingSettlementFrequency(defaultFundID, selectedFrequency, monthlySettlementDate ? new Date(monthlySettlementDate) : undefined);
}
Navigation.goBack();
};
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/WorkspaceTravelBillingSectionTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe('WorkspaceTravelBillingSection', () => {
expect(payButton).toBeNull();
});

it('should show confirmation modal and call payTravelInvoicingSpend on confirm', async () => {
it('should show confirmation modal and call payTravelBillingSpend on confirm', async () => {
await act(async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, mockPolicy);
await Onyx.merge(cardSettingsKey, {
Expand Down Expand Up @@ -453,7 +453,7 @@ describe('WorkspaceTravelBillingSection', () => {
}
await waitForBatchedUpdatesWithAct();

expect(payTravelBillingSpend).toHaveBeenCalledWith(WORKSPACE_ACCOUNT_ID, 5000);
expect(payTravelBillingSpend).toHaveBeenCalledWith(POLICY_ID, WORKSPACE_ACCOUNT_ID, 5000);
});

it('should hide Pay Balance button and show queued message when settlement is pending', async () => {
Expand Down
Loading