2023-03-02 11:40:36 -08:00
|
|
|
import React from 'react';
|
2022-12-16 15:33:07 -08:00
|
|
|
import { 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
|
|
|
|
2023-04-17 12:28:20 -07:00
|
|
|
import GroupLookupHoc from 'soapbox/components/hoc/group-lookup-hoc';
|
2023-03-02 11:40:36 -08:00
|
|
|
import { Column, Icon, Layout, Stack, Text } from 'soapbox/components/ui';
|
2022-12-12 14:36:56 -08:00
|
|
|
import GroupHeader from 'soapbox/features/group/components/group-header';
|
|
|
|
import LinkFooter from 'soapbox/features/ui/components/link-footer';
|
|
|
|
import BundleContainer from 'soapbox/features/ui/containers/bundle-container';
|
|
|
|
import {
|
|
|
|
CtaBanner,
|
2022-12-18 04:17:45 -08:00
|
|
|
GroupMediaPanel,
|
|
|
|
SignUpPanel,
|
2023-03-21 14:34:15 -07:00
|
|
|
SuggestedGroupsPanel,
|
2022-12-12 14:36:56 -08:00
|
|
|
} from 'soapbox/features/ui/util/async-components';
|
2023-03-23 05:43:41 -07:00
|
|
|
import { useOwnAccount } from 'soapbox/hooks';
|
|
|
|
import { useGroup } from 'soapbox/hooks/api';
|
2023-03-20 18:02:58 -07:00
|
|
|
import { useGroupMembershipRequests } from 'soapbox/hooks/api/groups/useGroupMembershipRequests';
|
2023-03-15 11:53:17 -07:00
|
|
|
import { Group } from 'soapbox/schemas';
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2022-12-15 14:51:30 -08:00
|
|
|
import { Tabs } from '../components/ui';
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2022-12-12 14:36:56 -08:00
|
|
|
interface IGroupPage {
|
|
|
|
params?: {
|
2023-04-17 12:28:20 -07:00
|
|
|
groupId?: string
|
2023-01-27 14:04:42 -08:00
|
|
|
}
|
|
|
|
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'>
|
|
|
|
<div className='rounded-full bg-gray-200 p-3'>
|
|
|
|
<Icon src={require('@tabler/icons/eye-off.svg')} className='h-6 w-6 text-gray-600' />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Text theme='muted'>
|
|
|
|
Content is only visible to group members
|
|
|
|
</Text>
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
|
|
|
|
const BlockedBlankslate = ({ group }: { group: Group }) => (
|
|
|
|
<Stack space={4} className='py-10' alignItems='center'>
|
|
|
|
<div className='rounded-full bg-danger-200 p-3'>
|
|
|
|
<Icon src={require('@tabler/icons/eye-off.svg')} className='h-6 w-6 text-danger-600' />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Text theme='muted'>
|
|
|
|
You are banned from
|
|
|
|
{' '}
|
|
|
|
<Text theme='inherit' tag='span' dangerouslySetInnerHTML={{ __html: group.display_name_html }} />
|
|
|
|
</Text>
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
|
2022-12-12 14:36:56 -08:00
|
|
|
/** Page to display a group. */
|
2022-12-15 14:51:30 -08:00
|
|
|
const GroupPage: React.FC<IGroupPage> = ({ 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-03-02 11:40:36 -08:00
|
|
|
const me = useOwnAccount();
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2023-04-17 12:28:20 -07:00
|
|
|
const id = params?.groupId || '';
|
2022-12-15 14:51:30 -08:00
|
|
|
|
2023-03-02 11:40:36 -08:00
|
|
|
const { group } = useGroup(id);
|
2023-03-20 18:02:58 -07:00
|
|
|
const { accounts: pending } = useGroupMembershipRequests(id);
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2023-03-15 11:53:17 -07:00
|
|
|
const isMember = !!group?.relationship?.member;
|
|
|
|
const isBlocked = group?.relationship?.blocked_by;
|
2023-03-02 11:40:36 -08:00
|
|
|
const isPrivate = group?.locked;
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2022-12-16 15:33:07 -08:00
|
|
|
const items = [
|
|
|
|
{
|
|
|
|
text: intl.formatMessage(messages.all),
|
2023-04-17 12:28:20 -07:00
|
|
|
to: group?.slug ? `/group/${group.slug}` : `/groups/${group?.id}`,
|
|
|
|
name: group?.slug ? '/group/:groupSlug' : '/groups/:groupId',
|
2022-12-16 15:33:07 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: intl.formatMessage(messages.members),
|
2023-04-17 12:28:20 -07:00
|
|
|
to: group?.slug ? `/group/${group.slug}/members` : `/groups/${group?.id}/members`,
|
|
|
|
name: group?.slug ? '/group/:groupSlug/members' : '/groups/:groupId/members',
|
2023-03-20 18:02:58 -07:00
|
|
|
count: pending.length,
|
2022-12-16 15:33:07 -08:00
|
|
|
},
|
2023-04-10 13:22:08 -07:00
|
|
|
{
|
|
|
|
text: intl.formatMessage(messages.media),
|
2023-04-17 12:28:20 -07:00
|
|
|
to: group?.slug ? `/group/${group.slug}/media` : `/groups/${group?.id}/media`,
|
|
|
|
name: group?.slug ? '/group/:groupSlug' : '/groups/:groupId/media',
|
2023-04-10 13:22:08 -07:00
|
|
|
},
|
2022-12-16 15:41:22 -08:00
|
|
|
];
|
2022-12-16 15:33:07 -08:00
|
|
|
|
2023-03-15 11:53:17 -07:00
|
|
|
const renderChildren = () => {
|
|
|
|
if (!isMember && isPrivate) {
|
|
|
|
return <PrivacyBlankslate />;
|
|
|
|
} else if (isBlocked) {
|
|
|
|
return <BlockedBlankslate group={group} />;
|
|
|
|
} 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}>
|
2022-12-15 14:51:30 -08:00
|
|
|
<GroupHeader group={group} />
|
2022-12-12 14:36:56 -08:00
|
|
|
|
2022-12-15 14:51:30 -08:00
|
|
|
<Tabs
|
2022-12-16 15:33:07 -08:00
|
|
|
items={items}
|
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>
|
|
|
|
|
|
|
|
{!me && (
|
|
|
|
<BundleContainer fetchComponent={CtaBanner}>
|
|
|
|
{Component => <Component key='cta-banner' />}
|
|
|
|
</BundleContainer>
|
|
|
|
)}
|
|
|
|
</Layout.Main>
|
|
|
|
|
|
|
|
<Layout.Aside>
|
|
|
|
{!me && (
|
|
|
|
<BundleContainer fetchComponent={SignUpPanel}>
|
|
|
|
{Component => <Component key='sign-up-panel' />}
|
|
|
|
</BundleContainer>
|
|
|
|
)}
|
2022-12-18 04:17:45 -08:00
|
|
|
<BundleContainer fetchComponent={GroupMediaPanel}>
|
|
|
|
{Component => <Component group={group} />}
|
|
|
|
</BundleContainer>
|
2023-03-21 14:34:15 -07:00
|
|
|
<BundleContainer fetchComponent={SuggestedGroupsPanel}>
|
|
|
|
{Component => <Component />}
|
|
|
|
</BundleContainer>
|
2022-12-12 14:36:56 -08:00
|
|
|
<LinkFooter key='link-footer' />
|
|
|
|
</Layout.Aside>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-04-17 12:28:20 -07:00
|
|
|
export default GroupLookupHoc(GroupPage as any) as any;
|