import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { useDispatch } from 'react-redux'; import { followAccount, unfollowAccount, blockAccount, unblockAccount, muteAccount, unmuteAccount, } from 'soapbox/actions/accounts'; import { openModal } from 'soapbox/actions/modals'; import { Button } from 'soapbox/components/ui'; import { useAppSelector, useFeatures } from 'soapbox/hooks'; import type { Account as AccountEntity } from 'soapbox/types/entities'; const messages = defineMessages({ block: { id: 'account.block', defaultMessage: 'Block @{name}' }, blocked: { id: 'account.blocked', defaultMessage: 'Blocked' }, edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' }, follow: { id: 'account.follow', defaultMessage: 'Follow' }, mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' }, remote_follow: { id: 'account.remote_follow', defaultMessage: 'Remote follow' }, requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' }, requested_small: { id: 'account.requested_small', defaultMessage: 'Awaiting approval' }, unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' }, unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' }, unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' }, }); interface iActionButton { account: AccountEntity actionType?: 'muting' | 'blocking' small?: boolean } const ActionButton = ({ account, actionType, small }: iActionButton) => { const dispatch = useDispatch(); const features = useFeatures(); const intl = useIntl(); const me = useAppSelector((state) => state.me); const handleFollow = () => { if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { dispatch(unfollowAccount(account.get('id'))); } else { dispatch(followAccount(account.get('id'))); } }; const handleBlock = () => { if (account.getIn(['relationship', 'blocking'])) { dispatch(unblockAccount(account.get('id'))); } else { dispatch(blockAccount(account.get('id'))); } }; const handleMute = () => { if (account.getIn(['relationship', 'muting'])) { dispatch(unmuteAccount(account.get('id'))); } else { dispatch(muteAccount(account.get('id'))); } }; const handleRemoteFollow = () => { dispatch(openModal('UNAUTHORIZED', { action: 'FOLLOW', account: account.get('id'), ap_id: account.get('url'), })); }; const mutingAction = () => { const isMuted = account.getIn(['relationship', 'muting']); const messageKey = isMuted ? messages.unmute : messages.mute; const text = intl.formatMessage(messageKey, { name: account.get('username') }); return ( ); } else if (account.getIn(['relationship', 'blocking'])) { // Unblock return (