Skip to content

Commit 2c2e733

Browse files
authored
Merge pull request #89427 from shubham1206agra/refactor-convertToDisplayString-10
2 parents 31b94e6 + 1d53688 commit 2c2e733

13 files changed

Lines changed: 114 additions & 11 deletions

File tree

src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ function TransactionPreviewContent({
156156
currentUserEmail,
157157
currentUserAccountID,
158158
originalTransaction,
159+
convertToDisplayString,
159160
}),
160-
[transactionPreviewCommonArguments, shouldShowRBR, violationMessage, reportActions, currentUserEmail, currentUserAccountID, originalTransaction],
161+
[transactionPreviewCommonArguments, shouldShowRBR, violationMessage, reportActions, currentUserEmail, currentUserAccountID, originalTransaction, convertToDisplayString],
161162
);
162163
const getTranslatedText = (item: TranslationPathOrText) => (item.translationPath ? translate(item.translationPath) : (item.text ?? ''));
163164

src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {SearchGroupBy} from '@components/Search/types';
1414
import type {ListItem} from '@components/SelectionList/types';
1515
import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs';
1616
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
17+
import {useCurrencyListActions} from '@hooks/useCurrencyList';
1718
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1819
import useLocalize from '@hooks/useLocalize';
1920
import useOnyx from '@hooks/useOnyx';
@@ -94,6 +95,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
9495
const {isLargeScreenWidth} = useResponsiveLayout();
9596
const currentUserDetails = useCurrentUserPersonalDetails();
9697
const isScreenFocused = useIsFocused();
98+
const {convertToDisplayString} = useCurrencyListActions();
9799

