mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
refactor(ui): address code review feedback
- Consolidate UnifiedQuotaResult type: import from utils.ts, re-export - Remove unused useCodexQuota/useGeminiQuota hooks (useAccountQuota handles all) - Remove unnecessary optional chaining where type guards guarantee property
This commit is contained in:
@@ -299,7 +299,7 @@ export function AccountCard({
|
||||
) : quota && isCodexQuotaResult(quota) ? (
|
||||
<div className="text-xs space-y-1">
|
||||
<p className="font-medium">Rate Limits:</p>
|
||||
{quota.windows?.map((w) => (
|
||||
{quota.windows.map((w) => (
|
||||
<div key={w.label} className="flex justify-between gap-4">
|
||||
<span className={cn(w.remainingPercent < 20 && 'text-red-500')}>
|
||||
{w.label}
|
||||
@@ -322,7 +322,7 @@ export function AccountCard({
|
||||
) : quota && isGeminiQuotaResult(quota) ? (
|
||||
<div className="text-xs space-y-1">
|
||||
<p className="font-medium">Buckets:</p>
|
||||
{quota.buckets?.map((b) => (
|
||||
{quota.buckets.map((b) => (
|
||||
<div key={b.id} className="flex justify-between gap-4">
|
||||
<span className={cn(b.remainingPercent < 20 && 'text-red-500')}>
|
||||
{b.label}
|
||||
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
CodexQuotaResult,
|
||||
GeminiCliQuotaResult,
|
||||
} from '@/lib/api-client';
|
||||
import type { UnifiedQuotaResult } from '@/lib/utils';
|
||||
|
||||
/** Per-account usage statistics */
|
||||
export interface AccountUsageStats {
|
||||
@@ -261,8 +262,8 @@ async function fetchGeminiQuotaApi(accountId: string): Promise<GeminiCliQuotaRes
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/** Unified quota result type for all providers */
|
||||
export type UnifiedQuotaResult = QuotaResult | CodexQuotaResult | GeminiCliQuotaResult;
|
||||
// Re-export unified type from utils for consumers
|
||||
export type { UnifiedQuotaResult } from '@/lib/utils';
|
||||
|
||||
/**
|
||||
* Fetch quota by provider (dispatcher)
|
||||
@@ -300,35 +301,3 @@ export function useAccountQuota(provider: string, accountId: string, enabled = t
|
||||
retry: 1,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to get Codex quota for a specific account
|
||||
*/
|
||||
export function useCodexQuota(accountId: string | null) {
|
||||
return useQuery({
|
||||
queryKey: ['codex-quota', accountId],
|
||||
queryFn: async () => {
|
||||
if (!accountId) throw new Error('Account ID required');
|
||||
return fetchCodexQuotaApi(accountId);
|
||||
},
|
||||
enabled: !!accountId,
|
||||
staleTime: 30000,
|
||||
refetchInterval: 60000,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to get Gemini CLI quota for a specific account
|
||||
*/
|
||||
export function useGeminiQuota(accountId: string | null) {
|
||||
return useQuery({
|
||||
queryKey: ['gemini-quota', accountId],
|
||||
queryFn: async () => {
|
||||
if (!accountId) throw new Error('Account ID required');
|
||||
return fetchGeminiQuotaApi(accountId);
|
||||
},
|
||||
enabled: !!accountId,
|
||||
staleTime: 30000,
|
||||
refetchInterval: 60000,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user