import React, { useRef, useState, useEffect, useCallback } from 'react'; import PropTypes from 'prop-types'; import { usePopup } from '../../../utils/hooks/'; import { PageStore } from '../../../utils/stores/'; import { PopupMain } from '../../_shared'; import { MaterialIcon } from '../../_shared/material-icon/MaterialIcon.jsx'; import { ManageItemDate } from './ManageMediaItem'; function ManageItemName(props) { if (void 0 !== props.url) { if (null !== props.name && '' !== props.name) { return ( {props.name} ); } } else if (null !== props.name && '' !== props.name) { return props.name; } return N/A; } function ManageItemUsername(props) { if (void 0 !== props.url) { if (null !== props.username && '' !== props.username) { return ( {props.username} ); } } else if (null !== props.username && '' !== props.username) { return props.username; } return N/A; } function ManageItemCommentActions(props) { const [popupContentRef, PopupContent, PopupTrigger] = usePopup(); const [isOpenPopup, setIsOpenPopup] = useState(false); function onPopupShow() { setIsOpenPopup(true); } function onPopupHide() { setIsOpenPopup(false); } function onCancel() { popupContentRef.current.tryToHide(); if ('function' === typeof props.onCancel) { props.onCancel(); } } function onProceed() { popupContentRef.current.tryToHide(); if ('function' === typeof props.onProceed) { props.onProceed(); } } const positionState = { updating: false, pending: 0 }; const onWindowResize = useCallback(function () { if (positionState.updating) { positionState.pending = positionState.pending + 1; } else { positionState.updating = true; const popupElem = props.containerRef.current.querySelector('.popup'); if (popupElem) { const containerClientRect = props.containerRef.current.getBoundingClientRect(); popupElem.style.position = 'fixed'; popupElem.style.left = containerClientRect.x + 'px'; if (document.body.offsetHeight < 32 + popupElem.offsetHeight + window.scrollY + containerClientRect.top) { popupElem.style.top = containerClientRect.y - popupElem.offsetHeight + 'px'; } else { popupElem.style.top = containerClientRect.y + containerClientRect.height + 'px'; } } setTimeout(() => { positionState.updating = false; if (positionState.pending) { positionState.pending = 0; onWindowResize(); } }, 8); } }, []); useEffect(() => { if (isOpenPopup) { PageStore.on('window_scroll', onWindowResize); PageStore.on('window_resize', onWindowResize); onWindowResize(); } else { PageStore.removeListener('window_scroll', onWindowResize); PageStore.removeListener('window_resize', onWindowResize); } }, [isOpenPopup]); return (
Member removal {'You\'re willing to remove member "' + props.name + '"'}?

); } export function ManageUsersItem(props) { const actionsContainerRef = useRef(null); const [selected, setSelected] = useState(false); function onRowCheck() { setSelected(!selected); } function onClickProceed() { if ('function' === typeof props.onProceedRemoval) { props.onProceedRemoval(props.username); } } useEffect(() => { if ('function' === typeof props.onCheckRow) { props.onCheckRow(props.username, selected); } }, [selected]); useEffect(() => { setSelected(props.selectedRow); }, [props.selectedRow]); return (
{props.has_roles ? (
{void 0 === props.roles ? ( N/A ) : props.roles.length ? ( props.roles.join('\n') ) : ( '-' )}
) : null} {props.has_verified ? (
{void 0 === props.is_verified ? ( N/A ) : props.is_verified ? ( ) : ( '-' )}
) : null} {props.has_trusted ? (
{void 0 === props.is_trusted ? ( N/A ) : props.is_trusted ? ( ) : ( '-' )}
) : null}
{void 0 === props.is_featured ? ( N/A ) : props.is_featured ? ( ) : ( '-' )}
); } ManageUsersItem.propTypes = { thumbnail_url: PropTypes.string, name: PropTypes.string, url: PropTypes.string, username: PropTypes.string, add_date: PropTypes.string, is_featured: PropTypes.bool, onCheckRow: PropTypes.func, selectedRow: PropTypes.bool.isRequired, hideDeleteAction: PropTypes.bool.isRequired, has_roles: PropTypes.bool, has_verified: PropTypes.bool, has_trusted: PropTypes.bool, roles: PropTypes.array, is_verified: PropTypes.bool, is_trusted: PropTypes.bool, }; ManageUsersItem.defaultProps = { has_roles: false, has_verified: false, has_trusted: false, };