From 3c4bcf80abfda02a296676b00d21372b7c40c5fa Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 20 Apr 2024 12:39:46 +0800 Subject: [PATCH] remove unused files --- src/components/transactionPropTypes.js | 96 ----- .../MoneyRequestParticipantsSelector.js | 361 ------------------ 2 files changed, 457 deletions(-) delete mode 100644 src/components/transactionPropTypes.js delete mode 100755 src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js diff --git a/src/components/transactionPropTypes.js b/src/components/transactionPropTypes.js deleted file mode 100644 index d1626b75d6cd..000000000000 --- a/src/components/transactionPropTypes.js +++ /dev/null @@ -1,96 +0,0 @@ -import lodashValues from 'lodash/values'; -import PropTypes from 'prop-types'; -import {translatableTextPropTypes} from '@libs/Localize'; -import CONST from '@src/CONST'; -import sourcePropTypes from './Image/sourcePropTypes'; - -export default PropTypes.shape({ - /** The transaction id */ - transactionID: PropTypes.string, - - /** The iouReportID associated with the transaction */ - reportID: PropTypes.string, - - /** The original transaction amount */ - amount: PropTypes.number, - - /** The edited transaction amount */ - modifiedAmount: PropTypes.number, - - /** The original created data */ - created: PropTypes.string, - - /** The edited transaction date */ - modifiedCreated: PropTypes.string, - - /** The filename of the associated receipt */ - filename: PropTypes.string, - - /** The original merchant name */ - merchant: PropTypes.string, - - /** The edited merchant name */ - modifiedMerchant: PropTypes.string, - - /** The comment object on the transaction */ - comment: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.shape({ - /** The text of the comment */ - comment: PropTypes.string, - - /** The waypoints defining the distance expense */ - waypoints: PropTypes.shape({ - /** The latitude of the waypoint */ - lat: PropTypes.number, - - /** The longitude of the waypoint */ - lng: PropTypes.number, - - /** The address of the waypoint */ - address: PropTypes.string, - - /** The name of the waypoint */ - name: PropTypes.string, - }), - }), - ]), - - /** The type of transaction */ - type: PropTypes.oneOf(lodashValues(CONST.TRANSACTION.TYPE)), - - /** Custom units attached to the transaction */ - customUnits: PropTypes.arrayOf( - PropTypes.shape({ - /** The name of the custom unit */ - name: PropTypes.string, - }), - ), - - /** Selected participants */ - participants: PropTypes.arrayOf( - PropTypes.shape({ - accountID: PropTypes.number, - login: PropTypes.string, - isPolicyExpenseChat: PropTypes.bool, - isOwnPolicyExpenseChat: PropTypes.bool, - selected: PropTypes.bool, - }), - ), - - /** The original currency of the transaction */ - currency: PropTypes.string, - - /** The edited currency of the transaction */ - modifiedCurrency: PropTypes.string, - - /** The receipt object associated with the transaction */ - receipt: PropTypes.shape({ - receiptID: PropTypes.number, - source: PropTypes.oneOfType([PropTypes.number, PropTypes.string, sourcePropTypes]), - state: PropTypes.string, - }), - - /** Server side errors keyed by microtime */ - errorFields: PropTypes.objectOf(PropTypes.objectOf(translatableTextPropTypes)), -}); diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js deleted file mode 100755 index 1bcaba0c691f..000000000000 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ /dev/null @@ -1,361 +0,0 @@ -import lodashGet from 'lodash/get'; -import lodashMap from 'lodash/map'; -import lodashReject from 'lodash/reject'; -import lodashSome from 'lodash/some'; -import PropTypes from 'prop-types'; -import React, {useCallback, useMemo} from 'react'; -import {useOnyx} from 'react-native-onyx'; -import Button from '@components/Button'; -import FormHelpMessage from '@components/FormHelpMessage'; -import {usePersonalDetails} from '@components/OnyxProvider'; -import {useOptionsList} from '@components/OptionListContextProvider'; -import {PressableWithFeedback} from '@components/Pressable'; -import ReferralProgramCTA from '@components/ReferralProgramCTA'; -import SelectCircle from '@components/SelectCircle'; -import SelectionList from '@components/SelectionList'; -import UserListItem from '@components/SelectionList/UserListItem'; -import useDebouncedState from '@hooks/useDebouncedState'; -import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners'; -import useLocalize from '@hooks/useLocalize'; -import useNetwork from '@hooks/useNetwork'; -import usePermissions from '@hooks/usePermissions'; -import useSearchTermAndSearch from '@hooks/useSearchTermAndSearch'; -import useThemeStyles from '@hooks/useThemeStyles'; -import * as DeviceCapabilities from '@libs/DeviceCapabilities'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; - -const propTypes = { - /** Callback to request parent modal to go to next step, which should be request */ - navigateToRequest: PropTypes.func.isRequired, - - /** Callback to request parent modal to go to next step, which should be split */ - navigateToSplit: PropTypes.func.isRequired, - - /** Callback to add participants in MoneyRequestModal */ - onAddParticipants: PropTypes.func.isRequired, - - /** 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, - }), - ), - - /** The type of IOU report, i.e. bill, request, send */ - iouType: PropTypes.string.isRequired, - - /** Whether the money request is a distance request or not */ - isDistanceRequest: PropTypes.bool, - - /** Whether the screen transition has ended */ - didScreenTransitionEnd: PropTypes.bool, -}; - -const defaultProps = { - participants: [], - isDistanceRequest: false, - didScreenTransitionEnd: false, -}; - -function MoneyRequestParticipantsSelector({participants, navigateToRequest, navigateToSplit, onAddParticipants, iouType, isDistanceRequest, didScreenTransitionEnd}) { - const {translate} = useLocalize(); - const styles = useThemeStyles(); - const [betas] = useOnyx(ONYXKEYS.BETAS); - const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); - const referralContentType = iouType === CONST.IOU.TYPE.SEND ? CONST.REFERRAL_PROGRAM.CONTENT_TYPES.SEND_MONEY : CONST.REFERRAL_PROGRAM.CONTENT_TYPES.MONEY_REQUEST; - const {isOffline} = useNetwork(); - const personalDetails = usePersonalDetails(); - const {options, areOptionsInitialized} = useOptionsList({shouldInitialize: didScreenTransitionEnd}); - const {canUseP2PDistanceRequests} = usePermissions(iouType); - - const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS; - const setSearchTermAndSearchInServer = useSearchTermAndSearch(setSearchTerm, maxParticipantsReached); - - const offlineMessage = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : ''; - - const newChatOptions = useMemo(() => { - const chatOptions = OptionsListUtils.getFilteredOptions( - options.reports, - options.personalDetails, - betas, - debouncedSearchTerm, - participants, - CONST.EXPENSIFY_EMAILS, - - // If we are using this component in the "Request money" flow then we pass the includeOwnedWorkspaceChats argument so that the current user - // sees the option to request money from their admin on their own Workspace Chat. - iouType === CONST.IOU.TYPE.REQUEST, - - canUseP2PDistanceRequests || !isDistanceRequest, - false, - {}, - [], - false, - {}, - [], - // We don't want the user to be able to invite individuals when they are in the "Distance request" flow for now. - // This functionality is being built here: https://github.com/Expensify/App/issues/23291 - canUseP2PDistanceRequests || !isDistanceRequest, - true, - ); - return { - recentReports: chatOptions.recentReports, - personalDetails: chatOptions.personalDetails, - userToInvite: chatOptions.userToInvite, - }; - }, [options.reports, options.personalDetails, betas, debouncedSearchTerm, participants, iouType, canUseP2PDistanceRequests, isDistanceRequest]); - - /** - * Returns the sections needed for the OptionsSelector - * - * @returns {Array} - */ - const sections = useMemo(() => { - const newSections = []; - - const formatResults = OptionsListUtils.formatSectionsFromSearchTerm( - debouncedSearchTerm, - participants, - newChatOptions.recentReports, - newChatOptions.personalDetails, - maxParticipantsReached, - personalDetails, - true, - ); - newSections.push(formatResults.section); - - if (maxParticipantsReached) { - return newSections; - } - - newSections.push({ - title: translate('common.recents'), - data: newChatOptions.recentReports, - shouldShow: newChatOptions.recentReports.length > 0, - }); - - newSections.push({ - title: translate('common.contacts'), - data: newChatOptions.personalDetails, - shouldShow: newChatOptions.personalDetails.length > 0, - }); - - if (newChatOptions.userToInvite && !OptionsListUtils.isCurrentUser(newChatOptions.userToInvite)) { - newSections.push({ - title: undefined, - data: lodashMap([newChatOptions.userToInvite], (participant) => { - const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); - return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, personalDetails); - }), - shouldShow: true, - }); - } - - return newSections; - }, [maxParticipantsReached, newChatOptions.personalDetails, newChatOptions.recentReports, newChatOptions.userToInvite, participants, personalDetails, debouncedSearchTerm, translate]); - - /** - * Adds a single participant to the request - * - * @param {Object} option - */ - const addSingleParticipant = useCallback( - (option) => { - if (participants.length) { - return; - } - onAddParticipants( - [ - { - accountID: option.accountID, - login: option.login, - isPolicyExpenseChat: option.isPolicyExpenseChat, - reportID: option.reportID, - selected: true, - searchText: option.searchText, - }, - ], - false, - ); - navigateToRequest(); - }, - [navigateToRequest, onAddParticipants, participants.length], - ); - - /** - * Removes a selected option from list if already selected. If not already selected add this option to the list. - * @param {Object} option - */ - const addParticipantToSelection = useCallback( - (option) => { - const isOptionSelected = (selectedOption) => { - if (selectedOption.accountID && selectedOption.accountID === option.accountID) { - return true; - } - - if (selectedOption.reportID && selectedOption.reportID === option.reportID) { - return true; - } - - return false; - }; - const isOptionInList = lodashSome(participants, isOptionSelected); - let newSelectedOptions; - - if (isOptionInList) { - newSelectedOptions = lodashReject(participants, isOptionSelected); - } else { - newSelectedOptions = [ - ...participants, - { - accountID: option.accountID, - login: option.login, - isPolicyExpenseChat: option.isPolicyExpenseChat, - reportID: option.reportID, - selected: true, - searchText: option.searchText, - }, - ]; - } - onAddParticipants(newSelectedOptions, newSelectedOptions.length !== 0); - }, - [participants, onAddParticipants], - ); - - const headerMessage = useMemo( - () => - OptionsListUtils.getHeaderMessage( - lodashGet(newChatOptions, 'personalDetails', []).length + lodashGet(newChatOptions, 'recentReports', []).length !== 0, - Boolean(newChatOptions.userToInvite), - debouncedSearchTerm.trim(), - maxParticipantsReached, - lodashSome(participants, (participant) => participant.searchText.toLowerCase().includes(debouncedSearchTerm.trim().toLowerCase())), - ), - [maxParticipantsReached, newChatOptions, participants, debouncedSearchTerm], - ); - - // Right now you can't split a request 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 show error message if you have a workspace and other participants - const hasPolicyExpenseChatParticipant = lodashSome(participants, (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 || !isDistanceRequest) && (iouType !== CONST.IOU.TYPE.SEND || iouType !== CONST.IOU.TYPE.TRACK_EXPENSE); - - const handleConfirmSelection = useCallback( - (keyEvent, option) => { - const shouldAddSingleParticipant = option && !participants.length; - - if (shouldShowSplitBillErrorMessage || (!participants.length && !option)) { - return; - } - - if (shouldAddSingleParticipant) { - addSingleParticipant(option); - return; - } - - navigateToSplit(); - }, - [shouldShowSplitBillErrorMessage, navigateToSplit, addSingleParticipant, participants.length], - ); - - const {isDismissed} = useDismissedReferralBanners({referralContentType}); - - const footerContent = useMemo(() => { - if (isDismissed && !shouldShowSplitBillErrorMessage && !participants.length) { - return null; - } - return ( - <> - {!isDismissed && ( - - )} - - {shouldShowSplitBillErrorMessage && ( - - )} - - {!!participants.length && ( -