98100
const oneTransactionItem = groupItem.isOneTransactionReport ? groupItem.transactions.at(0) : undefined;
99101
const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(oneTransactionItem?.reportID)}`);
@@ -141,6 +143,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
141143
allReportMetadata,
142144
cardFeeds,
143145
conciergeReportID,
146+
convertToDisplayString,
144147
}) as [TransactionListItemType[], number, boolean];
145148
transactions = sectionData.map((transactionItem) => ({
146149
...transactionItem,

src/components/Search/SearchStaticList.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeed
2222
import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
2323
import StatusBadge from '@components/StatusBadge';
2424
import TransactionItemRow from '@components/TransactionItemRow';
25+
import {useCurrencyListActions} from '@hooks/useCurrencyList';
2526
import useLocalize from '@hooks/useLocalize';
2627
import useStyleUtils from '@hooks/useStyleUtils';
2728
import useTheme from '@hooks/useTheme';
@@ -69,6 +70,7 @@ function SearchStaticList({
6970
const theme = useTheme();
7071
const StyleUtils = useStyleUtils();
7172
const {translate, localeCompare, formatPhoneNumber} = useLocalize();
73+
const {convertToDisplayString} = useCurrencyListActions();
7274
const session = useSession();
7375
const accountID = session?.accountID ?? CONST.DEFAULT_NUMBER_ID;
7476
const email = session?.email;
@@ -96,6 +98,7 @@ function SearchStaticList({
9698
bankAccountList: undefined,
9799
allReportMetadata: undefined,
98100
conciergeReportID: undefined,
101+
convertToDisplayString,
99102
});
100103

101104
return getSortedSections(type, status, filteredData, localeCompare, translate, sortBy, sortOrder, validGroupBy)

src/components/Search/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
1212
import {useWideRHPActions} from '@components/WideRHPContextProvider';
1313
import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs';
1414
import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet';
15+
import {useCurrencyListActions} from '@hooks/useCurrencyList';
1516
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1617
import useLocalize from '@hooks/useLocalize';
1718
import useMultipleSnapshots from '@hooks/useMultipleSnapshots';
@@ -352,6 +353,8 @@ function Search({
352353
selector: savedSearchSelector,
353354
});
354355

356+
const {convertToDisplayString} = useCurrencyListActions();
357+
355358
const validGroupBy = getValidGroupBy(groupBy);
356359
const prevValidGroupBy = usePrevious(validGroupBy);
357360
const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtil(searchResults, validGroupBy);
@@ -544,6 +547,7 @@ function Search({
544547
conciergeReportID,
545548
onyxPersonalDetailsList,
546549
policyForMovingExpenses,
550+
convertToDisplayString,
547551
});
548552
return {
549553
baseFilteredData: filteredData1,
@@ -576,6 +580,7 @@ function Search({
576580
conciergeReportID,
577581
onyxPersonalDetailsList,
578582
policyForMovingExpenses,
583+
convertToDisplayString,
579584
]);
580585

581586
// For group-by views, each grouped item has a transactionsQueryJSON with a hash pointing to a separate snapshot
@@ -612,6 +617,7 @@ function Search({
612617
cardFeeds,
613618
allReportMetadata,
614619
conciergeReportID,
620+
convertToDisplayString,
615621
});
616622
return {
617623
...item,
@@ -635,6 +641,7 @@ function Search({
635641
bankAccountList,
636642
allReportMetadata,
637643
conciergeReportID,
644+
convertToDisplayString,
638645
]);
639646

640647
const hasLoadedAllTransactions = useMemo(() => {

src/hooks/useSearchBulkActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
287287
'Workflows',
288288
]);
289289

290-
const {getCurrencyDecimals} = useCurrencyListActions();
290+
const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions();
291291

292292
const selectedTransactionReportIDs = useMemo(
293293
() => [
@@ -315,7 +315,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
315315
[selectedTransactions],
316316
);
317317
const selectedBulkCurrency = selectedReports.at(0)?.currency ?? Object.values(selectedTransactions).at(0)?.currency;
318-
const totalFormattedAmount = getTotalFormattedAmount(selectedReports, selectedTransactions, selectedBulkCurrency);
318+
const totalFormattedAmount = getTotalFormattedAmount(convertToDisplayString, selectedReports, selectedTransactions, selectedBulkCurrency);
319319

320320
const onlyShowPayElsewhere = useMemo(() => {
321321
const firstPolicyID = selectedPolicyIDs.at(0);

src/hooks/useSearchSections.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {Report} from '@src/types/onyx';
77
import type LastSearchParams from '@src/types/onyx/ReportNavigation';
88
import useActionLoadingReportIDs from './useActionLoadingReportIDs';
99
import useArchivedReportsIdSet from './useArchivedReportsIdSet';
10+
import {useCurrencyListActions} from './useCurrencyList';
1011
import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
1112
import useLocalize from './useLocalize';
1213
import useOnyx from './useOnyx';
@@ -39,6 +40,7 @@ function useSearchSections(): UseSearchSectionsResult {
3940
const currentUserDetails = useCurrentUserPersonalDetails();
4041
const {localeCompare, formatPhoneNumber, translate} = useLocalize();
4142
const isActionLoadingSet = useActionLoadingReportIDs();
43+
const {convertToDisplayString} = useCurrencyListActions();
4244

4345
const [exportReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {
4446
selector: selectFilteredReportActions,
@@ -76,6 +78,7 @@ function useSearchSections(): UseSearchSectionsResult {
7678
cardFeeds,
7779
allReportMetadata,
7880
conciergeReportID,
81+
convertToDisplayString,
7982
});
8083
results = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
8184
}

src/libs/SearchUIUtils.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ import type {CardFeedForDisplay} from './CardFeedUtils';
9999
import {getCardFeedsForDisplay} from './CardFeedUtils';
100100
import {getCardDescriptionForSearchTable, getFeedNameForDisplay} from './CardUtils';
101101
import {getDecodedCategoryName} from './CategoryUtils';
102-
import {convertToDisplayString, convertToDisplayStringWithoutCurrency} from './CurrencyUtils';
102+
import {convertToDisplayStringWithoutCurrency} from './CurrencyUtils';
103103
import DateUtils from './DateUtils';
104104
import interceptAnonymousUser from './interceptAnonymousUser';
105105
import isSearchTopmostFullScreenRoute from './Navigation/helpers/isSearchTopmostFullScreenRoute';
@@ -239,6 +239,7 @@ type GetReportSectionsParams = {
239239
currentUserEmail: string;
240240
translate: LocalizedTranslate;
241241
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
242+
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'];
242243
isActionLoadingSet: ReadonlySet<string> | undefined;
243244
isOffline: boolean | undefined;
244245
allTransactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
@@ -571,6 +572,7 @@ type GetSectionsParams = {
571572
translate: LocalizedTranslate;
572573
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
573574
bankAccountList: OnyxEntry<OnyxTypes.BankAccountList>;
575+
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'];
574576
groupBy?: SearchGroupBy;
575577
reportActions?: Record<string, OnyxTypes.ReportAction[]>;
576578
currentSearch?: SearchKey;
@@ -1566,7 +1568,12 @@ function shouldShowYear(
15661568
* @private
15671569
* Generates a display name for IOU reports considering the personal details of the payer and the transaction details.
15681570
*/
1569-
function getIOUReportName(translate: LocalizedTranslate, data: OnyxTypes.SearchResults['data'], reportItem: TransactionReportGroupListItemType) {
1571+
function getIOUReportName(
1572+
translate: LocalizedTranslate,
1573+
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'],
1574+
data: OnyxTypes.SearchResults['data'],
1575+
reportItem: TransactionReportGroupListItemType,
1576+
) {
15701577
const payerPersonalDetails = reportItem.managerID ? data.personalDetailsList?.[reportItem.managerID] : emptyPersonalDetails;
15711578
// For cases where the data personal detail for manager ID do not exist in search data.personalDetailsList
15721579
// we fallback to the display name of the personal detail data from onyx.
@@ -2607,6 +2614,7 @@ function getReportSections({
26072614
allReportMetadata,
26082615
queryJSON,
26092616
onyxPersonalDetailsList,
2617+
convertToDisplayString,
26102618
}: GetReportSectionsParams): [TransactionGroupListItemType[], number, boolean] {
26112619
const {
26122620
transactionKeys,
@@ -2741,7 +2749,7 @@ function getReportSections({
27412749
};
27422750

27432751
if (isIOUReport) {
2744-
reportIDToTransactions[reportKey].reportName = getIOUReportName(translate, data, reportIDToTransactions[reportKey]);
2752+
reportIDToTransactions[reportKey].reportName = getIOUReportName(translate, convertToDisplayString, data, reportIDToTransactions[reportKey]);
27452753
}
27462754
}
27472755
} else if (isTransactionEntry(key)) {
@@ -3392,6 +3400,7 @@ function getSections({
33923400
conciergeReportID,
33933401
onyxPersonalDetailsList,
33943402
policyForMovingExpenses,
3403+
convertToDisplayString,
33953404
}: GetSectionsParams): GetSectionsResult {
33963405
if (type === CONST.SEARCH.DATA_TYPES.CHAT) {
33973406
return [...getReportActionsSections(data, visibleReportActionsData), false];
@@ -3417,6 +3426,7 @@ function getSections({
34173426
allReportMetadata,
34183427
queryJSON,
34193428
onyxPersonalDetailsList,
3429+
convertToDisplayString,
34203430
});
34213431
}
34223432

src/libs/TransactionPreviewUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import truncate from 'lodash/truncate';
22
import type {OnyxEntry} from 'react-native-onyx';
3+
import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList';
34
import CONST from '@src/CONST';
45
import type {TranslationPaths} from '@src/languages/types';
56
import ROUTES from '@src/ROUTES';
67
import type * as OnyxTypes from '@src/types/onyx';
78
import {isEmptyObject} from '@src/types/utils/EmptyObject';
89
import {setReviewDuplicatesKey} from './actions/Transaction';
910
import {isCategoryMissing} from './CategoryUtils';
10-
import {convertToDisplayString} from './CurrencyUtils';
1111
import DateUtils from './DateUtils';
1212
import {hasDynamicExternalWorkflow} from './PolicyUtils';
1313
import {getMostRecentActiveDEWSubmitFailedAction, getOriginalMessage, isDynamicExternalWorkflowSubmitFailedAction, isMessageDeleted, isMoneyRequestAction} from './ReportActionsUtils';
@@ -211,6 +211,7 @@ function getTransactionPreviewTextAndTranslationPaths({
211211
currentUserEmail,
212212
currentUserAccountID,
213213
originalTransaction,
214+
convertToDisplayString,
214215
}: {
215216
iouReport: OnyxEntry<OnyxTypes.Report>;
216217
policy: OnyxEntry<OnyxTypes.Policy>;
@@ -225,6 +226,7 @@ function getTransactionPreviewTextAndTranslationPaths({
225226
currentUserEmail: string;
226227
currentUserAccountID: number;
227228
originalTransaction?: OnyxEntry<OnyxTypes.Transaction>;
229+
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'];
228230
}) {
229231
const isFetchingWaypoints = isFetchingWaypointsFromServer(transaction);
230232
const isTransactionOnHold = isOnHold(transaction);

src/libs/actions/Search.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {LocalizedTranslate} from '@components/LocaleContextProvider';
88
import type {PopoverMenuItem} from '@components/PopoverMenu';
99
import type {TransactionListItemType, TransactionReportGroupListItemType} from '@components/Search/SearchList/ListItem/types';
1010
import type {BankAccountMenuItem, BulkPaySelectionData, PaymentData, SearchQueryJSON, SelectedReports, SelectedTransactionInfo, SelectedTransactions} from '@components/Search/types';
11+
import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList';
1112
import * as API from '@libs/API';
1213
import {waitForWrites} from '@libs/API';
1314
import type {
@@ -20,7 +21,6 @@ import type {
2021
} from '@libs/API/parameters';
2122
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
2223
import {getCommandURL} from '@libs/ApiUtils';
23-
import {convertToDisplayString} from '@libs/CurrencyUtils';
2424
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
2525
import fileDownload from '@libs/fileDownload';
2626
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
@@ -1458,7 +1458,12 @@ function getPayMoneyOnSearchInvoiceParams(policyID: string | undefined, payAsBus
14581458
/**
14591459
* Return the total amount of selected transactions/reports.
14601460
*/
1461-
function getTotalFormattedAmount(selectedReports: SelectedReports[], selectedTransactions: SelectedTransactions, currency?: string): string {
1461+
function getTotalFormattedAmount(
1462+
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'],
1463+
selectedReports: SelectedReports[],
1464+
selectedTransactions: SelectedTransactions,
1465+
currency?: string,
1466+
): string {
14621467
const transactionKeys = Object.keys(selectedTransactions ?? {});
14631468
const totalAmount =
14641469
selectedReports.length > 0

src/pages/home/SpendOverTimeSection/useSpendOverTimeData.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {useEffect, useEffectEvent} from 'react';
33
import type {OnyxEntry} from 'react-native-onyx';
44
import type {ValueOf} from 'type-fest';
55
import type {GroupedItem, SearchQueryJSON} from '@components/Search/types';
6+
import {useCurrencyListActions} from '@hooks/useCurrencyList';
67
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
78
import useLocalize from '@hooks/useLocalize';
89
import useNetwork from '@hooks/useNetwork';
@@ -52,6 +53,7 @@ function useSpendOverTimeData() {
5253
const {groupBy, view} = queryJSON ?? {};
5354

5455
const {translate, localeCompare, formatPhoneNumber} = useLocalize();
56+
const {convertToDisplayString} = useCurrencyListActions();
5557
const {accountID, login} = useCurrentUserPersonalDetails();
5658
const [searchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${queryJSON?.hash}`);
5759
const isSearchLoading = !!searchResults?.search?.isLoading;
@@ -98,6 +100,7 @@ function useSpendOverTimeData() {
98100
bankAccountList: undefined,
99101
allReportMetadata: undefined,
100102
conciergeReportID: undefined,
103+
convertToDisplayString,
101104
})[0],
102105
localeCompare,
103106
translate,

0 commit comments

Comments
 (0)