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(user-interviews): copy interview link button per interviewee (#58695)

Paul D'Ambra900424d1f1bf
diff --git a/products/user_interviews/frontend/UserInterview.tsx b/products/user_interviews/frontend/UserInterview.tsx
index 10572af97765..a00c4da8b81f 100644
--- a/products/user_interviews/frontend/UserInterview.tsx
+++ b/products/user_interviews/frontend/UserInterview.tsx
@@ -1,11 +1,12 @@
import { useValues } from 'kea'
-import { IconArrowLeft, IconCheck, IconChevronRight, IconClock } from '@posthog/icons'
+import { IconArrowLeft, IconCheck, IconChevronRight, IconClock, IconCopy } from '@posthog/icons'
import { LemonButton, LemonSkeleton, LemonTag, LemonWidget } from '@posthog/lemon-ui'
import { NotFound } from 'lib/components/NotFound'
import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
import { Link } from 'lib/lemon-ui/Link'
+import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { SceneExport } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
@@ -217,6 +218,33 @@ function DetailRow({ label, value }: { label: string; value: string }): JSX.Elem
)
}
+function InterviewLinkCopyButton({ identifier, topicId }: { identifier: string; topicId: string }): JSX.Element {
+ const { linkForIdentifier, linksLoading } = useValues(userInterviewLogic({ id: topicId }))
+ const interviewUrl = linkForIdentifier(identifier)
+
+ const handleCopy = (e: React.MouseEvent): void => {
+ e.preventDefault()
+ e.stopPropagation()
+ if (!interviewUrl) {
+ return
+ }
+ void copyToClipboard(interviewUrl, 'interview link')
+ }
+
+ const disabledReason = interviewUrl ? undefined : linksLoading ? 'Generating link…' : 'No link available'
+
+ return (
+ <LemonButton
+ type="tertiary"
+ size="xsmall"
+ icon={<IconCopy />}
+ onClick={handleCopy}
+ disabledReason={disabledReason}
+ tooltip="Copy interview link"
+ />
+ )
+}
+
function PersonRow({
identifier,
topicId,
@@ -237,6 +265,7 @@ function PersonRow({
<div className="font-medium text-sm">{identifier}</div>
</div>
<div className="flex items-center gap-2">
+ <InterviewLinkCopyButton identifier={identifier} topicId={topicId} />
{hasResponded ? (
<LemonTag type="success" icon={<IconCheck />}>
Responded
diff --git a/products/user_interviews/frontend/userInterviewLogic.ts b/products/user_interviews/frontend/userInterviewLogic.ts
index 05e19ca5a5f6..275a713f33ae 100644
--- a/products/user_interviews/frontend/userInterviewLogic.ts
+++ b/products/user_interviews/frontend/userInterviewLogic.ts
@@ -6,8 +6,18 @@ import { urls } from 'scenes/urls'
import { Breadcrumb } from '~/types'
-import { userInterviewTopicsRetrieve, userInterviewTopicsIntervieweesList, userInterviewsList } from './generated/api'
-import type { UserInterviewTopicApi, IntervieweeContextApi, UserInterviewApi } from './generated/api.schemas'
+import {
+ userInterviewTopicsGenerateLinksCreate,
+ userInterviewTopicsIntervieweesList,
+ userInterviewTopicsRetrieve,
+ userInterviewsList,
+} from './generated/api'
+import type {
+ IntervieweeContextApi,
+ InterviewLinkApi,
+ UserInterviewApi,
+ UserInterviewTopicApi,
+} from './generated/api.schemas'
import type { userInterviewLogicType } from './userInterviewLogicType'
export interface UserInterviewLogicProps {
@@ -54,12 +64,36 @@ export const userInterviewLogic = kea<userInterviewLogicType>([
}
},
},
+ links: {
+ __default: [] as InterviewLinkApi[],
+ loadLinks: async (): Promise<InterviewLinkApi[]> => {
+ const projectId = String(teamLogic.values.currentTeamId)
+ const response = (await userInterviewTopicsGenerateLinksCreate(projectId, props.id)) as unknown as
+ | InterviewLinkApi[]
+ | { results?: InterviewLinkApi[] }
+ if (Array.isArray(response)) {
+ return response
+ }
+ return response.results ?? []
+ },
+ },
})),
selectors(({ props }) => ({
topicInterviews: [
(s) => [s.interviews],
(interviews): UserInterviewApi[] => interviews.filter((i) => i.topic === props.id),
],
+ linkByIdentifier: [
+ (s) => [s.links],
+ (links): Record<string, string> =>
+ Object.fromEntries(links.map((link) => [link.interviewee_identifier, link.interview_url])),
+ ],
+ linkForIdentifier: [
+ (s) => [s.linkByIdentifier],
+ (linkByIdentifier): ((identifier: string) => string | undefined) =>
+ (identifier: string) =>
+ linkByIdentifier[identifier],
+ ],
respondedIdentifiers: [
(s) => [s.topicInterviews],
(interviews): Set<string> => {
@@ -113,5 +147,6 @@ export const userInterviewLogic = kea<userInterviewLogicType>([
actions.loadTopic()
actions.loadInterviewees()
actions.loadInterviews()
+ actions.loadLinks()
}),
])