Skip to content

Commit c206fa4

Browse files
authored
fix(user-interviews): address qa-swarm findings on copy-link button (#58698)
1 parent 900424d commit c206fa4

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

products/user_interviews/frontend/UserInterview.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function DetailRow({ label, value }: { label: string; value: string }): JSX.Elem
219219
}
220220

221221
function InterviewLinkCopyButton({ identifier, topicId }: { identifier: string; topicId: string }): JSX.Element {
222-
const { linkForIdentifier, linksLoading } = useValues(userInterviewLogic({ id: topicId }))
222+
const { linkForIdentifier, linksLoading, linksLoadFailed } = useValues(userInterviewLogic({ id: topicId }))
223223
const interviewUrl = linkForIdentifier(identifier)
224224

225225
const handleCopy = (e: React.MouseEvent): void => {
@@ -231,7 +231,13 @@ function InterviewLinkCopyButton({ identifier, topicId }: { identifier: string;
231231
void copyToClipboard(interviewUrl, 'interview link')
232232
}
233233

234-
const disabledReason = interviewUrl ? undefined : linksLoading ? 'Generating link…' : 'No link available'
234+
const disabledReason = interviewUrl
235+
? undefined
236+
: linksLoadFailed
237+
? "Couldn't generate link — refresh to retry"
238+
: linksLoading
239+
? 'Generating link…'
240+
: 'No link available'
235241

236242
return (
237243
<LemonButton

products/user_interviews/frontend/userInterviewLogic.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterMount, kea, key, path, props, selectors } from 'kea'
1+
import { afterMount, kea, key, path, props, reducers, selectors } from 'kea'
22
import { loaders } from 'kea-loaders'
33

44
import { teamLogic } from 'scenes/teamLogic'
@@ -24,6 +24,13 @@ export interface UserInterviewLogicProps {
2424
id: string
2525
}
2626

27+
function unwrapPaginatedOrArray<T>(response: T[] | { results?: T[] }): T[] {
28+
if (Array.isArray(response)) {
29+
return response
30+
}
31+
return response.results ?? []
32+
}
33+
2734
export const userInterviewLogic = kea<userInterviewLogicType>([
2835
path(['products', 'user_interviews', 'frontend', 'userInterviewLogic']),
2936
props({} as UserInterviewLogicProps),
@@ -71,13 +78,19 @@ export const userInterviewLogic = kea<userInterviewLogicType>([
7178
const response = (await userInterviewTopicsGenerateLinksCreate(projectId, props.id)) as unknown as
7279
| InterviewLinkApi[]
7380
| { results?: InterviewLinkApi[] }
74-
if (Array.isArray(response)) {
75-
return response
76-
}
77-
return response.results ?? []
81+
return unwrapPaginatedOrArray(response)
7882
},
7983
},
8084
})),
85+
reducers({
86+
linksLoadFailed: [
87+
false,
88+
{
89+
loadLinks: () => false,
90+
loadLinksFailure: () => true,
91+
},
92+
],
93+
}),
8194
selectors(({ props }) => ({
8295
topicInterviews: [
8396
(s) => [s.interviews],

0 commit comments

Comments
 (0)