Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Search term is lost #32542

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -123,6 +124,8 @@ const modalScreenListeners = {
Modal.setModalVisibility(true);
},
beforeRemove: () => {
// Clear search input (WorkspaceInvitePage) when modal is closed
SearchInputManager.searchInput = '';
Modal.setModalVisibility(false);
},
};
Expand Down
5 changes: 5 additions & 0 deletions src/pages/workspace/SearchInputManager.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for reference

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// eslint-disable-next-line prefer-const
let searchInput = '';
export default {
searchInput,
};
13 changes: 12 additions & 1 deletion src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -75,6 +76,13 @@ function WorkspaceInvitePage(props) {
Policy.openWorkspaceInvitePage(props.route.params.policyID, _.keys(policyMemberEmailsToAccountIDs));
};

useEffect(() => {
if (!SearchInputManager.searchInput) {
return;
}
setSearchTerm(SearchInputManager.searchInput);
}, []);

useEffect(() => {
Policy.clearErrors(props.route.params.policyID);
openWorkspaceInvitePage();
Expand Down Expand Up @@ -255,7 +263,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}
Expand Down
18 changes: 17 additions & 1 deletion src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -85,6 +87,17 @@ function WorkspaceMembersPage(props) {
const isOfflineAndNoMemberDataAvailable = _.isEmpty(props.policyMembers) && props.network.isOffline;
const prevPersonalDetails = usePrevious(props.personalDetails);

const isFocusedScreen = useIsFocused();

useEffect(() => {
if (!SearchInputManager.searchInput) {
return;
}
setSearchValue(SearchInputManager.searchInput);
}, [isFocusedScreen]);

useEffect(() => () => (SearchInputManager.searchInput = ''), []);

/**
* Get filtered personalDetails list with current policyMembers
* @param {Object} policyMembers
Expand Down Expand Up @@ -466,7 +479,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)}
Expand Down
Loading