import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; import { logError } from '@edx/frontend-platform/logging'; import { Button, Dropdown, Icon, IconButton, ModalPopup, } from '@edx/paragon'; import { MoreHoriz } from '@edx/paragon/icons'; import { ContentActions } from '../../data/constants'; import { commentShape } from '../comments/comment/proptypes'; import messages from '../messages'; import { postShape } from '../posts/post/proptypes'; import { useActions } from '../utils'; function ActionsDropdown({ intl, commentOrPost, disabled, actionHandlers, }) { const [isOpen, setOpen] = useState(false); const dropdownIconRef = React.useRef(null); const actions = useActions(commentOrPost); const handleActions = (action) => { const actionFunction = actionHandlers[action]; if (actionFunction) { actionFunction(); } else { logError(`Unknown or unimplemented action ${action}`); } }; return ( <> setOpen(!isOpen)} alt={intl.formatMessage(messages.actionsAlt)} src={MoreHoriz} iconAs={Icon} disabled={disabled} size="sm" ref={dropdownIconRef} /> setOpen(false)} positionRef={dropdownIconRef} isOpen={isOpen} placement="auto-start" >
{actions.map(action => ( {action.action === ContentActions.DELETE && } { setOpen(false); handleActions(action.action); }} className="d-flex justify-content-start py-1.5 mr-4" > {intl.formatMessage(action.label)} ))}
); } ActionsDropdown.propTypes = { intl: intlShape.isRequired, commentOrPost: PropTypes.oneOfType([commentShape, postShape]).isRequired, disabled: PropTypes.bool, actionHandlers: PropTypes.objectOf(PropTypes.func).isRequired, }; ActionsDropdown.defaultProps = { disabled: false, }; export default injectIntl(ActionsDropdown);