1- import { afterMount , kea , key , path , props , selectors } from 'kea'
1+ import { afterMount , kea , key , path , props , reducers , selectors } from 'kea'
22import { loaders } from 'kea-loaders'
33
44import { 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+
2734export 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