From 6752e493967ca128a95a8c8c9ace509c1c07189a Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Fri, 24 Jan 2025 00:53:40 +0530 Subject: [PATCH 01/14] change function name --- src/components/MenuItem.tsx | 4 ++-- src/components/PinButton.tsx | 2 +- src/components/PromotedActionsBar.tsx | 2 +- src/components/Reactions/AddReactionBubble.tsx | 2 +- src/components/Reactions/MiniQuickEmojiReactions.tsx | 4 ++-- .../Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx | 2 +- src/components/ReportActionItem/TaskPreview.tsx | 2 +- src/components/ReportActionItem/TaskView.tsx | 4 ++-- src/components/Search/SearchRouter/SearchButton.tsx | 2 +- src/components/TaskHeaderActionButton.tsx | 2 +- src/libs/HeaderUtils.ts | 2 +- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 4 ++-- src/libs/actions/Session/index.ts | 4 ++-- src/pages/FlagCommentPage.tsx | 2 +- src/pages/ProfilePage.tsx | 4 ++-- src/pages/ReportDetailsPage.tsx | 4 ++-- src/pages/home/HeaderView.tsx | 4 ++-- src/pages/workspace/WorkspacesListPage.tsx | 4 ++-- 18 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/components/MenuItem.tsx b/src/components/MenuItem.tsx index 8492f18d2512..5564041d80cd 100644 --- a/src/components/MenuItem.tsx +++ b/src/components/MenuItem.tsx @@ -15,7 +15,7 @@ import getButtonState from '@libs/getButtonState'; import Parser from '@libs/Parser'; import type {AvatarSource} from '@libs/UserUtils'; import variables from '@styles/variables'; -import {checkIfActionIsAllowed} from '@userActions/Session'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import type {Icon as IconType} from '@src/types/onyx/OnyxCommon'; import type {TooltipAnchorAlignment} from '@src/types/utils/AnchorAlignment'; @@ -611,7 +611,7 @@ function MenuItem( {(isHovered) => ( shouldBlockSelection && shouldUseNarrowLayout && canUseTouchScreen() && ControlSelection.block()} onPressOut={ControlSelection.unblock} onSecondaryInteraction={onSecondaryInteraction} diff --git a/src/components/PinButton.tsx b/src/components/PinButton.tsx index 2ae74853d571..f6b12053c976 100644 --- a/src/components/PinButton.tsx +++ b/src/components/PinButton.tsx @@ -24,7 +24,7 @@ function PinButton({report}: PinButtonProps) { return ( ReportActions.togglePinnedState(report.reportID, report.isPinned ?? false))} + onPress={Session.callFnIfActionIsAllowed(() => ReportActions.togglePinnedState(report.reportID, report.isPinned ?? false))} style={styles.touchableButtonImage} accessibilityLabel={report.isPinned ? translate('common.unPin') : translate('common.pin')} role={CONST.ROLE.BUTTON} diff --git a/src/components/PromotedActionsBar.tsx b/src/components/PromotedActionsBar.tsx index e6ce3080ee0a..de1f38eb8ec3 100644 --- a/src/components/PromotedActionsBar.tsx +++ b/src/components/PromotedActionsBar.tsx @@ -54,7 +54,7 @@ const PromotedActions = { key: CONST.PROMOTED_ACTIONS.JOIN, icon: Expensicons.ChatBubbles, text: Localize.translateLocal('common.join'), - onSelected: Session.checkIfActionIsAllowed(() => { + onSelected: Session.callFnIfActionIsAllowed(() => { Navigation.dismissModal(); ReportActions.joinRoom(report); }), diff --git a/src/components/Reactions/AddReactionBubble.tsx b/src/components/Reactions/AddReactionBubble.tsx index 8364a6658270..dce1892737ba 100644 --- a/src/components/Reactions/AddReactionBubble.tsx +++ b/src/components/Reactions/AddReactionBubble.tsx @@ -90,7 +90,7 @@ function AddReactionBubble({onSelectEmoji, reportAction, onPressOpenPicker, onWi [styles.emojiReactionBubble, styles.userSelectNone, StyleUtils.getEmojiReactionBubbleStyle(hovered || pressed, false, isContextMenu)]} - onPress={Session.checkIfActionIsAllowed(onPress)} + onPress={Session.callFnIfActionIsAllowed(onPress)} onMouseDown={(event) => { // Allow text input blur when Add reaction is right clicked if (!event || event.button === 2) { diff --git a/src/components/Reactions/MiniQuickEmojiReactions.tsx b/src/components/Reactions/MiniQuickEmojiReactions.tsx index 815736d8af76..931fddc387a4 100644 --- a/src/components/Reactions/MiniQuickEmojiReactions.tsx +++ b/src/components/Reactions/MiniQuickEmojiReactions.tsx @@ -67,7 +67,7 @@ function MiniQuickEmojiReactions({ key={emoji.name} isDelayButtonStateComplete={false} tooltipText={`:${EmojiUtils.getLocalizedEmojiName(emoji.name, preferredLocale)}:`} - onPress={Session.checkIfActionIsAllowed(() => onEmojiSelected(emoji, emojiReactions))} + onPress={Session.callFnIfActionIsAllowed(() => onEmojiSelected(emoji, emojiReactions))} > { + onPress={Session.callFnIfActionIsAllowed(() => { if (!EmojiPickerAction.emojiPickerRef.current?.isEmojiPickerVisible) { openEmojiPicker(); } else { diff --git a/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx b/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx index 87968fa38261..862d426a3bcc 100644 --- a/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx +++ b/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx @@ -35,7 +35,7 @@ function BaseQuickEmojiReactions({ onEmojiSelected(emoji, emojiReactions))} + onPress={Session.callFnIfActionIsAllowed(() => onEmojiSelected(emoji, emojiReactions))} /> diff --git a/src/components/ReportActionItem/TaskPreview.tsx b/src/components/ReportActionItem/TaskPreview.tsx index 2ea295d16143..3b3eebc158c3 100644 --- a/src/components/ReportActionItem/TaskPreview.tsx +++ b/src/components/ReportActionItem/TaskPreview.tsx @@ -108,7 +108,7 @@ function TaskPreview({taskReportID, action, contextMenuAnchor, chatReportID, che style={[styles.mr2]} isChecked={isTaskCompleted} disabled={!Task.canActionTask(taskReport, currentUserPersonalDetails.accountID, taskOwnerAccountID, taskAssigneeAccountID)} - onPress={Session.checkIfActionIsAllowed(() => { + onPress={Session.callFnIfActionIsAllowed(() => { if (isTaskCompleted) { Task.reopenTask(taskReport, taskReportID); } else { diff --git a/src/components/ReportActionItem/TaskView.tsx b/src/components/ReportActionItem/TaskView.tsx index 7901426b33e0..d60419ac0426 100644 --- a/src/components/ReportActionItem/TaskView.tsx +++ b/src/components/ReportActionItem/TaskView.tsx @@ -63,7 +63,7 @@ function TaskView({report}: TaskViewProps) { {(hovered) => ( { + onPress={Session.callFnIfActionIsAllowed((e) => { if (isDisableInteractive) { return; } @@ -87,7 +87,7 @@ function TaskView({report}: TaskViewProps) { {translate('task.title')} { + onPress={Session.callFnIfActionIsAllowed(() => { // If we're already navigating to these task editing pages, early return not to mark as completed, otherwise we would have not found page. if (TaskUtils.isActiveTaskEditRoute(report.reportID)) { return; diff --git a/src/components/Search/SearchRouter/SearchButton.tsx b/src/components/Search/SearchRouter/SearchButton.tsx index e69a11c30da2..71fdfff7f50c 100644 --- a/src/components/Search/SearchRouter/SearchButton.tsx +++ b/src/components/Search/SearchRouter/SearchButton.tsx @@ -32,7 +32,7 @@ function SearchButton({style}: SearchButtonProps) { accessibilityLabel={translate('common.search')} style={[styles.flexRow, styles.touchableButtonImage, style]} // eslint-disable-next-line react-compiler/react-compiler - onPress={Session.checkIfActionIsAllowed(() => { + onPress={Session.callFnIfActionIsAllowed(() => { pressableRef?.current?.blur(); Timing.start(CONST.TIMING.OPEN_SEARCH); diff --git a/src/components/TaskHeaderActionButton.tsx b/src/components/TaskHeaderActionButton.tsx index dd2ba54c2f6d..5859d68955d3 100644 --- a/src/components/TaskHeaderActionButton.tsx +++ b/src/components/TaskHeaderActionButton.tsx @@ -31,7 +31,7 @@ function TaskHeaderActionButton({report}: TaskHeaderActionButtonProps) { success isDisabled={!Task.canActionTask(report, session?.accountID ?? CONST.DEFAULT_NUMBER_ID)} text={translate(ReportUtils.isCompletedTaskReport(report) ? 'task.markAsIncomplete' : 'task.markAsComplete')} - onPress={Session.checkIfActionIsAllowed(() => { + onPress={Session.callFnIfActionIsAllowed(() => { // If we're already navigating to these task editing pages, early return not to mark as completed, otherwise we would have not found page. if (TaskUtils.isActiveTaskEditRoute(report.reportID)) { return; diff --git a/src/libs/HeaderUtils.ts b/src/libs/HeaderUtils.ts index b31d59804c51..0d9588015e50 100644 --- a/src/libs/HeaderUtils.ts +++ b/src/libs/HeaderUtils.ts @@ -13,7 +13,7 @@ function getPinMenuItem(report: OnyxReport): ThreeDotsMenuItem { return { icon: Expensicons.Pin, text: Localize.translateLocal(isPinned ? 'common.unPin' : 'common.pin'), - onSelected: Session.checkIfActionIsAllowed(() => Report.togglePinnedState(report.reportID, isPinned)), + onSelected: Session.callFnIfActionIsAllowed(() => Report.togglePinnedState(report.reportID, isPinned)), }; } diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 82211eabe00f..be46952c0521 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -384,7 +384,7 @@ function AuthScreens() { const unsubscribeSearchShortcut = KeyboardShortcut.subscribe( searchShortcutConfig.shortcutKey, () => { - Session.checkIfActionIsAllowed(() => { + Session.callFnIfActionIsAllowed(() => { const state = navigationRef.getRootState(); const currentFocusedRoute = findFocusedRoute(state); if (isOnboardingFlowName(currentFocusedRoute?.name)) { @@ -401,7 +401,7 @@ function AuthScreens() { const unsubscribeChatShortcut = KeyboardShortcut.subscribe( chatShortcutConfig.shortcutKey, () => { - Modal.close(Session.checkIfActionIsAllowed(() => Navigation.navigate(ROUTES.NEW))); + Modal.close(Session.callFnIfActionIsAllowed(() => Navigation.navigate(ROUTES.NEW))); }, chatShortcutConfig.descriptionKey, chatShortcutConfig.modifiers, diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index ea764c24c2ad..a699b3751e2b 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -300,7 +300,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess * @returns same callback if the action is allowed, otherwise a function that signs out and redirects to sign in */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -function checkIfActionIsAllowed any) | void>(callback: TCallback, isAnonymousAction = false): TCallback | (() => void) { +function callFnIfActionIsAllowed any) | void>(callback: TCallback, isAnonymousAction = false): TCallback | (() => void) { if (isAnonymousUser() && !isAnonymousAction) { return () => signOutAndRedirectToSignIn(); } @@ -1289,7 +1289,7 @@ export { beginAppleSignIn, beginGoogleSignIn, setSupportAuthToken, - checkIfActionIsAllowed, + callFnIfActionIsAllowed, signIn, signInWithValidateCode, handleExitToNavigation, diff --git a/src/pages/FlagCommentPage.tsx b/src/pages/FlagCommentPage.tsx index fbedd5fc6c39..86170cd90ce3 100644 --- a/src/pages/FlagCommentPage.tsx +++ b/src/pages/FlagCommentPage.tsx @@ -122,7 +122,7 @@ function FlagCommentPage({parentReportAction, route, report, parentReport, repor shouldShowRightIcon title={item.name} description={item.description} - onPress={Session.checkIfActionIsAllowed(() => flagComment(item.severity))} + onPress={Session.callFnIfActionIsAllowed(() => flagComment(item.severity))} style={[styles.pt2, styles.pb4, styles.ph5, styles.flexRow]} furtherDetails={item.furtherDetails} furtherDetailsIcon={item.furtherDetailsIcon} diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index 485d612fc5ac..7aca6b8202a0 100755 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -41,7 +41,7 @@ import type {ProfileNavigatorParamList} from '@navigation/types'; import {openExternalLink} from '@userActions/Link'; import {openPublicProfilePage} from '@userActions/PersonalDetails'; import {hasErrorInPrivateNotes} from '@userActions/Report'; -import {checkIfActionIsAllowed, isAnonymousUser as isAnonymousUserSession} from '@userActions/Session'; +import {callFnIfActionIsAllowed, isAnonymousUser as isAnonymousUserSession} from '@userActions/Session'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -302,7 +302,7 @@ function ProfilePage({route}: ProfilePageProps) { title={translate('videoChatButtonAndMenu.tooltip')} icon={Expensicons.Phone} isAnonymousAction={false} - onPress={checkIfActionIsAllowed(() => { + onPress={callFnIfActionIsAllowed(() => { openExternalLink(guideCalendarLink); })} /> diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index ac6bd0fe904d..37bb53c2127c 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -124,7 +124,7 @@ import { setDeleteTransactionNavigateBackUrl, updateGroupChatAvatar, } from '@userActions/Report'; -import {checkIfActionIsAllowed} from '@userActions/Session'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; import {canActionTask as canActionTaskAction, canModifyTask as canModifyTaskAction, deleteTask, reopenTask} from '@userActions/Task'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -512,7 +512,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta icon: Expensicons.Checkmark, translationKey: 'task.markAsIncomplete', isAnonymousAction: false, - action: checkIfActionIsAllowed(() => { + action: callFnIfActionIsAllowed(() => { Navigation.dismissModal(); reopenTask(report); }), diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index 02dffe751beb..fa061d2a09a7 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -59,7 +59,7 @@ import { } from '@libs/ReportUtils'; import FreeTrial from '@pages/settings/Subscription/FreeTrial'; import {joinRoom} from '@userActions/Report'; -import {checkIfActionIsAllowed} from '@userActions/Session'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; import {deleteTask} from '@userActions/Task'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -152,7 +152,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, const shouldShowGuideBooking = !!account && report?.reportID === account?.adminsRoomReportID && !!account?.guideDetails?.calendarLink; - const join = checkIfActionIsAllowed(() => joinRoom(report)); + const join = callFnIfActionIsAllowed(() => joinRoom(report)); const canJoin = canJoinChat(report, parentReportAction, policy); diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index acd0b158fa67..7ad40c3bb76a 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -28,7 +28,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {isConnectionInProgress} from '@libs/actions/connections'; import {clearDeleteWorkspaceError, clearErrors, deleteWorkspace, leaveWorkspace, removeWorkspace, updateDefaultPolicy} from '@libs/actions/Policy/Policy'; -import {checkIfActionIsAllowed, isSupportAuthToken} from '@libs/actions/Session'; +import {callFnIfActionIsAllowed, isSupportAuthToken} from '@libs/actions/Session'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; import localeCompare from '@libs/LocaleCompare'; import getTopmostBottomTabRoute from '@libs/Navigation/getTopmostBottomTabRoute'; @@ -203,7 +203,7 @@ function WorkspacesListPage() { threeDotsMenuItems.push({ icon: Expensicons.Exit, text: translate('common.leave'), - onSelected: checkIfActionIsAllowed(() => leaveWorkspace(item.policyID)), + onSelected: callFnIfActionIsAllowed(() => leaveWorkspace(item.policyID)), }); } From e9e2f955e562cfad23e6640ae484cfe420293f90 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Mon, 27 Jan 2025 14:35:05 +0530 Subject: [PATCH 02/14] fix type error --- src/components/ReportActionItem/TaskPreview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/TaskPreview.tsx b/src/components/ReportActionItem/TaskPreview.tsx index b1f9d89440a0..251725abcba7 100644 --- a/src/components/ReportActionItem/TaskPreview.tsx +++ b/src/components/ReportActionItem/TaskPreview.tsx @@ -20,7 +20,7 @@ import useLocalize from '@hooks/useLocalize'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import {checkIfActionIsAllowed} from '@libs/actions/Session'; +import {callFnIfActionIsAllowed} from '@libs/actions/Session'; import {canActionTask, completeTask, getTaskAssigneeAccountID, reopenTask} from '@libs/actions/Task'; import ControlSelection from '@libs/ControlSelection'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; From cc18979518f770f31aede328d367bcf094029aaa Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Mon, 27 Jan 2025 14:43:59 +0530 Subject: [PATCH 03/14] fix Namespace imports not allowed in pinbutton and promotedactionsbar --- src/components/PinButton.tsx | 6 ++--- src/components/PromotedActionsBar.tsx | 32 +++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/components/PinButton.tsx b/src/components/PinButton.tsx index f6b12053c976..6f2702252ed5 100644 --- a/src/components/PinButton.tsx +++ b/src/components/PinButton.tsx @@ -2,8 +2,8 @@ import React from 'react'; import useLocalize from '@hooks/useLocalize'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as ReportActions from '@userActions/Report'; -import * as Session from '@userActions/Session'; +import {togglePinnedState} from '@userActions/Report'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import type {Report} from '@src/types/onyx'; import Icon from './Icon'; @@ -24,7 +24,7 @@ function PinButton({report}: PinButtonProps) { return ( ReportActions.togglePinnedState(report.reportID, report.isPinned ?? false))} + onPress={callFnIfActionIsAllowed(() => togglePinnedState(report.reportID, report.isPinned ?? false))} style={styles.touchableButtonImage} accessibilityLabel={report.isPinned ? translate('common.unPin') : translate('common.pin')} role={CONST.ROLE.BUTTON} diff --git a/src/components/PromotedActionsBar.tsx b/src/components/PromotedActionsBar.tsx index de1f38eb8ec3..ebf4e4cdf891 100644 --- a/src/components/PromotedActionsBar.tsx +++ b/src/components/PromotedActionsBar.tsx @@ -3,14 +3,14 @@ import type {StyleProp, ViewStyle} from 'react-native'; import {View} from 'react-native'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as HeaderUtils from '@libs/HeaderUtils'; -import * as Localize from '@libs/Localize'; +import {getPinMenuItem, getShareMenuItem} from '@libs/HeaderUtils'; +import {translateLocal} from '@libs/Localize'; import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; import type {RootStackParamList, State} from '@libs/Navigation/types'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as ReportActions from '@userActions/Report'; -import * as Session from '@userActions/Session'; +import {changeMoneyRequestHoldStatus} from '@libs/ReportUtils'; +import {joinRoom, navigateToAndOpenReport, navigateToAndOpenReportWithAccountIDs} from '@userActions/Report'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; @@ -44,25 +44,25 @@ type PromotedActionsType = Record P const PromotedActions = { pin: (report) => ({ key: CONST.PROMOTED_ACTIONS.PIN, - ...HeaderUtils.getPinMenuItem(report), + ...getPinMenuItem(report), }), share: (report, backTo) => ({ key: CONST.PROMOTED_ACTIONS.SHARE, - ...HeaderUtils.getShareMenuItem(report, backTo), + ...getShareMenuItem(report, backTo), }), join: (report) => ({ key: CONST.PROMOTED_ACTIONS.JOIN, icon: Expensicons.ChatBubbles, - text: Localize.translateLocal('common.join'), - onSelected: Session.callFnIfActionIsAllowed(() => { + text: translateLocal('common.join'), + onSelected: callFnIfActionIsAllowed(() => { Navigation.dismissModal(); - ReportActions.joinRoom(report); + joinRoom(report); }), }), message: ({reportID, accountID, login}) => ({ key: CONST.PROMOTED_ACTIONS.MESSAGE, icon: Expensicons.CommentBubbles, - text: Localize.translateLocal('common.message'), + text: translateLocal('common.message'), onSelected: () => { if (reportID) { Navigation.dismissModal(reportID); @@ -71,18 +71,18 @@ const PromotedActions = { // The accountID might be optimistic, so we should use the login if we have it if (login) { - ReportActions.navigateToAndOpenReport([login]); + navigateToAndOpenReport([login]); return; } if (accountID) { - ReportActions.navigateToAndOpenReportWithAccountIDs([accountID]); + navigateToAndOpenReportWithAccountIDs([accountID]); } }, }), hold: ({isTextHold, reportAction, reportID, isDelegateAccessRestricted, setIsNoDelegateAccessMenuVisible, currentSearchHash}) => ({ key: CONST.PROMOTED_ACTIONS.HOLD, icon: Expensicons.Stopwatch, - text: Localize.translateLocal(`iou.${isTextHold ? 'hold' : 'unhold'}`), + text: translateLocal(`iou.${isTextHold ? 'hold' : 'unhold'}`), onSelected: () => { if (isDelegateAccessRestricted) { setIsNoDelegateAccessMenuVisible(true); // Show the menu @@ -96,11 +96,11 @@ const PromotedActions = { const topmostCentralPaneRoute = getTopmostCentralPaneRoute(navigationRef.getRootState() as State); if (topmostCentralPaneRoute?.name !== SCREENS.SEARCH.CENTRAL_PANE && isTextHold) { - ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.REPORT_WITH_ID.getRoute(targetedReportID)); + changeMoneyRequestHoldStatus(reportAction, ROUTES.REPORT_WITH_ID.getRoute(targetedReportID)); return; } - ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.SEARCH_REPORT.getRoute({reportID: targetedReportID}), currentSearchHash); + changeMoneyRequestHoldStatus(reportAction, ROUTES.SEARCH_REPORT.getRoute({reportID: targetedReportID}), currentSearchHash); }, }), } satisfies PromotedActionsType; From 06c55f497a6a620832e699ea27c49c6b33f32884 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Mon, 27 Jan 2025 14:47:12 +0530 Subject: [PATCH 04/14] fix Namespace imports not allowed in AddReactionBubble --- src/components/Reactions/AddReactionBubble.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/Reactions/AddReactionBubble.tsx b/src/components/Reactions/AddReactionBubble.tsx index dce1892737ba..91837ed03819 100644 --- a/src/components/Reactions/AddReactionBubble.tsx +++ b/src/components/Reactions/AddReactionBubble.tsx @@ -11,9 +11,9 @@ import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import getButtonState from '@libs/getButtonState'; import variables from '@styles/variables'; -import * as EmojiPickerAction from '@userActions/EmojiPickerAction'; +import {emojiPickerRef, resetEmojiPopoverAnchor, showEmojiPicker} from '@userActions/EmojiPickerAction'; import type {AnchorOrigin} from '@userActions/EmojiPickerAction'; -import * as Session from '@userActions/Session'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import type {ReportAction} from '@src/types/onyx'; import type {CloseContextMenuCallback, OpenPickerCallback, PickerRefElement} from './QuickEmojiReactions/types'; @@ -54,11 +54,11 @@ function AddReactionBubble({onSelectEmoji, reportAction, onPressOpenPicker, onWi const ref = useRef(null); const {translate} = useLocalize(); - useEffect(() => EmojiPickerAction.resetEmojiPopoverAnchor, []); + useEffect(() => resetEmojiPopoverAnchor, []); const onPress = () => { const openPicker = (refParam?: PickerRefElement, anchorOrigin?: AnchorOrigin) => { - EmojiPickerAction.showEmojiPicker( + showEmojiPicker( () => { setIsEmojiPickerActive?.(false); }, @@ -72,7 +72,7 @@ function AddReactionBubble({onSelectEmoji, reportAction, onPressOpenPicker, onWi ); }; - if (!EmojiPickerAction.emojiPickerRef.current?.isEmojiPickerVisible) { + if (!emojiPickerRef.current?.isEmojiPickerVisible) { setIsEmojiPickerActive?.(true); if (onPressOpenPicker) { onPressOpenPicker(openPicker); @@ -81,7 +81,7 @@ function AddReactionBubble({onSelectEmoji, reportAction, onPressOpenPicker, onWi } } else { setIsEmojiPickerActive?.(false); - EmojiPickerAction.emojiPickerRef.current.hideEmojiPicker(); + emojiPickerRef.current.hideEmojiPicker(); } }; @@ -90,7 +90,7 @@ function AddReactionBubble({onSelectEmoji, reportAction, onPressOpenPicker, onWi [styles.emojiReactionBubble, styles.userSelectNone, StyleUtils.getEmojiReactionBubbleStyle(hovered || pressed, false, isContextMenu)]} - onPress={Session.callFnIfActionIsAllowed(onPress)} + onPress={callFnIfActionIsAllowed(onPress)} onMouseDown={(event) => { // Allow text input blur when Add reaction is right clicked if (!event || event.button === 2) { From 8b22e031dc294461f7e3d8a7f6575406d3da9bb2 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Mon, 27 Jan 2025 14:50:21 +0530 Subject: [PATCH 05/14] fix Namespace imports not allowed in MiniQuickEmojiReactions --- .../Reactions/MiniQuickEmojiReactions.tsx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/Reactions/MiniQuickEmojiReactions.tsx b/src/components/Reactions/MiniQuickEmojiReactions.tsx index 931fddc387a4..d083254a8b3c 100644 --- a/src/components/Reactions/MiniQuickEmojiReactions.tsx +++ b/src/components/Reactions/MiniQuickEmojiReactions.tsx @@ -9,11 +9,11 @@ import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as EmojiUtils from '@libs/EmojiUtils'; +import {getLocalizedEmojiName, getPreferredEmojiCode} from '@libs/EmojiUtils'; import getButtonState from '@libs/getButtonState'; import variables from '@styles/variables'; -import * as EmojiPickerAction from '@userActions/EmojiPickerAction'; -import * as Session from '@userActions/Session'; +import {emojiPickerRef, showEmojiPicker} from '@userActions/EmojiPickerAction'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {BaseQuickEmojiReactionsOnyxProps, BaseQuickEmojiReactionsProps} from './QuickEmojiReactions/types'; @@ -48,7 +48,7 @@ function MiniQuickEmojiReactions({ const openEmojiPicker = () => { onPressOpenPicker(); - EmojiPickerAction.showEmojiPicker( + showEmojiPicker( onEmojiPickerClosed, (emojiCode, emojiObject) => { onEmojiSelected(emojiObject, emojiReactions); @@ -66,24 +66,24 @@ function MiniQuickEmojiReactions({ onEmojiSelected(emoji, emojiReactions))} + tooltipText={`:${getLocalizedEmojiName(emoji.name, preferredLocale)}:`} + onPress={callFnIfActionIsAllowed(() => onEmojiSelected(emoji, emojiReactions))} > - {EmojiUtils.getPreferredEmojiCode(emoji, preferredSkinTone)} + {getPreferredEmojiCode(emoji, preferredSkinTone)} ))} { - if (!EmojiPickerAction.emojiPickerRef.current?.isEmojiPickerVisible) { + onPress={callFnIfActionIsAllowed(() => { + if (!emojiPickerRef.current?.isEmojiPickerVisible) { openEmojiPicker(); } else { - EmojiPickerAction.emojiPickerRef.current?.hideEmojiPicker(); + emojiPickerRef.current?.hideEmojiPicker(); } })} isDelayButtonStateComplete={false} From f8e6b06d3650e64a7caaa5e0cbead83217424e81 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Mon, 27 Jan 2025 14:52:07 +0530 Subject: [PATCH 06/14] fix Namespace imports not allowed in BaseQuickEmojiReactions --- .../QuickEmojiReactions/BaseQuickEmojiReactions.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx b/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx index 862d426a3bcc..19e6c1661784 100644 --- a/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx +++ b/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx @@ -6,8 +6,8 @@ import AddReactionBubble from '@components/Reactions/AddReactionBubble'; import EmojiReactionBubble from '@components/Reactions/EmojiReactionBubble'; import Tooltip from '@components/Tooltip'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as EmojiUtils from '@libs/EmojiUtils'; -import * as Session from '@userActions/Session'; +import {getLocalizedEmojiName, getPreferredEmojiCode} from '@libs/EmojiUtils'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {BaseQuickEmojiReactionsOnyxProps, BaseQuickEmojiReactionsProps} from './types'; @@ -28,14 +28,14 @@ function BaseQuickEmojiReactions({ {CONST.QUICK_REACTIONS.map((emoji: Emoji) => ( onEmojiSelected(emoji, emojiReactions))} + onPress={callFnIfActionIsAllowed(() => onEmojiSelected(emoji, emojiReactions))} /> From 01e28c07ef94d6a81c41d3bdaf730016cebc2be6 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Mon, 27 Jan 2025 18:05:06 +0530 Subject: [PATCH 07/14] fix Namespace imports not allowed in remaining files --- src/components/ReportActionItem/TaskView.tsx | 41 +++++++++---------- .../Search/SearchRouter/SearchButton.tsx | 4 +- src/components/TaskHeaderActionButton.tsx | 24 +++++------ src/libs/HeaderUtils.ts | 6 +-- src/pages/FlagCommentPage.tsx | 16 ++++---- 5 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/components/ReportActionItem/TaskView.tsx b/src/components/ReportActionItem/TaskView.tsx index d60419ac0426..fc05993fc3dc 100644 --- a/src/components/ReportActionItem/TaskView.tsx +++ b/src/components/ReportActionItem/TaskView.tsx @@ -17,11 +17,11 @@ import useThemeStyles from '@hooks/useThemeStyles'; import convertToLTR from '@libs/convertToLTR'; import getButtonState from '@libs/getButtonState'; import Navigation from '@libs/Navigation/Navigation'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as TaskUtils from '@libs/TaskUtils'; -import * as Session from '@userActions/Session'; -import * as Task from '@userActions/Task'; +import {getAvatarsForAccountIDs, getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils'; +import {getDisplayNameForParticipant, getDisplayNamesWithTooltips, isCompletedTaskReport, isOpenTaskReport} from '@libs/ReportUtils'; +import {isActiveTaskEditRoute} from '@libs/TaskUtils'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; +import {canActionTask as canActionTaskUtil, canModifyTask as canModifyTaskUtilAction, clearTaskErrors, completeTask, reopenTask, setTaskReport} from '@userActions/Task'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {Report} from '@src/types/onyx'; @@ -37,17 +37,14 @@ function TaskView({report}: TaskViewProps) { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const personalDetails = usePersonalDetails(); useEffect(() => { - Task.setTaskReport(report); + setTaskReport(report); }, [report]); const taskTitle = convertToLTR(report.reportName ?? ''); - const assigneeTooltipDetails = ReportUtils.getDisplayNamesWithTooltips( - OptionsListUtils.getPersonalDetailsForAccountIDs(report.managerID ? [report.managerID] : [], personalDetails), - false, - ); - const isOpen = ReportUtils.isOpenTaskReport(report); - const isCompleted = ReportUtils.isCompletedTaskReport(report); - const canModifyTask = Task.canModifyTask(report, currentUserPersonalDetails.accountID); - const canActionTask = Task.canActionTask(report, currentUserPersonalDetails.accountID); + const assigneeTooltipDetails = getDisplayNamesWithTooltips(getPersonalDetailsForAccountIDs(report.managerID ? [report.managerID] : [], personalDetails), false); + const isOpen = isOpenTaskReport(report); + const isCompleted = isCompletedTaskReport(report); + const canModifyTask = canModifyTaskUtilAction(report, currentUserPersonalDetails.accountID); + const canActionTask = canActionTaskUtil(report, currentUserPersonalDetails.accountID); const disableState = !canModifyTask; const isDisableInteractive = !canModifyTask || !isOpen; const {translate} = useLocalize(); @@ -57,13 +54,13 @@ function TaskView({report}: TaskViewProps) { Task.clearTaskErrors(report.reportID)} + onClose={() => clearTaskErrors(report.reportID)} errorRowStyles={styles.ph5} > {(hovered) => ( { + onPress={callFnIfActionIsAllowed((e) => { if (isDisableInteractive) { return; } @@ -87,15 +84,15 @@ function TaskView({report}: TaskViewProps) { {translate('task.title')} { + onPress={callFnIfActionIsAllowed(() => { // If we're already navigating to these task editing pages, early return not to mark as completed, otherwise we would have not found page. - if (TaskUtils.isActiveTaskEditRoute(report.reportID)) { + if (isActiveTaskEditRoute(report.reportID)) { return; } if (isCompleted) { - Task.reopenTask(report); + reopenTask(report); } else { - Task.completeTask(report); + completeTask(report); } })} isChecked={isCompleted} @@ -148,8 +145,8 @@ function TaskView({report}: TaskViewProps) { {report.managerID ? ( { + onPress={callFnIfActionIsAllowed(() => { pressableRef?.current?.blur(); Timing.start(CONST.TIMING.OPEN_SEARCH); diff --git a/src/components/TaskHeaderActionButton.tsx b/src/components/TaskHeaderActionButton.tsx index 5859d68955d3..7c2481c5c17f 100644 --- a/src/components/TaskHeaderActionButton.tsx +++ b/src/components/TaskHeaderActionButton.tsx @@ -2,10 +2,10 @@ import React from 'react'; import {View} from 'react-native'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as TaskUtils from '@libs/TaskUtils'; -import * as Session from '@userActions/Session'; -import * as Task from '@userActions/Task'; +import {canWriteInReport, isCompletedTaskReport} from '@libs/ReportUtils'; +import {isActiveTaskEditRoute} from '@libs/TaskUtils'; +import {callFnIfActionIsAllowed} from '@userActions/Session'; +import {canActionTask, completeTask, reopenTask} from '@userActions/Task'; import CONST from '@src/CONST'; import type * as OnyxTypes from '@src/types/onyx'; import Button from './Button'; @@ -21,7 +21,7 @@ function TaskHeaderActionButton({report}: TaskHeaderActionButtonProps) { const styles = useThemeStyles(); const session = useSession(); - if (!ReportUtils.canWriteInReport(report)) { + if (!canWriteInReport(report)) { return null; } @@ -29,17 +29,17 @@ function TaskHeaderActionButton({report}: TaskHeaderActionButtonProps) {