2021-08-16 20:47:18 -07:00
|
|
|
import { Alert } from 'antd';
|
2022-02-23 06:07:21 +03:00
|
|
|
import React from 'react';
|
2021-08-16 20:47:18 -07:00
|
|
|
import GroupHeader from './GroupHeader';
|
|
|
|
|
import { useGetGroupQuery } from '../../../graphql/group.generated';
|
|
|
|
|
import useUserParams from '../../shared/entitySearch/routingUtils/useUserParams';
|
2022-02-23 06:07:21 +03:00
|
|
|
import { EntityRelationshipsResult, EntityType } from '../../../types.generated';
|
2021-08-16 20:47:18 -07:00
|
|
|
import { Message } from '../../shared/Message';
|
|
|
|
|
import GroupMembers from './GroupMembers';
|
2021-08-31 22:00:56 -07:00
|
|
|
import { LegacyEntityProfile } from '../../shared/LegacyEntityProfile';
|
2021-10-07 16:14:35 -07:00
|
|
|
import { useEntityRegistry } from '../../useEntityRegistry';
|
2022-02-01 10:47:45 -08:00
|
|
|
import { decodeUrn } from '../shared/utils';
|
2022-02-23 06:07:21 +03:00
|
|
|
import GroupOwnerships from './GroupOwnerships';
|
2021-08-16 20:47:18 -07:00
|
|
|
|
|
|
|
|
const messageStyle = { marginTop: '10%' };
|
|
|
|
|
|
|
|
|
|
export enum TabType {
|
|
|
|
|
Members = 'Members',
|
|
|
|
|
Ownership = 'Ownership',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ENABLED_TAB_TYPES = [TabType.Members, TabType.Ownership];
|
|
|
|
|
|
|
|
|
|
const MEMBER_PAGE_SIZE = 20;
|
2022-02-23 06:07:21 +03:00
|
|
|
const OWNERSHIP_PAGE_SIZE = 10;
|
2021-08-16 20:47:18 -07:00
|
|
|
|
|
|
|
|
/**
|
2021-09-27 18:09:47 -05:00
|
|
|
* Responsible for reading & writing groups.
|
2021-08-16 20:47:18 -07:00
|
|
|
*/
|
|
|
|
|
export default function GroupProfile() {
|
2021-10-07 16:14:35 -07:00
|
|
|
const entityRegistry = useEntityRegistry();
|
2022-02-01 10:47:45 -08:00
|
|
|
const { urn: encodedUrn } = useUserParams();
|
|
|
|
|
const urn = encodedUrn && decodeUrn(encodedUrn);
|
2021-08-16 20:47:18 -07:00
|
|
|
const { loading, error, data } = useGetGroupQuery({ variables: { urn, membersCount: MEMBER_PAGE_SIZE } });
|
|
|
|
|
|
|
|
|
|
if (error || (!loading && !error && !data)) {
|
|
|
|
|
return <Alert type="error" message={error?.message || 'Group failed to load :('} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const groupMemberRelationships = data?.corpGroup?.relationships as EntityRelationshipsResult;
|
|
|
|
|
|
|
|
|
|
const getTabs = () => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
name: TabType.Members,
|
|
|
|
|
path: TabType.Members.toLocaleLowerCase(),
|
|
|
|
|
content: (
|
|
|
|
|
<GroupMembers
|
|
|
|
|
urn={urn}
|
|
|
|
|
initialRelationships={groupMemberRelationships}
|
|
|
|
|
pageSize={MEMBER_PAGE_SIZE}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: TabType.Ownership,
|
|
|
|
|
path: TabType.Ownership.toLocaleLowerCase(),
|
2022-02-23 06:07:21 +03:00
|
|
|
content: <GroupOwnerships data={data} pageSize={OWNERSHIP_PAGE_SIZE} />,
|
2021-08-16 20:47:18 -07:00
|
|
|
},
|
|
|
|
|
].filter((tab) => ENABLED_TAB_TYPES.includes(tab.name));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const description = data?.corpGroup?.info?.description;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2022-02-23 06:07:21 +03:00
|
|
|
{loading && <Message type="loading" content="Loading..." style={messageStyle} />}
|
2021-08-16 20:47:18 -07:00
|
|
|
{data && data?.corpGroup && (
|
2021-08-31 22:00:56 -07:00
|
|
|
<LegacyEntityProfile
|
2021-08-16 20:47:18 -07:00
|
|
|
title=""
|
|
|
|
|
tags={null}
|
|
|
|
|
header={
|
|
|
|
|
<GroupHeader
|
2021-10-07 16:14:35 -07:00
|
|
|
name={entityRegistry.getDisplayName(EntityType.CorpGroup, data?.corpGroup)}
|
2021-08-16 20:47:18 -07:00
|
|
|
description={description}
|
|
|
|
|
email={data?.corpGroup?.info?.email}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
tabs={getTabs()}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|