diff --git a/packages/shared/src/features/agentOnboarding/components/AgentOnboardingEntry.spec.tsx b/packages/shared/src/features/agentOnboarding/components/AgentOnboardingEntry.spec.tsx index a72b2ce255..b64100df4d 100644 --- a/packages/shared/src/features/agentOnboarding/components/AgentOnboardingEntry.spec.tsx +++ b/packages/shared/src/features/agentOnboarding/components/AgentOnboardingEntry.spec.tsx @@ -1,8 +1,10 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import { AgentOnboardingEntry } from './AgentOnboardingEntry'; import { useConditionalFeature } from '../../../hooks/useConditionalFeature'; import { useViewSize } from '../../../hooks/useViewSize'; +import { agentOnboardingPrompt } from '../prompt'; jest.mock('../../../hooks/useConditionalFeature', () => ({ useConditionalFeature: jest.fn(), @@ -14,20 +16,44 @@ jest.mock('../../../hooks/useViewSize', () => ({ const mockFlag = jest.mocked(useConditionalFeature); const mockViewSize = jest.mocked(useViewSize); +const writeText = jest.fn(); beforeEach(() => { jest.clearAllMocks(); mockViewSize.mockReturnValue(true); mockFlag.mockReturnValue({ value: true, isLoading: false }); + writeText.mockResolvedValue(undefined); + Object.defineProperty(navigator, 'clipboard', { + configurable: true, + value: { writeText }, + }); }); +const copyButton = () => + screen.getByRole('button', { name: 'Set up with your coding agent' }); + describe('AgentOnboardingEntry', () => { - it('links to agent onboarding when the experiment is on', () => { + it('copies the prompt and says what to do next', async () => { render(); + await userEvent.click(copyButton()); + + expect(writeText).toHaveBeenCalledWith(agentOnboardingPrompt); expect( - screen.getByRole('link', { name: 'Let it set up daily.dev for you' }), - ).toHaveAttribute('href', '/agents/onboarding'); + await screen.findByRole('button', { name: 'Prompt copied' }), + ).toBeInTheDocument(); + expect( + screen.getByText(/Paste it into your coding agent/), + ).toBeInTheDocument(); + }); + + it('shows the prompt when the clipboard is blocked', async () => { + writeText.mockRejectedValue(new Error('denied')); + render(); + + await userEvent.click(copyButton()); + + expect(await screen.findByText(agentOnboardingPrompt)).toBeInTheDocument(); }); it('renders nothing for the control group', () => { diff --git a/packages/shared/src/features/agentOnboarding/components/AgentOnboardingEntry.tsx b/packages/shared/src/features/agentOnboarding/components/AgentOnboardingEntry.tsx index cdc637164a..10db253b07 100644 --- a/packages/shared/src/features/agentOnboarding/components/AgentOnboardingEntry.tsx +++ b/packages/shared/src/features/agentOnboarding/components/AgentOnboardingEntry.tsx @@ -1,25 +1,29 @@ import type { ReactElement } from 'react'; -import React from 'react'; +import React, { useState } from 'react'; import classNames from 'classnames'; -import Link from '../../../components/utilities/Link'; +import { Button } from '../../../components/buttons/Button'; +import { ButtonSize, ButtonVariant } from '../../../components/buttons/common'; +import { TerminalIcon } from '../../../components/icons/Terminal'; +import { VIcon } from '../../../components/icons/V'; import { useLogContext } from '../../../contexts/LogContext'; import { useConditionalFeature } from '../../../hooks/useConditionalFeature'; import { useViewSize, ViewSize } from '../../../hooks/useViewSize'; -import { webappUrl } from '../../../lib/constants'; import { featureAgentOnboardingEntry } from '../../../lib/featureManagement'; import { LogEvent } from '../../../lib/log'; - -const agentOnboardingUrl = `${webappUrl}agents/onboarding`; +import { agentOnboardingPrompt } from '../prompt'; type AgentOnboardingEntryProps = { className?: string; }; +type CopyState = 'idle' | 'copied' | 'blocked'; + // Agents run on a computer, so smaller screens are left out of the experiment. export const AgentOnboardingEntry = ({ className, }: AgentOnboardingEntryProps): ReactElement | null => { const { logEvent } = useLogContext(); + const [copyState, setCopyState] = useState('idle'); const isLaptop = useViewSize(ViewSize.Laptop); const { value: isEnabled } = useConditionalFeature({ feature: featureAgentOnboardingEntry, @@ -30,20 +34,46 @@ export const AgentOnboardingEntry = ({ return null; } + const onCopy = async () => { + logEvent({ event_name: LogEvent.ClickAgentOnboardingEntry }); + + try { + await navigator.clipboard.writeText(agentOnboardingPrompt); + setCopyState('copied'); + } catch { + setCopyState('blocked'); + } + }; + + const isCopied = copyState === 'copied'; + return ( - - Use a coding agent?{' '} - - - logEvent({ event_name: LogEvent.ClickAgentOnboardingEntry }) - } - > - Let it set up daily.dev for you - - - +
+ +

+ {copyState === 'idle' && + 'Copies a prompt for Claude Code, Codex, or Cursor.'} + {isCopied && + 'Paste it into your coding agent. It sets up daily.dev for you.'} + {copyState === 'blocked' && ( + <> + Your browser blocked the clipboard. Copy this prompt into your + coding agent:{' '} + + {agentOnboardingPrompt} + + + )} +

+
); }; diff --git a/packages/shared/src/lib/featureManagement.ts b/packages/shared/src/lib/featureManagement.ts index 3c3eba338d..9dbd24ed34 100644 --- a/packages/shared/src/lib/featureManagement.ts +++ b/packages/shared/src/lib/featureManagement.ts @@ -434,8 +434,9 @@ export const featureWeeklyPicksChecks = new Feature( false, ); -// Experiment: a link from the sign-up screen into agent onboarding. +// Experiment: a sign-up screen button that copies the agent onboarding prompt. +// TEMP: on for preview testing only. Revert to false before merging. export const featureAgentOnboardingEntry = new Feature( 'agent_onboarding_entry', - false, + true, );