Skip to content

Commit f6208d1

Browse files
committed
handle unreported attendees
1 parent 93f8ea0 commit f6208d1

9 files changed

Lines changed: 49 additions & 9 deletions

File tree

src/components/Search/SearchList/BaseSearchList/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function BaseSearchList({
3333
newTransactions,
3434
selectedTransactions,
3535
customCardNames,
36+
policyForMovingExpenses,
3637
}: BaseSearchListProps) {
3738
const hasKeyBeenPressed = useRef(false);
3839
const isFocused = useIsFocused();
@@ -106,8 +107,8 @@ function BaseSearchList({
106107
}, [setHasKeyBeenPressed]);
107108

108109
const extraData = useMemo(
109-
() => [focusedIndex, columns, newTransactions, selectedTransactions, customCardNames],
110-
[focusedIndex, columns, newTransactions, selectedTransactions, customCardNames],
110+
() => [focusedIndex, columns, newTransactions, selectedTransactions, customCardNames, policyForMovingExpenses],
111+
[focusedIndex, columns, newTransactions, selectedTransactions, customCardNames, policyForMovingExpenses],
111112
);
112113

113114
return (

src/components/Search/SearchList/BaseSearchList/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {NativeSyntheticEvent} from 'react-native';
44
import type {SearchListItem} from '@components/Search/SearchList/ListItem/types';
55
import type {SearchColumnType, SelectedTransactions} from '@components/Search/types';
66
import type {ExtendedTargetedEvent} from '@components/SelectionList/ListItem/types';
7-
import type {Transaction} from '@src/types/onyx';
7+
import type {Policy, Transaction} from '@src/types/onyx';
88

99
type BaseSearchListProps = Pick<
1010
FlashListProps<SearchListItem>,
@@ -47,6 +47,9 @@ type BaseSearchListProps = Pick<
4747

4848
/** Custom card names for triggering re-render via extraData */
4949
customCardNames?: Record<number, string>;
50+
51+
/** Policy for moving expenses for triggering re-render via extraData */
52+
policyForMovingExpenses?: Policy;
5053
};
5154

5255
export default BaseSearchListProps;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function TransactionGroupListExpanded<TItem extends ListItem>({
5353
shouldDisplayEmptyView,
5454
searchTransactions,
5555
isInSingleTransactionReport,
56+
policyForMovingExpenses,
5657
onLongPress,
5758
}: TransactionGroupListExpandedProps<TItem>) {
5859
const theme = useTheme();
@@ -242,6 +243,7 @@ function TransactionGroupListExpanded<TItem extends ListItem>({
242243
onArrowRightPress={() => openReportInRHP(transaction)}
243244
shouldShowArrowRightOnNarrowLayout
244245
reportActions={exportedReportActions}
246+
policyForMovingExpenses={policyForMovingExpenses}
245247
/>
246248
);
247249
return (

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function TransactionListItem<TItem extends ListItem>({
5858
isLastItem,
5959
userBillingGracePeriodEnds,
6060
ownerBillingGracePeriodEnd,
61+
policyForMovingExpenses,
6162
}: TransactionListItemProps<TItem>) {
6263
const transactionItem = item as unknown as TransactionListItemType;
6364
const styles = useThemeStyles();
@@ -254,6 +255,7 @@ function TransactionListItem<TItem extends ListItem>({
254255
isHover={hovered}
255256
customCardNames={customCardNames}
256257
reportActions={exportedReportActions}
258+
policyForMovingExpenses={policyForMovingExpenses}
257259
/>
258260
</>
259261
)}

src/components/Search/SearchList/ListItem/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ type TransactionListItemProps<TItem extends ListItem> = ListItemProps<TItem> &
424424
columns?: SearchColumnType[];
425425
violations?: Record<string, TransactionViolations | undefined> | undefined;
426426
customCardNames?: Record<number, string>;
427+
policyForMovingExpenses?: Policy;
427428
};
428429

429430
type TransactionGroupListItemProps<TItem extends ListItem> = ListItemProps<TItem> &
@@ -435,11 +436,12 @@ type TransactionGroupListItemProps<TItem extends ListItem> = ListItemProps<TItem
435436
columns?: SearchColumnType[];
436437
newTransactionID?: string;
437438
violations?: Record<string, TransactionViolations | undefined> | undefined;
439+
policyForMovingExpenses?: Policy;
438440
};
439441

440442
type TransactionGroupListExpandedProps<TItem extends ListItem> = Pick<
441443
TransactionGroupListItemProps<TItem>,
442-
'showTooltip' | 'canSelectMultiple' | 'onCheckboxPress' | 'columns' | 'groupBy' | 'accountID' | 'isOffline' | 'violations' | 'onSelectRow'
444+
'showTooltip' | 'canSelectMultiple' | 'onCheckboxPress' | 'columns' | 'groupBy' | 'accountID' | 'isOffline' | 'violations' | 'onSelectRow' | 'policyForMovingExpenses'
443445
> & {
444446
transactions: TransactionListItemType[];
445447
transactionsVisibleLimit: number;

src/components/Search/SearchList/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import variables from '@styles/variables';
3636
import type {TransactionPreviewData} from '@userActions/Search';
3737
import CONST from '@src/CONST';
3838
import ONYXKEYS from '@src/ONYXKEYS';
39-
import type {Transaction, TransactionViolations} from '@src/types/onyx';
39+
import type {Policy, Transaction, TransactionViolations} from '@src/types/onyx';
4040
import BaseSearchList from './BaseSearchList';
4141
import type ChatListItem from './ListItem/ChatListItem';
4242
import type ExpenseReportListItem from './ListItem/ExpenseReportListItem';
@@ -133,6 +133,8 @@ type SearchListProps = Pick<FlashListProps<SearchListItem>, 'onScroll' | 'conten
133133
/** Whether all transactions have been loaded from snapshots in group-by views */
134134
hasLoadedAllTransactions?: boolean;
135135

136+
policyForMovingExpenses?: Policy;
137+
136138
/** Reference to the outer element */
137139
ref?: ForwardedRef<SearchListHandle>;
138140
};
@@ -217,6 +219,7 @@ function SearchList({
217219
customCardNames,
218220
selectedTransactions,
219221
hasLoadedAllTransactions,
222+
policyForMovingExpenses,
220223
ref,
221224
}: SearchListProps) {
222225
const styles = useThemeStyles();
@@ -439,6 +442,7 @@ function SearchList({
439442
queryJSONHash={hash}
440443
columns={columns}
441444
policies={policies}
445+
policyForMovingExpenses={policyForMovingExpenses}
442446
isDisabled={isDisabled}
443447
groupBy={groupBy}
444448
searchType={type}
@@ -492,6 +496,7 @@ function SearchList({
492496
customCardNames,
493497
selectedTransactions,
494498
ListFooterComponent,
499+
policyForMovingExpenses,
495500
],
496501
);
497502

@@ -559,6 +564,7 @@ function SearchList({
559564
newTransactions={newTransactions}
560565
selectedTransactions={selectedTransactions}
561566
customCardNames={customCardNames}
567+
policyForMovingExpenses={policyForMovingExpenses}
562568
/>
563569
<Modal
564570
isVisible={isModalVisible}

src/components/Search/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import useLocalize from '@hooks/useLocalize';
1717
import useMultipleSnapshots from '@hooks/useMultipleSnapshots';
1818
import useNetwork from '@hooks/useNetwork';
1919
import useOnyx from '@hooks/useOnyx';
20+
import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses';
2021
import usePrevious from '@hooks/usePrevious';
2122
import useResponsiveLayout from '@hooks/useResponsiveLayout';
2223
import useSearchHighlightAndScroll from '@hooks/useSearchHighlightAndScroll';
@@ -328,6 +329,8 @@ function Search({
328329
selector: selectFilteredReportActions,
329330
});
330331

332+
const {policyForMovingExpenses} = usePolicyForMovingExpenses();
333+
331334
const [cardFeeds, cardFeedsResult] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER);
332335
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
333336
const [onyxPersonalDetailsList] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
@@ -528,6 +531,7 @@ function Search({
528531
allReportMetadata,
529532
conciergeReportID,
530533
onyxPersonalDetailsList,
534+
policyForMovingExpenses,
531535
});
532536
return [filteredData1, filteredData1.length, allLength];
533537
}, [
@@ -554,6 +558,7 @@ function Search({
554558
allReportMetadata,
555559
conciergeReportID,
556560
onyxPersonalDetailsList,
561+
policyForMovingExpenses,
557562
]);
558563

559564
// For group-by views, each grouped item has a transactionsQueryJSON with a hash pointing to a separate snapshot
@@ -1678,6 +1683,7 @@ function Search({
16781683
newTransactions={newTransactions}
16791684
hasLoadedAllTransactions={hasLoadedAllTransactions}
16801685
customCardNames={customCardNames}
1686+
policyForMovingExpenses={policyForMovingExpenses}
16811687
/>
16821688
</Animated.View>
16831689
</SearchScopeProvider>

src/components/TransactionItemRow/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ type TransactionItemRowProps = {
146146
reportActions?: ReportAction[];
147147
checkboxSentryLabel?: string;
148148
isLargeScreenWidth?: boolean;
149+
policyForMovingExpenses?: Policy;
149150
};
150151

151152
const EMPTY_ACTIVE_STYLE: StyleProp<ViewStyle> = [];
@@ -199,6 +200,7 @@ function TransactionItemRow({
199200
reportActions,
200201
checkboxSentryLabel,
201202
isLargeScreenWidth: isLargeScreenWidthProp,
203+
policyForMovingExpenses,
202204
}: TransactionItemRowProps) {
203205
const styles = useThemeStyles();
204206
const {translate} = useLocalize();
@@ -273,7 +275,8 @@ function TransactionItemRow({
273275

274276
const transactionAttendees = useMemo(() => getAttendees(transactionItem, currentUserPersonalDetails), [transactionItem, currentUserPersonalDetails]);
275277

276-
const shouldShowAttendees = shouldShowAttendeesUtils(CONST.IOU.TYPE.SUBMIT, policy) && transactionAttendees.length > 0;
278+
const isUnReported = transactionItem.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
279+
const shouldShowAttendees = shouldShowAttendeesUtils(CONST.IOU.TYPE.SUBMIT, isUnReported ? policyForMovingExpenses : policy) && transactionAttendees.length > 0;
277280

278281
const totalPerAttendee = useMemo(() => {
279282
const attendeesCount = transactionAttendees.length ?? 0;

src/libs/SearchUIUtils.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ import {
185185
isPending,
186186
isScanning,
187187
isViolationDismissed,
188+
shouldShowAttendees as shouldShowAttendeesUtils,
188189
shouldShowViolation,
189190
} from './TransactionUtils';
190191
import {isInvalidMerchantValue} from './ValidationUtils';
@@ -243,6 +244,7 @@ type GetTransactionSectionsParams = {
243244
reportActions?: Record<string, OnyxTypes.ReportAction[]>;
244245
queryJSON?: SearchQueryJSON;
245246
cardFeeds?: OnyxCollection<OnyxTypes.CardFeeds>;
247+
policyForMovingExpenses?: OnyxTypes.Policy;
246248
};
247249

248250
const transactionColumnNamesToSortingProperty: TransactionSorting = {
@@ -545,6 +547,7 @@ type GetSectionsParams = {
545547
allReportMetadata: OnyxCollection<OnyxTypes.ReportMetadata>;
546548
conciergeReportID: string | undefined;
547549
onyxPersonalDetailsList?: OnyxTypes.PersonalDetailsList;
550+
policyForMovingExpenses?: OnyxTypes.Policy;
548551
};
549552

550553
/**
@@ -2008,6 +2011,7 @@ function getTransactionsSections({
20082011
reportActions = {},
20092012
queryJSON,
20102013
cardFeeds,
2014+
policyForMovingExpenses,
20112015
}: GetTransactionSectionsParams): [TransactionListItemType[], number] {
20122016
const {
20132017
transactionKeys,
@@ -2026,6 +2030,7 @@ function getTransactionsSections({
20262030
} = classifyAndPreprocess(data);
20272031

20282032
const personalDetailsMap = new Map(Object.entries(data.personalDetailsList ?? {}));
2033+
const currentUserPersonalDetails = personalDetailsMap.get(currentAccountID.toString()) ?? emptyPersonalDetails;
20292034

20302035
const transactionsSections: TransactionListItemType[] = [];
20312036

@@ -2080,9 +2085,17 @@ function getTransactionsSections({
20802085
const reportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionItem.reportID}`] ?? {};
20812086
const allActions = getActions(data, allViolations, key, currentSearch, currentUserEmail, currentAccountID, bankAccountList, reportMetadata, actions);
20822087
const transactionPendingAction = getTransactionPendingAction(transactionItem);
2088+
const transactionAttendees = getAttendees(transactionItem, currentUserPersonalDetails);
2089+
const isUnReported = transactionItem.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
2090+
const shouldShowAttendees = shouldShowAttendeesUtils(CONST.IOU.TYPE.SUBMIT, isUnReported ? policyForMovingExpenses : policy) && transactionAttendees.length > 0;
2091+
20832092
const transactionSection: TransactionListItemType = {
20842093
...transactionItem,
20852094
...(transactionPendingAction ? {pendingAction: transactionPendingAction} : {}),
2095+
comment: {
2096+
...transactionItem.comment,
2097+
attendees: shouldShowAttendees ? transactionAttendees : [],
2098+
},
20862099
keyForList: transactionItem.transactionID,
20872100
action: getAction(allActions),
20882101
allActions,
@@ -3353,6 +3366,7 @@ function getSections({
33533366
allReportMetadata,
33543367
conciergeReportID,
33553368
onyxPersonalDetailsList,
3369+
policyForMovingExpenses,
33563370
}: GetSectionsParams) {
33573371
if (type === CONST.SEARCH.DATA_TYPES.CHAT) {
33583372
return getReportActionsSections(data, visibleReportActionsData);
@@ -3420,6 +3434,7 @@ function getSections({
34203434
reportActions,
34213435
queryJSON,
34223436
cardFeeds,
3437+
policyForMovingExpenses,
34233438
});
34243439
}
34253440

@@ -3659,15 +3674,15 @@ function getSortedTransactionData(
36593674

36603675
if (sortBy === CONST.SEARCH.TABLE_COLUMNS.ATTENDEES) {
36613676
return data.sort((a, b) => {
3662-
const aValue = getAttendees(a, undefined).length;
3663-
const bValue = getAttendees(b, undefined).length;
3677+
const aValue = a.comment?.attendees?.length ?? 0;
3678+
const bValue = b.comment?.attendees?.length ?? 0;
36643679
return compareValues(aValue, bValue, sortOrder, sortBy, localeCompare);
36653680
});
36663681
}
36673682

36683683
if (sortBy === CONST.SEARCH.TABLE_COLUMNS.TOTAL_PER_ATTENDEE) {
36693684
const getTotalPerAttendee = (t: TransactionListItemType) => {
3670-
const attendeesCount = getAttendees(t, undefined).length;
3685+
const attendeesCount = t.comment?.attendees?.length ?? 0;
36713686
if (!attendeesCount) {
36723687
return 0;
36733688
}

0 commit comments

Comments
 (0)