Skip to content
Merged
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
25 changes: 15 additions & 10 deletions src/pages/iou/request/step/IOURequestEditReportCommon.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, {useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import {useOptionsList} from '@components/OptionListContextProvider';
import SelectionList from '@components/SelectionList';
import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem';
import type {ListItem} from '@components/SelectionList/types';
import UserListItem from '@components/SelectionList/UserListItem';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import Navigation from '@libs/Navigation/Navigation';
import {getOutstandingReportsForUser} from '@libs/ReportUtils';
import {getOutstandingReportsForUser, getPolicyName} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
Expand Down Expand Up @@ -44,6 +45,7 @@ type Props = {

function IOURequestEditReportCommon({backTo, transactionsReports, selectReport}: Props) {
const {translate} = useLocalize();
const {options} = useOptionsList();
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: (reports) => mapOnyxCollectionItems(reports, reportSelector), canBeMissing: true});
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {canBeMissing: true});
const [allPoliciesID] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (policies) => mapOnyxCollectionItems(policies, (policy) => policy?.id), canBeMissing: false});
Expand Down Expand Up @@ -79,13 +81,16 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport}:
.sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0)
.filter((report) => !debouncedSearchValue || report?.reportName?.toLowerCase().includes(debouncedSearchValue.toLowerCase()))
.filter((report): report is NonNullable<typeof report> => report !== undefined)
.map((report) => ({
text: report.reportName,
value: report.reportID,
keyForList: report.reportID,
isSelected: onlyReport && report.reportID === onlyReport?.reportID,
}));
}, [allReports, debouncedSearchValue, expenseReports, transactionsReports]);
.map((report) => {
const matchingOption = options.reports.find((option) => option.reportID === report.reportID);
return {
...matchingOption,
alternateText: getPolicyName({report}) ?? matchingOption?.alternateText,
value: report.reportID,
isSelected: onlyReport && report.reportID === onlyReport?.reportID,
};
});
}, [allReports, debouncedSearchValue, expenseReports, options.reports, transactionsReports]);

const navigateBack = () => {
Navigation.goBack(backTo);
Expand All @@ -111,7 +116,7 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport}:
shouldSingleExecuteRowSelect
headerMessage={headerMessage}
initiallyFocusedOptionKey={transactionsReports.length === 1 ? transactionsReports.at(0)?.reportID : undefined}
ListItem={UserListItem}
ListItem={InviteMemberListItem}
/>
</StepScreenWrapper>
);
Expand Down