1 import { useState } from 'react';
3 import type { PushNotification } from 'push.js';
4 import { c } from 'ttag';
6 import { Button } from '@proton/atoms';
7 import Badge from '@proton/components/components/badge/Badge';
8 import Field from '@proton/components/components/container/Field';
9 import { Status, create, getStatus, request } from '@proton/shared/lib/helpers/desktopNotification';
11 const testDefaultNotification = () => {
12 return create(c('Info').t`You have a new email`, {
13 body: 'Quarterly operations update',
14 icon: '/assets/img/notification-badge.gif',
21 export interface Props {
22 onTest?: () => Promise<PushNotification | undefined>;
25 const DesktopNotificationPanel = ({ onTest = testDefaultNotification }: Props) => {
26 const [status, setStatus] = useState<Status>(getStatus());
28 const handleEnable = () => {
30 () => setStatus(getStatus()),
31 () => setStatus(getStatus())
37 <Field className="pt-2">
38 <div className="mb-4">
39 <span className="mr-2">{c('Info').t`Desktop notifications are currently`}</span>
40 {status === Status.GRANTED ? (
41 <Badge type="success" className="m-0">{c('Desktop notification status').t`Enabled`}</Badge>
43 <Badge type="error" className="m-0">{c('Desktop notification status').t`Disabled`}</Badge>
47 {status === Status.GRANTED ? (
48 <Button size="small" onClick={onTest}>{c('Action').t`Send test notification`}</Button>
49 ) : status === Status.DEFAULT ? (
50 <Button size="small" onClick={handleEnable}>{c('Action')
51 .t`Enable desktop notification`}</Button>
59 export default DesktopNotificationPanel;