import React from 'react'; import { useSelector, useDispatch } from 'react-redux'; import ToggleOnOff from 'app/shared/components/toggle/toggleOnOff'; import { isEmpty } from 'lodash'; import { NOTIFICATIONS } from 'app/modules/notifications/store/notifications.constants'; import { notificationsSetEnableInit } from 'app/modules/notifications/store/notifications.actions'; import { selectNotifications } from '../store/notifications.selector'; import * as Text from 'app/shared/components/text/text'; const notificationButtons = (notifications, handleOnClick) => { if (isEmpty(notifications)) { return null; } return notifications.map((vesselNotification) => { return
handleOnClick(vesselNotification.id, active)} />
; }); }; const AccountNotificationsPage = () => { const notifications = useSelector(selectNotifications); const vesselNotifications = notifications.filter((notification) => notification.type === NOTIFICATIONS.TYPE_VESSELS); const documentsNotifications = notifications.filter((notification) => notification.type === NOTIFICATIONS.TYPE_DOCUMENTS); const dispatch = useDispatch(); const handleOnClick = (notificationId, active) => { dispatch(notificationsSetEnableInit({ notificationId, active })); }; const vesselSwitches = notificationButtons(vesselNotifications, handleOnClick); const documentsSwitches = notificationButtons(documentsNotifications, handleOnClick); return (
Vessels Notify me by email about {vesselSwitches}
Documents Notify me by email when new documents are added {documentsSwitches}
); }; export { AccountNotificationsPage };