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, kea, listeners, path, reducers, selectors } from 'kea'
import { router, urlToAction } from 'kea-router'

import { urls } from 'scenes/urls'

import type { SceneTabKey } from '../../types'

export type SceneTabConfig = {
    key: SceneTabKey
    label: string
    href: string
}

export const SCENE_TABS: SceneTabConfig[] = [
    {
        key: 'tickets',
        label: 'Tickets',
        href: urls.supportTickets(),
    },
    {
        key: 'settings',
        label: 'Settings',
        href: urls.supportSettings(),
    },
]

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface scenesTabsLogicValues {
    activeTab: SceneTabKey
    tabs: SceneTabConfig[]
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface scenesTabsLogicActions {
    setActiveTab: (tab: SceneTabKey) => {
        tab: SceneTabKey
    }
    setTab: (tab: SceneTabKey) => {
        tab: SceneTabKey
    }
}

export type scenesTabsLogicType = MakeLogicType<scenesTabsLogicValues, scenesTabsLogicActions>

export const scenesTabsLogic = kea<scenesTabsLogicType>([
    path(['products', 'conversations', 'frontend', 'components', 'ScenesTabs', 'scenesTabsLogic']),
    actions({
        setTab: (tab: SceneTabKey) => ({ tab }),
        setActiveTab: (tab: SceneTabKey) => ({ tab }),
    }),
    reducers({
        activeTab: [
            'tickets' as SceneTabKey,
            {
                setActiveTab: (_state: SceneTabKey, { tab }: { tab: SceneTabKey }) => tab,
            },
        ],
    }),
    selectors({
        tabs: [() => [], (): SceneTabConfig[] => SCENE_TABS],
    }),
    listeners({
        setTab: ({ tab }: { tab: SceneTabKey }) => {
            const target = SCENE_TABS.find((sceneTab) => sceneTab.key === tab)?.href
            if (target) {
                router.actions.push(target)
            }
        },
    }),
    urlToAction(({ actions }) => {
        return {
            '/support/tickets': () => actions.setActiveTab('tickets'),
            '/support/tickets/:ticketId': () => actions.setActiveTab('tickets'),
            '/support/settings': () => actions.setActiveTab('settings'),
        }
    }),
])