From 90d4cb95fe26c793d30333493eb6816959c18573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Thu, 18 Apr 2024 09:49:01 +0100 Subject: [PATCH 1/3] Refactor codebase to use IOUType and IOUAction types --- src/CONST.ts | 4 +- .../MoneyRequestConfirmationList.tsx | 12 +- ...raryForRefactorRequestConfirmationList.tsx | 14 +- src/libs/IOUUtils.ts | 18 +- src/libs/MoneyRequestUtils.ts | 6 +- src/libs/Navigation/types.ts | 132 +++--- src/libs/ReportUtils.ts | 443 +++++++++--------- src/libs/actions/IOU.ts | 91 ++-- .../AttachmentPickerWithMenuItems.tsx | 4 +- .../step/IOURequestStepParticipants.tsx | 16 +- 10 files changed, 367 insertions(+), 373 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index a6df33987c8d..b418715ce543 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -4341,8 +4341,10 @@ const CONST = { } as const; type Country = keyof typeof CONST.ALL_COUNTRIES; + type IOUType = ValueOf; +type IOUAction = ValueOf; -export type {Country, IOUType}; +export type {Country, IOUAction, IOUType}; export default CONST; diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 4b3e4096484f..d82d81a7c47f 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -5,7 +5,6 @@ import type {StyleProp, ViewStyle} from 'react-native'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; -import type {ValueOf} from 'type-fest'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import usePermissions from '@hooks/usePermissions'; @@ -24,6 +23,7 @@ import * as ReceiptUtils from '@libs/ReceiptUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import * as IOU from '@userActions/IOU'; +import type {IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; @@ -45,8 +45,6 @@ import ShowMoreButton from './ShowMoreButton'; import Switch from './Switch'; import Text from './Text'; -type IouType = ValueOf; - type MoneyRequestConfirmationListOnyxProps = { /** Collection of categories attached to a policy */ policyCategories: OnyxEntry; @@ -71,7 +69,7 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps & onConfirm?: (selectedParticipants: Array) => void; /** Callback to parent modal to send money */ - onSendMoney?: (paymentMethod: IouType | PaymentMethodType | undefined) => void; + onSendMoney?: (paymentMethod: IOUType | PaymentMethodType | undefined) => void; /** Callback to inform a participant is selected */ onSelectParticipant?: (option: Participant) => void; @@ -89,7 +87,7 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps & iouCurrencyCode?: string; /** IOU type */ - iouType?: IouType; + iouType?: IOUType; /** IOU date */ iouCreated?: string; @@ -337,7 +335,7 @@ function MoneyRequestConfirmationList({ setDidConfirm(false); } - const splitOrRequestOptions: Array> = useMemo(() => { + const splitOrRequestOptions: Array> = useMemo(() => { let text; if (isSplitBill && iouAmount === 0) { text = translate('iou.split'); @@ -472,7 +470,7 @@ function MoneyRequestConfirmationList({ }; const confirm = useCallback( - (paymentMethod: IouType | PaymentMethodType | undefined) => { + (paymentMethod: IOUType | PaymentMethodType | undefined) => { if (!selectedParticipants.length) { return; } diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.tsx b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.tsx index d6ac31749a27..11e6eec089f7 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.tsx +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.tsx @@ -2,11 +2,10 @@ import {useIsFocused} from '@react-navigation/native'; import {format} from 'date-fns'; import Str from 'expensify-common/lib/str'; import React, {useCallback, useEffect, useMemo, useReducer, useRef, useState} from 'react'; -import {View} from 'react-native'; import type {StyleProp, ViewStyle} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; +import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import type {ValueOf} from 'type-fest'; +import {withOnyx} from 'react-native-onyx'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import usePermissions from '@hooks/usePermissions'; @@ -14,8 +13,8 @@ import usePrevious from '@hooks/usePrevious'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import * as CurrencyUtils from '@libs/CurrencyUtils'; -import DistanceRequestUtils from '@libs/DistanceRequestUtils'; import type {DefaultMileageRate} from '@libs/DistanceRequestUtils'; +import DistanceRequestUtils from '@libs/DistanceRequestUtils'; import * as IOUUtils from '@libs/IOUUtils'; import Log from '@libs/Log'; import * as MoneyRequestUtils from '@libs/MoneyRequestUtils'; @@ -29,10 +28,11 @@ import playSound, {SOUNDS} from '@libs/Sound'; import * as TransactionUtils from '@libs/TransactionUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; import * as IOU from '@userActions/IOU'; +import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; import type {Route} from '@src/ROUTES'; +import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; @@ -92,7 +92,7 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps & iouCurrencyCode?: string; /** IOU type */ - iouType?: ValueOf; + iouType?: IOUType; /** IOU date */ iouCreated?: string; @@ -162,7 +162,7 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps & reportActionID?: string; - action?: ValueOf; + action?: IOUAction; }; const getTaxAmount = (transaction: OnyxEntry, defaultTaxValue: string) => { diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index 27eff132ef40..6a2051db0ed0 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -1,5 +1,5 @@ import type {OnyxEntry} from 'react-native-onyx'; -import type {ValueOf} from 'type-fest'; +import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {Report, Transaction} from '@src/types/onyx'; @@ -8,13 +8,7 @@ import * as CurrencyUtils from './CurrencyUtils'; import Navigation from './Navigation/Navigation'; import * as TransactionUtils from './TransactionUtils'; -function navigateToStartMoneyRequestStep( - requestType: IOURequestType, - iouType: ValueOf, - transactionID: string, - reportID: string, - iouAction?: ValueOf, -): void { +function navigateToStartMoneyRequestStep(requestType: IOURequestType, iouType: IOUType, transactionID: string, reportID: string, iouAction?: IOUAction): void { if (iouAction === CONST.IOU.ACTION.CATEGORIZE || iouAction === CONST.IOU.ACTION.MOVE) { Navigation.goBack(); return; @@ -134,7 +128,7 @@ function insertTagIntoTransactionTagsString(transactionTags: string, tag: string return tagArray.join(CONST.COLON).replace(/:*$/, ''); } -function isMovingTransactionFromTrackExpense(action?: ValueOf) { +function isMovingTransactionFromTrackExpense(action?: IOUAction) { if (action === CONST.IOU.ACTION.MOVE || action === CONST.IOU.ACTION.SHARE || action === CONST.IOU.ACTION.CATEGORIZE) { return true; } @@ -144,10 +138,10 @@ function isMovingTransactionFromTrackExpense(action?: ValueOf string): st /** * Check if distance expense or not */ -function isDistanceRequest(iouType: ValueOf, selectedTab: OnyxEntry): boolean { +function isDistanceRequest(iouType: IOUType, selectedTab: OnyxEntry): boolean { return iouType === CONST.IOU.TYPE.REQUEST && selectedTab === CONST.TAB_REQUEST.DISTANCE; } @@ -91,4 +91,4 @@ function isScanRequest(selectedTab: SelectedTabRequest): boolean { return selectedTab === CONST.TAB_REQUEST.SCAN; } -export {stripCommaFromAmount, stripDecimalsFromAmount, stripSpacesFromAmount, addLeadingZero, validateAmount, replaceAllDigits, isDistanceRequest, isScanRequest}; +export {addLeadingZero, isDistanceRequest, isScanRequest, replaceAllDigits, stripCommaFromAmount, stripDecimalsFromAmount, stripSpacesFromAmount, validateAmount}; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 7dd2f274aa9e..49829f707886 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -13,7 +13,7 @@ import type { import type {ValueOf} from 'type-fest'; import type {IOURequestType} from '@libs/actions/IOU'; import type CONST from '@src/CONST'; -import type {Country} from '@src/CONST'; +import type {Country, IOUAction, IOUType} from '@src/CONST'; import type NAVIGATORS from '@src/NAVIGATORS'; import type {HybridAppRoute, Route as Routes} from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; @@ -371,39 +371,39 @@ type MoneyRequestNavigatorParamList = { reportID: string; }; [SCREENS.MONEY_REQUEST.STEP_DATE]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; backTo: Routes; }; [SCREENS.MONEY_REQUEST.STEP_DESCRIPTION]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; backTo: Routes; reportActionID: string; }; [SCREENS.MONEY_REQUEST.STEP_CATEGORY]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportActionID: string; reportID: string; backTo: Routes; }; [SCREENS.MONEY_REQUEST.STEP_TAX_AMOUNT]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; backTo: Routes; currency?: string; }; [SCREENS.MONEY_REQUEST.STEP_TAG]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; backTo: Routes; @@ -411,23 +411,23 @@ type MoneyRequestNavigatorParamList = { orderWeight: string; }; [SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; backTo: Routes; }; [SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: { - iouType: ValueOf; + iouType: IOUType; reportID: string; backTo: Routes | undefined; - action: ValueOf; + action: IOUAction; pageIndex: string; transactionID: string; }; [SCREENS.MONEY_REQUEST.STEP_MERCHANT]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; backTo: Routes; @@ -442,8 +442,8 @@ type MoneyRequestNavigatorParamList = { threadReportID: number; }; [SCREENS.MONEY_REQUEST.STEP_DISTANCE]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; backTo: Routes; @@ -453,7 +453,7 @@ type MoneyRequestNavigatorParamList = { reportID: string; }; [SCREENS.MONEY_REQUEST.CREATE]: { - iouType: ValueOf; + iouType: IOUType; reportID: string; transactionID: string; @@ -464,44 +464,44 @@ type MoneyRequestNavigatorParamList = { currency: never; }; [SCREENS.MONEY_REQUEST.START]: { - iouType: ValueOf; + iouType: IOUType; reportID: string; transactionID: string; iouRequestType: IOURequestType; }; [SCREENS.MONEY_REQUEST.STEP_AMOUNT]: { - iouType: ValueOf; + iouType: IOUType; reportID: string; transactionID: string; backTo: Routes; - action: ValueOf; + action: IOUAction; currency?: string; }; [SCREENS.MONEY_REQUEST.STEP_PARTICIPANTS]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; }; [SCREENS.MONEY_REQUEST.STEP_CONFIRMATION]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; pageIndex?: string; backTo?: string; }; [SCREENS.MONEY_REQUEST.STEP_SCAN]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; pageIndex: number; backTo: Routes; }; [SCREENS.MONEY_REQUEST.STEP_CURRENCY]: { - action: ValueOf; - iouType: ValueOf; + action: IOUAction; + iouType: IOUType; transactionID: string; reportID: string; pageIndex?: string; @@ -805,54 +805,54 @@ type SwitchPolicyIDParams = { }; export type { - NavigationRef, - StackNavigationAction, - CentralPaneNavigatorParamList, + AddPersonalBankAccountNavigatorParamList, + AuthScreensParamList, + BackToParams, BottomTabName, + BottomTabNavigatorParamList, CentralPaneName, + CentralPaneNavigatorParamList, + ChatFinderNavigatorParamList, + DetailsNavigatorParamList, + EditRequestNavigatorParamList, + EnablePaymentsNavigatorParamList, + FlagCommentNavigatorParamList, FullScreenName, - RootStackParamList, - StateOrRoute, - NavigationStateRoute, + FullScreenNavigatorParamList, + LeftModalNavigatorParamList, + MoneyRequestNavigatorParamList, NavigationPartialRoute, + NavigationRef, NavigationRoot, - AuthScreensParamList, - BottomTabNavigatorParamList, - LeftModalNavigatorParamList, - RightModalNavigatorParamList, + NavigationStateRoute, + NewChatNavigatorParamList, + NewTaskNavigatorParamList, + OnboardEngagementNavigatorParamList, OnboardingModalNavigatorParamList, - WelcomeVideoModalNavigatorParamList, - PublicScreensParamList, - MoneyRequestNavigatorParamList, - SplitDetailsNavigatorParamList, - DetailsNavigatorParamList, + ParticipantsNavigatorParamList, + PrivateNotesNavigatorParamList, ProfileNavigatorParamList, + PublicScreensParamList, + ReferralDetailsNavigatorParamList, + ReimbursementAccountNavigatorParamList, + ReportDescriptionNavigatorParamList, ReportDetailsNavigatorParamList, ReportSettingsNavigatorParamList, - TaskDetailsNavigatorParamList, - ReportDescriptionNavigatorParamList, - ParticipantsNavigatorParamList, - RoomMembersNavigatorParamList, + RightModalNavigatorParamList, RoomInviteNavigatorParamList, - ChatFinderNavigatorParamList, - NewChatNavigatorParamList, - NewTaskNavigatorParamList, - TeachersUniteNavigatorParamList, + RoomMembersNavigatorParamList, + RootStackParamList, SettingsNavigatorParamList, - EnablePaymentsNavigatorParamList, - AddPersonalBankAccountNavigatorParamList, - WalletStatementNavigatorParamList, - FlagCommentNavigatorParamList, - EditRequestNavigatorParamList, - PrivateNotesNavigatorParamList, SignInNavigatorParamList, - ReferralDetailsNavigatorParamList, - ReimbursementAccountNavigatorParamList, + SplitDetailsNavigatorParamList, + StackNavigationAction, State, - WorkspaceSwitcherNavigatorParamList, - OnboardEngagementNavigatorParamList, + StateOrRoute, SwitchPolicyIDParams, - FullScreenNavigatorParamList, + TaskDetailsNavigatorParamList, + TeachersUniteNavigatorParamList, + WalletStatementNavigatorParamList, + WelcomeVideoModalNavigatorParamList, + WorkspaceSwitcherNavigatorParamList, WorkspacesCentralPaneNavigatorParamList, - BackToParams, }; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 28a0f6b385bb..560d1eb7e72d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -13,6 +13,7 @@ import type {FileObject} from '@components/AttachmentModal'; import * as Expensicons from '@components/Icon/Expensicons'; import * as defaultGroupAvatars from '@components/Icon/GroupDefaultAvatars'; import * as defaultWorkspaceAvatars from '@components/Icon/WorkspaceDefaultAvatars'; +import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import type {ParentNavigationSummaryParams, TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -5059,7 +5060,7 @@ function isGroupChatAdmin(report: OnyxEntry, accountID: number) { * None of the options should show in chat threads or if there is some special Expensify account * as a participant of the report. */ -function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, reportParticipants: number[], canUseTrackExpense = true): Array> { +function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, reportParticipants: number[], canUseTrackExpense = true): IOUType[] { // In any thread or task report, we do not allow any new expenses yet if (isChatThread(report) || isTaskReport(report) || (!canUseTrackExpense && isSelfDM(report))) { return []; @@ -5074,7 +5075,7 @@ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry currentUserPersonalDetails?.accountID !== accountID); const hasSingleOtherParticipantInReport = otherParticipants.length === 1; - let options: Array> = []; + let options: IOUType[] = []; if (isSelfDM(report)) { options = [CONST.IOU.TYPE.TRACK_EXPENSE]; @@ -5963,7 +5964,7 @@ function getReportActionActorAccountID(reportAction: OnyxEntry, io } } -function createDraftTransactionAndNavigateToParticipantSelector(transactionID: string, reportID: string, actionName: ValueOf, reportActionID: string): void { +function createDraftTransactionAndNavigateToParticipantSelector(transactionID: string, reportID: string, actionName: IOUAction, reportActionID: string): void { const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? ([] as ReportAction[]); @@ -6024,257 +6025,257 @@ function canReportBeMentionedWithinPolicy(report: OnyxEntry, policyID: s } export { - getReportParticipantsTitle, - isReportMessageAttachment, - findLastAccessedReport, - canBeAutoReimbursed, - canEditReportAction, - canFlagReportAction, - shouldShowFlagComment, - isActionCreator, - canDeleteReportAction, - canLeaveRoom, - sortReportsByLastRead, - isDefaultRoom, - isAdminRoom, - isAdminsOnlyPostingRoom, - isAnnounceRoom, - isUserCreatedPolicyRoom, - isChatRoom, - getChatRoomSubtitle, - getParentNavigationSubtitle, - getPolicyName, - getPolicyType, - isArchivedRoom, - isClosedExpenseReportWithNoExpenses, - isExpensifyOnlyParticipantInReport, - canCreateTaskInReport, - isPolicyExpenseChatAdmin, - isPolicyAdmin, - isPublicRoom, - isPublicAnnounceRoom, - isConciergeChatReport, - isProcessingReport, - isCurrentUserTheOnlyParticipant, - hasAutomatedExpensifyAccountIDs, - hasExpensifyGuidesEmails, - requiresAttentionFromCurrentUser, - isIOUOwnedByCurrentUser, - getMoneyRequestSpendBreakdown, - canShowReportRecipientLocalTime, - formatReportLastMessageText, - chatIncludesConcierge, - isPolicyExpenseChat, - isGroupPolicy, - isPaidGroupPolicy, - isControlPolicyExpenseChat, - isControlPolicyExpenseReport, - isPaidGroupPolicyExpenseChat, - isPaidGroupPolicyExpenseReport, - getIconsForParticipants, - getIcons, - getRoomWelcomeMessage, - getDisplayNamesWithTooltips, - getReportName, - getReport, - getReportNotificationPreference, - getReportIDFromLink, - getReportPolicyID, - getRouteFromLink, - getDeletedParentActionMessageForChatReport, - getLastVisibleMessage, - navigateToDetailsPage, - generateReportID, - hasReportNameError, - isUnread, - isUnreadWithMention, - buildOptimisticWorkspaceChats, - buildOptimisticTaskReport, + addDomainToShortMention, + areAllRequestsBeingSmartScanned, + buildOptimisticAddCommentReportAction, + buildOptimisticApprovedReportAction, + buildOptimisticCancelPaymentReportAction, + buildOptimisticChangedTaskAssigneeReportAction, buildOptimisticChatReport, - buildOptimisticGroupChatReport, buildOptimisticClosedReportAction, buildOptimisticCreatedReportAction, - buildOptimisticRenamedRoomReportAction, buildOptimisticEditedTaskFieldReportAction, - buildOptimisticChangedTaskAssigneeReportAction, - buildOptimisticIOUReport, - buildOptimisticApprovedReportAction, - buildOptimisticMovedReportAction, - buildOptimisticSubmittedReportAction, buildOptimisticExpenseReport, + buildOptimisticGroupChatReport, + buildOptimisticHoldReportAction, + buildOptimisticHoldReportActionComment, + buildOptimisticIOUReport, buildOptimisticIOUReportAction, - buildOptimisticMoneyRequestEntities, - buildOptimisticReportPreview, buildOptimisticModifiedExpenseReportAction, + buildOptimisticMoneyRequestEntities, + buildOptimisticMovedReportAction, buildOptimisticMovedTrackedExpenseModifiedReportAction, - buildOptimisticCancelPaymentReportAction, - updateReportPreview, - buildOptimisticTaskReportAction, - buildOptimisticAddCommentReportAction, + buildOptimisticRenamedRoomReportAction, + buildOptimisticReportPreview, + buildOptimisticSubmittedReportAction, buildOptimisticTaskCommentReportAction, - updateOptimisticParentReportAction, - getOptimisticDataForParentReportAction, - shouldReportBeInOptionList, + buildOptimisticTaskReport, + buildOptimisticTaskReportAction, + buildOptimisticUnHoldReportAction, + buildOptimisticWorkspaceChats, + buildParticipantsFromAccountIDs, + buildTransactionThread, + canAccessReport, + canAddOrDeleteTransactions, + canBeAutoReimbursed, + canCreateRequest, + canCreateTaskInReport, + canDeleteReportAction, + canEditFieldOfMoneyRequest, + canEditMoneyRequest, + canEditPolicyDescription, + canEditReportAction, + canEditReportDescription, + canEditRoomVisibility, + canEditWriteCapability, + canFlagReportAction, + canLeavePolicyExpenseChat, + canLeaveRoom, + canReportBeMentionedWithinPolicy, + canRequestMoney, + canSeeDefaultRoom, + canShowReportRecipientLocalTime, + canUserPerformWriteAction, + chatIncludesChronos, + chatIncludesConcierge, + createDraftTransactionAndNavigateToParticipantSelector, + doesReportBelongToWorkspace, + doesTransactionThreadHaveViolations, + findLastAccessedReport, + findSelfDMReportID, + formatReportLastMessageText, + generateReportID, + getAddWorkspaceRoomOrChatReportErrors, + getAllAncestorReportActionIDs, + getAllAncestorReportActions, + getAllHeldTransactions, + getAllPolicyReports, + getAllWorkspaceReports, + getAvailableReportFields, + getBankAccountRoute, getChatByParticipants, getChatByParticipantsAndPolicy, - getAllPolicyReports, - getIOUReportActionMessage, - getDisplayNameForParticipant, - getWorkspaceIcon, - isOptimisticPersonalDetail, - shouldDisableDetailPage, - isChatReport, - isCurrentUserSubmitter, - isExpenseReport, - isExpenseRequest, - isIOUReport, - isTaskReport, - isOpenTaskReport, - isCanceledTaskReport, - isCompletedTaskReport, - isReportManager, - isReportApproved, - isMoneyRequestReport, - isMoneyRequest, - chatIncludesChronos, - getNewMarkerReportActionID, - canSeeDefaultRoom, + getChatRoomSubtitle, + getChildReportNotificationPreference, + getCommentLength, + getDefaultGroupAvatar, getDefaultWorkspaceAvatar, getDefaultWorkspaceAvatarTestID, - getCommentLength, - getParsedComment, - addDomainToShortMention, + getDeletedParentActionMessageForChatReport, + getDisplayNameForParticipant, + getDisplayNamesWithTooltips, + getGroupChatName, + getIOUReportActionDisplayMessage, + getIOUReportActionMessage, + getIcons, + getIconsForParticipants, + getIndicatedMissingPaymentMethod, + getLastUpdatedReport, + getLastVisibleMessage, getMoneyRequestOptions, - canCreateRequest, - hasIOUWaitingOnCurrentUserBankAccount, - canRequestMoney, - getWhisperDisplayNames, - getWorkspaceAvatar, - isThread, - isChatThread, - isThreadFirstChat, - isChildReport, - shouldReportShowSubscript, - isReportDataReady, - isValidReportIDFromPath, - isSettled, - isAllowedToComment, - getBankAccountRoute, - getRootParentReport, - getReportPreviewMessage, - isMoneyRequestReportPendingDeletion, - canUserPerformWriteAction, + getMoneyRequestSpendBreakdown, + getNewMarkerReportActionID, + getNonHeldAndFullAmount, + getOptimisticDataForParentReportAction, getOriginalReportID, - canAccessReport, - getAddWorkspaceRoomOrChatReportErrors, + getOutstandingChildRequest, + getParentNavigationSubtitle, + getParsedComment, + getParticipantAccountIDs, + getParticipants, + getPayeeName, + getPendingChatMembers, + getPersonalDetailsForAccountID, + getPolicyDescriptionText, + getPolicyName, + getPolicyType, + getReimbursementDeQueuedActionMessage, + getReimbursementQueuedActionMessage, + getReport, + getReportActionActorAccountID, + getReportDescriptionText, + getReportFieldKey, + getReportIDFromLink, + getReportName, + getReportNotificationPreference, getReportOfflinePendingActionAndErrors, - isDM, - isSelfDM, - getWorkspaceChats, - getAllWorkspaceReports, - shouldDisableRename, - hasSingleParticipant, + getReportParticipantsTitle, + getReportPolicyID, + getReportPreviewMessage, getReportRecipientAccountIDs, - isOneOnOneChat, - isOneTransactionThread, - isPayer, - goBackToDetailsPage, - getTransactionReportName, - getTransactionDetails, + getRoom, + getRoomWelcomeMessage, + getRootParentReport, + getRouteFromLink, getTaskAssigneeChatOnyxData, - canEditMoneyRequest, - canEditFieldOfMoneyRequest, - buildTransactionThread, - areAllRequestsBeingSmartScanned, + getTransactionDetails, + getTransactionReportName, getTransactionsWithReceipts, - hasOnlyTransactionsWithPendingRoutes, - hasNonReimbursableTransactions, - hasMissingSmartscanFields, - getIOUReportActionDisplayMessage, - isWaitingForAssigneeToCompleteTask, - isDeprecatedGroupDM, - isOpenExpenseReport, - shouldUseFullTitleToDisplay, - parseReportRouteParams, - getReimbursementQueuedActionMessage, - getReimbursementDeQueuedActionMessage, - getPersonalDetailsForAccountID, - getRoom, - canEditReportDescription, - doesTransactionThreadHaveViolations, - shouldDisplayTransactionThreadViolations, - hasViolations, - navigateToPrivateNotes, - canEditWriteCapability, - isHoldCreator, + getUserDetailTooltipText, + getVisibleChatMemberAccountIDs, + getWhisperDisplayNames, + getWorkspaceAvatar, + getWorkspaceChats, + getWorkspaceIcon, + goBackToDetailsPage, + hasActionsWithErrors, + hasAutomatedExpensifyAccountIDs, + hasExpensifyGuidesEmails, hasHeldExpenses, + hasIOUWaitingOnCurrentUserBankAccount, + hasMissingPaymentMethod, + hasMissingSmartscanFields, + hasNonReimbursableTransactions, hasOnlyHeldExpenses, - getNonHeldAndFullAmount, + hasOnlyTransactionsWithPendingRoutes, + hasReportNameError, + hasSingleParticipant, hasSmartscanError, - shouldAutoFocusOnKeyPress, - buildOptimisticHoldReportAction, - buildOptimisticHoldReportActionComment, - buildOptimisticUnHoldReportAction, - shouldDisplayThreadReplies, - shouldDisableThread, - getUserDetailTooltipText, - doesReportBelongToWorkspace, - getChildReportNotificationPreference, - getAllAncestorReportActions, - isReportParticipant, - isValidReport, - getReportDescriptionText, - isReportFieldOfTypeTitle, - hasMissingPaymentMethod, - isIOUReportUsingReport, hasUpdatedTotal, + hasViolations, + isActionCreator, + isAdminRoom, + isAdminsOnlyPostingRoom, + isAllowedToApproveExpenseReport, + isAllowedToComment, + isAllowedToSubmitDraftExpenseReport, + isAnnounceRoom, + isArchivedRoom, + isCanceledTaskReport, + isChatReport, + isChatRoom, + isChatThread, + isChildReport, + isClosedExpenseReportWithNoExpenses, + isCompletedTaskReport, + isConciergeChatReport, + isControlPolicyExpenseChat, + isControlPolicyExpenseReport, + isCurrentUserSubmitter, + isCurrentUserTheOnlyParticipant, + isDM, + isDefaultRoom, + isDeprecatedGroupDM, + isExpenseReport, + isExpenseRequest, + isExpensifyOnlyParticipantInReport, + isGroupChat, + isGroupChatAdmin, + isGroupPolicy, + isHoldCreator, + isIOUOwnedByCurrentUser, + isIOUReport, + isIOUReportUsingReport, + isJoinRequestInAdminRoom, + isMoneyRequest, + isMoneyRequestReport, + isMoneyRequestReportPendingDeletion, + isOneOnOneChat, + isOneTransactionThread, + isOpenExpenseReport, + isOpenTaskReport, + isOptimisticPersonalDetail, + isPaidGroupPolicy, + isPaidGroupPolicyExpenseChat, + isPaidGroupPolicyExpenseReport, + isPayer, + isPolicyAdmin, + isPolicyExpenseChat, + isPolicyExpenseChatAdmin, + isProcessingReport, + isPublicAnnounceRoom, + isPublicRoom, + isReportApproved, + isReportDataReady, isReportFieldDisabled, - getAvailableReportFields, + isReportFieldOfTypeTitle, + isReportManager, + isReportMessageAttachment, isReportOwner, - getReportFieldKey, + isReportParticipant, + isSelfDM, + isSettled, + isTaskReport, + isThread, + isThreadFirstChat, + isTrackExpenseReport, + isUnread, + isUnreadWithMention, + isUserCreatedPolicyRoom, + isValidReport, + isValidReportIDFromPath, + isWaitingForAssigneeToCompleteTask, + navigateToDetailsPage, + navigateToPrivateNotes, + parseReportRouteParams, reportFieldsEnabled, - getAllAncestorReportActionIDs, - getPendingChatMembers, - canEditRoomVisibility, - canEditPolicyDescription, - getPolicyDescriptionText, - getDefaultGroupAvatar, - isAllowedToSubmitDraftExpenseReport, - isAllowedToApproveExpenseReport, - findSelfDMReportID, - getIndicatedMissingPaymentMethod, - isJoinRequestInAdminRoom, - canAddOrDeleteTransactions, + requiresAttentionFromCurrentUser, + shouldAutoFocusOnKeyPress, shouldCreateNewMoneyRequestReport, - getLastUpdatedReport, - isGroupChat, - isTrackExpenseReport, - hasActionsWithErrors, - createDraftTransactionAndNavigateToParticipantSelector, - getReportActionActorAccountID, - getGroupChatName, - canLeavePolicyExpenseChat, - getOutstandingChildRequest, - getVisibleChatMemberAccountIDs, - getParticipantAccountIDs, - getParticipants, - isGroupChatAdmin, - buildParticipantsFromAccountIDs, - canReportBeMentionedWithinPolicy, - getAllHeldTransactions, - getPayeeName, + shouldDisableDetailPage, + shouldDisableRename, + shouldDisableThread, + shouldDisplayThreadReplies, + shouldDisplayTransactionThreadViolations, + shouldReportBeInOptionList, + shouldReportShowSubscript, + shouldShowFlagComment, + shouldUseFullTitleToDisplay, + sortReportsByLastRead, + updateOptimisticParentReportAction, + updateReportPreview, }; export type { - ExpenseOriginalMessage, - OptionData, - OptimisticChatReport, + Ancestor, DisplayNameWithTooltips, - OptimisticTaskReportAction, + ExpenseOriginalMessage, OptimisticAddCommentReportAction, - OptimisticCreatedReportAction, + OptimisticChatReport, OptimisticClosedReportAction, - Ancestor, + OptimisticCreatedReportAction, OptimisticIOUReportAction, + OptimisticTaskReportAction, + OptionData, TransactionDetails, }; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 83caa65e1d77..0c8306cd9d54 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2,8 +2,8 @@ import type {ParamListBase, StackNavigationState} from '@react-navigation/native import {format} from 'date-fns'; import fastMerge from 'expensify-common/lib/fastMerge'; import Str from 'expensify-common/lib/str'; -import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import ReceiptGeneric from '@assets/images/receipt-generic.png'; import * as API from '@libs/API'; @@ -40,12 +40,13 @@ import Permissions from '@libs/Permissions'; import * as PhoneNumber from '@libs/PhoneNumber'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; -import * as ReportUtils from '@libs/ReportUtils'; import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, TransactionDetails} from '@libs/ReportUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import * as UserUtils from '@libs/UserUtils'; import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import type {NavigationPartialRoute} from '@navigation/types'; +import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -377,7 +378,7 @@ function updateMoneyRequestTypeParams(routes: StackNavigationState, reportID: string, requestType?: IOURequestType) { +function startMoneyRequest(iouType: IOUType, reportID: string, requestType?: IOURequestType) { clearMoneyRequest(CONST.IOU.OPTIMISTIC_TRANSACTION_ID); switch (requestType) { case CONST.IOU.REQUEST_TYPE.MANUAL: @@ -2782,7 +2783,7 @@ function requestMoney( policyTagList?: OnyxEntry, policyCategories?: OnyxEntry, gpsPoints?: GPSPoint, - action?: ValueOf, + action?: IOUAction, actionableWhisperReportActionID?: string, linkedTrackedExpenseReportAction?: OnyxTypes.ReportAction, linkedTrackedExpenseReportID?: string, @@ -2924,7 +2925,7 @@ function trackExpense( policyCategories?: OnyxEntry, gpsPoints?: GPSPoint, validWaypoints?: WaypointCollection, - action?: ValueOf, + action?: IOUAction, actionableWhisperReportActionID?: string, linkedTrackedExpenseReportAction?: OnyxTypes.ReportAction, linkedTrackedExpenseReportID?: string, @@ -5971,7 +5972,7 @@ function navigateToStartStepIfScanFileCannotBeRead( receiptPath: ReceiptSource | undefined, onSuccess: (file: File) => void, requestType: IOURequestType, - iouType: ValueOf, + iouType: IOUType, transactionID: string, reportID: string, receiptType: string | undefined, @@ -5996,67 +5997,67 @@ function savePreferredPaymentMethod(policyID: string, paymentMethod: PaymentMeth Onyx.merge(`${ONYXKEYS.NVP_LAST_PAYMENT_METHOD}`, {[policyID]: paymentMethod}); } -export type {GPSPoint as GpsPoint, IOURequestType}; export { - setMoneyRequestParticipants, + approveMoneyRequest, + canApproveIOU, + canIOUBePaid, + cancelPayment, + clearMoneyRequest, + completeSplitBill, createDistanceRequest, + createDraftTransaction, deleteMoneyRequest, deleteTrackExpense, - splitBill, - splitBillAndOpenReport, - setDraftSplitTransaction, - startSplitBill, - completeSplitBill, + detachReceipt, + editMoneyRequest, + initMoneyRequest, + navigateToStartStepIfScanFileCannotBeRead, + payMoneyRequest, + putOnHold, + replaceReceipt, requestMoney, + resetMoneyRequestInfo, + savePreferredPaymentMethod, sendMoneyElsewhere, - approveMoneyRequest, - submitReport, - payMoneyRequest, sendMoneyWithWallet, - initMoneyRequest, - startMoneyRequest, - resetMoneyRequestInfo, - clearMoneyRequest, - updateMoneyRequestTypeParams, + setDraftSplitTransaction, + setMoneyRequestAmount, setMoneyRequestAmount_temporaryForRefactor, + setMoneyRequestBillable, setMoneyRequestBillable_temporaryForRefactor, + setMoneyRequestCategory, setMoneyRequestCreated, + setMoneyRequestCurrency, setMoneyRequestCurrency_temporaryForRefactor, setMoneyRequestDescription, - setMoneyRequestParticipants_temporaryForRefactor, - setMoneyRequestPendingFields, - setMoneyRequestReceipt, - setMoneyRequestAmount, - setMoneyRequestBillable, - setMoneyRequestCategory, - setMoneyRequestCurrency, setMoneyRequestId, setMoneyRequestMerchant, + setMoneyRequestParticipants, setMoneyRequestParticipantsFromReport, + setMoneyRequestParticipants_temporaryForRefactor, + setMoneyRequestPendingFields, + setMoneyRequestReceipt, setMoneyRequestTag, setMoneyRequestTaxAmount, setMoneyRequestTaxRate, setShownHoldUseExplanation, - updateMoneyRequestDate, + splitBill, + splitBillAndOpenReport, + startMoneyRequest, + startSplitBill, + submitReport, + trackExpense, + unholdRequest, + updateMoneyRequestAmountAndCurrency, updateMoneyRequestBillable, + updateMoneyRequestCategory, + updateMoneyRequestDate, + updateMoneyRequestDescription, + updateMoneyRequestDistance, updateMoneyRequestMerchant, updateMoneyRequestTag, updateMoneyRequestTaxAmount, updateMoneyRequestTaxRate, - updateMoneyRequestDistance, - updateMoneyRequestCategory, - updateMoneyRequestAmountAndCurrency, - updateMoneyRequestDescription, - replaceReceipt, - detachReceipt, - editMoneyRequest, - putOnHold, - unholdRequest, - cancelPayment, - navigateToStartStepIfScanFileCannotBeRead, - savePreferredPaymentMethod, - trackExpense, - canIOUBePaid, - canApproveIOU, - createDraftTransaction, + updateMoneyRequestTypeParams, }; +export type {GPSPoint as GpsPoint, IOURequestType}; diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index ab24c6667ad4..1294d2ca8aea 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -3,7 +3,6 @@ import React, {useCallback, useEffect, useMemo} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; -import type {ValueOf} from 'type-fest'; import type {FileObject} from '@components/AttachmentModal'; import AttachmentPicker from '@components/AttachmentPicker'; import Icon from '@components/Icon'; @@ -23,11 +22,12 @@ import * as ReportUtils from '@libs/ReportUtils'; import * as IOU from '@userActions/IOU'; import * as Report from '@userActions/Report'; import * as Task from '@userActions/Task'; +import type {IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; -type MoneyRequestOptions = Record, PopoverMenuItem>; +type MoneyRequestOptions = Record; type AttachmentPickerWithMenuItemsOnyxProps = { /** The policy tied to the report */ diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index 125c2a93b8a1..ff4c715223c1 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -2,36 +2,34 @@ import {useNavigation} from '@react-navigation/native'; import lodashIsEqual from 'lodash/isEqual'; import React, {useCallback, useEffect, useMemo, useRef} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; -import type {ValueOf} from 'type-fest'; import useLocalize from '@hooks/useLocalize'; 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 * as IOU from '@userActions/IOU'; +import type {IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {Transaction} from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; import StepScreenWrapper from './StepScreenWrapper'; -import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNotFound'; -import withWritableReportOrNotFound from './withWritableReportOrNotFound'; +import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; +import withWritableReportOrNotFound from './withWritableReportOrNotFound'; type IOURequestStepParticipantsOnyxProps = { /** The transaction object being modified in Onyx */ transaction: OnyxEntry; }; -type IOUValueType = ValueOf; - type IOURequestStepParticipantsProps = IOURequestStepParticipantsOnyxProps & WithWritableReportOrNotFoundProps & WithFullTransactionOrNotFoundProps; -type IOURef = IOUValueType | null; +type IOURef = IOUType | null; function IOURequestStepParticipants({ route: { @@ -100,7 +98,7 @@ function IOURequestStepParticipants({ }, [participants, updateRouteParams]); const addParticipant = useCallback( - (val: Participant[], selectedIouType: IOUValueType) => { + (val: Participant[], selectedIouType: IOUType) => { const isSplit = selectedIouType === CONST.IOU.TYPE.SPLIT; // It's only possible to switch between REQUEST and SPLIT. // We want to update the IOU type only if it's not updated yet to prevent unnecessary updates. @@ -136,9 +134,9 @@ function IOURequestStepParticipants({ ); const goToNextStep = useCallback( - (selectedIouType: IOUValueType) => { + (selectedIouType: IOUType) => { const isSplit = selectedIouType === CONST.IOU.TYPE.SPLIT; - let nextStepIOUType: IOUValueType = CONST.IOU.TYPE.REQUEST; + let nextStepIOUType: IOUType = CONST.IOU.TYPE.REQUEST; if (isSplit && iouType !== CONST.IOU.TYPE.REQUEST) { nextStepIOUType = CONST.IOU.TYPE.SPLIT; From 7935c670ed484771b69b5d0ca0e80b0f3d77dbcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Thu, 18 Apr 2024 10:59:53 +0100 Subject: [PATCH 2/3] Reduce string unions on ROUTES.ts --- src/ROUTES.ts | 99 ++++++++++++--------------- src/components/MoneyRequestHeader.tsx | 6 +- 2 files changed, 50 insertions(+), 55 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 7d73d8e55503..bd9454e38c7b 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -1,5 +1,6 @@ import type {ValueOf} from 'type-fest'; import type CONST from './CONST'; +import type {IOUAction, IOUType} from './CONST'; import type {IOURequestType} from './libs/actions/IOU'; import type AssertTypesNotEqual from './types/utils/AssertTypesNotEqual'; @@ -205,7 +206,7 @@ const ROUTES = { EDIT_REQUEST: { route: 'r/:threadReportID/edit/:field/:tagIndex?', getRoute: (threadReportID: string, field: ValueOf, tagIndex?: number) => - `r/${threadReportID}/edit/${field}${typeof tagIndex === 'number' ? `/${tagIndex}` : ''}` as const, + `r/${threadReportID}/edit/${field as string}${typeof tagIndex === 'number' ? `/${tagIndex}` : ''}` as const, }, EDIT_CURRENCY_REQUEST: { route: 'r/:threadReportID/edit/currency', @@ -274,7 +275,7 @@ const ROUTES = { EDIT_SPLIT_BILL: { route: `r/:reportID/split/:reportActionID/edit/:field/:tagIndex?`, getRoute: (reportID: string, reportActionID: string, field: ValueOf, tagIndex?: number) => - `r/${reportID}/split/${reportActionID}/edit/${field}${typeof tagIndex === 'number' ? `/${tagIndex}` : ''}` as const, + `r/${reportID}/split/${reportActionID}/edit/${field as string}${typeof tagIndex === 'number' ? `/${tagIndex}` : ''}` as const, }, TASK_TITLE: { route: 'r/:reportID/title', @@ -306,122 +307,112 @@ const ROUTES = { }, MONEY_REQUEST_PARTICIPANTS: { route: ':iouType/new/participants/:reportID?', - getRoute: (iouType: string, reportID = '') => `${iouType}/new/participants/${reportID}` as const, + getRoute: (iouType: IOUType, reportID = '') => `${iouType}/new/participants/${reportID}` as const, }, MONEY_REQUEST_HOLD_REASON: { - route: ':iouType/edit/reason/:transactionID?', - getRoute: (iouType: string, transactionID: string, reportID: string, backTo: string) => `${iouType}/edit/reason/${transactionID}?backTo=${backTo}&reportID=${reportID}` as const, + route: ':type/edit/reason/:transactionID?', + getRoute: (type: ValueOf, transactionID: string, reportID: string, backTo: string) => `${type}/edit/reason/${transactionID}?backTo=${backTo}&reportID=${reportID}` as const, }, MONEY_REQUEST_MERCHANT: { route: ':iouType/new/merchant/:reportID?', - getRoute: (iouType: string, reportID = '') => `${iouType}/new/merchant/${reportID}` as const, + getRoute: (iouType: IOUType, reportID = '') => `${iouType}/new/merchant/${reportID}` as const, }, MONEY_REQUEST_RECEIPT: { route: ':iouType/new/receipt/:reportID?', - getRoute: (iouType: string, reportID = '') => `${iouType}/new/receipt/${reportID}` as const, + getRoute: (iouType: IOUType, reportID = '') => `${iouType}/new/receipt/${reportID}` as const, }, MONEY_REQUEST_CREATE: { route: ':action/:iouType/start/:transactionID/:reportID', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string) => - `${action}/${iouType}/start/${transactionID}/${reportID}` as const, + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `${action as string}/${iouType as string}/start/${transactionID}/${reportID}` as const, }, MONEY_REQUEST_STEP_CONFIRMATION: { route: ':action/:iouType/confirmation/:transactionID/:reportID', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string) => - `${action}/${iouType}/confirmation/${transactionID}/${reportID}` as const, + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => + `${action as string}/${iouType as string}/confirmation/${transactionID}/${reportID}` as const, }, MONEY_REQUEST_STEP_AMOUNT: { route: ':action/:iouType/amount/:transactionID/:reportID', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/amount/${transactionID}/${reportID}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/amount/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_TAX_RATE: { route: ':action/:iouType/taxRate/:transactionID/:reportID?', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/taxRate/${transactionID}/${reportID}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/taxRate/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_TAX_AMOUNT: { route: ':action/:iouType/taxAmount/:transactionID/:reportID?', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/taxAmount/${transactionID}/${reportID}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/taxAmount/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_CATEGORY: { route: ':action/:iouType/category/:transactionID/:reportID/:reportActionID?', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '', reportActionID?: string) => - getUrlWithBackToParam(`${action}/${iouType}/category/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '', reportActionID?: string) => + getUrlWithBackToParam(`${action as string}/${iouType as string}/category/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), }, MONEY_REQUEST_STEP_CURRENCY: { route: ':action/:iouType/currency/:transactionID/:reportID/:pageIndex?', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, pageIndex = '', currency = '', backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/currency/${transactionID}/${reportID}/${pageIndex}?currency=${currency}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, pageIndex = '', currency = '', backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/currency/${transactionID}/${reportID}/${pageIndex}?currency=${currency}`, backTo), }, MONEY_REQUEST_STEP_DATE: { route: ':action/:iouType/date/:transactionID/:reportID', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/date/${transactionID}/${reportID}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/date/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_DESCRIPTION: { route: ':action/:iouType/description/:transactionID/:reportID/:reportActionID?', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '', reportActionID?: string) => - getUrlWithBackToParam(`${action}/${iouType}/description/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '', reportActionID?: string) => + getUrlWithBackToParam(`${action as string}/${iouType as string}/description/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), }, MONEY_REQUEST_STEP_DISTANCE: { route: ':action/:iouType/distance/:transactionID/:reportID', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/distance/${transactionID}/${reportID}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/distance/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_MERCHANT: { route: ':action/:iouType/merchant/:transactionID/:reportID', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/merchant/${transactionID}/${reportID}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/merchant/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_PARTICIPANTS: { route: ':action/:iouType/participants/:transactionID/:reportID', - getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '', action: ValueOf = 'create') => - getUrlWithBackToParam(`${action}/${iouType}/participants/${transactionID}/${reportID}`, backTo), + getRoute: (iouType: IOUType, transactionID: string, reportID: string, backTo = '', action: IOUAction = 'create') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/participants/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_SCAN: { route: ':action/:iouType/scan/:transactionID/:reportID', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/scan/${transactionID}/${reportID}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/scan/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_TAG: { route: ':action/:iouType/tag/:orderWeight/:transactionID/:reportID/:reportActionID?', - getRoute: ( - action: ValueOf, - iouType: ValueOf, - orderWeight: number, - transactionID: string, - reportID: string, - backTo = '', - reportActionID?: string, - ) => getUrlWithBackToParam(`${action}/${iouType}/tag/${orderWeight}/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, orderWeight: number, transactionID: string, reportID: string, backTo = '', reportActionID?: string) => + getUrlWithBackToParam(`${action as string}/${iouType as string}/tag/${orderWeight}/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), }, MONEY_REQUEST_STEP_WAYPOINT: { route: ':action/:iouType/waypoint/:transactionID/:reportID/:pageIndex', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID?: string, pageIndex = '', backTo = '') => - getUrlWithBackToParam(`${action}/${iouType}/waypoint/${transactionID}/${reportID}/${pageIndex}`, backTo), + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID?: string, pageIndex = '', backTo = '') => + getUrlWithBackToParam(`${action as string}/${iouType as string}/waypoint/${transactionID}/${reportID}/${pageIndex}`, backTo), }, // This URL is used as a redirect to one of the create tabs below. This is so that we can message users with a link // straight to those flows without needing to have optimistic transaction and report IDs. MONEY_REQUEST_START: { route: 'start/:iouType/:iouRequestType', - getRoute: (iouType: ValueOf, iouRequestType: IOURequestType) => `start/${iouType}/${iouRequestType}` as const, + getRoute: (iouType: IOUType, iouRequestType: IOURequestType) => `start/${iouType as string}/${iouRequestType}` as const, }, MONEY_REQUEST_CREATE_TAB_DISTANCE: { route: ':action/:iouType/start/:transactionID/:reportID/distance', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string) => - `create/${iouType}/start/${transactionID}/${reportID}/distance` as const, + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `create/${iouType as string}/start/${transactionID}/${reportID}/distance` as const, }, MONEY_REQUEST_CREATE_TAB_MANUAL: { route: ':action/:iouType/start/:transactionID/:reportID/manual', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string) => - `${action}/${iouType}/start/${transactionID}/${reportID}/manual` as const, + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => + `${action as string}/${iouType as string}/start/${transactionID}/${reportID}/manual` as const, }, MONEY_REQUEST_CREATE_TAB_SCAN: { route: ':action/:iouType/start/:transactionID/:reportID/scan', - getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string) => - `create/${iouType}/start/${transactionID}/${reportID}/scan` as const, + getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `create/${iouType as string}/start/${transactionID}/${reportID}/scan` as const, }, MONEY_REQUEST_STATE_SELECTOR: { @@ -654,7 +645,7 @@ const ROUTES = { WORKSPACE_OWNER_CHANGE_CHECK: { route: 'settings/workspaces/:policyID/change-owner/:accountID/:error', getRoute: (policyID: string, accountID: number, error: ValueOf) => - `settings/workspaces/${policyID}/change-owner/${accountID}/${error}` as const, + `settings/workspaces/${policyID}/change-owner/${accountID}/${error as string}` as const, }, WORKSPACE_TAX_CREATE: { route: 'settings/workspaces/:policyID/taxes/new', @@ -742,7 +733,7 @@ const HYBRID_APP_ROUTES = { MONEY_REQUEST_CREATE: '/request/new/scan', } as const; -export {getUrlWithBackToParam, HYBRID_APP_ROUTES}; +export {HYBRID_APP_ROUTES, getUrlWithBackToParam}; export default ROUTES; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -762,4 +753,4 @@ type RouteIsPlainString = AssertTypesNotEqual Date: Thu, 18 Apr 2024 11:32:24 +0100 Subject: [PATCH 3/3] Fix prettier --- src/ROUTES.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index bd9454e38c7b..69bf075adcf7 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -311,7 +311,8 @@ const ROUTES = { }, MONEY_REQUEST_HOLD_REASON: { route: ':type/edit/reason/:transactionID?', - getRoute: (type: ValueOf, transactionID: string, reportID: string, backTo: string) => `${type}/edit/reason/${transactionID}?backTo=${backTo}&reportID=${reportID}` as const, + getRoute: (type: ValueOf, transactionID: string, reportID: string, backTo: string) => + `${type}/edit/reason/${transactionID}?backTo=${backTo}&reportID=${reportID}` as const, }, MONEY_REQUEST_MERCHANT: { route: ':iouType/new/merchant/:reportID?',