Skip to content

Commit

Permalink
feat: add get member by id
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallah75 committed Jun 17, 2021
1 parent 10c9445 commit 228cd3c
Show file tree
Hide file tree
Showing 3 changed files with 675 additions and 87 deletions.
2 changes: 2 additions & 0 deletions src/config/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const buildItemKey = (id: UUID) => [ITEMS_KEY, id];
export const buildItemChildrenKey = (id: UUID) => [ITEMS_KEY, id, 'children'];
export const SHARED_ITEMS_KEY = 'shared';
export const CURRENT_MEMBER_KEY = 'currentMember';
export const MEMBERS_KEY = 'members';
export const buildMemberKey = (id: UUID) => [MEMBERS_KEY, id];
export const buildItemParentsKey = (id: UUID) => [ITEMS_KEY, id, 'parents'];

export const getKeyForParentId = (parentId: UUID | null) =>
Expand Down
14 changes: 11 additions & 3 deletions src/hooks/member.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useQuery } from 'react-query';
import { Map } from 'immutable';
import * as Api from '../api';
import { CURRENT_MEMBER_KEY } from '../config/keys';
import { QueryClientConfig } from '../types';
import { buildMemberKey, CURRENT_MEMBER_KEY } from '../config/keys';
import { QueryClientConfig, UUID } from '../types';

export default (queryConfig: QueryClientConfig) => {
const { retry, cacheTime, staleTime } = queryConfig;
Expand All @@ -20,5 +20,13 @@ export default (queryConfig: QueryClientConfig) => {
...defaultOptions,
});

return { useCurrentMember };
const useMember = (id: UUID) =>
useQuery({
queryKey: buildMemberKey(id),
queryFn: () => Api.getMember({id}, queryConfig).then((data) => Map(data)),
enabled: Boolean(id),
...defaultOptions,
})

return { useCurrentMember, useMember };
};
Loading

0 comments on commit 228cd3c

Please sign in to comment.