Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ function useConfirmationValidation({
if (!isScanRequestUtil(transaction) && !isTimeRequest && !isDistanceRequest && iouAmount === 0 && isP2P) {
return {errorKey: 'common.error.invalidAmount'};
}
if (isNewManualExpenseFlowEnabled && !transaction?.isAmountSet) {
// isAmountSet only applies to manual expenses — scan, per diem, distance, and time set amount programmatically.
if (isNewManualExpenseFlowEnabled && transaction?.iouRequestType === CONST.IOU.REQUEST_TYPE.MANUAL && !transaction?.isAmountSet) {
return {errorKey: 'common.error.fieldRequired'};
}
const merchantValue = iouMerchant ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ function AmountField({
const decimals = getCurrencyDecimals(effectiveCurrency);
// In the new manual expense flow the amount field starts empty (transaction.amount defaults to 0 before the user
// touches it). Once the user explicitly sets an amount – including 0 – isAmountSet becomes true and we show the
// real value. This avoids showing "$0.00" as a pre-filled default.
const transactionAmount = isNewManualExpenseFlowEnabled && !transaction?.isAmountSet ? '' : convertToFrontendAmountAsString(amount, decimals);
// real value. This avoids showing "$0.00" as a pre-filled default. Scan and other non-manual flows populate
// amount programmatically and never set isAmountSet.
const shouldShowEmptyAmount = isNewManualExpenseFlowEnabled && !transaction?.isAmountSet && transaction?.iouRequestType === CONST.IOU.REQUEST_TYPE.MANUAL;
const transactionAmount = shouldShowEmptyAmount ? '' : convertToFrontendAmountAsString(amount, decimals);
const allowNegative = shouldEnableNegative(report, policy, iouType, transaction?.participants);

// `autoFocus` on our TextInput only runs on mount. Closing and reopening the RHP often keeps the same mounted
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/hooks/useConfirmationValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,51 @@ describe('useConfirmationValidation', () => {
expect(result.current.validate()).toEqual({errorKey: null});
});

it('returns fieldRequired for manual expense when amount is not set in new manual expense flow', () => {
const {result} = renderHook(() =>
useConfirmationValidation({
...baseParams,
isNewManualExpenseFlowEnabled: true,
transaction: {transactionID: 'txn1', comment: {}, amount: 0, iouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL} as unknown as OnyxTypes.Transaction,
}),
);
expect(result.current.validate()).toEqual({errorKey: 'common.error.fieldRequired'});
});

it('does not return fieldRequired for scan expense when amount is not set in new manual expense flow', () => {
const {result} = renderHook(() =>
useConfirmationValidation({
...baseParams,
isNewManualExpenseFlowEnabled: true,
transaction: {
transactionID: 'txn1',
comment: {},
amount: 1000,
iouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
receipt: {source: 'https://example.com/receipt.jpg'},
} as unknown as OnyxTypes.Transaction,
}),
);
expect(result.current.validate()).toEqual({errorKey: null});
});

it('does not return fieldRequired for per diem expense when amount is not set in new manual expense flow', () => {
const {result} = renderHook(() =>
useConfirmationValidation({
...baseParams,
isNewManualExpenseFlowEnabled: true,
isPerDiemRequest: true,
transaction: {
transactionID: 'txn1',
amount: 5000,
iouRequestType: CONST.IOU.REQUEST_TYPE.PER_DIEM,
comment: {customUnit: {subRates: [{quantity: 1, rate: 5000}]}},
} as unknown as OnyxTypes.Transaction,
}),
);
expect(result.current.validate()).toEqual({errorKey: null});
});

it('returns null for PAY type without payment method', () => {
const {result} = renderHook(() => useConfirmationValidation({...baseParams, iouType: CONST.IOU.TYPE.PAY}));
expect(result.current.validate()).toBeNull();
Expand Down
Loading