MCPcopy Create free account
hub / github.com/CodebuffAI/codebuff / CreditMonitor

Function CreditMonitor

web/src/components/organization/credit-monitor.tsx:85–425  ·  view source on GitHub ↗
({
  organizationId,
  orgSlug, // Destructure orgSlug
  noCardWrapper = false,
}: CreditMonitorProps)

Source from the content-addressed store, hash-verified

83}
84
85export function CreditMonitor({
86 organizationId,
87 orgSlug, // Destructure orgSlug
88 noCardWrapper = false,
89}: CreditMonitorProps) {
90 const isMobile = useIsMobile()
91
92 const {
93 data: creditStatus,
94 isLoading,
95 isFetching,
96 dataUpdatedAt,
97 } = useQuery({
98 queryKey: ['creditStatus', organizationId],
99 queryFn: () => fetchCreditStatus(organizationId),
100 staleTime: 2 * 60 * 1000, // 2 minutes
101 refetchInterval: 5 * 60 * 1000, // 5 minutes
102 refetchOnWindowFocus: false,
103 })
104
105 const { data: orgSettings, isLoading: isLoadingSettings } = useQuery({
106 queryKey: ['organizationSettings', organizationId],
107 queryFn: () => fetchOrganizationSettings(organizationId),
108 staleTime: 5 * 60 * 1000, // 5 minutes
109 refetchOnWindowFocus: false,
110 })
111
112 // BILLING_DISABLED: Auto-topup hook results unused while billing is disabled
113 // These would be used by handleEnableAutoTopup and the auto-topup banner
114 const {
115 isEnabled: _autoTopupEnabled,
116 canManageAutoTopup: _canManageAutoTopup,
117 handleToggleAutoTopup: _handleToggleAutoTopup,
118 isPending: _isAutoTopupPending,
119 } = useOrgAutoTopup(organizationId)
120
121 const queryClient = useQueryClient()
122
123 const handleRefresh = () => {
124 queryClient.invalidateQueries({
125 queryKey: ['creditStatus', organizationId],
126 })
127 queryClient.invalidateQueries({
128 queryKey: ['organizationSettings', organizationId],
129 })
130 }
131
132 // BILLING_DISABLED: handleEnableAutoTopup functionality disabled
133 // This function previously enabled auto-topup and navigated to billing page.
134 // Uncomment when re-enabling org billing.
135 /*
136 const handleEnableAutoTopup = async () => {
137 if (!orgSettings || !canManageAutoTopup) return
138
139 setIsRedirecting(true)
140
141 try {
142 const success = await handleToggleAutoTopup(true)

Callers

nothing calls this directly

Calls 5

useIsMobileFunction · 0.90
useOrgAutoTopupFunction · 0.90
cnFunction · 0.90
fetchCreditStatusFunction · 0.85

Tested by

no test coverage detected