import { useAtomValue } from "@effect/atom-react"; import { AuthSettingsWriteScope, type EnvironmentId } from "@t3tools/contracts"; import { useState } from "react"; import { serverEnvironment } from "../../state/server"; import { useEnvironmentScope } from "../../state/session"; import { useAtomCommand } from "../../state/use-atom-command"; import { Switch } from "../ui/switch"; import { SettingsRow } from "./settingsLayout"; export function ProductAnalyticsControl({ environmentId, label, }: { readonly environmentId: EnvironmentId; readonly label: string; }) { const settings = useAtomValue(serverEnvironment.settingsValueAtom(environmentId)); const config = useAtomValue(serverEnvironment.configValueAtom(environmentId)); const supported = config?.environment.capabilities.productAnalyticsConsent === true; const canWrite = useEnvironmentScope(environmentId, AuthSettingsWriteScope); const updateSettings = useAtomCommand(serverEnvironment.updateSettings, { reportFailure: true }); const [pending, setPending] = useState(false); return ( { setPending(true); void updateSettings({ environmentId, input: { patch: { telemetryEnabled: enabled } }, }).finally(() => setPending(false)); }} /> } /> ); }