From 63b9f50925437986e1d83fbfb4ab8e44953aae25 Mon Sep 17 00:00:00 2001 From: Johan Book <13253042+johanbook@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:05:17 +0200 Subject: [PATCH] feat(web-ui): add button to enable notifcations (#924) Co-authored-by: Johan Book <{ID}+{username}@users.noreply.github.com> --- .../web-ui/public/locales/en/settings.json | 12 ++++- .../web-ui/public/locales/sv/settings.json | 12 ++++- .../SettingsPage/SettingsPage.container.tsx | 49 ++++++++++++++----- .../pages/SettingsPage/SettingsPage.nav.tsx | 6 +-- 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/services/web-ui/public/locales/en/settings.json b/services/web-ui/public/locales/en/settings.json index cd3e2539..d85a7c81 100644 --- a/services/web-ui/public/locales/en/settings.json +++ b/services/web-ui/public/locales/en/settings.json @@ -1,5 +1,4 @@ { - "description": "These are the permanent settings you can change. More settings will be added here in the future.", "danger-zone": { "description": "These are actions that cannot be undone", "header": "Danger zone", @@ -12,5 +11,14 @@ } }, "darkmode": "Darkmode", - "header": "Settings" + "header": "Settings", + "notifications": { + "header": "Notifications", + "enable": { + "description": "Enable push notifications for this device", + "button": "Enable", + "error": "Failed to enable push notifications", + "success": "Enabled push notifications" + } + } } diff --git a/services/web-ui/public/locales/sv/settings.json b/services/web-ui/public/locales/sv/settings.json index 02d823e8..6b5e3de4 100644 --- a/services/web-ui/public/locales/sv/settings.json +++ b/services/web-ui/public/locales/sv/settings.json @@ -1,5 +1,4 @@ { - "description": "Här kan du ändra dina permanenta inställningar. Detta kommer att komma mer här allteftersom.", "danger-zone": { "description": "Detta är åtgärder som inte kan ångras", "header": "Farozon", @@ -12,5 +11,14 @@ } }, "darkmode": "Mörkerläge", - "header": "Inställningar" + "header": "Inställningar", + "notifications": { + "header": "Push-notiser", + "enable": { + "description": "Aktivera push-notiser på denna enhet", + "button": "Aktivera", + "error": "Ett fel uppstod vid aktivering av notiser", + "success": "Notiser har aktiverats" + } + } } diff --git a/services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.container.tsx b/services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.container.tsx index f7b77916..0b26b74b 100644 --- a/services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.container.tsx +++ b/services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.container.tsx @@ -6,6 +6,7 @@ import { useDialog } from "src/core/dialog"; import { useTranslation } from "src/core/i18n"; import { useMutation } from "src/core/query"; import { useSnackbar } from "src/core/snackbar"; +import { registerServiceWorker } from "src/registerServiceWorker"; import { SettingsPageNav } from "./SettingsPage.nav"; @@ -15,11 +16,20 @@ export function SettingsPageContainer(): ReactElement { const snackbar = useSnackbar(); const deleteAccountMutation = useMutation({ - onError: () => snackbar.success(t("danger-zone.delete-account.success")), - onSuccess: () => snackbar.error(t("danger-zone.delete-account.error")), + onError: () => snackbar.error(t("danger-zone.delete-account.error")), + onSuccess: () => snackbar.success(t("danger-zone.delete-account.success")), mutationFn: () => profileApi.deleteCurrentProfile(), }); + const enableNotificationsMutation = useMutation({ + onError: () => snackbar.error(t("notifications.enable.error")), + onSuccess: () => snackbar.success(t("notifications.enable.success")), + mutationFn: async () => { + await Notification.requestPermission(); + await registerServiceWorker(); + }, + }); + function handleClickDelete() { openDialog(ConfirmationDialog, { description: t("danger-zone.delete-account.description"), @@ -33,6 +43,23 @@ export function SettingsPageContainer(): ReactElement { return ( + + {t("notifications.header")} + + + + {t("notifications.enable.description")} + + + + {t("danger-zone.header")} @@ -41,16 +68,14 @@ export function SettingsPageContainer(): ReactElement { {t("danger-zone.description")} -
- -
+
); } diff --git a/services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.nav.tsx b/services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.nav.tsx index f11aea38..4bb21ba4 100644 --- a/services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.nav.tsx +++ b/services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.nav.tsx @@ -34,11 +34,7 @@ export function SettingsPageNav({ return ( ); }