Skip to content

Commit be68892

Browse files
Johan BookJohan Book
Johan Book
authored and
Johan Book
committed
feat(web-ui): add button to enable notifcations
1 parent 8230773 commit be68892

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,14 @@
1212
}
1313
},
1414
"darkmode": "Darkmode",
15-
"header": "Settings"
15+
"header": "Settings",
16+
"notifications": {
17+
"header": "Notifications",
18+
"enable": {
19+
"description": "Enable push notifications for this device",
20+
"button": "Enable",
21+
"error": "Failed to enable push notifications",
22+
"success": "Enabled push notifications"
23+
}
24+
}
1625
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,14 @@
1212
}
1313
},
1414
"darkmode": "Mörkerläge",
15-
"header": "Inställningar"
15+
"header": "Inställningar",
16+
"notifications": {
17+
"header": "Push-notiser",
18+
"enable": {
19+
"description": "Aktivera push-notiser på denna enhet",
20+
"button": "Aktivera",
21+
"error": "Ett fel uppstod vid aktivering av notiser",
22+
"success": "Notiser har aktiverats"
23+
}
24+
}
1625
}

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@ import { useMutation } from "src/core/query";
88
import { useSnackbar } from "src/core/snackbar";
99

1010
import { SettingsPageNav } from "./SettingsPage.nav";
11+
import {registerServiceWorker} from "src/registerServiceWorker";
1112

1213
export function SettingsPageContainer(): ReactElement {
1314
const { t } = useTranslation("settings");
1415
const { openDialog } = useDialog();
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 sx={{ paddingTop: 3 }} 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
}

0 commit comments

Comments
 (0)