diff --git a/src/app/features/settings/notifications/DeregisterPushNotifications.tsx b/src/app/features/settings/notifications/DeregisterPushNotifications.tsx new file mode 100644 index 00000000..bc6b65d4 --- /dev/null +++ b/src/app/features/settings/notifications/DeregisterPushNotifications.tsx @@ -0,0 +1,149 @@ +import React, { useState } from 'react'; +import FocusTrap from 'focus-trap-react'; +import { + Box, + Button, + color, + config, + Dialog, + Header, + Icon, + IconButton, + Icons, + Overlay, + OverlayBackdrop, + OverlayCenter, + Spinner, + Text, +} from 'folds'; +import { useAtom } from 'jotai'; +import { useMatrixClient } from '../../../hooks/useMatrixClient'; +import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback'; +import { useSetting } from '../../../state/hooks/settings'; +import { settingsAtom } from '../../../state/settings'; +import { pushSubscriptionAtom } from '../../../state/pushSubscription'; +import { deRegisterAllPushers } from './PushNotifications'; +import { SettingTile } from '../../../components/setting-tile'; + +type ConfirmDeregisterDialogProps = { + onClose: () => void; + onConfirm: () => void; + isLoading: boolean; +}; + +function ConfirmDeregisterDialog({ onClose, onConfirm, isLoading }: ConfirmDeregisterDialogProps) { + return ( + }> + + + +
+ + Reset All Push Notifications + + + + +
+ + + This will remove push notifications from all your sessions and devices. This action + cannot be undone. Are you sure you want to continue? + + + + + + +
+
+
+
+ ); +} + +export function DeregisterAllPushersSetting() { + const mx = useMatrixClient(); + const [deregisterState] = useAsyncCallback(deRegisterAllPushers); + const [isConfirming, setIsConfirming] = useState(false); + const [usePushNotifications, setPushNotifications] = useSetting( + settingsAtom, + 'usePushNotifications' + ); + + const [pushSubscription, setPushSubscription] = useAtom(pushSubscriptionAtom); + + const handleOpenConfirmDialog = () => { + setIsConfirming(true); + }; + + const handleCloseConfirmDialog = () => { + if (deregisterState.status === AsyncStatus.Loading) return; + setIsConfirming(false); + }; + + const handleConfirmDeregister = async () => { + await deRegisterAllPushers(mx); + setPushNotifications(false); + setPushSubscription(null); + setIsConfirming(false); + }; + + return ( + <> + {isConfirming && ( + + )} + + + + This will remove push notifications from all your sessions/devices. You will need to + re-enable them on each device individually. + + {deregisterState.status === AsyncStatus.Error && ( + +
+ Failed to deregister devices. Please try again. +
+ )} + {deregisterState.status === AsyncStatus.Success && ( + +
+ Successfully deregistered all devices. +
+ )} + + } + after={ + + } + /> + + ); +}