feat(telemetry): opt-in admin alert pushes
- telemetryAlerts metadata flag, admin-gated server fn - alerts sent only to admins with the flag enabled - settings toggle visible to admins only, under device notifications
This commit is contained in:
@@ -1,11 +1,46 @@
|
||||
import { useState } from "react";
|
||||
import { Box, Title, Stack, Switch, Button, Text, Group } from "@mantine/core";
|
||||
import { Trans, useLingui } from "@lingui/react/macro";
|
||||
import { useWebPush } from "@/hooks/use-web-push";
|
||||
import { useAuth } from "@/contexts/auth-context";
|
||||
import { useIsAdmin } from "@/features/core/hooks/use-is-admin";
|
||||
import { updateUserTelemetryAlerts } from "@/features/settings/server";
|
||||
import toast from "@/lib/sonner";
|
||||
|
||||
const TelemetryAlertsSwitch = () => {
|
||||
const { t } = useLingui();
|
||||
const { metadata, set } = useAuth();
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const handleToggle = async (checked: boolean) => {
|
||||
setSaving(true);
|
||||
try {
|
||||
const result = await updateUserTelemetryAlerts({ data: checked });
|
||||
if (result?.metadata) {
|
||||
set({ metadata: result.metadata });
|
||||
}
|
||||
} catch {
|
||||
toast.error(t`Couldn't update telemetry alerts`);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Switch
|
||||
checked={metadata?.telemetryAlerts === true}
|
||||
onChange={(e) => handleToggle(e.currentTarget.checked)}
|
||||
disabled={saving}
|
||||
label={t`Telemetry alerts`}
|
||||
description={t`Error spikes and failing functions, pushed to this account`}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export function NotificationsSection() {
|
||||
const { supported, configured, permission, subscribed, busy, enable, disable, sendTest } =
|
||||
useWebPush();
|
||||
const isAdmin = useIsAdmin();
|
||||
const { t } = useLingui();
|
||||
|
||||
if (!supported || !configured) {
|
||||
@@ -64,6 +99,7 @@ export function NotificationsSection() {
|
||||
disabled={busy}
|
||||
label={t`Enable notifications on this device`}
|
||||
/>
|
||||
{subscribed && isAdmin && <TelemetryAlertsSwitch />}
|
||||
{subscribed && (
|
||||
<Group>
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user