From eb9c843ee8e474b0cd9743120bab3feb64169de7 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 14:19:28 +0700 Subject: [PATCH 1/4] fix search term is lost --- src/pages/workspace/SearchInputManager.js | 5 +++++ src/pages/workspace/WorkspaceInvitePage.js | 15 ++++++++++++++- src/pages/workspace/WorkspaceMembersPage.js | 20 +++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/pages/workspace/SearchInputManager.js diff --git a/src/pages/workspace/SearchInputManager.js b/src/pages/workspace/SearchInputManager.js new file mode 100644 index 000000000000..599f7cca6cf9 --- /dev/null +++ b/src/pages/workspace/SearchInputManager.js @@ -0,0 +1,5 @@ +// eslint-disable-next-line prefer-const +let searchInput = ''; +export default { + searchInput, +}; diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index 4bef69c82414..dfcd1e555ed7 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -21,6 +21,7 @@ import * as Policy from '@userActions/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import SearchInputManager from './SearchInputManager'; import {policyDefaultProps, policyPropTypes} from './withPolicy'; import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; @@ -75,6 +76,15 @@ function WorkspaceInvitePage(props) { Policy.openWorkspaceInvitePage(props.route.params.policyID, _.keys(policyMemberEmailsToAccountIDs)); }; + useEffect(() => { + if (!SearchInputManager.searchInput) { + return; + } + if (SearchInputManager.searchInput) { + setSearchTerm(SearchInputManager.searchInput); + } + }, []); + useEffect(() => { Policy.clearErrors(props.route.params.policyID); openWorkspaceInvitePage(); @@ -255,7 +265,10 @@ function WorkspaceInvitePage(props) { sections={sections} textInputLabel={translate('optionsSelector.nameEmailOrPhoneNumber')} textInputValue={searchTerm} - onChangeText={setSearchTerm} + onChangeText={(value) => { + SearchInputManager.searchInput = value; + setSearchTerm(value); + }} headerMessage={headerMessage} onSelectRow={toggleOption} onConfirm={inviteUser} diff --git a/src/pages/workspace/WorkspaceMembersPage.js b/src/pages/workspace/WorkspaceMembersPage.js index 09b613350705..e055afc206a0 100644 --- a/src/pages/workspace/WorkspaceMembersPage.js +++ b/src/pages/workspace/WorkspaceMembersPage.js @@ -1,3 +1,4 @@ +import {useIsFocused} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; @@ -32,6 +33,7 @@ import * as Policy from '@userActions/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import SearchInputManager from './SearchInputManager'; import {policyDefaultProps, policyPropTypes} from './withPolicy'; import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; @@ -85,6 +87,19 @@ function WorkspaceMembersPage(props) { const isOfflineAndNoMemberDataAvailable = _.isEmpty(props.policyMembers) && props.network.isOffline; const prevPersonalDetails = usePrevious(props.personalDetails); + const isFocusedScreen = useIsFocused(); + + useEffect(() => { + if (!SearchInputManager.searchInput) { + return; + } + if (SearchInputManager.searchInput) { + setSearchValue(SearchInputManager.searchInput); + } + }, [isFocusedScreen]); + + useEffect(() => () => (SearchInputManager.searchInput = ''), []); + /** * Get filtered personalDetails list with current policyMembers * @param {Object} policyMembers @@ -466,7 +481,10 @@ function WorkspaceMembersPage(props) { sections={[{data, indexOffset: 0, isDisabled: false}]} textInputLabel={props.translate('optionsSelector.findMember')} textInputValue={searchValue} - onChangeText={setSearchValue} + onChangeText={(value) => { + SearchInputManager.searchInput = value; + setSearchValue(value); + }} headerMessage={getHeaderMessage()} headerContent={getHeaderContent()} onSelectRow={(item) => toggleUser(item.accountID)} From f931e044e6bebd0468b01db477e4af47f8d94998 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 21:10:43 +0700 Subject: [PATCH 2/4] fix update based on suggestions --- src/pages/workspace/WorkspaceInvitePage.js | 4 +--- src/pages/workspace/WorkspaceMembersPage.js | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index dfcd1e555ed7..b18c234ea44d 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -80,9 +80,7 @@ function WorkspaceInvitePage(props) { if (!SearchInputManager.searchInput) { return; } - if (SearchInputManager.searchInput) { - setSearchTerm(SearchInputManager.searchInput); - } + setSearchTerm(SearchInputManager.searchInput); }, []); useEffect(() => { diff --git a/src/pages/workspace/WorkspaceMembersPage.js b/src/pages/workspace/WorkspaceMembersPage.js index e055afc206a0..d5cdbcfc69d8 100644 --- a/src/pages/workspace/WorkspaceMembersPage.js +++ b/src/pages/workspace/WorkspaceMembersPage.js @@ -93,9 +93,7 @@ function WorkspaceMembersPage(props) { if (!SearchInputManager.searchInput) { return; } - if (SearchInputManager.searchInput) { - setSearchValue(SearchInputManager.searchInput); - } + setSearchValue(SearchInputManager.searchInput); }, [isFocusedScreen]); useEffect(() => () => (SearchInputManager.searchInput = ''), []); From 7142a459f66d653c9ed609d7974402b5ef499734 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 23:41:12 +0700 Subject: [PATCH 3/4] fix clear input once rhn closed --- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index a78b38728136..6684e476b4f3 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -13,6 +13,7 @@ import type {AuthScreensParamList} from '@navigation/types'; import DemoSetupPage from '@pages/DemoSetupPage'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; import DesktopSignInRedirectPage from '@pages/signin/DesktopSignInRedirectPage'; +import SearchInputManager from '@pages/workspace/SearchInputManager'; import useThemeStyles from '@styles/useThemeStyles'; import * as App from '@userActions/App'; import * as Download from '@userActions/Download'; @@ -123,6 +124,8 @@ const modalScreenListeners = { Modal.setModalVisibility(true); }, beforeRemove: () => { + // Clear search input (WorkspaceMembersPage) when modal is closed + SearchInputManager.searchInput = ''; Modal.setModalVisibility(false); }, }; From d180ba9d9d53898397363a1cba5add7918e31e4c Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 7 Dec 2023 00:44:15 +0700 Subject: [PATCH 4/4] fix update comment --- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 6684e476b4f3..5e8a9f502dc5 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -124,7 +124,7 @@ const modalScreenListeners = { Modal.setModalVisibility(true); }, beforeRemove: () => { - // Clear search input (WorkspaceMembersPage) when modal is closed + // Clear search input (WorkspaceInvitePage) when modal is closed SearchInputManager.searchInput = ''; Modal.setModalVisibility(false); },