* wip * wip * wip * format * wip(mobile): lint and format * cleanup * nits * nits * idiomatic react * nit * format all root files
31 lines
1002 B
TypeScript
31 lines
1002 B
TypeScript
import { useQuery, useMutation, skipToken } from '@tanstack/react-query';
|
|
import { apiClient } from '@/api/client';
|
|
import type { BillingCadence } from '@/api/types';
|
|
|
|
export function useNetworkBilling(networkId: string | undefined) {
|
|
return useQuery({
|
|
queryKey: ['network-billing', networkId],
|
|
queryFn: networkId
|
|
? () => apiClient.getNetworkBilling(networkId)
|
|
: skipToken,
|
|
// Refetch on window focus so the UI catches up after the user returns
|
|
// from Stripe Checkout (webhook may land a second or two later).
|
|
// FIX: doesn't work with electron
|
|
refetchOnWindowFocus: true,
|
|
refetchInterval: 10000,
|
|
});
|
|
}
|
|
|
|
export function useCreateCheckoutSession(networkId: string) {
|
|
return useMutation({
|
|
mutationFn: (cadence: BillingCadence) =>
|
|
apiClient.createCheckoutSession(networkId, cadence),
|
|
});
|
|
}
|
|
|
|
export function useCreatePortalSession(networkId: string) {
|
|
return useMutation({
|
|
mutationFn: () => apiClient.createPortalSession(networkId),
|
|
});
|
|
}
|