: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 { MakeLogicType, kea, key, path, props } from 'kea'
import { forms } from 'kea-forms'
import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from 'kea-forms'
export type LemonDialogFormPropsType = {
/** Per-field validators. The second argument is the whole form, for fields whose validity
* depends on another field (e.g. a setting that is only required once a toggle is on). */
errors?: Record<string, (value: any, allValues: Record<string, any>) => string | undefined>
/** Unique key that isolates this dialog's form state from other open dialogs. */
dialogKey?: string
/** Surface field errors inline once a field is touched, instead of only via the submit button tooltip. */
showErrorsOnTouch?: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface lemonDialogLogicValues {
form: Record<string, string>
formAllErrors: Record<string, any>
formChanged: boolean
formErrors: DeepPartialMap<Record<string, string>, ValidationErrorType>
formHasErrors: boolean
formManualErrors: Record<string, any>
formTouched: boolean
formTouches: Record<string, boolean>
formValidationErrors: DeepPartialMap<Record<string, string>, ValidationErrorType>
isFormSubmitting: boolean
isFormValid: boolean
showFormErrors: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface lemonDialogLogicActions {
resetForm: (values?: Record<string, string>) => {
values?: Record<string, string>
}
setFormManualErrors: (errors: Record<string, any>) => {
errors: Record<string, any>
}
setFormValue: (
key: FieldName,
value: any
) => {
name: FieldName
value: any
}
setFormValues: (values: DeepPartial<Record<string, string>>) => {
values: DeepPartial<Record<string, string>>
}
submitForm: () => {
value: boolean
}
submitFormFailure: (
error: Error,
errors: Record<string, any>
) => {
error: Error
errors: Record<string, any>
}
submitFormRequest: (form: Record<string, string>) => {
form: Record<string, string>
}
submitFormSuccess: (form: Record<string, string>) => {
form: Record<string, string>
}
touchFormField: (key: string) => {
key: string
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface lemonDialogLogicMeta {
key: string
}
export type lemonDialogLogicType = MakeLogicType<
lemonDialogLogicValues,
lemonDialogLogicActions,
LemonDialogFormPropsType,
lemonDialogLogicMeta
>
export const lemonDialogLogic = kea<lemonDialogLogicType>([
props({} as LemonDialogFormPropsType),
key(({ dialogKey }) => dialogKey ?? 'default'),
path((k) => ['components', 'lemon-dialog', 'lemonDialogLogic', k]),
forms(({ props }) => ({
form: {
options: { showErrorsOnTouch: props.showErrorsOnTouch ?? false },
defaults: {} as Record<string, string>,
errors: (values: Record<string, string>) => {
const entries = Object.entries(props.errors || []).map(([key, valueOf]) => {
const result = valueOf(values[key], values)
return [key, result]
})
return Object.fromEntries(entries)
},
},
})),
])