Skip to content
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ const translations = {
canceled: 'Abgebrochen',
posted: 'Gepostet',
deleteReceipt: 'Beleg löschen',
findExpense: 'Ausgabe finden',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `hat eine Ausgabe gelöscht (${amount} für ${merchant})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `verschob eine Ausgabe${reportName ? `von ${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `verschob diese Ausgabe${reportName ? `to <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ const translations = {
canceled: 'Canceled',
posted: 'Posted',
deleteReceipt: 'Delete receipt',
findExpense: 'Find expense',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `deleted an expense (${amount} for ${merchant})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `moved an expense${reportName ? ` from ${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `moved this expense${reportName ? ` to <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,7 @@ const translations = {
pendingMatchWithCreditCardDescription: 'Recibo pendiente de adjuntar con la transacción de la tarjeta. Márcalo como efectivo para cancelar.',
markAsCash: 'Marcar como efectivo',
routePending: 'Ruta pendiente...',
findExpense: 'Buscar gasto',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `eliminó un gasto (${amount} para ${merchant})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `movió un gasto${reportName ? ` desde ${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `movió este gasto${reportName ? ` a <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ const translations = {
canceled: 'Annulé',
posted: 'Publié',
deleteReceipt: 'Supprimer le reçu',
findExpense: 'Trouver une dépense',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `supprimé une dépense (${amount} pour ${merchant})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `a déplacé une dépense${reportName ? `de ${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `déplacé cette dépense${reportName ? `à <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@ const translations = {
canceled: 'Annullato',
posted: 'Pubblicato',
deleteReceipt: 'Elimina ricevuta',
findExpense: 'Trova spesa',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `ha eliminato una spesa (${amount} per ${merchant})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `ha spostato una spesa${reportName ? `da ${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `spostato questa spesa${reportName ? `a <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ const translations = {
canceled: 'キャンセルされました',
posted: '投稿済み',
deleteReceipt: '領収書を削除',
findExpense: '経費を検索',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `経費を削除しました (${merchant}の${amount})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `費用${reportName ? `${reportName} から` : ''}を移動しました`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `この経費${reportName ? `to <a href="${reportUrl}">${reportName}</a>` : ''}を移動しました`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@ const translations = {
canceled: 'Geannuleerd',
posted: 'Geplaatst',
deleteReceipt: 'Verwijder bonnetje',
findExpense: 'Uitgave zoeken',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `verwijderde een uitgave (${amount} voor ${merchant})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `verplaatste een uitgave${reportName ? `van ${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `heeft deze uitgave verplaatst${reportName ? `naar <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ const translations = {
canceled: 'Anulowano',
posted: 'Opublikowano',
deleteReceipt: 'Usuń paragon',
findExpense: 'Znajdź wydatek',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `usunął wydatek (${amount} dla ${merchant})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `przeniósł wydatek${reportName ? `z ${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `przeniesiono ten wydatek${reportName ? `do <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ const translations = {
canceled: 'Cancelado',
posted: 'Publicado',
deleteReceipt: 'Excluir recibo',
findExpense: 'Encontrar despesa',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `excluiu uma despesa (${amount} para ${merchant})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `moveu uma despesa${reportName ? `de ${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `moveu esta despesa${reportName ? `para <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ const translations = {
canceled: '已取消',
posted: '已发布',
deleteReceipt: '删除收据',
findExpense: '查找费用',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `删除了一笔费用 (${merchant} 的 ${amount})`,
movedFromReport: ({reportName}: MovedFromReportParams) => `移动了一笔费用${reportName ? `来自${reportName}` : ''}`,
movedTransaction: ({reportUrl, reportName}: MovedTransactionParams) => `移动了此费用${reportName ? `至 <a href="${reportUrl}">${reportName}</a>` : ''}`,
Expand Down
60 changes: 54 additions & 6 deletions src/pages/AddUnreportedExpense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionListWithSections';
import type {ListItem, SectionListDataType, SelectionListHandle} from '@components/SelectionListWithSections/types';
import UnreportedExpensesSkeleton from '@components/Skeletons/UnreportedExpensesSkeleton';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import {fetchUnreportedExpenses} from '@libs/actions/UnreportedExpenses';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import type {AddUnreportedExpensesParamList} from '@libs/Navigation/types';
import Permissions from '@libs/Permissions';
import {canSubmitPerDiemExpenseFromWorkspace, getPerDiemCustomUnit} from '@libs/PolicyUtils';
import {isIOUReport} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {createUnreportedExpenseSections, isPerDiemRequest} from '@libs/TransactionUtils';
import tokenizedSearch from '@libs/tokenizedSearch';
import {createUnreportedExpenseSections, getAmount, getCurrency, getDescription, getMerchant, isPerDiemRequest} from '@libs/TransactionUtils';
import Navigation from '@navigation/Navigation';
import type {PlatformStackScreenProps} from '@navigation/PlatformStackNavigation/types';
import {convertBulkTrackedExpensesToIOU, startMoneyRequest} from '@userActions/IOU';
Expand All @@ -45,6 +48,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
const [offset, setOffset] = useState(0);
const {isOffline} = useNetwork();
const [selectedIds, setSelectedIds] = useState(new Set<string>());
const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');

const {reportID, backToReport} = route.params;
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
Expand Down Expand Up @@ -106,11 +110,50 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {

const styles = useThemeStyles();
const selectionListRef = useRef<SelectionListHandle>(null);
const sections: Array<SectionListDataType<Transaction & ListItem>> = useMemo(() => createUnreportedExpenseSections(transactions), [transactions]);
const filteredTransactions = useMemo(() => {
if (!debouncedSearchValue.trim()) {
return transactions;
}

return tokenizedSearch(transactions, debouncedSearchValue, (transaction) => {
const searchableFields: string[] = [];

const merchant = getMerchant(transaction);
if (merchant !== CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT) {
searchableFields.push(merchant);
}

const description = getDescription(transaction);
if (description.trim()) {
searchableFields.push(description);
}

const amount = getAmount(transaction);
const currency = getCurrency(transaction);
const formattedAmount = convertToDisplayString(amount, currency);
searchableFields.push(formattedAmount);
Comment on lines +119 to +134

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have added a condition to normalize the amount. Not doing so caused #72803


return searchableFields;
});
}, [transactions, debouncedSearchValue]);

const sections: Array<SectionListDataType<Transaction & ListItem>> = useMemo(() => createUnreportedExpenseSections(filteredTransactions), [filteredTransactions]);

const shouldShowTextInput = useMemo(() => {
return transactions.length >= CONST.SEARCH_ITEM_LIMIT;
}, [transactions.length]);

const headerMessage = useMemo(() => {
if (debouncedSearchValue.trim() && sections.at(0)?.data.length === 0) {
return translate('common.noResultsFound');
}
return '';
}, [debouncedSearchValue, sections, translate]);

const thereIsNoUnreportedTransaction = !((sections.at(0)?.data.length ?? 0) > 0);
const hasSearchTerm = debouncedSearchValue.trim().length > 0;
const isShowingEmptyState = !hasSearchTerm && transactions.length === 0;

if (thereIsNoUnreportedTransaction && isLoadingUnreportedTransactions) {
if (isShowingEmptyState && isLoadingUnreportedTransactions) {
return (
<ScreenWrapper
shouldEnableKeyboardAvoidingView={false}
Expand All @@ -129,7 +172,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
);
}

if (thereIsNoUnreportedTransaction) {
if (isShowingEmptyState) {
return (
<ScreenWrapper
shouldEnableKeyboardAvoidingView={false}
Expand Down Expand Up @@ -203,7 +246,12 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
return newIds;
});
}}
shouldShowTextInput={false}
isSelected={(item) => selectedIds.has(item.transactionID)}
shouldShowTextInput={shouldShowTextInput}
textInputValue={searchValue}
textInputLabel={shouldShowTextInput ? translate('iou.findExpense') : undefined}
onChangeText={setSearchValue}
headerMessage={headerMessage}
canSelectMultiple
sections={sections}
ListItem={UnreportedExpenseListItem}
Expand Down
6 changes: 2 additions & 4 deletions src/pages/UnreportedExpenseListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useRef, useState} from 'react';
import React, {useRef} from 'react';
import type {View} from 'react-native';
import {getButtonRole} from '@components/Button/utils';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand Down Expand Up @@ -31,7 +31,7 @@ function UnreportedExpenseListItem<TItem extends ListItem>({
}: UnreportedExpenseListItemProps<TItem>) {
const styles = useThemeStyles();
const transactionItem = item as unknown as TransactionListItemType;
const [isSelected, setIsSelected] = useState<boolean>(false);
const isSelected = !!item.isSelected;
const theme = useTheme();

const pressableStyle = [styles.transactionListItemStyle, isSelected && styles.activeComponentBG];
Expand All @@ -55,7 +55,6 @@ function UnreportedExpenseListItem<TItem extends ListItem>({
ref={pressableRef}
onPress={() => {
onSelectRow(item);
setIsSelected((val) => !val);
}}
disabled={isItemDisabled}
accessibilityLabel={item.text ?? ''}
Expand All @@ -80,7 +79,6 @@ function UnreportedExpenseListItem<TItem extends ListItem>({
taxAmountColumnSize={CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL}
onCheckboxPress={() => {
onSelectRow(item);
setIsSelected((val) => !val);
}}
isDisabled={isItemDisabled}
shouldShowCheckbox
Expand Down
Loading
Loading