2026-03-17 12:04:57 +05:30
|
|
|
import { useState, useEffect, useCallback } from 'react'
|
|
|
|
|
|
|
|
|
|
interface BillingInfo {
|
2026-03-18 16:15:02 +05:30
|
|
|
userEmail: string | null
|
|
|
|
|
userId: string | null
|
2026-03-18 14:29:21 +05:30
|
|
|
subscriptionPlan: string | null
|
|
|
|
|
subscriptionStatus: string | null
|
2026-04-07 21:51:17 +05:30
|
|
|
trialExpiresAt: string | null
|
2026-03-17 12:04:57 +05:30
|
|
|
sanctionedCredits: number
|
|
|
|
|
availableCredits: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function useBilling(isRowboatConnected: boolean) {
|
|
|
|
|
const [billing, setBilling] = useState<BillingInfo | null>(null)
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
|
|
|
|
|
|
|
|
const fetchBilling = useCallback(async () => {
|
|
|
|
|
if (!isRowboatConnected) {
|
|
|
|
|
setBilling(null)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
setIsLoading(true)
|
|
|
|
|
const result = await window.ipc.invoke('billing:getInfo', null)
|
|
|
|
|
setBilling(result)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Failed to fetch billing info:', error)
|
|
|
|
|
setBilling(null)
|
|
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false)
|
|
|
|
|
}
|
|
|
|
|
}, [isRowboatConnected])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchBilling()
|
|
|
|
|
}, [fetchBilling])
|
|
|
|
|
|
|
|
|
|
return { billing, isLoading, refresh: fetchBilling }
|
|
|
|
|
}
|