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.

11.5 KB
Raw Blame
import { Meta, StoryObj } from '@storybook/react'
import { useActions, useMountedLogic } from 'kea'
import { router } from 'kea-router'

import { useDelayedOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { App } from 'scenes/App'
import { availableOnboardingProducts } from 'scenes/onboarding/shared/utils'
import { urls } from 'scenes/urls'

import { mswDecorator, useStorybookMocks } from '~/mocks/browser'
import { billingJson } from '~/mocks/fixtures/_billing'
import { billingUnsubscribedJson } from '~/mocks/fixtures/_billing_unsubscribed'
import domainConnectJson from '~/mocks/fixtures/_domain_connect_check.json'
import preflightJson from '~/mocks/fixtures/_preflight.json'
import { ProductKey } from '~/queries/schema/schema-general'
import { OnboardingStepKey } from '~/types'

import { onboardingLogic } from './onboardingLogic'

const meta: Meta = {
    title: 'Scenes-Other/Onboarding',
    parameters: {
        layout: 'fullscreen',
        viewMode: 'story',
        mockDate: '2023-05-25',
    },
    decorators: [
        mswDecorator({
            get: {
                '/_preflight': {
                    ...preflightJson,
                    cloud: true,
                    realm: 'cloud',
                },
                '/stats': {},
                '/events': {},
                '/api/billing/': {
                    ...billingJson,
                },
                '/api/environments/:team_id/integrations/domain-connect/check': domainConnectJson,
                '/api/environments/:team_id/external_data_sources/wizard': () => {
                    return [
                        200,
                        {
                            // 4 featured ones
                            Github: {
                                name: 'Github',
                                iconPath: '/static/services/github.png',
                                fields: [],
                                caption: '',
                                featured: true,
                            },
                            Hubspot: {
                                name: 'Hubspot',
                                iconPath: '/static/services/hubspot.png',
                                fields: [],
                                caption: '',
                                featured: true,
                            },
                            Postgres: {
                                name: 'Postgres',
                                iconPath: '/static/services/postgres.png',
                                fields: [],
                                caption: '',
                                featured: true,
                            },
                            Stripe: {
                                name: 'Stripe',
                                iconPath: '/static/services/stripe.png',
                                fields: [],
                                caption: '',
                                featured: true,
                            },
                            // Extra sources to be displayed under button
                            Ashby: {
                                name: 'Ashby',
                                iconPath: '/static/services/ashby.png',
                                fields: [],
                                caption: '',
                                featured: false,
                            },
                            Supabase: {
                                name: 'Supabase',
                                iconPath: '/static/services/supabase.png',
                                fields: [],
                                caption: '',
                                featured: false,
                            },
                            Shopify: {
                                name: 'Shopify',
                                iconPath: '/static/services/shopify.png',
                                fields: [],
                                caption: '',
                                featured: false,
                            },
                        },
                    ]
                },
            },
            patch: {
                '/api/environments/:team_id/add_product_intent/': {},
            },
        }),
    ],
}
export default meta

type Story = StoryObj<{}>

// ==========================================
// SDK Install (one example)
// ==========================================

export const SDKInstall: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.PRODUCT_ANALYTICS])
            router.actions.push(
                urls.onboarding({ productKey: ProductKey.PRODUCT_ANALYTICS, stepKey: OnboardingStepKey.INSTALL })
            )
        })

        return <App />
    },
    parameters: {
        testOptions: { waitForSelector: '[data-attr="sdk-continue"]' },
    },
}

export const AIObservabilitySDKInstall: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.AI_OBSERVABILITY])
            router.actions.push(
                urls.onboarding({ productKey: ProductKey.AI_OBSERVABILITY, stepKey: OnboardingStepKey.INSTALL })
            )
        })

        return <App />
    },
    parameters: {
        testOptions: { waitForSelector: '[data-attr="sdk-continue"]' },
    },
}

// ==========================================
// Product Configuration Steps
// ==========================================

export const ProductAnalyticsConfiguration: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.PRODUCT_ANALYTICS])
            router.actions.push(
                urls.onboarding({
                    productKey: ProductKey.PRODUCT_ANALYTICS,
                    stepKey: OnboardingStepKey.PRODUCT_CONFIGURATION,
                })
            )
        })

        return <App />
    },
}

export const SessionReplayConfiguration: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.SESSION_REPLAY])
            router.actions.push(
                urls.onboarding({
                    productKey: ProductKey.SESSION_REPLAY,
                    stepKey: OnboardingStepKey.PRODUCT_CONFIGURATION,
                })
            )
        })

        return <App />
    },
}

export const SessionReplayOptIn: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.PRODUCT_ANALYTICS])
            router.actions.push(
                urls.onboarding({ productKey: ProductKey.PRODUCT_ANALYTICS, stepKey: OnboardingStepKey.SESSION_REPLAY })
            )
        })

        return <App />
    },
}

// ==========================================
// Web Analytics
// ==========================================

export const AuthorizedDomains: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.WEB_ANALYTICS])
            router.actions.push(
                urls.onboarding({ productKey: ProductKey.WEB_ANALYTICS, stepKey: OnboardingStepKey.AUTHORIZED_DOMAINS })
            )
        })

        return <App />
    },
}

// ==========================================
// Data Warehouse
// ==========================================

export const LinkData: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.DATA_WAREHOUSE])
            router.actions.push(
                urls.onboarding({ productKey: ProductKey.DATA_WAREHOUSE, stepKey: OnboardingStepKey.LINK_DATA })
            )
        })

        return <App />
    },
}

// ==========================================
// Error Tracking
// ==========================================

export const SourceMaps: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.ERROR_TRACKING])
            router.actions.push(
                urls.onboarding({ productKey: ProductKey.ERROR_TRACKING, stepKey: OnboardingStepKey.SOURCE_MAPS })
            )
        })

        return <App />
    },
}

export const Alerts: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.ERROR_TRACKING])
            router.actions.push(
                urls.onboarding({ productKey: ProductKey.ERROR_TRACKING, stepKey: OnboardingStepKey.ALERTS })
            )
        })

        return <App />
    },
}

// ==========================================
// Workflows
// ==========================================

export const WorkflowsCustomInstallationInstructions: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.WORKFLOWS])
            router.actions.push(
                urls.onboarding({
                    productKey: ProductKey.WORKFLOWS,
                    stepKey: OnboardingStepKey.INSTALL,
                })
            )
        })

        return <App />
    },
}

// ==========================================
// Shared Steps
// ==========================================

export const BillingPlans: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)

        useStorybookMocks({
            get: {
                '/api/billing/': {
                    ...billingUnsubscribedJson,
                },
            },
        })

        useDelayedOnMountEffect(() => {
            router.actions.push(
                urls.onboarding({
                    productKey: ProductKey.PRODUCT_ANALYTICS,
                    // Use the namespaced id so currentFlowStep resolves via exact match
                    // (loose-match by bare stepKey races with the billing-gated flow rebuild).
                    step: `${OnboardingStepKey.PLANS}:${ProductKey.PRODUCT_ANALYTICS}`,
                })
            )
        })

        return <App />
    },
}

export const InviteTeammates: Story = {
    render: () => {
        useMountedLogic(onboardingLogic)
        const { setProduct } = useActions(onboardingLogic)

        useDelayedOnMountEffect(() => {
            setProduct(availableOnboardingProducts[ProductKey.PRODUCT_ANALYTICS])
            router.actions.push(
                urls.onboarding({
                    productKey: ProductKey.PRODUCT_ANALYTICS,
                    stepKey: OnboardingStepKey.INVITE_TEAMMATES,
                })
            )
        })

        return <App />
    },
}