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.

1.8 KB
Raw Blame
import { MakeLogicType, kea, key, path, props } from 'kea'
import { lazyLoaders } from 'kea-loaders'

import { getPersonMessageAssets, MessageAsset } from 'products/workflows/frontend/Workflows/messageAssetsApi'

export interface PersonEmailsLogicProps {
    teamId: number
    personId: string
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface personEmailsLogicValues {
    emails: MessageAsset[]
    emailsLoading: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface personEmailsLogicActions {
    loadEmails: () => any
    loadEmailsFailure: (
        error: string,
        errorObject?: any
    ) => {
        error: string
        errorObject?: any
    }
    loadEmailsSuccess: (
        emails: MessageAsset[],
        payload?: any
    ) => {
        emails: MessageAsset[]
        payload?: any
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface personEmailsLogicMeta {
    key: string
}

export type personEmailsLogicType = MakeLogicType<
    personEmailsLogicValues,
    personEmailsLogicActions,
    PersonEmailsLogicProps,
    personEmailsLogicMeta
>

export const personEmailsLogic = kea<personEmailsLogicType>([
    path(['scenes', 'persons', 'personEmailsLogic']),
    props({} as PersonEmailsLogicProps),
    key((props) => `${props.teamId}-${props.personId}`),
    lazyLoaders(({ props }) => ({
        emails: [
            [] as MessageAsset[],
            {
                loadEmails: async () => {
                    if (!props.personId) {
                        return []
                    }
                    return await getPersonMessageAssets(props.teamId, props.personId)
                },
            },
        ],
    })),
])