// @flow import React from 'react'; import classnames from 'classnames'; import Button from 'component/button'; import ChannelThumbnail from 'component/channelThumbnail'; import ClaimPreview from 'component/claimPreview'; import Card from 'component/common/card'; import { FormField } from 'component/common/form'; import FormFieldDuration from 'component/formFieldDuration'; import usePersistedState from 'effects/use-persisted-state'; import { Modal } from 'modal/modal'; import { getChannelFromClaim } from 'util/claim'; const TAB = { PERSONAL: 'personal', MODERATOR: 'moderator', ADMIN: 'admin', }; const BLOCK = { PERMANENT: 'permanent', TIMEOUT: 'timeout', }; type Props = { contentUri: string, commenterUri: string, offendingCommentId?: string, // --- redux --- activeChannelClaim: ?ChannelClaim, contentClaim: ?Claim, contentClaimIsMine: ?boolean, moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } }, doHideModal: () => void, doCommentModBlock: (commenterUri: string, offendingCommentId: ?string, timeoutSec: ?number) => void, doCommentModBlockAsAdmin: ( commenterUri: string, offendingCommentId: ?string, blockerId: ?string, timeoutSec: ?number ) => void, doCommentModBlockAsModerator: ( commenterUri: string, offendingCommentId: ?string, creatorUri: string, blockerId: ?string, timeoutSec: ?number ) => void, }; export default function ModalBlockChannel(props: Props) { const { commenterUri, offendingCommentId, activeChannelClaim, contentClaim, contentClaimIsMine, moderationDelegatorsById, doHideModal, doCommentModBlock, doCommentModBlockAsAdmin, doCommentModBlockAsModerator, } = props; const contentChannelClaim = getChannelFromClaim(contentClaim); const activeModeratorInfo = activeChannelClaim && moderationDelegatorsById[activeChannelClaim.claim_id]; const activeChannelIsAdmin = activeChannelClaim && activeModeratorInfo && activeModeratorInfo.global; const activeChannelIsModerator = activeChannelClaim && contentChannelClaim && activeModeratorInfo && Object.values(activeModeratorInfo.delegators).includes(contentChannelClaim.claim_id); const [tab, setTab] = usePersistedState('ModalBlockChannel:tab', TAB.PERSONAL); const [blockType, setBlockType] = usePersistedState('ModalBlockChannel:blockType', BLOCK.PERMANENT); const [timeoutInput, setTimeoutInput] = usePersistedState('ModalBlockChannel:timeoutInput', '10m'); const [timeoutSec, setTimeoutSec] = React.useState(-1); const isPersonalTheOnlyTab = !activeChannelIsModerator && !activeChannelIsAdmin; const isTimeoutAvail = contentClaimIsMine || activeChannelIsModerator; const blockButtonDisabled = blockType === BLOCK.TIMEOUT && timeoutSec < 1; // ************************************************************************** // ************************************************************************** // Check settings validity on mount. React.useEffect(() => { if ( isPersonalTheOnlyTab || (tab === TAB.MODERATOR && !activeChannelIsModerator) || (tab === TAB.ADMIN && !activeChannelIsAdmin) ) { setTab(TAB.PERSONAL); } if (!isTimeoutAvail && blockType === BLOCK.TIMEOUT) { setBlockType(BLOCK.PERMANENT); } }, []); // eslint-disable-line react-hooks/exhaustive-deps // ************************************************************************** // ************************************************************************** function getTabElem(value, label) { return (