import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; import { useIntl } from '@edx/frontend-platform/i18n'; import PropTypes from 'prop-types'; import { Icon } from '@edx/paragon'; import { Link } from 'react-router-dom'; import * as timeago from 'timeago.js'; import { getIconByType } from './utils'; import { markNotificationsAsRead } from './data/thunks'; import messages from './messages'; import timeLocale from '../common/time-locale'; const NotificationRowItem = ({ id, type, contentUrl, content, courseName, createdAt, lastRead, }) => { timeago.register('time-locale', timeLocale); const intl = useIntl(); const dispatch = useDispatch(); const handleMarkAsRead = useCallback(() => { dispatch(markNotificationsAsRead(id)); }, [dispatch, id]); const { icon: iconComponent, class: iconClass } = getIconByType(type); return (
{courseName} {intl.formatMessage(messages.fullStop)} {timeago.format(createdAt, 'time-locale')}
{!lastRead && (
)}
); }; NotificationRowItem.propTypes = { id: PropTypes.string.isRequired, type: PropTypes.string.isRequired, contentUrl: PropTypes.string.isRequired, content: PropTypes.node.isRequired, courseName: PropTypes.string.isRequired, createdAt: PropTypes.string.isRequired, lastRead: PropTypes.string.isRequired, }; export default React.memo(NotificationRowItem);