From 6ba70347fc110df5320759e7927f3135e4715e8c Mon Sep 17 00:00:00 2001 From: Yauheni Pasiukevich Date: Mon, 29 Apr 2024 16:50:22 +0200 Subject: [PATCH 1/5] =?UTF-8?q?[TS=20migration]=20Migrate=20MoneyTemporary?= =?UTF-8?q?ForRefactorRequestParticipantsSelector.js=C2=A0to=C2=A0MoneyReq?= =?UTF-8?q?uestParticipantsSelector.tsx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CONST.ts | 3 +- src/components/ReferralProgramCTA.tsx | 4 +- ...s => MoneyRequestParticipantsSelector.tsx} | 115 ++++++++---------- .../step/IOURequestStepParticipants.tsx | 2 +- src/types/onyx/IOU.ts | 1 + 5 files changed, 59 insertions(+), 66 deletions(-) rename src/pages/iou/request/{MoneyTemporaryForRefactorRequestParticipantsSelector.js => MoneyRequestParticipantsSelector.tsx} (77%) diff --git a/src/CONST.ts b/src/CONST.ts index 83690d5e9a85..dde80daf8a32 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -4718,7 +4718,8 @@ type Country = keyof typeof CONST.ALL_COUNTRIES; type IOUType = ValueOf; type IOUAction = ValueOf; +type IOURequestType = ValueOf; -export type {Country, IOUAction, IOUType, RateAndUnit, OnboardingPurposeType}; +export type {Country, IOUAction, IOUType, RateAndUnit, OnboardingPurposeType, IOURequestType}; export default CONST; diff --git a/src/components/ReferralProgramCTA.tsx b/src/components/ReferralProgramCTA.tsx index 237fc8f955a3..086b875451c0 100644 --- a/src/components/ReferralProgramCTA.tsx +++ b/src/components/ReferralProgramCTA.tsx @@ -1,5 +1,5 @@ import React, {useEffect} from 'react'; -import type {ViewStyle} from 'react-native'; +import type {StyleProp, ViewStyle} from 'react-native'; import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners'; import useLocalize from '@hooks/useLocalize'; import useTheme from '@hooks/useTheme'; @@ -19,7 +19,7 @@ type ReferralProgramCTAProps = { | typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.START_CHAT | typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.PAY_SOMEONE | typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND; - style?: ViewStyle; + style?: StyleProp; onDismiss?: () => void; }; diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx similarity index 77% rename from src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js rename to src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index 7ae6d25e1b4f..47279c48fea0 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -1,12 +1,8 @@ -import lodashGet from 'lodash/get'; import lodashIsEqual from 'lodash/isEqual'; -import lodashMap from 'lodash/map'; import lodashPick from 'lodash/pick'; import lodashReject from 'lodash/reject'; -import lodashSome from 'lodash/some'; -import lodashValues from 'lodash/values'; -import PropTypes from 'prop-types'; import React, {memo, useCallback, useEffect, useMemo} from 'react'; +import type {GestureResponderEvent} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import FormHelpMessage from '@components/FormHelpMessage'; @@ -23,46 +19,43 @@ import usePermissions from '@hooks/usePermissions'; import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus'; import useThemeStyles from '@hooks/useThemeStyles'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; +import type {MaybePhraseKey} from '@libs/Localize'; +import type {Options} from '@libs/OptionsListUtils'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as Policy from '@userActions/Policy'; import * as Report from '@userActions/Report'; +import type {IOUAction, IOURequestType, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {Participant} from '@src/types/onyx/IOU'; -const propTypes = { +type MoneyRequestParticipantsSelectorProps = { /** Callback to request parent modal to go to next step, which should be split */ - onFinish: PropTypes.func.isRequired, + onFinish: (value?: string) => void; /** Callback to add participants in MoneyRequestModal */ - onParticipantsAdded: PropTypes.func.isRequired, - + onParticipantsAdded: (value: Participant[]) => void; /** Selected participants from MoneyRequestModal with login */ - participants: PropTypes.arrayOf( - PropTypes.shape({ - accountID: PropTypes.number, - login: PropTypes.string, - isPolicyExpenseChat: PropTypes.bool, - isOwnPolicyExpenseChat: PropTypes.bool, - selected: PropTypes.bool, - }), - ), + participants?: Participant[]; /** The type of IOU report, i.e. split, request, send, track */ - iouType: PropTypes.oneOf(lodashValues(CONST.IOU.TYPE)).isRequired, + iouType: IOUType; /** The expense type, ie. manual, scan, distance */ - iouRequestType: PropTypes.oneOf(lodashValues(CONST.IOU.REQUEST_TYPE)).isRequired, + iouRequestType: IOURequestType; /** The action of the IOU, i.e. create, split, move */ - action: PropTypes.oneOf(lodashValues(CONST.IOU.ACTION)), -}; - -const defaultProps = { - participants: [], - action: CONST.IOU.ACTION.CREATE, + action?: IOUAction; }; -function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onFinish, onParticipantsAdded, iouType, iouRequestType, action}) { +function MoneyRequestParticipantsSelector({ + participants = [], + onFinish, + onParticipantsAdded, + iouType, + iouRequestType, + action = CONST.IOU.ACTION.CREATE, +}: MoneyRequestParticipantsSelectorProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); @@ -78,12 +71,12 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF shouldInitialize: didScreenTransitionEnd, }); - const offlineMessage = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : ''; + const offlineMessage: MaybePhraseKey = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : ''; const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS; const isIOUSplit = iouType === CONST.IOU.TYPE.SPLIT; - const isCategorizeOrShareAction = [CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(action); + const isCategorizeOrShareAction = ([CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE] as string[]).includes(action); const shouldShowReferralBanner = !isDismissed && iouType !== CONST.IOU.TYPE.INVOICE; @@ -97,7 +90,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF * @returns {Array} */ const [sections, newChatOptions] = useMemo(() => { - const newSections = []; + const newSections: OptionsListUtils.CategorySection[] = []; if (!areOptionsInitialized || !didScreenTransitionEnd) { return [newSections, {}]; } @@ -113,14 +106,14 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF // sees the option to submit an expense from their admin on their own Workspace Chat. (iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.SPLIT) && action !== CONST.IOU.ACTION.SUBMIT, - (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, + (canUseP2PDistanceRequests ?? iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, false, {}, [], false, {}, [], - (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, + (canUseP2PDistanceRequests ?? iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, false, undefined, undefined, @@ -134,7 +127,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF const formatResults = OptionsListUtils.formatSectionsFromSearchTerm( debouncedSearchTerm, - participants, + participants.map((participant) => ({...participant, reportID: participant.reportID ?? ''})), chatOptions.recentReports, chatOptions.personalDetails, maxParticipantsReached, @@ -160,11 +153,14 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF shouldShow: chatOptions.personalDetails.length > 0, }); - if (chatOptions.userToInvite && !OptionsListUtils.isCurrentUser(chatOptions.userToInvite)) { + if ( + chatOptions.userToInvite && + !OptionsListUtils.isCurrentUser({...chatOptions.userToInvite, accountID: chatOptions.userToInvite?.accountID ?? -1, status: chatOptions.userToInvite?.status ?? undefined}) + ) { newSections.push({ title: undefined, - data: lodashMap([chatOptions.userToInvite], (participant) => { - const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); + data: [chatOptions.userToInvite].map((participant) => { + const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false; return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, personalDetails); }), shouldShow: true, @@ -196,8 +192,8 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF * @param {Object} option */ const addSingleParticipant = useCallback( - (option) => { - const newParticipants = [ + (option: Participant) => { + const newParticipants: Participant[] = [ { ...lodashPick(option, 'accountID', 'login', 'isPolicyExpenseChat', 'reportID', 'searchText', 'policyID'), selected: true, @@ -206,10 +202,10 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF ]; if (iouType === CONST.IOU.TYPE.INVOICE) { - const primaryPolicy = Policy.getPrimaryPolicy(activePolicyID); + const primaryPolicy = Policy.getPrimaryPolicy(activePolicyID ?? undefined); newParticipants.push({ - policyID: primaryPolicy.id, + policyID: primaryPolicy?.id, isSender: true, selected: false, iouType, @@ -228,20 +224,20 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF * @param {Object} option */ const addParticipantToSelection = useCallback( - (option) => { - const isOptionSelected = (selectedOption) => { - if (selectedOption.accountID && selectedOption.accountID === option.accountID) { + (option: Participant) => { + const isOptionSelected = (selectedOption: Participant) => { + if (selectedOption.accountID && selectedOption.accountID === option?.accountID) { return true; } - if (selectedOption.reportID && selectedOption.reportID === option.reportID) { + if (selectedOption.reportID && selectedOption.reportID === option?.reportID) { return true; } return false; }; - const isOptionInList = lodashSome(participants, isOptionSelected); - let newSelectedOptions; + const isOptionInList = participants.some(isOptionSelected); + let newSelectedOptions: Participant[]; if (isOptionInList) { newSelectedOptions = lodashReject(participants, isOptionSelected); @@ -269,11 +265,11 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF const headerMessage = useMemo( () => OptionsListUtils.getHeaderMessage( - lodashGet(newChatOptions, 'personalDetails', []).length + lodashGet(newChatOptions, 'recentReports', []).length !== 0, - Boolean(newChatOptions.userToInvite), + ((newChatOptions as Options)?.personalDetails ?? []).length + ((newChatOptions as Options)?.recentReports ?? []).length !== 0, + Boolean((newChatOptions as Options)?.userToInvite), debouncedSearchTerm.trim(), maxParticipantsReached, - lodashSome(participants, (participant) => participant.searchText.toLowerCase().includes(debouncedSearchTerm.trim().toLowerCase())), + participants.some((participant) => participant?.searchText?.toLowerCase().includes(debouncedSearchTerm.trim().toLowerCase())), ), [maxParticipantsReached, newChatOptions, participants, debouncedSearchTerm], ); @@ -281,17 +277,17 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF // Right now you can't split an expense with a workspace and other additional participants // This is getting properly fixed in https://github.com/Expensify/App/issues/27508, but as a stop-gap to prevent // the app from crashing on native when you try to do this, we'll going to hide the button if you have a workspace and other participants - const hasPolicyExpenseChatParticipant = lodashSome(participants, (participant) => participant.isPolicyExpenseChat); + const hasPolicyExpenseChatParticipant = participants.some((participant) => participant.isPolicyExpenseChat); const shouldShowSplitBillErrorMessage = participants.length > 1 && hasPolicyExpenseChatParticipant; // canUseP2PDistanceRequests is true if the iouType is track expense, but we don't want to allow splitting distance with track expense yet const isAllowedToSplit = - (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && - ![CONST.IOU.TYPE.PAY, CONST.IOU.TYPE.TRACK, CONST.IOU.TYPE.INVOICE].includes(iouType) && - ![CONST.IOU.ACTION.SHARE, CONST.IOU.ACTION.SUBMIT, CONST.IOU.ACTION.CATEGORIZE].includes(action); + (canUseP2PDistanceRequests ?? iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && + !([CONST.IOU.TYPE.PAY, CONST.IOU.TYPE.TRACK, CONST.IOU.TYPE.INVOICE] as string[]).includes(iouType) && + !([CONST.IOU.ACTION.SHARE, CONST.IOU.ACTION.SUBMIT, CONST.IOU.ACTION.CATEGORIZE] as string[]).includes(action); const handleConfirmSelection = useCallback( - (keyEvent, option) => { + (keyEvent?: GestureResponderEvent | KeyboardEvent, option?: Participant) => { const shouldAddSingleParticipant = option && !participants.length; if (shouldShowSplitBillErrorMessage || (!participants.length && !option)) { return; @@ -362,15 +358,10 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF ); } -MoneyTemporaryForRefactorRequestParticipantsSelector.propTypes = propTypes; -MoneyTemporaryForRefactorRequestParticipantsSelector.defaultProps = defaultProps; -MoneyTemporaryForRefactorRequestParticipantsSelector.displayName = 'MoneyTemporaryForRefactorRequestParticipantsSelector'; +MoneyRequestParticipantsSelector.displayName = 'MoneyTemporaryForRefactorRequestParticipantsSelector'; export default memo( - MoneyTemporaryForRefactorRequestParticipantsSelector, + MoneyRequestParticipantsSelector, (prevProps, nextProps) => - lodashIsEqual(prevProps.participants, nextProps.participants) && - prevProps.iouRequestType === nextProps.iouRequestType && - prevProps.iouType === nextProps.iouType && - lodashIsEqual(prevProps.betas, nextProps.betas), + lodashIsEqual(prevProps.participants, nextProps.participants) && prevProps.iouRequestType === nextProps.iouRequestType && prevProps.iouType === nextProps.iouType, ); diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index be95cb03e95b..3f917a14ae11 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -5,7 +5,7 @@ import DistanceRequestUtils from '@libs/DistanceRequestUtils'; import * as IOUUtils from '@libs/IOUUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as TransactionUtils from '@libs/TransactionUtils'; -import MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector'; +import MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyRequestParticipantsSelector'; import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; diff --git a/src/types/onyx/IOU.ts b/src/types/onyx/IOU.ts index 726b94c5f6d3..82bf4d6efc04 100644 --- a/src/types/onyx/IOU.ts +++ b/src/types/onyx/IOU.ts @@ -23,6 +23,7 @@ type Participant = { isSelected?: boolean; isSelfDM?: boolean; isSender?: boolean; + iouType?: string; }; type Split = { From 0f1e6981e226dcf7a060f1a71df6c30f8aeb9962 Mon Sep 17 00:00:00 2001 From: Yauheni Pasiukevich Date: Mon, 6 May 2024 13:57:31 +0200 Subject: [PATCH 2/5] address comments --- .../MoneyRequestParticipantsSelector.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index 58db91c0f240..24221a700b35 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -75,7 +75,7 @@ function MoneyRequestParticipantsSelector({ const offlineMessage: MaybePhraseKey = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : ''; const isIOUSplit = iouType === CONST.IOU.TYPE.SPLIT; - const isCategorizeOrShareAction = ([CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE] as string[]).includes(action); + const isCategorizeOrShareAction = [CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].some((option) => option === action); const shouldShowReferralBanner = !isDismissed && iouType !== CONST.IOU.TYPE.INVOICE; @@ -105,14 +105,14 @@ function MoneyRequestParticipantsSelector({ // sees the option to submit an expense from their admin on their own Workspace Chat. (iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.SPLIT) && action !== CONST.IOU.ACTION.SUBMIT, - (canUseP2PDistanceRequests ?? iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, + (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, false, {}, [], false, {}, [], - (canUseP2PDistanceRequests ?? iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, + (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, false, undefined, undefined, @@ -124,7 +124,14 @@ function MoneyRequestParticipantsSelector({ isCategorizeOrShareAction ? 0 : undefined, ); - const formatResults = OptionsListUtils.formatSectionsFromSearchTerm(debouncedSearchTerm, participants.map((participant) => ({...participant, reportID: participant.reportID ?? ''})), chatOptions.recentReports, chatOptions.personalDetails, personalDetails, true); + const formatResults = OptionsListUtils.formatSectionsFromSearchTerm( + debouncedSearchTerm, + participants.map((participant) => ({...participant, reportID: participant.reportID ?? ''})), + chatOptions.recentReports, + chatOptions.personalDetails, + personalDetails, + true, + ); newSections.push(formatResults.section); @@ -268,8 +275,8 @@ function MoneyRequestParticipantsSelector({ // canUseP2PDistanceRequests is true if the iouType is track expense, but we don't want to allow splitting distance with track expense yet const isAllowedToSplit = (canUseP2PDistanceRequests ?? iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && - !([CONST.IOU.TYPE.PAY, CONST.IOU.TYPE.TRACK, CONST.IOU.TYPE.INVOICE] as string[]).includes(iouType) && - !([CONST.IOU.ACTION.SHARE, CONST.IOU.ACTION.SUBMIT, CONST.IOU.ACTION.CATEGORIZE] as string[]).includes(action); + ![CONST.IOU.TYPE.PAY, CONST.IOU.TYPE.TRACK, CONST.IOU.TYPE.INVOICE].some((option) => option === iouType) && + ![CONST.IOU.ACTION.SHARE, CONST.IOU.ACTION.SUBMIT, CONST.IOU.ACTION.CATEGORIZE].some((option) => option === action); const handleConfirmSelection = useCallback( (keyEvent?: GestureResponderEvent | KeyboardEvent, option?: Participant) => { From 43cb0109ba834ebc53fb98e1374cff21be0e4486 Mon Sep 17 00:00:00 2001 From: Yauheni Pasiukevich Date: Mon, 6 May 2024 14:17:50 +0200 Subject: [PATCH 3/5] fix lint --- src/pages/iou/request/MoneyRequestParticipantsSelector.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index 24221a700b35..e2965aba73ea 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -105,6 +105,7 @@ function MoneyRequestParticipantsSelector({ // sees the option to submit an expense from their admin on their own Workspace Chat. (iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.SPLIT) && action !== CONST.IOU.ACTION.SUBMIT, + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, false, {}, @@ -112,6 +113,7 @@ function MoneyRequestParticipantsSelector({ false, {}, [], + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, false, undefined, From c5c3c450d1720f7f99171b17eb4a21d4425990c2 Mon Sep 17 00:00:00 2001 From: Yauheni Pasiukevich Date: Tue, 7 May 2024 11:13:24 +0200 Subject: [PATCH 4/5] fix regression, type update --- src/libs/actions/Policy.ts | 2 +- src/pages/iou/request/MoneyRequestParticipantsSelector.tsx | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 2c08dd321b11..f861b899911c 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -282,7 +282,7 @@ function getPolicy(policyID: string | undefined): Policy | EmptyObject { /** * Returns a primary policy for the user */ -function getPrimaryPolicy(activePolicyID?: string): Policy | undefined { +function getPrimaryPolicy(activePolicyID?: OnyxEntry): Policy | undefined { const activeAdminWorkspaces = PolicyUtils.getActiveAdminWorkspaces(allPolicies); const primaryPolicy: Policy | null | undefined = allPolicies?.[activePolicyID ?? '']; diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index e2965aba73ea..8f8e686b6a71 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -197,7 +197,7 @@ function MoneyRequestParticipantsSelector({ ]; if (iouType === CONST.IOU.TYPE.INVOICE) { - const primaryPolicy = Policy.getPrimaryPolicy(activePolicyID ?? undefined); + const primaryPolicy = Policy.getPrimaryPolicy(activePolicyID); newParticipants.push({ policyID: primaryPolicy?.id, @@ -276,7 +276,8 @@ function MoneyRequestParticipantsSelector({ // canUseP2PDistanceRequests is true if the iouType is track expense, but we don't want to allow splitting distance with track expense yet const isAllowedToSplit = - (canUseP2PDistanceRequests ?? iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && ![CONST.IOU.TYPE.PAY, CONST.IOU.TYPE.TRACK, CONST.IOU.TYPE.INVOICE].some((option) => option === iouType) && ![CONST.IOU.ACTION.SHARE, CONST.IOU.ACTION.SUBMIT, CONST.IOU.ACTION.CATEGORIZE].some((option) => option === action); From a407e7dd3eeb35ed676600b1fb9c71eb6c6f5db0 Mon Sep 17 00:00:00 2001 From: Yauheni Pasiukevich Date: Tue, 7 May 2024 11:23:08 +0200 Subject: [PATCH 5/5] update property to required --- .../iou/request/MoneyRequestParticipantsSelector.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index 8f8e686b6a71..ec05c5ad6fda 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -45,17 +45,10 @@ type MoneyRequestParticipantsSelectorProps = { iouRequestType: IOURequestType; /** The action of the IOU, i.e. create, split, move */ - action?: IOUAction; + action: IOUAction; }; -function MoneyRequestParticipantsSelector({ - participants = [], - onFinish, - onParticipantsAdded, - iouType, - iouRequestType, - action = CONST.IOU.ACTION.CREATE, -}: MoneyRequestParticipantsSelectorProps) { +function MoneyRequestParticipantsSelector({participants = [], onFinish, onParticipantsAdded, iouType, iouRequestType, action}: MoneyRequestParticipantsSelectorProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');