@@ -4,7 +4,12 @@ import * as React from 'react';
44import noop from 'lodash/noop' ;
55import API from '../../../api' ;
66import type { UserCollection , UserMini } from '../../../common/types/core' ;
7- import type { ContactByEmailObject , ContentSharingHooksOptions , GetContactsByEmailFnType } from '../types' ;
7+ import type {
8+ ContactByEmailObject ,
9+ ContentSharingHooksOptions ,
10+ GetContactByEmailFnType ,
11+ GetContactsByEmailFnType ,
12+ } from '../types' ;
813
914/**
1015 * Generate the getContactsByEmail() function, which is used for looking up contacts added to the collaborators field in the USM.
@@ -38,41 +43,43 @@ function useContactsByEmail(
3843 return resolve ( { } ) ;
3944 } ;
4045
41- const updatedGetContactsByEmailFn : GetContactsByEmailFnType =
42- ( ) => ( filterTerm : { [ emails : string ] : string } ) => {
43- if ( ! filterTerm || ! Array . isArray ( filterTerm . emails ) || ! filterTerm . emails . length ) {
46+ if ( isContentSharingV2Enabled ) {
47+ const getContactsByEmailV2 : GetContactByEmailFnType = ( ) => email => {
48+ if ( ! email ) {
4449 return Promise . resolve ( { } ) ;
4550 }
46- const parsedFilterTerm = filterTerm . emails [ 0 ] ;
4751
48- return new Promise ( ( resolve : ( result : ContactByEmailObject | Array < UserMini > ) => void ) => {
52+ return new Promise ( resolve => {
4953 api . getMarkerBasedUsersAPI ( false ) . getUsersInEnterprise (
5054 itemID ,
51- ( response : UserCollection ) => resolveAPICall ( resolve , response , transformUsers ) ,
55+ response => resolveAPICall ( resolve , response , transformUsers ) ,
5256 handleError ,
53- { filter_term : parsedFilterTerm } ,
57+ { filter_term : email } ,
5458 ) ;
5559 } ) ;
5660 } ;
5761
58- const getContactsByEmailV2 = ( ) = > email => {
59- if ( ! email ) {
60- return Promise . resolve ( { } ) ;
61- }
62+ setGetContactsByEmail ( getContactsByEmailV2 ) ;
63+ } else {
64+ const updatedGetContactsByEmailFn : GetContactsByEmailFnType =
65+ ( ) => ( filterTerm : { [ emails : string ] : string } ) => {
66+ if ( ! filterTerm || ! Array . isArray ( filterTerm . emails ) || ! filterTerm . emails . length ) {
67+ return Promise . resolve ( { } ) ;
68+ }
69+ const parsedFilterTerm = filterTerm . emails [ 0 ] ;
6270
63- return new Promise ( resolve => {
64- api . getMarkerBasedUsersAPI ( false ) . getUsersInEnterprise (
65- itemID ,
66- response => resolveAPICall ( resolve , response , transformUsers ) ,
67- handleError ,
68- { filter_term : email } ,
69- ) ;
70- } ) ;
71- } ;
71+ return new Promise ( ( resolve : ( result : ContactByEmailObject | Array < UserMini > ) => void ) => {
72+ api. getMarkerBasedUsersAPI ( false ) . getUsersInEnterprise (
73+ itemID ,
74+ ( response : UserCollection ) => resolveAPICall ( resolve , response , transformUsers ) ,
75+ handleError ,
76+ { filter_term : parsedFilterTerm } ,
77+ ) ;
78+ } ) ;
79+ } ;
7280
73- isContentSharingV2Enabled
74- ? setGetContactsByEmail ( getContactsByEmailV2 )
75- : setGetContactsByEmail ( updatedGetContactsByEmailFn ) ;
81+ setGetContactsByEmail ( updatedGetContactsByEmailFn ) ;
82+ }
7683 } , [ api , getContactsByEmail , handleError , handleSuccess , isContentSharingV2Enabled , itemID , transformUsers ] ) ;
7784
7885 return getContactsByEmail ;
0 commit comments