@@ -7,12 +7,14 @@ const BASE = '/api/admin/mothership'
77async function mothershipPost (
88 endpoint : string ,
99 environment : MothershipEnv ,
10- body ?: Record < string , unknown >
10+ body ?: Record < string , unknown > ,
11+ signal ?: AbortSignal
1112) {
1213 const res = await fetch ( `${ BASE } ?env=${ environment } &endpoint=${ endpoint } ` , {
1314 method : 'POST' ,
1415 headers : { 'Content-Type' : 'application/json' } ,
1516 ...( body ? { body : JSON . stringify ( body ) } : { } ) ,
17+ signal,
1618 } )
1719 if ( ! res . ok ) {
1820 const err = await res . json ( ) . catch ( ( ) => ( { error : res . statusText } ) )
@@ -24,10 +26,11 @@ async function mothershipPost(
2426async function mothershipGet (
2527 endpoint : string ,
2628 environment : MothershipEnv ,
27- params ?: Record < string , string >
29+ params ?: Record < string , string > ,
30+ signal ?: AbortSignal
2831) {
2932 const qs = new URLSearchParams ( { env : environment , endpoint, ...params } )
30- const res = await fetch ( `${ BASE } ?${ qs . toString ( ) } ` , { method : 'GET' } )
33+ const res = await fetch ( `${ BASE } ?${ qs . toString ( ) } ` , { method : 'GET' , signal } )
3134 if ( ! res . ok ) {
3235 const err = await res . json ( ) . catch ( ( ) => ( { error : res . statusText } ) )
3336 throw new Error ( err . message || err . error || `Request failed (${ res . status } )` )
@@ -58,12 +61,17 @@ export function useMothershipRequests(
5861) {
5962 return useQuery ( {
6063 queryKey : mothershipKeys . requests ( environment , start , end , userId ) ,
61- queryFn : ( ) =>
62- mothershipPost ( 'requests' , environment , {
63- start,
64- end,
65- ...( userId ? { userId } : { } ) ,
66- } ) ,
64+ queryFn : ( { signal } ) =>
65+ mothershipPost (
66+ 'requests' ,
67+ environment ,
68+ {
69+ start,
70+ end,
71+ ...( userId ? { userId } : { } ) ,
72+ } ,
73+ signal
74+ ) ,
6775 enabled : ! ! start && ! ! end ,
6876 staleTime : 60 * 1000 ,
6977 placeholderData : keepPreviousData ,
@@ -73,7 +81,7 @@ export function useMothershipRequests(
7381export function useMothershipUserBreakdown ( environment : MothershipEnv , start : string , end : string ) {
7482 return useQuery ( {
7583 queryKey : mothershipKeys . userBreakdown ( environment , start , end ) ,
76- queryFn : ( ) => mothershipPost ( 'user-breakdown' , environment , { start, end } ) ,
84+ queryFn : ( { signal } ) => mothershipPost ( 'user-breakdown' , environment , { start, end } , signal ) ,
7785 enabled : ! ! start && ! ! end ,
7886 staleTime : 60 * 1000 ,
7987 placeholderData : keepPreviousData ,
@@ -83,7 +91,7 @@ export function useMothershipUserBreakdown(environment: MothershipEnv, start: st
8391export function useMothershipLicenses ( environment : MothershipEnv ) {
8492 return useQuery ( {
8593 queryKey : mothershipKeys . licenses ( environment ) ,
86- queryFn : ( ) => mothershipGet ( 'licenses' , environment ) ,
94+ queryFn : ( { signal } ) => mothershipGet ( 'licenses' , environment , undefined , signal ) ,
8795 staleTime : 60 * 1000 ,
8896 } )
8997}
@@ -95,11 +103,16 @@ export function useMothershipLicenseDetails(
95103) {
96104 return useQuery ( {
97105 queryKey : mothershipKeys . licenseDetails ( environment , id , name ) ,
98- queryFn : ( ) =>
99- mothershipPost ( 'licenses/details' , environment , {
100- ...( id ? { id } : { } ) ,
101- ...( name ? { name } : { } ) ,
102- } ) ,
106+ queryFn : ( { signal } ) =>
107+ mothershipPost (
108+ 'licenses/details' ,
109+ environment ,
110+ {
111+ ...( id ? { id } : { } ) ,
112+ ...( name ? { name } : { } ) ,
113+ } ,
114+ signal
115+ ) ,
103116 enabled : ! ! ( id || name ) ,
104117 staleTime : 60 * 1000 ,
105118 } )
@@ -120,7 +133,8 @@ export function useMothershipEnterpriseStats(
120133) {
121134 return useQuery ( {
122135 queryKey : mothershipKeys . enterpriseStats ( environment , customerType , start , end ) ,
123- queryFn : ( ) => mothershipPost ( 'enterprise-stats' , environment , { customerType, start, end } ) ,
136+ queryFn : ( { signal } ) =>
137+ mothershipPost ( 'enterprise-stats' , environment , { customerType, start, end } , signal ) ,
124138 enabled : ! ! customerType && ! ! start && ! ! end ,
125139 staleTime : 60 * 1000 ,
126140 placeholderData : keepPreviousData ,
@@ -130,7 +144,7 @@ export function useMothershipEnterpriseStats(
130144export function useMothershipTrace ( environment : MothershipEnv , requestId : string ) {
131145 return useQuery ( {
132146 queryKey : mothershipKeys . trace ( environment , requestId ) ,
133- queryFn : ( ) => mothershipGet ( 'traces' , environment , { requestId } ) ,
147+ queryFn : ( { signal } ) => mothershipGet ( 'traces' , environment , { requestId } , signal ) ,
134148 enabled : ! ! requestId ,
135149 staleTime : 60 * 1000 ,
136150 } )
0 commit comments