2023-03-23 12:20:19 -07:00
|
|
|
import React, { useMemo } from 'react';
|
2023-04-26 12:53:52 -07:00
|
|
|
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
2022-12-15 14:51:30 -08:00
|
|
|
import { useRouteMatch } from 'react-router-dom';
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2024-08-28 04:41:08 -07:00
|
|
|
import { useGroup, useGroupMembershipRequests } from 'pl-fe/api/hooks';
|
|
|
|
import { Column, Icon, Layout, Stack, Text, Tabs } from 'pl-fe/components/ui';
|
|
|
|
import GroupHeader from 'pl-fe/features/group/components/group-header';
|
|
|
|
import LinkFooter from 'pl-fe/features/ui/components/link-footer';
|
2022-12-12 14:36:56 -08:00
|
|
|
import {
|
2022-12-18 04:17:45 -08:00
|
|
|
GroupMediaPanel,
|
|
|
|
SignUpPanel,
|
2024-08-28 04:41:08 -07:00
|
|
|
} from 'pl-fe/features/ui/util/async-components';
|
|
|
|
import { useOwnAccount } from 'pl-fe/hooks';
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2022-12-16 15:33:07 -08:00
|
|
|
const messages = defineMessages({
|
|
|
|
all: { id: 'group.tabs.all', defaultMessage: 'All' },
|
|
|
|
members: { id: 'group.tabs.members', defaultMessage: 'Members' },
|
2023-04-10 13:22:08 -07:00
|
|
|
media: { id: 'group.tabs.media', defaultMessage: 'Media' },
|
2022-12-16 15:33:07 -08:00
|
|
|
});
|
|
|
|
|
2024-08-24 06:01:17 -07:00
|
|
|
interface IGroupLayout {
|
2022-12-12 14:36:56 -08:00
|
|
|
params?: {
|
2023-10-02 11:54:02 -07:00
|
|
|
groupId?: string;
|
|
|
|
};
|
|
|
|
children: React.ReactNode;
|
2022-12-12 14:36:56 -08:00
|
|
|
}
|
|
|
|
|
2023-03-15 11:53:17 -07:00
|
|
|
const PrivacyBlankslate = () => (
|
|
|
|
<Stack space={4} className='py-10' alignItems='center'>
|
2023-04-26 12:53:52 -07:00
|
|
|
<div className='rounded-full bg-gray-200 p-3 dark:bg-gray-800'>
|
|
|
|
<Icon
|
2024-04-03 04:28:30 -07:00
|
|
|
src={require('@tabler/icons/outline/eye-off.svg')}
|
2024-09-21 15:09:45 -07:00
|
|
|
className='size-6 text-gray-600 dark:text-gray-600'
|
2023-04-26 12:53:52 -07:00
|
|
|
/>
|
2023-03-15 11:53:17 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<Text theme='muted'>
|
2023-04-26 12:53:52 -07:00
|
|
|
<FormattedMessage
|
|
|
|
id='group.private.message'
|
|
|
|
defaultMessage='Content is only visible to group members'
|
|
|
|
/>
|
2023-03-15 11:53:17 -07:00
|
|
|
</Text>
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
|
2024-08-24 06:01:17 -07:00
|
|
|
/** Layout to display a group. */
|
|
|
|
const GroupLayout: React.FC<IGroupLayout> = ({ params, children }) => {
|
2022-12-16 15:33:07 -08:00
|
|
|
const intl = useIntl();
|
2022-12-15 14:51:30 -08:00
|
|
|
const match = useRouteMatch();
|
2023-06-25 10:35:09 -07:00
|
|
|
const { account: me } = useOwnAccount();
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
const groupId = params?.groupId || '';
|
2022-12-15 14:51:30 -08:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
const { group } = useGroup(groupId);
|
|
|
|
const { accounts: pending } = useGroupMembershipRequests(groupId);
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2023-03-15 11:53:17 -07:00
|
|
|
const isMember = !!group?.relationship?.member;
|
2023-03-02 11:40:36 -08:00
|
|
|
const isPrivate = group?.locked;
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2023-03-23 12:20:19 -07:00
|
|
|
const tabItems = useMemo(() => {
|
|
|
|
const items = [];
|
|
|
|
items.push({
|
2022-12-16 15:33:07 -08:00
|
|
|
text: intl.formatMessage(messages.all),
|
2024-08-11 01:48:58 -07:00
|
|
|
to: `/groups/${groupId}`,
|
2024-06-23 10:29:18 -07:00
|
|
|
name: '/groups/:groupId',
|
2023-03-23 12:20:19 -07:00
|
|
|
});
|
|
|
|
|
2023-05-05 05:35:21 -07:00
|
|
|
items.push(
|
|
|
|
{
|
|
|
|
text: intl.formatMessage(messages.media),
|
2024-08-11 01:48:58 -07:00
|
|
|
to: `/groups/${groupId}/media`,
|
2024-06-23 10:29:18 -07:00
|
|
|
name: '/groups/:groupId/media',
|
2023-05-05 05:35:21 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: intl.formatMessage(messages.members),
|
2024-08-11 01:48:58 -07:00
|
|
|
to: `/groups/${groupId}/members`,
|
2024-06-23 10:29:18 -07:00
|
|
|
name: '/groups/:groupId/members',
|
2023-05-05 05:35:21 -07:00
|
|
|
count: pending.length,
|
|
|
|
},
|
|
|
|
);
|
2023-03-23 12:20:19 -07:00
|
|
|
|
|
|
|
return items;
|
2024-08-11 01:48:58 -07:00
|
|
|
}, [pending.length, groupId]);
|
2022-12-16 15:33:07 -08:00
|
|
|
|
2023-03-15 11:53:17 -07:00
|
|
|
const renderChildren = () => {
|
2024-06-18 14:59:15 -07:00
|
|
|
if (!isMember && isPrivate) {
|
2023-03-15 11:53:17 -07:00
|
|
|
return <PrivacyBlankslate />;
|
|
|
|
} else {
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-12 14:36:56 -08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Layout.Main>
|
2023-04-11 05:55:17 -07:00
|
|
|
<Column size='lg' label={group ? group.display_name : ''} withHeader={false}>
|
2024-10-13 12:03:54 -07:00
|
|
|
<GroupHeader key={`group-header-${groupId}`} group={group} />
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2022-12-15 14:51:30 -08:00
|
|
|
<Tabs
|
2024-08-11 01:48:58 -07:00
|
|
|
key={`group-tabs-${groupId}`}
|
2023-03-23 12:20:19 -07:00
|
|
|
items={tabItems}
|
2022-12-15 14:51:30 -08:00
|
|
|
activeItem={match.path}
|
|
|
|
/>
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2023-03-15 11:53:17 -07:00
|
|
|
{renderChildren()}
|
2022-12-12 14:36:56 -08:00
|
|
|
</Column>
|
|
|
|
</Layout.Main>
|
|
|
|
|
|
|
|
<Layout.Aside>
|
|
|
|
{!me && (
|
2023-10-07 15:14:45 -07:00
|
|
|
<SignUpPanel />
|
2022-12-12 14:36:56 -08:00
|
|
|
)}
|
2023-10-07 15:14:45 -07:00
|
|
|
<GroupMediaPanel group={group} />
|
|
|
|
<LinkFooter />
|
2022-12-12 14:36:56 -08:00
|
|
|
</Layout.Aside>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-08-24 06:01:17 -07:00
|
|
|
export { GroupLayout as default };
|