From 1c5fd8323e056f1058ec17ed4c3024bdbd4c1677 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 10 Nov 2023 16:52:21 +0700 Subject: [PATCH] fix/22534-draft-proposal --- src/pages/workspace/SearchInputRef.ts | 11 +++++++++++ src/pages/workspace/WorkspaceInvitePage.js | 14 +++++++++++++- src/pages/workspace/WorkspaceMembersPage.js | 17 +++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/pages/workspace/SearchInputRef.ts diff --git a/src/pages/workspace/SearchInputRef.ts b/src/pages/workspace/SearchInputRef.ts new file mode 100644 index 000000000000..0dd54009e85c --- /dev/null +++ b/src/pages/workspace/SearchInputRef.ts @@ -0,0 +1,11 @@ +import React from 'react'; +import {TextInput} from 'react-native'; + +const searchInputRef = React.createRef(); +let onSearchInputChange: (text: string) => void = () => {}; +let searchInput: string = ''; +export default { + searchInputRef, + onSearchInputChange, + searchInput, +}; diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index ee6e2d826198..d99efd14a7dd 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 SearchInputRef from './SearchInputRef'; import {policyDefaultProps, policyPropTypes} from './withPolicy'; import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; @@ -225,6 +226,14 @@ function WorkspaceInvitePage(props) { return OptionsListUtils.getHeaderMessage(personalDetails.length !== 0, usersToInvite.length > 0, searchValue); }, [excludedUsers, translate, searchTerm, policyName, usersToInvite, personalDetails.length]); + useEffect(() => { + if (!SearchInputRef.searchInput) { + return; + } + if (SearchInputRef.searchInput) { + setSearchTerm(SearchInputRef.searchInput); + } + }, []); return ( { + SearchInputRef.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 65ec35766332..df404b79d639 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 SearchInputRef from './SearchInputRef'; import {policyDefaultProps, policyPropTypes} from './withPolicy'; import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; @@ -402,7 +404,15 @@ function WorkspaceMembersPage(props) { /> ); }; - + const isFocusedScreen = useIsFocused(); + useEffect(() => { + if (!SearchInputRef.searchInput) { + return; + } + if (SearchInputRef.searchInput) { + setSearchValue(SearchInputRef.searchInput); + } + }, [isFocusedScreen]); return ( { + SearchInputRef.searchInput = value; + setSearchValue(value); + }} headerMessage={getHeaderMessage()} headerContent={getHeaderContent()} onSelectRow={(item) => toggleUser(item.accountID)}