:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { useActions, useValues } from 'kea'
import { LemonSwitch } from '@posthog/lemon-ui'
import { teamLogic } from 'scenes/teamLogic'
import { TeamType } from '~/types'
export function TeamSettingToggle({
field,
label,
invert,
onChange,
disabledReason,
}: {
field: keyof TeamType
label: string
/** When true, the toggle shows as ON when the field is false (e.g. autocapture_opt_out) */
invert?: boolean
/** Optional callback after the team is updated */
onChange?: (checked: boolean) => void
disabledReason?: string | null
}): JSX.Element {
const { updateCurrentTeam } = useActions(teamLogic)
const { currentTeam, currentTeamLoading } = useValues(teamLogic)
const rawValue = !!currentTeam?.[field]
const displayChecked = invert ? !rawValue : rawValue
return (
<LemonSwitch
onChange={(checked) => {
const newValue = invert ? !checked : checked
updateCurrentTeam({ [field]: newValue })
onChange?.(checked)
}}
checked={displayChecked}
disabled={currentTeamLoading}
disabledReason={disabledReason}
label={label}
bordered
/>
)
}