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.2 KB
Raw Blame
import type { ReactNode } from 'react'

import { WizardReview } from 'lib/components/WizardReview'

import { AlertWizardStep } from 'products/alerts/frontend/components/AlertWizard'

interface WizardStepInput {
    nameNode: ReactNode
    definitionNode: ReactNode
    previewNode: ReactNode
    scheduleNode: ReactNode
    notifyNode: ReactNode
    advancedNode: ReactNode
    summary: { fires: string; cadence: string; notifies: string }
    thresholdValidationError?: string
    scheduleRestrictionFormError?: string
    alertFormHasErrors: boolean
    alertName: string
}

export function buildWizardSteps(input: WizardStepInput): AlertWizardStep[] {
    const { summary, alertFormHasErrors } = input
    const reviewFires = summary.fires || 'a configured threshold'
    const reviewCadence = summary.cadence || 'a cadence'
    const reviewNotifies = summary.notifies || 'no one yet'
    const monitorCannotAdvanceReason = !input.alertName ? 'Enter an alert name.' : input.thresholdValidationError
    const monitorCanAdvance = !monitorCannotAdvanceReason

    return [
        {
            key: 'monitor',
            title: 'Monitor',
            description: 'Pick what this alert watches and when it should fire.',
            canAdvance: monitorCanAdvance,
            cannotAdvanceReason: monitorCannotAdvanceReason,
            content: (
                <div className="space-y-4">
                    {input.nameNode}
                    {input.previewNode}
                    {input.definitionNode}
                </div>
            ),
        },
        {
            key: 'schedule',
            title: 'Schedule',
            description: 'How often this alert runs.',
            canAdvance: !input.scheduleRestrictionFormError,
            cannotAdvanceReason: input.scheduleRestrictionFormError,
            content: (
                <div className="space-y-3">
                    {input.scheduleNode}
                    {input.advancedNode}
                </div>
            ),
        },
        {
            key: 'notify',
            title: 'Notify',
            description: 'Who gets told when this alert fires.',
            canAdvance: true,
            content: <div className="space-y-4">{input.notifyNode}</div>,
        },
        {
            key: 'review',
            title: 'Review',
            description: 'Confirm what this alert will do, then create it.',
            canAdvance: !alertFormHasErrors,
            cannotAdvanceReason: alertFormHasErrors ? 'Fix the errors in previous steps before creating.' : undefined,
            content: (
                <WizardReview
                    items={[
                        { label: 'Fires when', value: reviewFires },
                        { label: 'Runs', value: reviewCadence },
                        { label: 'Notifies', value: reviewNotifies },
                    ]}
                    footer={
                        <p className="text-xs text-muted">
                            You can adjust any of this later without stepping through the wizard. Editing an existing
                            alert opens straight to its sections.
                        </p>
                    }
                />
            ),
        },
    ]
}