From 3d8ee52a154633fad76c596d73873e40558134f9 Mon Sep 17 00:00:00 2001 From: yohlo Date: Tue, 25 Aug 2026 23:33:01 -0700 Subject: [PATCH] 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 --- src/contexts/auth-context.tsx | 1 + .../components/notifications-section.tsx | 36 +++++++++++++ src/features/settings/server.ts | 28 +++++++++- src/lib/telemetry/alerts.server.ts | 4 ++ src/locales/de/messages.po | 54 +++++++++++-------- src/locales/en/messages.po | 54 +++++++++++-------- src/locales/es/messages.po | 54 +++++++++++-------- src/locales/ja/messages.po | 54 +++++++++++-------- 8 files changed, 200 insertions(+), 85 deletions(-) diff --git a/src/contexts/auth-context.tsx b/src/contexts/auth-context.tsx index a7e0e07..a5073d7 100644 --- a/src/contexts/auth-context.tsx +++ b/src/contexts/auth-context.tsx @@ -18,6 +18,7 @@ interface AuthData { theme?: string; locale?: string; seenThemesHint?: boolean; + telemetryAlerts?: boolean; }; roles: string[]; phone: string; diff --git a/src/features/settings/components/notifications-section.tsx b/src/features/settings/components/notifications-section.tsx index 2cd40f3..7153bf2 100644 --- a/src/features/settings/components/notifications-section.tsx +++ b/src/features/settings/components/notifications-section.tsx @@ -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 ( + 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 && } {subscribed && (