|
1 | 1 | import React, { useState } from 'react';
|
2 | 2 | import { Typography } from 'antd';
|
3 |
| -import { CorpUser, EntityRelationship } from '../../../types.generated'; |
| 3 | +import { useRouteMatch } from 'react-router-dom'; |
| 4 | +import { useHistory } from 'react-router'; |
| 5 | +import { CorpUser, EntityRelationshipsResult } from '../../../types.generated'; |
4 | 6 | import { useEntityRegistry } from '../../useEntityRegistry';
|
5 |
| -import { TagsSection } from '../shared/SidebarStyledComponents'; |
| 7 | +import { ShowMoreButton, TagsSection } from '../shared/SidebarStyledComponents'; |
6 | 8 | import { ShowMoreSection } from '../shared/sidebarSection/ShowMoreSection';
|
7 | 9 | import { GroupMemberLink } from './GroupMemberLink';
|
| 10 | +import { TabType } from './types'; |
8 | 11 |
|
9 | 12 | type Props = {
|
10 |
| - relationships: Array<EntityRelationship>; |
| 13 | + groupMemberRelationships: EntityRelationshipsResult; |
11 | 14 | };
|
12 |
| -const DEFAULT_MAX_ENTITIES_TO_SHOW = 4; |
| 15 | +const DEFAULT_MAX_ENTITIES_TO_SHOW = 5; |
13 | 16 |
|
14 |
| -export default function GroupMembersSidebarSectionContent({ relationships }: Props) { |
| 17 | +export default function GroupMembersSidebarSectionContent({ groupMemberRelationships }: Props) { |
| 18 | + const history = useHistory(); |
| 19 | + const { url } = useRouteMatch(); |
15 | 20 | const [entityCount, setEntityCount] = useState(DEFAULT_MAX_ENTITIES_TO_SHOW);
|
16 | 21 |
|
17 | 22 | const entityRegistry = useEntityRegistry();
|
18 |
| - const relationshipsCount = relationships?.length || 0; |
| 23 | + const relationshipsTotal = groupMemberRelationships?.total || 0; |
| 24 | + const relationshipsAvailableCount = groupMemberRelationships.relationships?.length || 0; |
19 | 25 | return (
|
20 | 26 | <>
|
21 | 27 | <TagsSection>
|
22 |
| - {relationships.length === 0 && ( |
| 28 | + {relationshipsTotal === 0 && ( |
23 | 29 | <Typography.Paragraph type="secondary">No members yet.</Typography.Paragraph>
|
24 | 30 | )}
|
25 |
| - {relationships.length > 0 && |
26 |
| - relationships.map((item, index) => { |
| 31 | + {relationshipsTotal > 0 && |
| 32 | + groupMemberRelationships.relationships.map((item, index) => { |
27 | 33 | const user = item.entity as CorpUser;
|
28 | 34 | return index < entityCount && <GroupMemberLink user={user} entityRegistry={entityRegistry} />;
|
29 | 35 | })}
|
30 | 36 | </TagsSection>
|
31 |
| - {relationshipsCount > entityCount && ( |
| 37 | + {relationshipsAvailableCount > entityCount && ( |
32 | 38 | <ShowMoreSection
|
33 |
| - totalCount={relationshipsCount} |
| 39 | + totalCount={relationshipsAvailableCount} |
34 | 40 | entityCount={entityCount}
|
35 | 41 | setEntityCount={setEntityCount}
|
36 | 42 | showMaxEntity={DEFAULT_MAX_ENTITIES_TO_SHOW}
|
37 | 43 | />
|
38 | 44 | )}
|
| 45 | + {relationshipsTotal > relationshipsAvailableCount && entityCount >= relationshipsAvailableCount && ( |
| 46 | + <ShowMoreButton onClick={() => history.replace(`${url}/${TabType.Members.toLocaleLowerCase()}`)}> |
| 47 | + View all members |
| 48 | + </ShowMoreButton> |
| 49 | + )} |
39 | 50 | </>
|
40 | 51 | );
|
41 | 52 | }
|
0 commit comments