import React, { Fragment, useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import city3 from '../../../styles/utils/images/dropdown-header/city3.jpg'; import PerfectScrollbar from 'react-perfect-scrollbar'; import reduxConnect from '../../../redux/utils/connect'; import cl from 'classnames'; import { Alert, Button, DropdownMenu, DropdownToggle, Nav, NavItem, UncontrolledDropdown } from 'reactstrap'; import { Interpolate, translate } from 'react-i18next'; import { compose } from 'redux'; import { IoIosNotificationsOutline } from 'react-icons/io'; function Notifications({ alerts, t, actions }) { const [alertsList, setAlertsList] = useState([]); useEffect(() => { // Empty list when mounts actions.removeAllAlerts(); }, []); useEffect(() => { const newAlerts = alerts .reverse() .map((alert) => { return typeof alert === 'string' ? { message: alert } : alert; }) .map((alert) => { const interpolateParameters = alert ? alert.parameters : {}; const i18nKey = alert && `alerts.${alert.type}.${alert.transKey}`; let type, msg; type = alert.type ? oldValueMapping[alert.type] : 'warning'; msg = t(i18nKey, { ...interpolateParameters, defaultValue: alert.message || t('error.unknown') }); return { type, msg }; }); setAlertsList(newAlerts); }, [alerts.length]); const isRTL = document.documentElement.dir === 'rtl'; return (
{alertsList.length > 0 ? t('userSettings.notifications') : ''}
{t('userSettings.notifications')}
1 ? 'userSettings.notificationsSub_plural' : 'userSettings.notificationsSub' } alertLength={alertsList.length} />
{alertsList.length > 0 && (
{alertsList.map((item, i) => (

{item.type}

{item.msg}
))}
)} ); } const oldValueMapping = { notice: 'success', warning: 'warning', error: 'error' }; const colorsMapping = { success: 'success', warning: 'warning', error: 'danger' }; Notifications.propTypes = { t: PropTypes.func.isRequired, alerts: PropTypes.array.isRequired, actions: PropTypes.object.isRequired }; const applyDecorators = compose( reduxConnect('alerts', ['common', 'alerts']), translate(['common'], { wait: true }) ); export default applyDecorators(Notifications);