@@ -2,7 +2,7 @@ import Column from "antd/es/table/Column";
2
2
import OrgApi from "api/orgApi" ;
3
3
import { GroupUser , MEMBER_ROLE , OrgUser } from "constants/orgConstants" ;
4
4
import { CheckBox , CustomModal , Search } from "lowcoder-design" ;
5
- import { CSSProperties , ReactNode , useEffect , useRef , useState } from "react" ;
5
+ import { CSSProperties , ReactNode , useEffect , useRef , useState , useCallback } from "react" ;
6
6
import { connect , useDispatch } from "react-redux" ;
7
7
import { AppState } from "redux/reducers" ;
8
8
import { fetchGroupUsersAction ,
@@ -17,6 +17,7 @@ import { isGroupAdmin } from "util/permissionUtils";
17
17
import { SuperUserIcon } from "lowcoder-design" ;
18
18
import { EmptyContent } from "pages/common/styledComponent" ;
19
19
import { trans } from "i18n" ;
20
+ import { debounce } from "lodash" ;
20
21
21
22
const TableWrapper = styled . div `
22
23
margin-right: -16px;
@@ -46,14 +47,21 @@ function AddGroupUserDialog(props: {
46
47
const [ searchValue , setSearchValue ] = useState ( "" )
47
48
const dispatch = useDispatch ( ) ;
48
49
50
+ const debouncedFetchPotentialMembers = useCallback (
51
+ debounce ( ( searchVal : string ) => {
52
+ dispatch ( fetchGroupPotentialMembersAction ( searchVal , groupId ) ) ;
53
+ } , 500 ) ,
54
+ [ dispatch , groupId ]
55
+ ) ;
56
+
49
57
useEffect ( ( ) => {
50
- const timer = setTimeout ( ( ) => {
51
- if ( searchValue . length > 2 || searchValue === "" )
52
- dispatch ( fetchGroupPotentialMembersAction ( searchValue , groupId ) ) ;
53
- return
54
- } , 500 ) ;
55
- return ( ) => clearTimeout ( timer ) ;
56
- } , [ searchValue ] )
58
+ if ( searchValue . length > 2 || searchValue === "" ) {
59
+ debouncedFetchPotentialMembers ( searchValue ) ;
60
+ }
61
+ return ( ) => {
62
+ debouncedFetchPotentialMembers . cancel ( ) ;
63
+ } ;
64
+ } , [ searchValue , debouncedFetchPotentialMembers ] ) ;
57
65
58
66
useEffect ( ( ) => {
59
67
if ( dialogVisible ) {
0 commit comments