import React, { useEffect, useRef, useState, } from 'react'; import PropTypes from 'prop-types'; import { useIntl } from '@edx/frontend-platform/i18n'; import { ActionRow, IconButton, Icon } from '@openedx/paragon'; import { Close, ThumbUpOutline, ThumbDownOffAlt } from '@openedx/paragon/icons'; import './index.scss'; import messages from './messages'; import useFeedbackWidget from './useFeedbackWidget'; const FeedbackWidget = ({ courseId, translationLanguage, unitId, userId, }) => { const { formatMessage } = useIntl(); const ref = useRef(null); const [elemReady, setElemReady] = useState(false); const { closeFeedbackWidget, showFeedbackWidget, showGratitudeText, onThumbsUpClick, onThumbsDownClick, } = useFeedbackWidget({ courseId, translationLanguage, unitId, userId, }); useEffect(() => { if (ref.current) { const domNode = document.getElementById('whole-course-translation-feedback-widget'); domNode.appendChild(ref.current); setElemReady(true); } }, [ref.current]); return (
{(showFeedbackWidget || showGratitudeText) ? (
{ showFeedbackWidget && (
{formatMessage(messages.rateTranslationText)}
|
) } { showGratitudeText && (
{formatMessage(messages.gratitudeText)}
) }
) : null}
); }; FeedbackWidget.propTypes = { courseId: PropTypes.string.isRequired, translationLanguage: PropTypes.string.isRequired, userId: PropTypes.string.isRequired, unitId: PropTypes.string.isRequired, }; FeedbackWidget.defaultProps = {}; export default FeedbackWidget;