Skip to content

Commit

Permalink
Merge pull request #32542 from DylanDylann/fix/22534-web-search-term-…
Browse files Browse the repository at this point in the history
…in-workspacememberpage-lost

Fix: Search term is lost
  • Loading branch information
rlinoz authored Dec 6, 2023
2 parents 2e8cfdb + d180ba9 commit 395830a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
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
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

0 comments on commit 395830a

Please sign in to comment.