2021-10-27 16:38:10 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import useBrowserNotifications from '$web/component/browserNotificationSettings/use-browser-notifications';
|
|
|
|
import 'scss/component/notifications-banner.scss';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
|
|
|
|
|
|
|
export const BrowserNotificationBanner = () => {
|
2021-11-12 18:06:07 +01:00
|
|
|
const {
|
|
|
|
pushInitialized,
|
|
|
|
pushSupported,
|
|
|
|
pushEnabled,
|
|
|
|
pushPermission,
|
|
|
|
pushToggle,
|
|
|
|
pushErrorModal,
|
|
|
|
} = useBrowserNotifications();
|
2021-10-27 16:38:10 +02:00
|
|
|
const [hasAcknowledgedPush, setHasAcknowledgedPush] = usePersistedState('push-nag', false);
|
|
|
|
|
2021-11-12 18:06:07 +01:00
|
|
|
if (!pushInitialized || !pushSupported || pushEnabled || pushPermission === 'denied' || hasAcknowledgedPush) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-10-27 16:38:10 +02:00
|
|
|
|
|
|
|
const handleClose = () => setHasAcknowledgedPush(true);
|
|
|
|
|
|
|
|
return (
|
2021-11-01 19:51:23 +01:00
|
|
|
<>
|
|
|
|
<div className="browserNotificationsBanner notice-message">
|
|
|
|
<div className="browserNotificationsBanner__overview">
|
|
|
|
<Icon className="browserNotificationsBanner__icon" icon={ICONS.NOTIFICATION} size={32} />
|
|
|
|
<p>
|
|
|
|
<strong>{__('Realtime push notifications straight to your browser.')}</strong>
|
|
|
|
<br />
|
|
|
|
<span className="notificationsBlocked__subText">{__("Don't miss another notification again.")}</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="browserNotificationsBanner__actions">
|
|
|
|
<Button
|
|
|
|
className="browserNotificationsBanner__button"
|
|
|
|
button="primary"
|
|
|
|
title={__('Enable Push Notifications')}
|
|
|
|
label={__('Enable Push Notifications')}
|
|
|
|
onClick={pushToggle}
|
|
|
|
/>
|
|
|
|
<Button button="close" title={__('Dismiss')} icon={ICONS.REMOVE} onClick={handleClose} />
|
|
|
|
</div>
|
2021-10-27 16:38:10 +02:00
|
|
|
</div>
|
2021-11-01 19:51:23 +01:00
|
|
|
{pushErrorModal()}
|
|
|
|
</>
|
2021-10-27 16:38:10 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default BrowserNotificationBanner;
|