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.

3.0 KB
Raw Blame
import { Meta, StoryObj } from '@storybook/react'

import { LemonButton, LemonCheckbox } from '@posthog/lemon-ui'

import { ImpersonationReasonModal } from './ImpersonationReasonModal'

const meta: Meta<typeof ImpersonationReasonModal> = {
    title: 'Layout/Impersonation Reason Modal',
    component: ImpersonationReasonModal,
    parameters: {
        layout: 'padded',
        viewMode: 'story',
    },
}
export default meta
type Story = StoryObj<typeof ImpersonationReasonModal>

const noop = (): void => {}

const IMPERSONATED_EMAIL = '[email protected]'

function ModalShell({ children }: { children: React.ReactNode }): JSX.Element {
    return <div className="bg-default p-4">{children}</div>
}

export const SessionExpiredReImpersonation: Story = {
    render: () => (
        <ModalShell>
            <ImpersonationReasonModal
                isOpen
                onConfirm={noop}
                title="Impersonation session expired"
                description={`Your session impersonating ${IMPERSONATED_EMAIL} has expired.`}
                confirmText="Re-impersonate"
                closable={false}
                cancelButton={{
                    label: 'Return to admin',
                    status: 'danger',
                    onClick: noop,
                    sideAction: {
                        dropdown: {
                            placement: 'top-end',
                            overlay: (
                                <LemonButton fullWidth onClick={noop}>
                                    Return to PostHog
                                </LemonButton>
                            ),
                        },
                    },
                }}
                inline
            >
                <LemonCheckbox checked onChange={noop} label="Read-only mode (recommended)" />
            </ImpersonationReasonModal>
        </ModalShell>
    ),
}

export const UpgradeToReadWrite: Story = {
    render: () => (
        <ModalShell>
            <ImpersonationReasonModal
                isOpen
                onClose={noop}
                onConfirm={noop}
                title="Upgrade to read-write impersonation"
                description="Read-write mode allows you to make changes on behalf of the user. Please provide a reason for this upgrade."
                confirmText="Upgrade"
                inline
            />
        </ModalShell>
    ),
}

export const Loading: Story = {
    parameters: {
        // The primary button spins while loading — don't wait for it to disappear.
        testOptions: { waitForLoadersToDisappear: false },
    },
    render: () => (
        <ModalShell>
            <ImpersonationReasonModal
                isOpen
                onClose={noop}
                onConfirm={noop}
                title="Upgrade to read-write impersonation"
                description="Read-write mode allows you to make changes on behalf of the user. Please provide a reason for this upgrade."
                confirmText="Upgrade"
                loading
                inline
            />
        </ModalShell>
    ),
}