diff --git a/web/modals/push-notif-modal.css b/web/modals/push-notif-modal.css new file mode 100644 --- /dev/null +++ b/web/modals/push-notif-modal.css @@ -0,0 +1,14 @@ +.container { + padding: 0 40px 32px; + border-radius: 8px; + color: var(--modal-fg); +} +.text { + font-size: var(--xl-font-20); + padding: 5px 0px 20px; +} +.buttonContainer { + display: flex; + justify-content: flex-end; + gap: 24px; +} diff --git a/web/modals/push-notif-modal.react.js b/web/modals/push-notif-modal.react.js new file mode 100644 --- /dev/null +++ b/web/modals/push-notif-modal.react.js @@ -0,0 +1,57 @@ +// @flow + +import * as React from 'react'; + +import { useModalContext } from 'lib/components/modal-provider.react.js'; + +import Modal from './modal.react.js'; +import css from './push-notif-modal.css'; +import Button from '../components/button.react.js'; +import { useCreatePushSubscription } from '../push-notif/push-notifs-handler.js'; + +const PushNotifModal: React.ComponentType<{}> = React.memo( + function PushNotifModal(): React.Node { + const { popModal } = useModalContext(); + + const createPushSubscription = useCreatePushSubscription(); + + const onEnable = React.useCallback(async () => { + popModal(); + + if (Notification.permission !== 'granted') { + const permissionResult = await Notification.requestPermission(); + if (permissionResult !== 'granted') { + return; + } + } + + await createPushSubscription(); + }, [createPushSubscription, popModal]); + + return ( + +
+

+ Would you like to enable push notifications? +

+
+ + +
+
+
+ ); + }, +); + +export default PushNotifModal;