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.

feat(workflows): open the email domain wizard from setup entry points (#120425)

Meikel Ratze41b28de95c5
diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
index b8d9c58abd41..e86b968e06a2 100644
--- a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
@@ -118,6 +118,7 @@ export function BroadcastContentStep(): JSX.Element {
{senderSetup ? (
<EmailSetupModal
integration={senderSetup === 'new' ? undefined : senderSetup}
+ entry="broadcast"
onClose={closeSenderSetup}
onComplete={closeSenderSetup}
/>
diff --git a/products/workflows/frontend/Channels/EmailDomain/EmailDomainSetupModal.tsx b/products/workflows/frontend/Channels/EmailDomain/EmailDomainSetupModal.tsx
new file mode 100644
index 000000000000..151fc0f6ca7c
--- /dev/null
+++ b/products/workflows/frontend/Channels/EmailDomain/EmailDomainSetupModal.tsx
@@ -0,0 +1,107 @@
+import { useValues } from 'kea'
+import posthog from 'posthog-js'
+import { useEffect, useState } from 'react'
+
+import { IconExternal } from '@posthog/icons'
+import { LemonButton, LemonModal, LemonSkeleton } from '@posthog/lemon-ui'
+
+import { urls } from 'scenes/urls'
+
+import { IntegrationType } from '~/types'
+
+import { BindEmailDomainLogics } from './BindEmailDomainLogics'
+import { AgentHandoffModal } from './components/AgentHandoffModal'
+import { emailDomainLogic } from './emailDomainLogic'
+import { DomainStep } from './steps/DomainStep'
+import { ReadyStep } from './steps/ReadyStep'
+import { SettingsStep } from './steps/SettingsStep'
+import { UnavailableStep } from './steps/UnavailableStep'
+import { VerifyingStep } from './steps/VerifyingStep'
+
+export interface EmailDomainSetupModalProps {
+ integration?: IntegrationType | null
+ entry: 'channels' | 'broadcast' | 'configure'
+ onComplete: (integrationId?: number) => void
+ onClose: (savedIntegrationId?: number) => void
+}
+
+function ModalStep(): JSX.Element {
+ const { phase } = useValues(emailDomainLogic)
+ switch (phase) {
+ case 'unavailable':
+ return <UnavailableStep />
+ case 'settings':
+ return <SettingsStep />
+ case 'verifying':
+ return <VerifyingStep />
+ case 'ready':
+ return <ReadyStep />
+ default:
+ return <LemonSkeleton className="h-40" />
+ }
+}
+
+function ModalSettings({
+ integrationId,
+ openInNewTab,
+ onLeave,
+}: {
+ integrationId: number
+ openInNewTab: boolean
+ onLeave: () => void
+}): JSX.Element {
+ return (
+ <BindEmailDomainLogics id={String(integrationId)}>
+ <div className="@container flex flex-col gap-6">
+ <ModalStep />
+ <LemonButton
+ type="tertiary"
+ className="self-center"
+ to={urls.workflowsEmailDomain(integrationId)}
+ targetBlank={openInNewTab}
+ onClick={onLeave}
+ sideIcon={<IconExternal />}
+ >
+ Open full page
+ </LemonButton>
+ <AgentHandoffModal />
+ </div>
+ </BindEmailDomainLogics>
+ )
+}
+
+export function EmailDomainSetupModal({
+ integration,
+ entry,
+ onComplete,
+ onClose,
+}: EmailDomainSetupModalProps): JSX.Element {
+ const [integrationId, setIntegrationId] = useState<number | null>(integration?.id ?? null)
+
+ useEffect(() => {
+ // pinned: analytics event name
+ posthog.capture('email domain setup started', { entry })
+ }, [entry])
+
+ return (
+ <LemonModal
+ title={integrationId ? 'Verify your sending domain' : 'Set up a sending domain'}
+ width={720}
+ onClose={() => (integrationId ? onComplete(integrationId) : onClose())}
+ >
+ {integrationId ? (
+ // A broadcast saves its new sender a moment after the modal hands it over, so leaving the
+ // page right away would drop it. The full page opens next to the broadcast instead.
+ <ModalSettings
+ integrationId={integrationId}
+ openInNewTab={entry === 'broadcast'}
+ onLeave={() => onComplete(integrationId)}
+ />
+ ) : (
+ <div className="@container">
+ <DomainStep logicKey="modal" onCreated={(created) => setIntegrationId(created.id)} />
+ </div>
+ )}
+ </LemonModal>
+ )
+}
diff --git a/products/workflows/frontend/Channels/EmailDomain/emailDomainEntryPoints.test.tsx b/products/workflows/frontend/Channels/EmailDomain/emailDomainEntryPoints.test.tsx
new file mode 100644
index 000000000000..530dadea3407
--- /dev/null
+++ b/products/workflows/frontend/Channels/EmailDomain/emailDomainEntryPoints.test.tsx
@@ -0,0 +1,178 @@
+import '@testing-library/jest-dom'
+
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { Provider } from 'kea'
+import { router } from 'kea-router'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { urls } from 'scenes/urls'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { EmailSetupModal } from '../EmailSetup/EmailSetupModal'
+import { MessageChannels } from '../MessageChannels'
+import { FakeEmailDomainBackend } from './__mocks__/fakeEmailDomainBackend'
+
+const DOMAIN = 'mail.acme.com'
+const SENDER_ID = 42
+const LEGACY_MODAL_TITLE = 'Configure email sender'
+
+const element = (attr: string): HTMLElement => {
+ const found = document.querySelector<HTMLElement>(`[data-attr="${attr}"]`)
+ if (!found) {
+ throw new Error(`No element with data-attr ${attr} on the page`)
+ }
+ return found
+}
+
+const flush = async (): Promise<void> => {
+ await act(async () => {
+ await jest.advanceTimersByTimeAsync(0)
+ })
+}
+
+const renderInApp = async (ui: JSX.Element): Promise<void> => {
+ render(<Provider>{ui}</Provider>)
+ await flush()
+}
+
+type EntryExpectation = (pagePath: string) => void
+
+const expectOldModal: EntryExpectation = () => {
+ expect(screen.getByText(LEGACY_MODAL_TITLE)).toBeInTheDocument()
+ expect(router.values.location.pathname).toMatch(/\/workflows\/channels$/)
+}
+
+const expectSendingDomainPage: EntryExpectation = (pagePath) => {
+ expect(router.values.location.pathname).toMatch(new RegExp(`${pagePath}$`))
+ expect(screen.queryByText(LEGACY_MODAL_TITLE)).not.toBeInTheDocument()
+}
+
+const expectWizardModalForSender: EntryExpectation = (pagePath) => {
+ expect(screen.getByText('Verify your sending domain')).toBeInTheDocument()
+ expect(router.values.location.pathname).toMatch(/\/workflows\/channels$/)
+ expect(screen.getByText('Open full page').closest('a')).toHaveAttribute('href', expect.stringContaining(pagePath))
+}
+
+const expectOldBroadcastModal = (): void => {
+ expect(screen.getByText(LEGACY_MODAL_TITLE)).toBeInTheDocument()
+}
+
+const expectWizardInBroadcastModal = (): void => {
+ expect(screen.getByText('Set up a sending domain')).toBeInTheDocument()
+ expect(screen.getByText('Which domain should your emails come from?')).toBeInTheDocument()
+}
+
+describe('email domain setup entry points', () => {
+ let backend: FakeEmailDomainBackend
+
+ const setWizardFlag = (enabled: boolean): void => {
+ featureFlagLogic.actions.setFeatureFlags(enabled ? [FEATURE_FLAGS.WORKFLOWS_EMAIL_DOMAIN_WIZARD] : [], {
+ [FEATURE_FLAGS.WORKFLOWS_EMAIL_DOMAIN_WIZARD]: enabled,
+ })
+ }
+
+ beforeEach(() => {
+ jest.useFakeTimers()
+ backend = new FakeEmailDomainBackend()
+ backend.hostDnsAt('acme.com', 'cloudflare')
+ useMocks(backend.mocks())
+ initKeaTests()
+ featureFlagLogic.mount()
+ router.actions.push(urls.workflows('channels'))
+ })
+
+ afterEach(() => {
+ cleanup()
+ jest.useRealTimers()
+ })
+
+ describe.each([
+ ['off', false, expectOldModal, expectOldModal, expectOldBroadcastModal],
+ ['on', true, expectSendingDomainPage, expectWizardModalForSender, expectWizardInBroadcastModal],
+ ])('with the wizard flag %s', (_, wizardEnabled, expectEntry, expectConfigure, expectBroadcastModal) => {
+ beforeEach(() => setWizardFlag(wizardEnabled))
+
+ it('starts from the email card in the channel catalog', async () => {
+ await renderInApp(<MessageChannels />)
+ expect(screen.queryByText(LEGACY_MODAL_TITLE)).not.toBeInTheDocument()
+ fireEvent.click(element('workflows-channel-catalog-connect-email'))
+ await flush()
+ expectEntry(urls.workflowsEmailDomain('new'))
+ })
+
+ it('starts from configure on an unverified sender', async () => {
+ backend.addSender({ email: `hello@${DOMAIN}` })
+ await renderInApp(<MessageChannels />)
+ fireEvent.click(screen.getByText(DOMAIN))
+ expect(screen.getByText('Unverified')).toBeInTheDocument()
+ fireEvent.click(screen.getByText('Configure'))
+ await flush()
+ expectConfigure(urls.workflowsEmailDomain(SENDER_ID))
+ })
+
+ it('keeps the sender settings for configure on a verified sender', async () => {
+ backend.addSender({ email: `hello@${DOMAIN}`, verified: true })
+ await renderInApp(<MessageChannels />)
+ fireEvent.click(screen.getByText(DOMAIN))
+ fireEvent.click(screen.getByText('Configure'))
+ await flush()
+ expectOldModal('')
+ })
+
+ it('starts from the broadcast sender modal', async () => {
+ const onComplete = jest.fn()
+ await renderInApp(<EmailSetupModal entry="broadcast" onClose={jest.fn()} onComplete={onComplete} />)
+ expectBroadcastModal()
+ expect(onComplete).not.toHaveBeenCalled()
+ })
+ })
+
+ it('closes the setup modal when the person opens the full page from configure', async () => {
+ setWizardFlag(true)
+ backend.addSender({ email: `hello@${DOMAIN}` })
+ await renderInApp(<MessageChannels />)
+ fireEvent.click(screen.getByText(DOMAIN))
+ fireEvent.click(screen.getByText('Configure'))
+ await flush()
+
+ fireEvent.click(screen.getByText('Open full page'))
+ await flush()
+
+ expect(router.values.location.pathname).toMatch(new RegExp(`${urls.workflowsEmailDomain(SENDER_ID)}$`))
+ expect(integrationsLogic.values.setupModalOpen).toBe(false)
+ })
+
+ it.each([
+ ['broadcast' as const, '_blank'],
+ [undefined, null],
+ ])(
+ 'stays open for the settings after creating a sender, and reports it when closed (entry %s)',
+ async (entry, fullPageTarget) => {
+ setWizardFlag(true)
+ const onComplete = jest.fn()
+ const onClose = jest.fn()
+ await renderInApp(<EmailSetupModal entry={entry} onClose={onClose} onComplete={onComplete} />)
+
+ fireEvent.change(document.getElementById('email-domain-another-domain') as HTMLInputElement, {
+ target: { value: 'acme.com' },
+ })
+ fireEvent.click(element('email-domain-use-custom-domain'))
+ fireEvent.click(element('email-domain-continue'))
+ await flush()
+
+ expect(onComplete).not.toHaveBeenCalled()
+ expect(screen.getByText('Verify your sending domain')).toBeInTheDocument()
+ expect(screen.getByText('Add 8 settings at Cloudflare')).toBeInTheDocument()
+ expect(screen.getByText('Open full page').closest('a')?.getAttribute('target') ?? null).toBe(fullPageTarget)
+
+ fireEvent.click(screen.getByLabelText('close'))
+ await flush()
+ expect(onComplete).toHaveBeenCalledWith(SENDER_ID)
+ expect(onClose).not.toHaveBeenCalled()
+ }
+ )
+})
diff --git a/products/workflows/frontend/Channels/EmailDomain/useStartEmailDomainSetup.ts b/products/workflows/frontend/Channels/EmailDomain/useStartEmailDomainSetup.ts
new file mode 100644
index 000000000000..6024cfc56138
--- /dev/null
+++ b/products/workflows/frontend/Channels/EmailDomain/useStartEmailDomainSetup.ts
@@ -0,0 +1,24 @@
+import { useValues } from 'kea'
+import { router } from 'kea-router'
+import posthog from 'posthog-js'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { urls } from 'scenes/urls'
+
+export type EmailDomainSetupEntry = 'channels' | 'broadcast'
+
+export function openEmailDomainSetupPage(entry: EmailDomainSetupEntry): void {
+ // pinned: analytics event name
+ posthog.capture('email domain setup started', { entry })
+ router.actions.push(urls.workflowsEmailDomain('new'))
+}
+
+/** Opens the sending domain page when the wizard flag is on. Returns null when the flag is off, so the caller keeps its modal. */
+export function useStartEmailDomainSetup(entry: EmailDomainSetupEntry): (() => void) | null {
+ const { featureFlags } = useValues(featureFlagLogic)
+ if (!featureFlags[FEATURE_FLAGS.WORKFLOWS_EMAIL_DOMAIN_WIZARD]) {
+ return null
+ }
+ return () => openEmailDomainSetupPage(entry)
+}
diff --git a/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx b/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
index 2a59e7c75665..6b873ca92a26 100644
--- a/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
+++ b/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
@@ -15,11 +15,26 @@ import {
import { DomainConnectBanner } from 'lib/components/DomainConnect'
import { FlaggedFeature } from 'lib/components/FlaggedFeature'
+import { FEATURE_FLAGS } from 'lib/constants'
import { LemonField } from 'lib/lemon-ui/LemonField'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { EmailDomainSetupModal, EmailDomainSetupModalProps } from '../EmailDomain/EmailDomainSetupModal'
import { DnsRecord, EmailSetupModalLogicProps, emailSetupModalLogic } from './emailSetupModalLogic'
-export const EmailSetupModal = (props: EmailSetupModalLogicProps): JSX.Element => {
+export type EmailSetupModalProps = EmailSetupModalLogicProps & { entry?: EmailDomainSetupModalProps['entry'] }
+
+export const EmailSetupModal = ({ entry, ...props }: EmailSetupModalProps): JSX.Element => {
+ const { featureFlags } = useValues(featureFlagLogic)
+ // A verified sender keeps the settings form, which edits what the wizard does not: reply-to and the bounce subdomain.
+ const editsVerifiedSender = props.integration?.config?.verified === true
+ if (featureFlags[FEATURE_FLAGS.WORKFLOWS_EMAIL_DOMAIN_WIZARD] && !editsVerifiedSender) {
+ return <EmailDomainSetupModal {...props} entry={entry ?? (props.integration ? 'configure' : 'channels')} />
+ }
+ return <LegacyEmailSetupModal {...props} />
+}
+
+const LegacyEmailSetupModal = (props: EmailSetupModalLogicProps): JSX.Element => {
const logic = emailSetupModalLogic(props)
const { savedIntegration, verificationLoading, isEmailSenderSubmitting, dnsRecords, domain, isDomainVerified } =
useValues(logic)
diff --git a/products/workflows/frontend/Channels/channelCatalogLogic.ts b/products/workflows/frontend/Channels/channelCatalogLogic.ts
index 842e323f374c..b0881131a1f9 100644
--- a/products/workflows/frontend/Channels/channelCatalogLogic.ts
+++ b/products/workflows/frontend/Channels/channelCatalogLogic.ts
@@ -11,6 +11,7 @@ import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import type { FeatureFlagsSet } from '../../../../frontend/src/lib/logic/featureFlagLogic'
import type { IntegrationType } from '../../../../frontend/src/types'
import { CATALOG_CHANNELS, ChannelSummary, PUSH_CHANNELS, summarizeChannel } from './channelSummary'
+import { openEmailDomainSetupPage } from './EmailDomain/useStartEmailDomainSetup'
import type { ChannelType } from './MessageChannels'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -117,6 +118,10 @@ export const channelCatalogLogic = kea<channelCatalogLogicType>([
})
return
}
+ if (kind === 'email' && values.featureFlags[FEATURE_FLAGS.WORKFLOWS_EMAIL_DOMAIN_WIZARD]) {
+ openEmailDomainSetupPage('channels')
+ return
+ }
actions.openSetupModal(undefined, kind)
},
})),
diff --git a/products/workflows/frontend/MessagingTabActions.tsx b/products/workflows/frontend/MessagingTabActions.tsx
index 2c5322e01b55..7e349efbf070 100644
--- a/products/workflows/frontend/MessagingTabActions.tsx
+++ b/products/workflows/frontend/MessagingTabActions.tsx
@@ -14,6 +14,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { AccessControlLevel, AccessControlResourceType } from '~/types'
+import { useStartEmailDomainSetup } from './Channels/EmailDomain/useStartEmailDomainSetup'
import type { MessagingNavTabKey } from './messagingTabs'
import { optOutCategoriesLogic } from './OptOuts/optOutCategoriesLogic'
import { QuillMessagingTabActions } from './QuillMessagingTabActions'
@@ -62,6 +63,7 @@ function NewTemplateButton(): JSX.Element {
function NewChannelButton({ channelsUrl }: { channelsUrl: string }): JSX.Element {
const { featureFlags } = useValues(featureFlagLogic)
const { openSetupModal } = useActions(integrationsLogic)
+ const startEmailDomainSetup = useStartEmailDomainSetup('channels')
const newChannelRestrictedReason = useRestrictedArea({
scope: RestrictionScope.Project,
minimumAccessLevel: TeamMembershipLevel.Admin,
@@ -74,7 +76,7 @@ function NewChannelButton({ channelsUrl }: { channelsUrl: string }): JSX.Element
<IconLetter /> Email
</div>
),
- onClick: () => openSetupModal(undefined, 'email'),
+ onClick: startEmailDomainSetup ?? (() => openSetupModal(undefined, 'email')),
},
{