|
1 | 1 | import {useMemo} from 'react'; |
| 2 | +import type {OnyxEntry} from 'react-native-onyx'; |
2 | 3 | import {createTypeMenuSections} from '@libs/SearchUIUtils'; |
3 | 4 | import ONYXKEYS from '@src/ONYXKEYS'; |
| 5 | +import type {Policy} from '@src/types/onyx'; |
| 6 | +import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems'; |
4 | 7 | import useCardFeedsForDisplay from './useCardFeedsForDisplay'; |
5 | 8 | import useOnyx from './useOnyx'; |
6 | 9 |
|
| 10 | +const policySelector = (policy: OnyxEntry<Policy>): OnyxEntry<Policy> => |
| 11 | + policy && { |
| 12 | + id: policy.id, |
| 13 | + name: policy.name, |
| 14 | + type: policy.type, |
| 15 | + role: policy.role, |
| 16 | + owner: policy.owner, |
| 17 | + outputCurrency: policy.outputCurrency, |
| 18 | + isPolicyExpenseChatEnabled: policy.isPolicyExpenseChatEnabled, |
| 19 | + reimburser: policy.reimburser, |
| 20 | + exporter: policy.exporter, |
| 21 | + approver: policy.approver, |
| 22 | + approvalMode: policy.approvalMode, |
| 23 | + employeeList: policy.employeeList, |
| 24 | + reimbursementChoice: policy.reimbursementChoice, |
| 25 | + areCompanyCardsEnabled: policy.areCompanyCardsEnabled, |
| 26 | + }; |
| 27 | + |
7 | 28 | /** |
8 | 29 | * Get a list of all search groupings, along with their search items. Also returns the |
9 | 30 | * currently focused search, based on the hash |
10 | 31 | */ |
11 | 32 | const useSearchTypeMenuSections = () => { |
12 | 33 | const {defaultCardFeed, cardFeedsByPolicy} = useCardFeedsForDisplay(); |
13 | 34 |
|
14 | | - const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); |
| 35 | + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (policies) => mapOnyxCollectionItems(policies, policySelector), canBeMissing: true}); |
15 | 36 | const [currentUserLoginAndAccountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => ({email: session?.email, accountID: session?.accountID}), canBeMissing: false}); |
16 | 37 |
|
17 | 38 | const typeMenuSections = useMemo( |
|
0 commit comments