Skip to content

Commit 97d1af6

Browse files
committed
fix: pass correct current user id
1 parent b517321 commit 97d1af6

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

src/elements/content-sharing/__tests__/useContacts.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function FakeComponent({
3434
const [getContacts, setGetContacts] = React.useState(null);
3535

3636
const updatedGetContactsFn = useContacts(api, MOCK_ITEM_ID, {
37+
currentUserId: '123',
3738
handleSuccess,
3839
handleError,
3940
transformGroups,

src/elements/content-sharing/hooks/__tests__/useContactService.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@ describe('elements/content-sharing/hooks/useContactService', () => {
2626
jest.clearAllMocks();
2727
});
2828

29-
test('should return null contactService when currentUserID is null or undefined', () => {
30-
[null, undefined].forEach(currentUserID => {
31-
const { result } = renderHook(() => useContactService(mockApi, mockItemID, currentUserID));
32-
expect(result.current.contactService).toBeNull();
33-
});
34-
});
35-
3629
test('should return contactService with getContacts function', () => {
3730
const { result } = renderHook(() => useContactService(mockApi, mockItemID, mockCurrentUserID));
3831

3932
expect(useContacts).toHaveBeenCalledWith(mockApi, mockItemID, {
33+
currentUserId: mockCurrentUserID,
34+
isContentSharingV2Enabled: true,
4035
transformUsers: expect.any(Function),
4136
transformGroups: expect.any(Function),
4237
});
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
import * as React from 'react';
2-
31
import { convertGroupContactsResponse, convertUserContactsResponse } from '../utils';
42
import useContacts from './useContacts';
53

6-
export const useContactService = (api, itemID, currentUserId) => {
7-
const getContacts = useContacts(api, itemID, {
4+
export const useContactService = (api, itemId, currentUserId) => {
5+
const getContacts = useContacts(api, itemId, {
6+
currentUserId,
7+
isContentSharingV2Enabled: true,
88
transformUsers: data => convertUserContactsResponse(data, currentUserId),
99
transformGroups: data => convertGroupContactsResponse(data),
1010
});
1111

12-
const contactService = React.useMemo(() => {
13-
if (!currentUserId) {
14-
return null;
15-
}
16-
17-
return { getContacts };
18-
}, [currentUserId, getContacts]);
19-
20-
return { contactService };
12+
return { contactService: { getContacts } };
2113
};

src/elements/content-sharing/hooks/useContacts.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@ import type { ContentSharingHooksOptions, GetContactsFnType } from '../types';
1717
*/
1818
function useContacts(api: API, itemID: string, options: ContentSharingHooksOptions): GetContactsFnType | null {
1919
const [getContacts, setGetContacts] = React.useState<null | GetContactsFnType>(null);
20-
const { handleSuccess = noop, handleError = noop, transformGroups, transformUsers } = options;
20+
const {
21+
currentUserId,
22+
handleSuccess = noop,
23+
handleError = noop,
24+
isContentSharingV2Enabled,
25+
transformGroups,
26+
transformUsers,
27+
} = options;
2128

2229
React.useEffect(() => {
23-
if (getContacts) return;
30+
if (getContacts || (isContentSharingV2Enabled && !currentUserId)) {
31+
return;
32+
}
2433

2534
const resolveAPICall = (
2635
resolve: (result: Array<Object>) => void,
@@ -60,7 +69,17 @@ function useContacts(api: API, itemID: string, options: ContentSharingHooksOptio
6069
return Promise.all([getUsers, getGroups]).then(contactArrays => [...contactArrays[0], ...contactArrays[1]]);
6170
};
6271
setGetContacts(updatedGetContactsFn);
63-
}, [api, getContacts, handleError, handleSuccess, itemID, transformGroups, transformUsers]);
72+
}, [
73+
api,
74+
currentUserId,
75+
getContacts,
76+
handleError,
77+
handleSuccess,
78+
isContentSharingV2Enabled,
79+
itemID,
80+
transformGroups,
81+
transformUsers,
82+
]);
6483

6584
return getContacts;
6685
}

src/elements/content-sharing/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export type ContentSharingItemAPIResponse = {
9292
};
9393

9494
export type ContentSharingHooksOptions = {
95+
currentUserId?: string,
9596
handleError?: Function,
9697
handleRemoveSharedLinkError?: Function,
9798
handleRemoveSharedLinkSuccess?: Function,

0 commit comments

Comments
 (0)