Skip to content

: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.

2.2 KB
Raw Blame
import { MakeLogicType, actions, connect, kea, listeners, path, reducers } from 'kea'

import { globalModalsLogic } from '~/layout/globalModalsLogic'
import { organizationLogic } from '~/scenes/organizationLogic'
import { projectLogic } from '~/scenes/projectLogic'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface modalInterruptionTrackingLogicValues {
    isCreateOrganizationModalShown: boolean // globalModalsLogic
    isCreateProjectModalShown: boolean // globalModalsLogic
    interruptedForm: string | null
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface modalInterruptionTrackingLogicActions {
    createOrganization: (name: string) => string // organizationLogic
    createProject: (args_0: { name: string }) => {
        name: string
    } // projectLogic
    setInterruptedForm: (form: string | null) => {
        form: string | null
    }
}

export type modalInterruptionTrackingLogicType = MakeLogicType<
    modalInterruptionTrackingLogicValues,
    modalInterruptionTrackingLogicActions
>

export const modalInterruptionTrackingLogic = kea<modalInterruptionTrackingLogicType>([
    path(['lib', 'components', 'TimeSensitiveAuthentication', 'modalInterruptionTrackingLogic']),
    connect(() => ({
        values: [globalModalsLogic, ['isCreateOrganizationModalShown', 'isCreateProjectModalShown']],
        actions: [organizationLogic, ['createOrganization'], projectLogic, ['createProject']],
    })),
    actions({
        setInterruptedForm: (form: string | null) => ({ form }),
    }),
    reducers({
        interruptedForm: [
            null as string | null,
            {
                setInterruptedForm: (_, { form }) => form,
            },
        ],
    }),
    listeners(({ actions, values }) => ({
        createOrganization: () => {
            if (values.isCreateOrganizationModalShown) {
                actions.setInterruptedForm('create_organization_modal')
            }
        },

        createProject: () => {
            if (values.isCreateProjectModalShown) {
                actions.setInterruptedForm('create_project_modal')
            }
        },
    })),
])