@@ -18,6 +18,8 @@ import DeviceCapabilities from "../../../DeviceCapabilities";
1818import Picker from "../../../shared/Picker" ;
1919import { useGetInstanceInfoQuery } from "../../../../api" ;
2020import { usePostHog } from "posthog-react-native/lib/posthog-react-native/src/hooks/usePostHog" ;
21+ import { useState } from "react" ;
22+ import { PostHogPersistedProperty } from "posthog-react-native/lib/posthog-core/src/types" ;
2123
2224interface SettingsProps {
2325 onClose : ( ) => void ;
@@ -33,6 +35,9 @@ export const Settings = ({ onClose }: SettingsProps) => {
3335
3436 const { data : instanceInfo } = useGetInstanceInfoQuery ( backend ) ;
3537 const { currentInstanceConfig } = useAppConfigContext ( ) ;
38+ const [ isOptedOut , setIsOptedOut ] = useState (
39+ posthog . getPersistedProperty ( PostHogPersistedProperty . OptedOut ) || false ,
40+ ) ;
3641
3742 const handleLeaveInstance = ( ) => {
3843 writeToAsyncStorage ( STORAGE . DATASOURCE , "" ) . then ( ( ) => {
@@ -48,12 +53,16 @@ export const Settings = ({ onClose }: SettingsProps) => {
4853 const handleToggleDebugMode = ( debugModeOn : boolean ) => {
4954 setIsDebugMode ( debugModeOn ) ;
5055 writeToAsyncStorage ( STORAGE . DEBUG_MODE , String ( debugModeOn ) ) ;
56+ } ;
5157
52- if ( debugModeOn ) {
58+ const handleToggleOptOutCheckbox = ( optOut : boolean ) => {
59+ if ( ! optOut ) {
5360 posthog . optIn ( ) ;
5461 } else {
5562 posthog . optOut ( ) ;
5663 }
64+
65+ setIsOptedOut ( optOut ) ;
5766 } ;
5867
5968 return (
@@ -78,7 +87,14 @@ export const Settings = ({ onClose }: SettingsProps) => {
7887 items = { LANGUAGE_OPTIONS }
7988 />
8089 < Spacer height = { spacing . xl } />
81- < Checkbox checked = { isDebugMode } onChange = { handleToggleDebugMode } label = { t ( "debugLogging" ) } />
90+ < Checkbox
91+ disabled = { isOptedOut }
92+ checked = { isDebugMode && ! isOptedOut }
93+ onChange = { handleToggleDebugMode }
94+ label = { t ( "debugLogging" ) }
95+ />
96+ < Spacer height = { spacing . md } />
97+ < Checkbox checked = { isOptedOut } onChange = { handleToggleOptOutCheckbox } label = { t ( "optOutOfDiagnostics" ) } />
8298 < Spacer height = { spacing . xl } />
8399 { ! primaryBackend && (
84100 < >
0 commit comments