Skip to content

Commit

Permalink
feat(web-ui): add button to enable notifcations (#924)
Browse files Browse the repository at this point in the history
Co-authored-by: Johan Book <{ID}+{username}@users.noreply.github.com>
  • Loading branch information
johanbook and Johan Book authored Jul 24, 2024
1 parent 8230773 commit 63b9f50
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
12 changes: 10 additions & 2 deletions services/web-ui/public/locales/en/settings.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
}
}
12 changes: 10 additions & 2 deletions services/web-ui/public/locales/sv/settings.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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"),
Expand All @@ -33,6 +43,23 @@ export function SettingsPageContainer(): ReactElement {

return (
<SettingsPageNav>
<Typography gutterBottom variant="h6">
{t("notifications.header")}
</Typography>

<Typography color="textSecondary" sx={{ pb: 2 }}>
{t("notifications.enable.description")}
</Typography>

<Button
color="inherit"
loading={enableNotificationsMutation.isPending}
onClick={() => enableNotificationsMutation.mutate()}
variant="outlined"
>
{t("notifications.enable.button")}
</Button>

<Typography gutterBottom sx={{ paddingTop: 3 }} variant="h6">
{t("danger-zone.header")}
</Typography>
Expand All @@ -41,16 +68,14 @@ export function SettingsPageContainer(): ReactElement {
{t("danger-zone.description")}
</Typography>

<div>
<Button
color="error"
loading={deleteAccountMutation.isPending}
onClick={handleClickDelete}
variant="contained"
>
{t("danger-zone.delete-account.button")}
</Button>
</div>
<Button
color="error"
loading={deleteAccountMutation.isPending}
onClick={handleClickDelete}
variant="contained"
>
{t("danger-zone.delete-account.button")}
</Button>
</SettingsPageNav>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export function SettingsPageNav({

return (
<Nav appBarContent={appBarContent}>
<Box sx={{ pt: 1, px: 3 }}>
<Typography color="textSecondary">{t("description")}</Typography>

{children}
</Box>
<Box sx={{ pt: 1, px: 3 }}>{children}</Box>
</Nav>
);
}

0 comments on commit 63b9f50

Please sign in to comment.