Skip to content

Commit 63b9f50

Browse files
johanbookJohan Book
and
Johan Book
authored
feat(web-ui): add button to enable notifcations (#924)
Co-authored-by: Johan Book <{ID}+{username}@users.noreply.github.com>
1 parent 8230773 commit 63b9f50

File tree

4 files changed

+58
-21
lines changed

4 files changed

+58
-21
lines changed

services/web-ui/public/locales/en/settings.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"description": "These are the permanent settings you can change. More settings will be added here in the future.",
32
"danger-zone": {
43
"description": "These are actions that cannot be undone",
54
"header": "Danger zone",
@@ -12,5 +11,14 @@
1211
}
1312
},
1413
"darkmode": "Darkmode",
15-
"header": "Settings"
14+
"header": "Settings",
15+
"notifications": {
16+
"header": "Notifications",
17+
"enable": {
18+
"description": "Enable push notifications for this device",
19+
"button": "Enable",
20+
"error": "Failed to enable push notifications",
21+
"success": "Enabled push notifications"
22+
}
23+
}
1624
}

services/web-ui/public/locales/sv/settings.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"description": "Här kan du ändra dina permanenta inställningar. Detta kommer att komma mer här allteftersom.",
32
"danger-zone": {
43
"description": "Detta är åtgärder som inte kan ångras",
54
"header": "Farozon",
@@ -12,5 +11,14 @@
1211
}
1312
},
1413
"darkmode": "Mörkerläge",
15-
"header": "Inställningar"
14+
"header": "Inställningar",
15+
"notifications": {
16+
"header": "Push-notiser",
17+
"enable": {
18+
"description": "Aktivera push-notiser på denna enhet",
19+
"button": "Aktivera",
20+
"error": "Ett fel uppstod vid aktivering av notiser",
21+
"success": "Notiser har aktiverats"
22+
}
23+
}
1624
}

services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.container.tsx

+37-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useDialog } from "src/core/dialog";
66
import { useTranslation } from "src/core/i18n";
77
import { useMutation } from "src/core/query";
88
import { useSnackbar } from "src/core/snackbar";
9+
import { registerServiceWorker } from "src/registerServiceWorker";
910

1011
import { SettingsPageNav } from "./SettingsPage.nav";
1112

@@ -15,11 +16,20 @@ export function SettingsPageContainer(): ReactElement {
1516
const snackbar = useSnackbar();
1617

1718
const deleteAccountMutation = useMutation({
18-
onError: () => snackbar.success(t("danger-zone.delete-account.success")),
19-
onSuccess: () => snackbar.error(t("danger-zone.delete-account.error")),
19+
onError: () => snackbar.error(t("danger-zone.delete-account.error")),
20+
onSuccess: () => snackbar.success(t("danger-zone.delete-account.success")),
2021
mutationFn: () => profileApi.deleteCurrentProfile(),
2122
});
2223

24+
const enableNotificationsMutation = useMutation({
25+
onError: () => snackbar.error(t("notifications.enable.error")),
26+
onSuccess: () => snackbar.success(t("notifications.enable.success")),
27+
mutationFn: async () => {
28+
await Notification.requestPermission();
29+
await registerServiceWorker();
30+
},
31+
});
32+
2333
function handleClickDelete() {
2434
openDialog(ConfirmationDialog, {
2535
description: t("danger-zone.delete-account.description"),
@@ -33,6 +43,23 @@ export function SettingsPageContainer(): ReactElement {
3343

3444
return (
3545
<SettingsPageNav>
46+
<Typography gutterBottom variant="h6">
47+
{t("notifications.header")}
48+
</Typography>
49+
50+
<Typography color="textSecondary" sx={{ pb: 2 }}>
51+
{t("notifications.enable.description")}
52+
</Typography>
53+
54+
<Button
55+
color="inherit"
56+
loading={enableNotificationsMutation.isPending}
57+
onClick={() => enableNotificationsMutation.mutate()}
58+
variant="outlined"
59+
>
60+
{t("notifications.enable.button")}
61+
</Button>
62+
3663
<Typography gutterBottom sx={{ paddingTop: 3 }} variant="h6">
3764
{t("danger-zone.header")}
3865
</Typography>
@@ -41,16 +68,14 @@ export function SettingsPageContainer(): ReactElement {
4168
{t("danger-zone.description")}
4269
</Typography>
4370

44-
<div>
45-
<Button
46-
color="error"
47-
loading={deleteAccountMutation.isPending}
48-
onClick={handleClickDelete}
49-
variant="contained"
50-
>
51-
{t("danger-zone.delete-account.button")}
52-
</Button>
53-
</div>
71+
<Button
72+
color="error"
73+
loading={deleteAccountMutation.isPending}
74+
onClick={handleClickDelete}
75+
variant="contained"
76+
>
77+
{t("danger-zone.delete-account.button")}
78+
</Button>
5479
</SettingsPageNav>
5580
);
5681
}

services/web-ui/src/features/settings/pages/SettingsPage/SettingsPage.nav.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ export function SettingsPageNav({
3434

3535
return (
3636
<Nav appBarContent={appBarContent}>
37-
<Box sx={{ pt: 1, px: 3 }}>
38-
<Typography color="textSecondary">{t("description")}</Typography>
39-
40-
{children}
41-
</Box>
37+
<Box sx={{ pt: 1, px: 3 }}>{children}</Box>
4238
</Nav>
4339
);
4440
}

0 commit comments

Comments
 (0)