import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { useRouteMatch } from 'react-router-dom'; import GroupLookupHoc from 'soapbox/components/hoc/group-lookup-hoc'; import { Column, Icon, Layout, Stack, Text } from 'soapbox/components/ui'; 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, GroupMediaPanel, SignUpPanel, SuggestedGroupsPanel, } from 'soapbox/features/ui/util/async-components'; import { useOwnAccount } from 'soapbox/hooks'; import { useGroup } from 'soapbox/hooks/api'; import { useGroupMembershipRequests } from 'soapbox/hooks/api/groups/useGroupMembershipRequests'; import { Group } from 'soapbox/schemas'; import { Tabs } from '../components/ui'; const messages = defineMessages({ all: { id: 'group.tabs.all', defaultMessage: 'All' }, members: { id: 'group.tabs.members', defaultMessage: 'Members' }, media: { id: 'group.tabs.media', defaultMessage: 'Media' }, }); interface IGroupPage { params?: { groupId?: string } children: React.ReactNode } const PrivacyBlankslate = () => (
Content is only visible to group members
); const BlockedBlankslate = ({ group }: { group: Group }) => (
You are banned from {' '}
); /** Page to display a group. */ const GroupPage: React.FC = ({ params, children }) => { const intl = useIntl(); const match = useRouteMatch(); const me = useOwnAccount(); const id = params?.groupId || ''; const { group } = useGroup(id); const { accounts: pending } = useGroupMembershipRequests(id); const isMember = !!group?.relationship?.member; const isBlocked = group?.relationship?.blocked_by; const isPrivate = group?.locked; const items = [ { text: intl.formatMessage(messages.all), to: group?.slug ? `/group/${group.slug}` : `/groups/${group?.id}`, name: group?.slug ? '/group/:groupSlug' : '/groups/:groupId', }, { text: intl.formatMessage(messages.members), to: group?.slug ? `/group/${group.slug}/members` : `/groups/${group?.id}/members`, name: group?.slug ? '/group/:groupSlug/members' : '/groups/:groupId/members', count: pending.length, }, { text: intl.formatMessage(messages.media), to: group?.slug ? `/group/${group.slug}/media` : `/groups/${group?.id}/media`, name: group?.slug ? '/group/:groupSlug' : '/groups/:groupId/media', }, ]; const renderChildren = () => { if (!isMember && isPrivate) { return ; } else if (isBlocked) { return ; } else { return children; } }; return ( <> {renderChildren()} {!me && ( {Component => } )} {!me && ( {Component => } )} {Component => } {Component => } ); }; export default GroupLookupHoc(GroupPage as any) as any;