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
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6714,6 +6714,7 @@ const CONST = {
CARD: 'card',
DISTANCE: 'distance',
PER_DIEM: 'perDiem',
TIME: 'time',
},
WITHDRAWAL_TYPE: {
EXPENSIFY_CARD: 'expensify-card',
Expand Down
13 changes: 9 additions & 4 deletions src/components/TransactionItemRow/DataCells/TypeCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import useOnyx from '@hooks/useOnyx';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {getTransactionType, isExpensifyCardTransaction, isPending} from '@libs/TransactionUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type IconAsset from '@src/types/utils/IconAsset';
import type TransactionDataCellProps from './TransactionDataCellProps';

const getTypeIcon = (icons: Record<'Car' | 'CreditCard' | 'Cash', IconAsset>, type?: string) => {
const getTypeIcon = (icons: Record<'Car' | 'CreditCard' | 'Cash' | 'Clock', IconAsset>, type?: string) => {
switch (type) {
case CONST.SEARCH.TRANSACTION_TYPE.CARD:
return icons.CreditCard;
case CONST.SEARCH.TRANSACTION_TYPE.DISTANCE:
return icons.Car;
case CONST.SEARCH.TRANSACTION_TYPE.TIME:
return icons.Clock;
case CONST.SEARCH.TRANSACTION_TYPE.CASH:
default:
return icons.Cash;
Expand All @@ -31,6 +34,8 @@ const getTypeText = (type?: string): TranslationPaths => {
return 'common.distance';
case CONST.SEARCH.TRANSACTION_TYPE.CARD:
return 'iou.card';
case CONST.SEARCH.TRANSACTION_TYPE.TIME:
return 'iou.time';
case CONST.SEARCH.TRANSACTION_TYPE.CASH:
default:
return 'iou.cash';
Expand All @@ -41,7 +46,7 @@ function TypeCell({transactionItem, shouldUseNarrowLayout, shouldShowTooltip}: T
const {translate} = useLocalize();
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
const theme = useTheme();
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Car', 'CreditCard', 'CreditCardHourglass', 'Cash']);
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Car', 'CreditCard', 'CreditCardHourglass', 'Cash', 'Clock']);
const type = getTransactionType(transactionItem, cardList);
const isPendingExpensifyCardTransaction = isExpensifyCardTransaction(transactionItem) && isPending(transactionItem);
const typeIcon = isPendingExpensifyCardTransaction ? expensifyIcons.CreditCardHourglass : getTypeIcon(expensifyIcons, type);
Expand All @@ -58,8 +63,8 @@ function TypeCell({transactionItem, shouldUseNarrowLayout, shouldShowTooltip}: T
<Icon
src={typeIcon}
fill={theme.icon}
height={20}
width={20}
height={variables.iconSizeNormal}
width={variables.iconSizeNormal}
/>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,8 @@ function getExpenseTypeTranslationKey(expenseType: ValueOf<typeof CONST.SEARCH.T
return 'iou.cash';
case CONST.SEARCH.TRANSACTION_TYPE.PER_DIEM:
return 'common.perDiem';
case CONST.SEARCH.TRANSACTION_TYPE.TIME:
return 'iou.time';
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
};

let deprecatedAllReports: OnyxCollection<Report> = {};
Onyx.connect({

Check warning on line 127 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -133,7 +133,7 @@
});

let deprecatedAllTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 136 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (deprecatedAllTransactionViolations = value),
Expand Down Expand Up @@ -210,6 +210,10 @@
return type === CONST.TRANSACTION.TYPE.CUSTOM_UNIT && customUnitName === CONST.CUSTOM_UNITS.NAME_PER_DIEM_INTERNATIONAL;
}

function isTimeRequest(transaction: OnyxEntry<Transaction>): boolean {
return transaction?.comment?.type === CONST.TRANSACTION.TYPE.TIME;
}

function isCorporateCardTransaction(transaction: OnyxEntry<Transaction>): boolean {
return isManagedCardTransaction(transaction) && transaction?.comment?.liabilityType === CONST.TRANSACTION.LIABILITY_TYPE.RESTRICT;
}
Expand Down Expand Up @@ -273,6 +277,10 @@
return CONST.SEARCH.TRANSACTION_TYPE.PER_DIEM;
}

if (isTimeRequest(transaction)) {
return CONST.SEARCH.TRANSACTION_TYPE.TIME;
}

const cardID = transaction?.cardID;
if (cardID && cardList?.[cardID]?.cardName === CONST.COMPANY_CARDS.CARD_NAME.CASH) {
return CONST.SEARCH.TRANSACTION_TYPE.CASH;
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/TransactionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,21 @@ describe('TransactionUtils', () => {

expect(TransactionUtils.getTransactionType(transaction)).toBe(CONST.SEARCH.TRANSACTION_TYPE.CASH);
});

it('returns time when the transaction has a comment with time type', () => {
const transaction = generateTransaction({
comment: {
type: 'time',
units: {
count: 2,
unit: 'h',
rate: 50,
},
},
});

expect(TransactionUtils.getTransactionType(transaction)).toBe(CONST.SEARCH.TRANSACTION_TYPE.TIME);
});
});

describe('calculateTaxAmount', () => {
Expand Down
Loading