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.4 KB
Raw Blame
import { Meta, StoryObj } from '@storybook/react'

import { mswDecorator } from '~/mocks/browser'

import type { CohortUsedInResponseApi } from 'products/cohorts/frontend/generated/api.schemas'

import { DeleteCohortDialog } from './DeleteCohortDialog'

const emptyBlock = { results: [], total: 0, hidden: 0, has_more: false }

const usedIn: CohortUsedInResponseApi = {
    feature_flags: {
        results: [
            { id: 1, key: 'new-checkout', name: 'New checkout', archived: false },
            { id: 2, key: 'paused-banner', name: 'Paused banner', archived: false },
            { id: 3, key: 'old-banner', name: 'Old banner', archived: true },
        ],
        total: 3,
        hidden: 0,
        has_more: false,
    },
    insights: {
        results: [{ id: 5, short_id: 'abc123', name: 'Weekly signups' }],
        total: 1,
        hidden: 0,
        has_more: false,
    },
    cohorts: emptyBlock,
    test_account_filters: {
        results: [{ id: 42, name: 'Staging' }],
        total: 1,
        has_more: false,
    },
    workflows: {
        results: [{ id: '0192a7f0-0000-7000-8000-000000000001', name: 'Welcome series', status: 'active' }],
        total: 2,
        hidden: 1,
        has_more: true,
    },
}

const meta: Meta<typeof DeleteCohortDialog> = {
    component: DeleteCohortDialog,
    title: 'Scenes-App/People/Delete cohort dialog',
    // In the app the dialog sits in a LemonModal, which is never narrower than 28rem. Rendering the
    // bare component lets it shrink to its text, so the snapshot would wrap at a width no user sees.
    decorators: [
        (Story) => (
            <div className="w-[28rem]">
                <Story />
            </div>
        ),
    ],
    args: {
        cohortId: 1,
        cohortName: 'Power users',
        onConfirm: () => {},
        closeDialog: () => {},
    },
}
export default meta

type Story = StoryObj<typeof DeleteCohortDialog>

export const Blocked: Story = {
    decorators: [mswDecorator({ get: { '/api/projects/:team_id/cohorts/:id/used_in/': usedIn } })],
}

export const NothingUsesIt: Story = {
    decorators: [
        mswDecorator({
            get: {
                '/api/projects/:team_id/cohorts/:id/used_in/': {
                    feature_flags: emptyBlock,
                    insights: emptyBlock,
                    cohorts: emptyBlock,
                    test_account_filters: emptyBlock,
                },
            },
        }),
    ],
}