: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { Meta, StoryObj } from '@storybook/react'
import { useStorybookMocks } from '~/mocks/browser'
import { useAvailableFeatures } from '~/mocks/features'
import { mockIntegration } from '~/test/mocks'
import { AvailableFeature, IntegrationType, SLACK_INTEGRATION_SCOPES } from '~/types'
import { Slack } from '../definitions/slack'
import { SlackIntegration } from './SlackIntegration'
type StoryArgs = { instanceConfigured?: boolean; integrated?: boolean }
const SLACK_INSTANCE_SETTINGS = [
{ key: 'SLACK_APP_CLIENT_ID', value: '910200304849.3676478528614' },
{ key: 'SLACK_APP_CLIENT_SECRET', value: '*****' },
]
const meta: Meta<StoryArgs> = {
title: 'Components/Integrations/Slack',
parameters: { mockDate: '2023-01-01' },
render: ({ instanceConfigured = true, integrated = false }) => {
useAvailableFeatures([AvailableFeature.SUBSCRIPTIONS])
useStorybookMocks({
get: {
'/api/projects/:id/integrations': { results: integrated ? [mockIntegration] : [] },
'/api/instance_settings': {
results: instanceConfigured ? SLACK_INSTANCE_SETTINGS : [],
},
},
})
return <SlackIntegration />
},
}
export default meta
type Story = StoryObj<StoryArgs>
export const SlackIntegration_: Story = {}
export const SlackIntegrationInstanceNotConfigured: Story = {
args: { instanceConfigured: false },
}
export const SlackIntegrationAdded: Story = {
args: { integrated: true },
}
// ---- OAuth landing page (``/project/:id/integrations/slack``) ----------------------------
//
// The settings-side ``SlackIntegration`` component above does not exercise the full-page
// success / warning surface that the OAuth callback lands users on. These stories render
// ``Slack.FullPage`` against a mocked integrations endpoint so the green-success and
// missing-scope warning states appear in snapshot diffs.
const renderFullPage = ({ integrations }: { integrations: IntegrationType[] }): JSX.Element => {
useAvailableFeatures([AvailableFeature.SUBSCRIPTIONS])
useStorybookMocks({
get: {
'/api/projects/:id/integrations': { results: integrations },
'/api/instance_settings': { results: SLACK_INSTANCE_SETTINGS },
},
})
return <Slack.FullPage />
}
const mockSlackIntegrationWithScopes = (scopes: string[]): IntegrationType => ({
...mockIntegration,
config: { ...mockIntegration.config, scope: scopes.join(',') },
})
export const SlackFullPageConnect: StoryObj = {
name: 'Full Page — Connect',
render: () => renderFullPage({ integrations: [] }),
}
export const SlackFullPageConnectedAllScopes: StoryObj = {
name: 'Full Page — Connected (all scopes)',
render: () =>
renderFullPage({
integrations: [mockSlackIntegrationWithScopes([...SLACK_INTEGRATION_SCOPES])],
}),
}
export const SlackFullPageConnectedMissingScopes: StoryObj = {
name: 'Full Page — Connected (missing scopes)',
render: () =>
renderFullPage({
// A legacy notifications-only scope set: enough to send messages, but missing
// app_mentions:read / users:read* etc., so the page should flip into "needs attention".
integrations: [
mockSlackIntegrationWithScopes(['channels:read', 'groups:read', 'chat:write', 'chat:write.customize']),
],
}),
}