import React, { useCallback, useEffect } from 'react'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { authorizeGroupMembershipRequest, fetchGroup, fetchGroupMembershipRequests, rejectGroupMembershipRequest } from 'soapbox/actions/groups'; import snackbar from 'soapbox/actions/snackbar'; import Account from 'soapbox/components/account'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Button, Column, HStack, Spinner } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import { makeGetAccount, makeGetGroup } from 'soapbox/selectors'; import ColumnForbidden from '../ui/components/column-forbidden'; type RouteParams = { id: string }; const messages = defineMessages({ heading: { id: 'column.group_pending_requests', defaultMessage: 'Pending requests' }, authorize: { id: 'group.group_mod_authorize', defaultMessage: 'Accept' }, authorized: { id: 'group.group_mod_authorize.success', defaultMessage: 'Accepted @{name} to group' }, reject: { id: 'group.group_mod_reject', defaultMessage: 'Reject' }, rejected: { id: 'group.group_mod_reject.success', defaultMessage: 'Rejected @{name} from group' }, }); interface IMembershipRequest { accountId: string groupId: string } const MembershipRequest: React.FC = ({ accountId, groupId }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const getAccount = useCallback(makeGetAccount(), []); const account = useAppSelector((state) => getAccount(state, accountId)); if (!account) return null; const handleAuthorize = () => dispatch(authorizeGroupMembershipRequest(groupId, accountId)).then(() => { dispatch(snackbar.success(intl.formatMessage(messages.authorized, { name: account.acct }))); }); const handleReject = () => dispatch(rejectGroupMembershipRequest(groupId, accountId)).then(() => { dispatch(snackbar.success(intl.formatMessage(messages.rejected, { name: account.acct }))); }); return (