: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
feat(workflows): add guided onboarding for messaging and automation (#113835)
Meikel Ratze1ce763ade09
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 7c3aab0a6c7c..6162b57df68e 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -635,6 +635,7 @@ export const FEATURE_FLAGS = {WORKFLOWS_DELAY_UNTIL_DATE: 'workflows-delay-until-date', // owner: @dmarchuk #team-workflowsWORKFLOWS_EMAIL_REPUTATION: 'workflows-email-reputation', // owner: #team-workflowsWORKFLOWS_EMAIL_SENDER_ROTATION: 'workflows-email-sender-rotation', // owner: @arthurdedeus #team-workflows+ WORKFLOWS_GUIDED_ONBOARDING: 'workflows-guided-onboarding', // owner: #team-workflows, first-run path choice and the messaging setup guideWORKFLOWS_INTERNAL_EVENT_FILTERS: 'workflows-internal-event-filters', // owner: @haven #team-workflowsWORKFLOWS_ISP_SENDING_HEALTH: 'workflows-isp-sending-health', // owner: #team-workflowsWORKFLOWS_LINEAR_VIEW: 'workflows-linear-view', // owner: #team-workflowsdiff --git a/products/workflows/frontend/MessagingSetup.tsx b/products/workflows/frontend/MessagingSetup.tsxindex ba300ba8af44..75da34635181 100644--- a/products/workflows/frontend/MessagingSetup.tsx+++ b/products/workflows/frontend/MessagingSetup.tsx@@ -1,5 +1,10 @@+import { useValues } from 'kea'+import { LemonButton } from '@posthog/lemon-ui'+import { FEATURE_FLAGS } from 'lib/constants'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import {MESSAGING_SETUP_TAB_KEYS,MESSAGING_TAB_CONTENT,@@ -7,6 +12,8 @@ import {MessagingNavTabKey,MessagingSetupTabKey,} from './messagingTabs'+import { MessagingSetupGuide } from './setupGuide/MessagingSetupGuide'+import { MessagingSetupMenuStatus } from './setupGuide/MessagingSetupMenuStatus'export interface MessagingSetupProps {tab: MessagingSetupTabKey@@ -15,8 +22,12 @@ export interface MessagingSetupProps {/** The sending setup tabs behind one "Messaging" tab, with a side menu that keeps each tab's own URL. */export function MessagingSetup({ tab, linkFor }: MessagingSetupProps): JSX.Element {+ const { featureFlags } = useValues(featureFlagLogic)+ const guidedOnboardingEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_GUIDED_ONBOARDING]+return (<>+ {guidedOnboardingEnabled && <MessagingSetupGuide linkFor={linkFor} />}<div className="flex flex-col gap-4 @min-[48rem]/main-content:flex-row"><navclassName="flex flex-row flex-wrap gap-1 shrink-0 @min-[48rem]/main-content:flex-col @min-[48rem]/main-content:w-52"@@ -28,6 +39,7 @@ export function MessagingSetup({ tab, linkFor }: MessagingSetupProps): JSX.Elemesize="small"to={linkFor(key)}active={key === tab}+ sideIcon={guidedOnboardingEnabled ? <MessagingSetupMenuStatus tab={key} /> : undefined}data-attr={`messaging-setup-menu-${key}`}>{MESSAGING_TAB_LABELS[key]}diff --git a/products/workflows/frontend/Workflows/WorkflowsTable.tsx b/products/workflows/frontend/Workflows/WorkflowsTable.tsxindex 93e771344590..c2e0ce1d03f5 100644--- a/products/workflows/frontend/Workflows/WorkflowsTable.tsx+++ b/products/workflows/frontend/Workflows/WorkflowsTable.tsx@@ -29,6 +29,8 @@ import { urls } from 'scenes/urls'import { AccessControlLevel, AccessControlResourceType } from '~/types'+import { AutomationSuggestionBanner } from '../setupGuide/AutomationSuggestionBanner'+import { MessagingSetupReminderBanner } from '../setupGuide/MessagingSetupReminderBanner'import { getHogFlowStep } from './hogflows/steps/HogFlowSteps'import { HogFlow } from './hogflows/types'import { workflowLogic } from './workflowLogic'@@ -116,6 +118,7 @@ export function WorkflowsTable(): JSX.Element {const { featureFlags } = useValues(featureFlagLogic)const selfOptimisingEnabled = !!featureFlags[FEATURE_FLAGS.SELF_OPTIMISING_WORKFLOWS]const newNavigationEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_NEW_NAVIGATION]+ const guidedOnboardingEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_GUIDED_ONBOARDING]const logic = workflowsLogic()const {workflowsLoading,@@ -392,6 +395,7 @@ export function WorkflowsTable(): JSX.Element {return (<div className="workflows-section" data-attr="workflows-table" data-loading={workflowsLoading}><>+ {guidedOnboardingEnabled && <MessagingSetupReminderBanner />}{newNavigationEnabled && (<div className="mb-3"><LemonSegmentedButton<WorkflowTypeFilter>@@ -494,6 +498,7 @@ export function WorkflowsTable(): JSX.Element {nouns={['workflow', 'workflows']}emptyState="No workflows matching filters"/>+ {guidedOnboardingEnabled && <AutomationSuggestionBanner />}</></div>)diff --git a/products/workflows/frontend/WorkflowsScene.tsx b/products/workflows/frontend/WorkflowsScene.tsxindex 61e5a4c4557d..df330175a53b 100644--- a/products/workflows/frontend/WorkflowsScene.tsx+++ b/products/workflows/frontend/WorkflowsScene.tsx@@ -25,6 +25,7 @@ import { workflowsEmptyState } from './emptyState/workflowsEmptyState'import { MessagingSetup } from './MessagingSetup'import { MessagingTabActions } from './MessagingTabActions'import { isMessagingSetupTab, messagingNavTabs } from './messagingTabs'+import { MessagingSetupTabLabel } from './setupGuide/MessagingSetupTabLabel'import { newWorkflowLogic } from './Workflows/newWorkflowLogic'import { NewWorkflowModal } from './Workflows/NewWorkflowModal'import { workflowTemplatesLogic } from './Workflows/templates/workflowTemplatesLogic'@@ -158,6 +159,7 @@ export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {const { currentTab: routeTab } = useValues(workflowsSceneLogic(props))const { featureFlags } = useValues(featureFlagLogic)const newNavigationEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_NEW_NAVIGATION]+ const guidedOnboardingEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_GUIDED_ONBOARDING]// The workflow templates page exists only in the new navigation.const currentTab: WorkflowsSceneTab = !newNavigationEnabled && routeTab === 'templates' ? 'workflows' : routeTabconst { startNewWorkflow } = useActions(newWorkflowLogic)@@ -229,7 +231,7 @@ export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {content: <WorkflowsTemplates tab={currentTab === 'templates' ? 'templates' : 'library'} />,},{- label: 'Messaging',+ label: guidedOnboardingEnabled ? <MessagingSetupTabLabel /> : 'Messaging',key: 'messaging-setup',link: urls.workflows('channels'),content: (diff --git a/products/workflows/frontend/emptyState/workflowsEmptyState.tsx b/products/workflows/frontend/emptyState/workflowsEmptyState.tsxindex 113949495b46..83d26360fa6d 100644--- a/products/workflows/frontend/emptyState/workflowsEmptyState.tsx+++ b/products/workflows/frontend/emptyState/workflowsEmptyState.tsx@@ -3,10 +3,12 @@ import { IconDecisionTree } from '@posthog/icons'import { pngHoggie } from 'lib/brand/hoggies'import type { SceneProductEmptyState } from 'lib/components/ProductEmptyState/types'+import { FEATURE_FLAGS } from 'lib/constants'import { Scene } from 'scenes/sceneTypes'import { ProductKey } from '~/queries/schema/schema-general'+import { WorkflowsPathChoice } from '../setupGuide/WorkflowsPathChoice'import { urlForNewWorkflowComposer } from '../Workflows/newWorkflowLogic'import { WorkflowsPreview } from './WorkflowsPreview'import { workflowsSetupLogic } from './workflowsSetupLogic'@@ -40,5 +42,16 @@ export const workflowsEmptyState: SceneProductEmptyState = {docsUrl: 'https://posthog.com/docs/workflows',previewLabel: 'Your journeys, once running',Preview: WorkflowsPreview,+ featureFlagOverrides: {+ [FEATURE_FLAGS.WORKFLOWS_GUIDED_ONBOARDING]: {+ text: {+ 'needs-setup': {+ headline: 'What do you want to build first?',+ lead: 'Message your users with email, SMS and push, or automate work with Slack alerts, webhooks and AI tasks. You can do both later. This choice only picks where we start.',+ },+ },+ PrimaryAction: WorkflowsPathChoice,+ },+ },},}diff --git a/products/workflows/frontend/setupGuide/AutomationSuggestionBanner.tsx b/products/workflows/frontend/setupGuide/AutomationSuggestionBanner.tsxnew file mode 100644index 000000000000..a6eab479b547--- /dev/null+++ b/products/workflows/frontend/setupGuide/AutomationSuggestionBanner.tsx@@ -0,0 +1,30 @@+import { useActions, useValues } from 'kea'++import { LemonBanner } from '@posthog/lemon-ui'++import { workflowsSetupGuideLogic } from './workflowsSetupGuideLogic'++/** A one-time suggestion for people who started with messaging, so they learn that workflows also automate work. */+export function AutomationSuggestionBanner(): JSX.Element | null {+ const { showAutomationSuggestion } = useValues(workflowsSetupGuideLogic)+ const { dismissAutomationSuggestion, browseTemplates } = useActions(workflowsSetupGuideLogic)++ if (!showAutomationSuggestion) {+ return null+ }++ return (+ <LemonBanner+ type="info"+ className="mt-4"+ onClose={dismissAutomationSuggestion}+ action={{+ children: 'See automation templates',+ onClick: () => browseTemplates('automation'),+ 'data-attr': 'workflows-automation-suggestion',+ }}+ >+ You can also automate other work, for example a Slack alert when a large company signs up.+ </LemonBanner>+ )+}diff --git a/products/workflows/frontend/setupGuide/MessagingSetupGuide.tsx b/products/workflows/frontend/setupGuide/MessagingSetupGuide.tsxnew file mode 100644index 000000000000..3cd14faddf76--- /dev/null+++ b/products/workflows/frontend/setupGuide/MessagingSetupGuide.tsx@@ -0,0 +1,58 @@+import { useActions, useValues } from 'kea'++import { IconCheckCircle, IconCircleDashed } from '@posthog/icons'+import { LemonButton } from '@posthog/lemon-ui'++import { LemonCard } from 'lib/lemon-ui/LemonCard'++import type { MessagingNavTabKey } from '../messagingTabs'+import { SETUP_GUIDE_STEP_LABELS, SETUP_GUIDE_STEP_TABS } from './setupGuideSteps'+import { workflowsSetupGuideLogic } from './workflowsSetupGuideLogic'++/** The messaging setup checklist. Each step opens the real setup page, so people learn where things live. */+export function MessagingSetupGuide({ linkFor }: { linkFor: (tab: MessagingNavTabKey) => string }): JSX.Element | null {+ const { steps, showGuide, completedCount, nextStep } = useValues(workflowsSetupGuideLogic)+ const { hideGuide, stepClicked } = useActions(workflowsSetupGuideLogic)++ if (!showGuide || !steps) {+ return null+ }++ return (+ <LemonCard hoverEffect={false} className="mb-4 p-4" data-attr="messaging-setup-guide">+ <div className="flex flex-wrap items-center justify-between gap-2">+ <h3 className="mb-0 text-base font-semibold">Set up messaging</h3>+ <div className="flex items-center gap-2">+ <span className="text-secondary text-sm">{`${completedCount} of ${steps.length} done`}</span>+ <LemonButton+ size="small"+ type="tertiary"+ onClick={hideGuide}+ data-attr="messaging-setup-guide-hide"+ >+ Hide guide+ </LemonButton>+ </div>+ </div>+ <div className="flex flex-wrap gap-2 mt-3">+ {steps.map((step) => {+ const tab = SETUP_GUIDE_STEP_TABS[step.key]+ return (+ <LemonButton+ key={step.key}+ type="secondary"+ size="small"+ active={step.key === nextStep}+ icon={step.done ? <IconCheckCircle className="text-success" /> : <IconCircleDashed />}+ to={tab ? linkFor(tab) : undefined}+ onClick={() => stepClicked(step.key)}+ data-attr={`messaging-setup-guide-step-${step.key}`}+ >+ {SETUP_GUIDE_STEP_LABELS[step.key]}+ </LemonButton>+ )+ })}+ </div>+ </LemonCard>+ )+}diff --git a/products/workflows/frontend/setupGuide/MessagingSetupMenuStatus.tsx b/products/workflows/frontend/setupGuide/MessagingSetupMenuStatus.tsxnew file mode 100644index 000000000000..d036d779ce4e--- /dev/null+++ b/products/workflows/frontend/setupGuide/MessagingSetupMenuStatus.tsx@@ -0,0 +1,38 @@+import { useValues } from 'kea'++import { IconCheckCircle } from '@posthog/icons'+import { LemonTag } from '@posthog/lemon-ui'++import type { MessagingSetupTabKey } from '../messagingTabs'+import { workflowsSetupGuideLogic } from './workflowsSetupGuideLogic'++/** The setup state of one Messaging menu item: done, or what is still open. */+export function MessagingSetupMenuStatus({ tab }: { tab: MessagingSetupTabKey }): JSX.Element | null {+ const { steps } = useValues(workflowsSetupGuideLogic)++ if (!steps) {+ return null+ }+ const isDone = (key: string): boolean => steps.some((step) => step.key === key && step.done)++ if (tab === 'channels') {+ if (isDone('domain')) {+ return <IconCheckCircle className="text-success" />+ }+ return (+ <LemonTag size="small" type="warning">+ {isDone('channel') ? 'Verify' : 'Set up'}+ </LemonTag>+ )+ }+ if (tab === 'opt-outs') {+ return isDone('opt-outs') ? (+ <IconCheckCircle className="text-success" />+ ) : (+ <LemonTag size="small" type="warning">+ Set up+ </LemonTag>+ )+ }+ return null+}diff --git a/products/workflows/frontend/setupGuide/MessagingSetupReminderBanner.tsx b/products/workflows/frontend/setupGuide/MessagingSetupReminderBanner.tsxnew file mode 100644index 000000000000..6c1ce8a3abec--- /dev/null+++ b/products/workflows/frontend/setupGuide/MessagingSetupReminderBanner.tsx@@ -0,0 +1,35 @@+import { useActions, useValues } from 'kea'++import { LemonBanner } from '@posthog/lemon-ui'++import { urls } from 'scenes/urls'++import { SETUP_GUIDE_STEP_LABELS, SETUP_GUIDE_STEP_TABS } from './setupGuideSteps'+import { workflowsSetupGuideLogic } from './workflowsSetupGuideLogic'++/** One line on the workflows list that keeps the next messaging setup step in view until setup is done. */+export function MessagingSetupReminderBanner(): JSX.Element | null {+ const { showMessagingReminder, nextStep, completedCount, steps } = useValues(workflowsSetupGuideLogic)+ const { hideGuide, stepClicked } = useActions(workflowsSetupGuideLogic)++ if (!showMessagingReminder || !nextStep || !steps) {+ return null+ }+ const tab = SETUP_GUIDE_STEP_TABS[nextStep]++ return (+ <LemonBanner+ type="info"+ className="mb-4"+ onClose={hideGuide}+ action={{+ children: 'Continue setup',+ to: tab ? urls.workflows(tab) : undefined,+ onClick: () => stepClicked(nextStep),+ 'data-attr': 'messaging-setup-reminder-continue',+ }}+ >+ {`Messaging setup: ${completedCount} of ${steps.length} done. Next: ${SETUP_GUIDE_STEP_LABELS[nextStep].toLowerCase()}.`}+ </LemonBanner>+ )+}diff --git a/products/workflows/frontend/setupGuide/MessagingSetupTabLabel.tsx b/products/workflows/frontend/setupGuide/MessagingSetupTabLabel.tsxnew file mode 100644index 000000000000..f03e9bf7eb5f--- /dev/null+++ b/products/workflows/frontend/setupGuide/MessagingSetupTabLabel.tsx@@ -0,0 +1,17 @@+import { useValues } from 'kea'++import { LemonBadge } from '@posthog/lemon-ui'++import { workflowsSetupGuideLogic } from './workflowsSetupGuideLogic'++/** The "Messaging" tab label, with a dot while a person who chose messaging has setup steps open. */+export function MessagingSetupTabLabel(): JSX.Element {+ const { showMessagingReminder } = useValues(workflowsSetupGuideLogic)++ return (+ <span className="flex items-center gap-1">+ <span>Messaging</span>+ {showMessagingReminder && <LemonBadge status="warning" size="small" position="none" />}+ </span>+ )+}diff --git a/products/workflows/frontend/setupGuide/WorkflowsPathChoice.tsx b/products/workflows/frontend/setupGuide/WorkflowsPathChoice.tsxnew file mode 100644index 000000000000..3838d93b4b87--- /dev/null+++ b/products/workflows/frontend/setupGuide/WorkflowsPathChoice.tsx@@ -0,0 +1,25 @@+import { useActions } from 'kea'++import { LemonButton } from '@posthog/lemon-ui'++import { workflowsSetupGuideLogic } from './workflowsSetupGuideLogic'++/** The first-run choice on the workflows empty state. The choice picks the onboarding a person gets. */+export function WorkflowsPathChoice(): JSX.Element {+ const { choosePath } = useActions(workflowsSetupGuideLogic)++ return (+ <div className="flex flex-wrap gap-2">+ <LemonButton type="primary" onClick={() => choosePath('messaging')} data-attr="workflows-path-messaging">+ Message your users+ </LemonButton>+ <LemonButton+ type="secondary"+ onClick={() => choosePath('automation')}+ data-attr="workflows-path-automation"+ >+ Automate a process+ </LemonButton>+ </div>+ )+}diff --git a/products/workflows/frontend/setupGuide/setupGuideSteps.test.ts b/products/workflows/frontend/setupGuide/setupGuideSteps.test.tsnew file mode 100644index 000000000000..974ec589b9bb--- /dev/null+++ b/products/workflows/frontend/setupGuide/setupGuideSteps.test.ts@@ -0,0 +1,46 @@+import { SetupGuideInputs, deriveSetupGuideSteps } from './setupGuideSteps'++const LOADED: SetupGuideInputs = {+ emailChannels: [],+ optOutCategoryCount: 0,+ emailTemplateCount: 0,+ hasMessagingWorkflow: false,+}++describe('deriveSetupGuideSteps', () => {+ test.each<[string, Partial<SetupGuideInputs>]>([+ ['channels', { emailChannels: null }],+ ['opt-out categories', { optOutCategoryCount: null }],+ ['email templates', { emailTemplateCount: null }],+ ['messaging workflows', { hasMessagingWorkflow: null }],+ ])('is unknown while %s are loading', (_, missing) => {+ expect(deriveSetupGuideSteps({ ...LOADED, ...missing })).toBeNull()+ })++ test.each<[string, Partial<SetupGuideInputs>, string[]]>([+ ['nothing set up', {}, []],+ [+ 'an unverified channel completes only the channel step',+ { emailChannels: [{ verified: false }] },+ ['channel'],+ ],+ [+ 'one verified channel among several completes the domain step',+ { emailChannels: [{ verified: false }, { verified: true }] },+ ['channel', 'domain'],+ ],+ [+ 'everything set up',+ {+ emailChannels: [{ verified: true }],+ optOutCategoryCount: 2,+ emailTemplateCount: 1,+ hasMessagingWorkflow: true,+ },+ ['channel', 'domain', 'opt-outs', 'email-template', 'first-journey'],+ ],+ ])('%s', (_, inputs, expectedDone) => {+ const steps = deriveSetupGuideSteps({ ...LOADED, ...inputs })+ expect(steps?.filter((step) => step.done).map((step) => step.key)).toEqual(expectedDone)+ })+})diff --git a/products/workflows/frontend/setupGuide/setupGuideSteps.ts b/products/workflows/frontend/setupGuide/setupGuideSteps.tsnew file mode 100644index 000000000000..1df651c85faf--- /dev/null+++ b/products/workflows/frontend/setupGuide/setupGuideSteps.ts@@ -0,0 +1,57 @@+// pinned: analytics property values for the setup guide events - renaming breaks dashboards+export const SETUP_GUIDE_STEP_KEYS = ['channel', 'domain', 'opt-outs', 'email-template', 'first-journey'] as const+export type SetupGuideStepKey = (typeof SETUP_GUIDE_STEP_KEYS)[number]++export interface SetupGuideStep {+ key: SetupGuideStepKey+ done: boolean+}++/** What the guide reads to decide which steps are done. `null` means the value has not loaded yet. */+export interface SetupGuideInputs {+ emailChannels: { verified: boolean }[] | null+ optOutCategoryCount: number | null+ emailTemplateCount: number | null+ hasMessagingWorkflow: boolean | null+}++/**+ * The messaging setup steps, in order. Returns `null` until every input has loaded, so the guide never+ * shows a step as open only because its data is still on the way.+ */+export function deriveSetupGuideSteps(inputs: SetupGuideInputs): SetupGuideStep[] | null {+ const { emailChannels, optOutCategoryCount, emailTemplateCount, hasMessagingWorkflow } = inputs+ if (+ emailChannels === null ||+ optOutCategoryCount === null ||+ emailTemplateCount === null ||+ hasMessagingWorkflow === null+ ) {+ return null+ }+ const done: Record<SetupGuideStepKey, boolean> = {+ channel: emailChannels.length > 0,+ domain: emailChannels.some((channel) => channel.verified),+ 'opt-outs': optOutCategoryCount > 0,+ 'email-template': emailTemplateCount > 0,+ 'first-journey': hasMessagingWorkflow,+ }+ return SETUP_GUIDE_STEP_KEYS.map((key) => ({ key, done: done[key] }))+}++export const SETUP_GUIDE_STEP_LABELS: Record<SetupGuideStepKey, string> = {+ channel: 'Connect an email channel',+ domain: 'Verify your sending domain',+ 'opt-outs': 'Add opt-out categories',+ 'email-template': 'Design your first email',+ 'first-journey': 'Start your first journey',+}++/** The setup tab a step opens. The first journey opens the workflow templates instead, so it has no tab. */+export const SETUP_GUIDE_STEP_TABS: Record<SetupGuideStepKey, 'channels' | 'opt-outs' | 'library' | null> = {+ channel: 'channels',+ domain: 'channels',+ 'opt-outs': 'opt-outs',+ 'email-template': 'library',+ 'first-journey': null,+}diff --git a/products/workflows/frontend/setupGuide/workflowsSetupGuideLogic.ts b/products/workflows/frontend/setupGuide/workflowsSetupGuideLogic.tsnew file mode 100644index 000000000000..3b53564cf152--- /dev/null+++ b/products/workflows/frontend/setupGuide/workflowsSetupGuideLogic.ts@@ -0,0 +1,312 @@+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'+import { loaders } from 'kea-loaders'+import { router } from 'kea-router'+import { subscriptions } from 'kea-subscriptions'+import posthog from 'posthog-js'++import { FEATURE_FLAGS } from 'lib/constants'+import { integrationsLogic } from 'lib/integrations/integrationsLogic'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { projectLogic } from 'scenes/projectLogic'+import { teamLogic } from 'scenes/teamLogic'+import { urls } from 'scenes/urls'++import type { FeatureFlagsSet } from '../../../../frontend/src/lib/logic/featureFlagLogic'+import type { IntegrationType } from '../../../../frontend/src/types'+import { hogFlowsList } from '../generated/api'+import { optOutCategoriesLogic } from '../OptOuts/optOutCategoriesLogic'+import type { MessageCategory } from '../OptOuts/optOutCategoriesLogic'+import { messageTemplatesLogic } from '../TemplateLibrary/messageTemplatesLogic'+import type { MessageTemplate } from '../TemplateLibrary/types'+import { urlForNewWorkflowComposer } from '../Workflows/newWorkflowLogic'+import { workflowTemplatesLogic } from '../Workflows/templates/workflowTemplatesLogic'+import type { WorkflowTemplateTypeFilter } from '../Workflows/workflowTypeFilters'+import { SetupGuideStep, SetupGuideStepKey, deriveSetupGuideSteps } from './setupGuideSteps'++// pinned: analytics property values for `workflows onboarding path selected` - renaming breaks dashboards+export type WorkflowsOnboardingPath = 'messaging' | 'automation'++export interface TeamSetupGuideState {+ path: WorkflowsOnboardingPath | null+ guideHidden: boolean+ automationSuggestionDismissed: boolean+}++const EMPTY_TEAM_STATE: TeamSetupGuideState = { path: null, guideHidden: false, automationSuggestionDismissed: false }++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface workflowsSetupGuideLogicValues {+ featureFlags: FeatureFlagsSet // featureFlagLogic+ integrations: IntegrationType[] | null // integrationsLogic+ templates: MessageTemplate[] // messageTemplatesLogic+ templatesLoading: boolean // messageTemplatesLogic+ categories: MessageCategory[] // optOutCategoriesLogic+ categoriesLoading: boolean // optOutCategoriesLogic+ currentProjectId: number | null // projectLogic+ currentTeamId: number | null // teamLogic+ chosenPath: WorkflowsOnboardingPath | null+ completedCount: number+ hasMessagingWorkflow: boolean | null+ hasMessagingWorkflowLoading: boolean+ isComplete: boolean | null+ nextStep: SetupGuideStepKey | null+ showAutomationSuggestion: boolean+ showGuide: boolean+ showMessagingReminder: boolean+ stateByTeam: Record<string, TeamSetupGuideState>+ steps: SetupGuideStep[] | null+ teamState: TeamSetupGuideState+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface workflowsSetupGuideLogicActions {+ setTypeFilter: (typeFilter: WorkflowTemplateTypeFilter) => {+ typeFilter: WorkflowTemplateTypeFilter+ } // workflowTemplatesLogic+ browseTemplates: (typeFilter: WorkflowTemplateTypeFilter) => {+ typeFilter: WorkflowTemplateTypeFilter+ }+ choosePath: (path: WorkflowsOnboardingPath) => {+ path: WorkflowsOnboardingPath+ }+ dismissAutomationSuggestion: () => {+ value: true+ }+ hideGuide: () => {+ value: true+ }+ loadHasMessagingWorkflow: () => any+ loadHasMessagingWorkflowFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadHasMessagingWorkflowSuccess: (+ hasMessagingWorkflow: boolean,+ payload?: any+ ) => {+ hasMessagingWorkflow: boolean+ payload?: any+ }+ stepClicked: (step: SetupGuideStepKey) => {+ step: 'channel' | 'domain' | 'email-template' | 'first-journey' | 'opt-outs'+ }+ updateTeamState: (+ teamId: string,+ update: Partial<TeamSetupGuideState>+ ) => {+ teamId: string+ update: Partial<TeamSetupGuideState>+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface workflowsSetupGuideLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ teamState: (+ stateByTeam: Record<string, TeamSetupGuideState>,+ currentTeamId: number | null+ ) => TeamSetupGuideState+ chosenPath: (teamState: TeamSetupGuideState) => WorkflowsOnboardingPath | null+ steps: (+ integrations: IntegrationType[] | null,+ categories: import('products/messaging/frontend/generated/api.schemas').MessageCategoryApi[],+ categoriesLoading: boolean,+ templates: MessageTemplate[],+ templatesLoading: boolean,+ hasMessagingWorkflow: boolean | null+ ) => SetupGuideStep[] | null+ completedCount: (steps: SetupGuideStep[] | null) => number+ nextStep: (steps: SetupGuideStep[] | null) => SetupGuideStepKey | null+ isComplete: (steps: SetupGuideStep[] | null) => boolean | null+ showGuide: (isComplete: boolean | null, teamState: TeamSetupGuideState) => boolean+ showMessagingReminder: (showGuide: boolean, chosenPath: WorkflowsOnboardingPath | null) => boolean+ showAutomationSuggestion: (teamState: TeamSetupGuideState) => boolean+ }+}++export type workflowsSetupGuideLogicType = MakeLogicType<+ workflowsSetupGuideLogicValues,+ workflowsSetupGuideLogicActions,+ Record<string, any>,+ workflowsSetupGuideLogicMeta+>++export const workflowsSetupGuideLogic = kea<workflowsSetupGuideLogicType>([+ path(['products', 'workflows', 'frontend', 'setupGuide', 'workflowsSetupGuideLogic']),+ connect(() => ({+ values: [+ teamLogic,+ ['currentTeamId'],+ projectLogic,+ ['currentProjectId'],+ featureFlagLogic,+ ['featureFlags'],+ integrationsLogic,+ ['integrations'],+ optOutCategoriesLogic,+ ['categories', 'categoriesLoading'],+ messageTemplatesLogic,+ ['templates', 'templatesLoading'],+ ],+ actions: [workflowTemplatesLogic, ['setTypeFilter']],+ })),+ actions({+ choosePath: (path: WorkflowsOnboardingPath) => ({ path }),+ hideGuide: true,+ dismissAutomationSuggestion: true,+ stepClicked: (step: SetupGuideStepKey) => ({ step }),+ browseTemplates: (typeFilter: WorkflowTemplateTypeFilter) => ({ typeFilter }),+ updateTeamState: (teamId: string, update: Partial<TeamSetupGuideState>) => ({ teamId, update }),+ }),+ reducers({+ // Keyed by team ID, so the choice and the hidden guide in one project do not carry over to another.+ stateByTeam: [+ {} as Record<string, TeamSetupGuideState>,+ { persist: true },+ {+ updateTeamState: (state, { teamId, update }) => ({+ ...state,+ [teamId]: { ...EMPTY_TEAM_STATE, ...state[teamId], ...update },+ }),+ },+ ],+ }),+ loaders(({ values }) => ({+ hasMessagingWorkflow: [+ null as boolean | null,+ {+ loadHasMessagingWorkflow: async () => {+ const response = await hogFlowsList(String(values.currentProjectId), {+ type: 'messaging',+ limit: 1,+ })+ return response.count > 0+ },+ },+ ],+ })),+ selectors({+ teamState: [+ (s) => [s.stateByTeam, s.currentTeamId],+ (stateByTeam: Record<string, TeamSetupGuideState>, currentTeamId: number | null): TeamSetupGuideState =>+ (currentTeamId !== null && stateByTeam[String(currentTeamId)]) || EMPTY_TEAM_STATE,+ ],+ chosenPath: [(s) => [s.teamState], (teamState: TeamSetupGuideState) => teamState.path],+ steps: [+ (s) => [+ s.integrations,+ s.categories,+ s.categoriesLoading,+ s.templates,+ s.templatesLoading,+ s.hasMessagingWorkflow,+ ],+ (+ integrations: IntegrationType[] | null,+ categories: import('products/messaging/frontend/generated/api.schemas').MessageCategoryApi[],+ categoriesLoading: boolean,+ templates: MessageTemplate[],+ templatesLoading: boolean,+ hasMessagingWorkflow: boolean | null+ ): SetupGuideStep[] | null =>+ deriveSetupGuideSteps({+ emailChannels:+ integrations === null+ ? null+ : integrations+ .filter((integration) => integration.kind === 'email')+ .map((integration) => ({ verified: integration.config?.verified === true })),+ // The loaders start from an empty list, so "loading" is the only way to tell "not loaded yet".+ optOutCategoryCount: categoriesLoading && categories.length === 0 ? null : categories.length,+ emailTemplateCount: templatesLoading && templates.length === 0 ? null : templates.length,+ hasMessagingWorkflow,+ }),+ ],+ completedCount: [+ (s) => [s.steps],+ (steps: SetupGuideStep[] | null): number => steps?.filter((step) => step.done).length ?? 0,+ ],+ nextStep: [+ (s) => [s.steps],+ (steps: SetupGuideStep[] | null): SetupGuideStepKey | null =>+ steps?.find((step) => !step.done)?.key ?? null,+ ],+ isComplete: [+ (s) => [s.steps],+ (steps: SetupGuideStep[] | null): boolean | null =>+ steps === null ? null : steps.every((step) => step.done),+ ],+ showGuide: [+ (s) => [s.isComplete, s.teamState],+ (isComplete: boolean | null, teamState: TeamSetupGuideState): boolean =>+ isComplete === false && !teamState.guideHidden,+ ],+ /** The list banner and the tab dot are for people who asked for messaging. Others find the guide in setup. */+ showMessagingReminder: [+ (s) => [s.showGuide, s.chosenPath],+ (showGuide: boolean, chosenPath: WorkflowsOnboardingPath | null): boolean =>+ showGuide && chosenPath === 'messaging',+ ],+ showAutomationSuggestion: [+ (s) => [s.teamState],+ (teamState: TeamSetupGuideState): boolean =>+ teamState.path === 'messaging' && !teamState.automationSuggestionDismissed,+ ],+ }),+ listeners(({ actions, values }) => ({+ choosePath: ({ path }) => {+ if (values.currentTeamId !== null) {+ actions.updateTeamState(String(values.currentTeamId), { path })+ }+ // pinned: analytics event name - renaming breaks dashboards+ posthog.capture('workflows onboarding path selected', { path })+ if (path === 'messaging') {+ router.actions.push(urls.workflows('channels'))+ } else {+ actions.browseTemplates('automation')+ }+ },+ hideGuide: () => {+ if (values.currentTeamId !== null) {+ actions.updateTeamState(String(values.currentTeamId), { guideHidden: true })+ }+ // pinned: analytics event name - renaming breaks dashboards+ posthog.capture('workflows setup guide hidden', { completed_steps: values.completedCount })+ },+ dismissAutomationSuggestion: () => {+ if (values.currentTeamId !== null) {+ actions.updateTeamState(String(values.currentTeamId), { automationSuggestionDismissed: true })+ }+ },+ stepClicked: ({ step }) => {+ // pinned: analytics event name - renaming breaks dashboards+ posthog.capture('workflows setup guide step clicked', { step })+ if (step === 'first-journey') {+ actions.browseTemplates('messaging')+ }+ },+ browseTemplates: ({ typeFilter }) => {+ if (!values.featureFlags[FEATURE_FLAGS.WORKFLOWS_NEW_NAVIGATION]) {+ // The templates page is part of the new navigation. Without it, start from nothing.+ router.actions.push(urlForNewWorkflowComposer())+ return+ }+ actions.setTypeFilter(typeFilter)+ router.actions.push(urls.workflows('templates'))+ },+ })),+ subscriptions(({ values }) => ({+ isComplete: (isComplete: boolean | null, wasComplete: boolean | null) => {+ if (isComplete && wasComplete === false) {+ // pinned: analytics event name - renaming breaks dashboards+ posthog.capture('workflows setup guide completed', { path: values.chosenPath })+ }+ },+ })),+ afterMount(({ actions }) => {+ actions.loadHasMessagingWorkflow()+ }),+])