mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-31 22:21:30 +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) ? (
|
) : quota && isCodexQuotaResult(quota) ? (
|
||||||
<div className="text-xs space-y-1">
|
<div className="text-xs space-y-1">
|
||||||
<p className="font-medium">Rate Limits:</p>
|
<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">
|
<div key={w.label} className="flex justify-between gap-4">
|
||||||
<span className={cn(w.remainingPercent < 20 && 'text-red-500')}>
|
<span className={cn(w.remainingPercent < 20 && 'text-red-500')}>
|
||||||
{w.label}
|
{w.label}
|
||||||
@@ -322,7 +322,7 @@ export function AccountCard({
|
|||||||
) : quota && isGeminiQuotaResult(quota) ? (
|
) : quota && isGeminiQuotaResult(quota) ? (
|
||||||
<div className="text-xs space-y-1">
|
<div className="text-xs space-y-1">
|
||||||
<p className="font-medium">Buckets:</p>
|
<p className="font-medium">Buckets:</p>
|
||||||
{quota.buckets?.map((b) => (
|
{quota.buckets.map((b) => (
|
||||||
<div key={b.id} className="flex justify-between gap-4">
|
<div key={b.id} className="flex justify-between gap-4">
|
||||||
<span className={cn(b.remainingPercent < 20 && 'text-red-500')}>
|
<span className={cn(b.remainingPercent < 20 && 'text-red-500')}>
|
||||||
{b.label}
|
{b.label}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import type {
|
|||||||
CodexQuotaResult,
|
CodexQuotaResult,
|
||||||
GeminiCliQuotaResult,
|
GeminiCliQuotaResult,
|
||||||
} from '@/lib/api-client';
|
} from '@/lib/api-client';
|
||||||
|
import type { UnifiedQuotaResult } from '@/lib/utils';
|
||||||
|
|
||||||
/** Per-account usage statistics */
|
/** Per-account usage statistics */
|
||||||
export interface AccountUsageStats {
|
export interface AccountUsageStats {
|
||||||
@@ -261,8 +262,8 @@ async function fetchGeminiQuotaApi(accountId: string): Promise<GeminiCliQuotaRes
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Unified quota result type for all providers */
|
// Re-export unified type from utils for consumers
|
||||||
export type UnifiedQuotaResult = QuotaResult | CodexQuotaResult | GeminiCliQuotaResult;
|
export type { UnifiedQuotaResult } from '@/lib/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch quota by provider (dispatcher)
|
* Fetch quota by provider (dispatcher)
|
||||||
@@ -300,35 +301,3 @@ export function useAccountQuota(provider: string, accountId: string, enabled = t
|
|||||||
retry: 1,
|
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