rowboat/apps/x/apps/renderer/src/hooks/useBilling.ts
tusharmagar 75ffbc781c Add billing error handling and UI updates
- Introduced billing error patterns to match specific error messages and display appropriate user prompts in the ChatSidebar.
- Enhanced SidebarContentPanel and AccountSettings components to reflect subscription status, including trial expiration details.
- Updated button actions to direct users to the app URL for subscription management and upgrades.
- Added a new Payment section in AccountSettings for managing invoices and payment methods, with conditional rendering based on subscription status.
2026-04-07 21:51:17 +05:30

39 lines
1,022 B
TypeScript

import { useState, useEffect, useCallback } from 'react'
interface BillingInfo {
userEmail: string | null
userId: string | null
subscriptionPlan: string | null
subscriptionStatus: string | null
trialExpiresAt: string | null
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 }
}