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.

4.4 KB
Raw Blame
import { MOCK_SECOND_ORGANIZATION_MEMBER } from 'lib/api.mock'

import type { Meta, StoryObj } from '@storybook/react'
import { waitFor } from '@testing-library/react'

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

import { memberOffboardingLogic } from './memberOffboardingLogic'
import { MemberOffboardingModal } from './MemberOffboardingModal'

const resources = [
    {
        id: 'public_link:dashboard:1:4',
        resource_id: '4',
        kind: 'dashboard',
        name: 'Product adoption',
        url: '/project/1/dashboard/4',
        password_protected: true,
        team_id: 1,
        project_name: 'Website',
    },
    {
        id: 'public_link:dashboard:2:5',
        resource_id: '5',
        kind: 'dashboard',
        name: 'Growth overview',
        url: '/project/2/dashboard/5',
        password_protected: false,
        team_id: 2,
        project_name: 'App',
    },
    {
        id: 'public_link:dashboard:1:1',
        resource_id: '1',
        kind: 'dashboard',
        name: 'Product overview',
        url: '/project/1/dashboard/1',
        password_protected: false,
        team_id: 1,
        project_name: 'Website',
    },
    {
        id: 'public_link:insight:1:2',
        resource_id: '2',
        kind: 'insight',
        name: 'Weekly acquisition',
        url: '/project/1/insights/trends01',
        password_protected: true,
        team_id: 1,
        project_name: 'Website',
    },
    {
        id: 'public_link:notebook:2:3',
        resource_id: 'analysis',
        kind: 'notebook',
        name: 'Acquisition analysis',
        url: '/project/2/notebooks/analysis',
        password_protected: true,
        team_id: 2,
        project_name: 'App',
    },
    {
        id: 'subscription:1',
        resource_id: '1',
        destination_type: 'email',
        destination: '[email protected],[email protected]',
        kind: 'subscription',
        name: 'Weekly product overview',
        url: '/project/1/subscriptions/1',
        password_protected: false,
        team_id: 1,
        project_name: 'Website',
        created_at: '2026-10-20T10:00:00Z',
    },
    {
        id: 'alert:1',
        resource_id: '1',
        kind: 'alert',
        name: 'Weekly usage drop',
        url: '/project/1/alerts?alert_type=insights&alert_id=1',
        password_protected: false,
        team_id: 1,
        project_name: 'Website',
        created_at: '2026-10-20T10:00:00Z',
    },
]

async function openMemberOffboarding(): Promise<void> {
    await waitFor(() => {
        if (!memberOffboardingLogic.isMounted()) {
            throw new Error('Waiting for member offboarding to mount')
        }
    })
    memberOffboardingLogic.actions.open(MOCK_SECOND_ORGANIZATION_MEMBER)
}

const meta: Meta<typeof MemberOffboardingModal> = {
    title: 'Scenes-App/Settings/Organization/Member offboarding',
    component: MemberOffboardingModal,
    parameters: {
        testOptions: { snapshotTargetSelector: '.LemonModal' },
    },
    decorators: [
        mswDecorator({
            patch: {
                '/api/projects/:project/subscriptions/:id/': () => [200, {}],
                '/api/projects/:project/alerts/:id/': () => [200, {}],
                '/api/projects/:project/:kind/:resource/sharing/': () => [204, null],
            },
            get: {
                '/api/organizations/:organizationId/members/:userUuid/offboarding_preview/': resources,
                '/api/organizations/:organizationId/members/:userUuid/scoped_api_keys/': { has_keys: false, keys: [] },
            },
        }),
    ],
    play: async () => {
        await openMemberOffboarding()
        const logic = memberOffboardingLogic
        await waitFor(() => {
            if (!logic.values.resources?.length) {
                throw new Error(logic.values.loadError || 'Waiting for resource review')
            }
        })
    },
}
export default meta

type Story = StoryObj<typeof meta>
export const ReviewResources: Story = {}
export const NoResources: Story = {
    decorators: [
        mswDecorator({ get: { '/api/organizations/:organizationId/members/:userUuid/offboarding_preview/': [] } }),
    ],
    play: async () => {
        await openMemberOffboarding()
        const logic = memberOffboardingLogic
        await waitFor(() => {
            if (logic.values.resourcesLoading || logic.values.resources === null) {
                throw new Error(logic.values.loadError || 'Waiting for resource review')
            }
        })
    },
}