Publication IA: - 4 templates (magazine, brief, essay, simple) avec CSS riche - Rewrite IA (article/exercises/tutorial/reference/mixed) - Modération avec timeout 12s + fallback safe - Quotas publish_enhance par tier (basic=2, pro=15, business=100) - Détection contenu stale (hash) - Migration DB publishedContent/publishedTemplate/publishedSourceHash Fixes: - cheerio v1.2: Element -> AnyNode (domhandler), decodeEntities cast - _isShared ajouté au type Note (champ virtuel serveur) - callout colors PDF export: extraction fonction pure testable - admin/published: guard note.userId null - Cmd+S fonctionne en mode dialog (pas seulement fullPage) i18n: - 23 clés publish* traduites dans les 15 locales - Extension Web Clipper: 13 locales mise à jour Tests: - callout-colors.test.ts (6 tests) - note-visible-in-view.test.ts (5 tests) - entitlements.test.ts + byok-entitlements.test.ts: mock usageLog + unstubAllEnvs - 199/199 tests passent Tracker: user-stories.md sync avec sprint-status.yaml
101 lines
3.3 KiB
TypeScript
101 lines
3.3 KiB
TypeScript
'use client';
|
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { Loader2, BarChart2 } from 'lucide-react';
|
|
import { useLanguage } from '@/lib/i18n';
|
|
import { cn } from '@/lib/utils';
|
|
|
|
interface QuotaEntry {
|
|
remaining: number;
|
|
limit: number;
|
|
used: number;
|
|
}
|
|
|
|
type Quotas = Record<string, QuotaEntry>;
|
|
|
|
const FEATURE_LABEL_KEYS: Record<string, string> = {
|
|
aiSummary: 'sidebar.aiSummary',
|
|
aiFlashcards: 'sidebar.aiFlashcards',
|
|
aiMindmap: 'sidebar.aiMindmap',
|
|
aiTranscribe: 'sidebar.aiTranscribe',
|
|
aiDiagram: 'sidebar.aiDiagram',
|
|
aiAgent: 'sidebar.aiAgent',
|
|
publish_enhance: 'usageMeter.featurePublishEnhance',
|
|
};
|
|
|
|
function UsageBar({ used, limit, isUnlimited }: { used: number; limit: number; isUnlimited: boolean }) {
|
|
const pct = isUnlimited ? 0 : Math.min(100, limit > 0 ? (used / limit) * 100 : 0);
|
|
const color =
|
|
pct >= 90 ? 'bg-rose-500' : pct >= 70 ? 'bg-amber-500' : 'bg-primary';
|
|
|
|
return (
|
|
<div className="h-1.5 w-full rounded-full bg-foreground/10 overflow-hidden">
|
|
{!isUnlimited && (
|
|
<div
|
|
className={cn('h-full rounded-full transition-all', color)}
|
|
style={{ width: `${pct}%` }}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function UsageBreakdown() {
|
|
const { t } = useLanguage();
|
|
|
|
const { data, isLoading } = useQuery<{ quotas: Quotas }>({
|
|
queryKey: ['usage', 'current'],
|
|
queryFn: async () => {
|
|
const res = await fetch('/api/usage/current');
|
|
if (!res.ok) throw new Error('Failed to fetch usage');
|
|
return res.json();
|
|
},
|
|
});
|
|
|
|
const quotas = data?.quotas ?? {};
|
|
const entries = Object.entries(quotas);
|
|
|
|
return (
|
|
<div className="rounded-xl border border-border/40 bg-paper p-6 space-y-4">
|
|
<div className="flex items-center gap-2">
|
|
<BarChart2 className="h-4 w-4 text-muted-foreground" />
|
|
<h3 className="text-sm font-semibold text-foreground">
|
|
{t('billing.usageThisPeriod')}
|
|
</h3>
|
|
</div>
|
|
|
|
{isLoading ? (
|
|
<div className="flex justify-center py-4">
|
|
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
|
|
</div>
|
|
) : entries.length === 0 ? (
|
|
<p className="text-xs text-muted-foreground py-2">{t('billing.noUsage')}</p>
|
|
) : (
|
|
<div className="space-y-3">
|
|
{entries.map(([feature, quota]) => {
|
|
const isUnlimited = quota.limit === -1 || !isFinite(quota.limit);
|
|
const labelKey = FEATURE_LABEL_KEYS[feature];
|
|
const label = labelKey ? t(labelKey) : feature;
|
|
|
|
return (
|
|
<div key={feature} className="space-y-1">
|
|
<div className="flex items-center justify-between">
|
|
<span className="text-xs text-muted-foreground">{label}</span>
|
|
<span className="text-xs font-medium text-foreground tabular-nums">
|
|
{isUnlimited ? (
|
|
<span className="text-primary/80 dark:text-primary">{t('billing.unlimited')}</span>
|
|
) : (
|
|
`${quota.used} / ${quota.limit}`
|
|
)}
|
|
</span>
|
|
</div>
|
|
<UsageBar used={quota.used} limit={quota.limit} isUnlimited={isUnlimited} />
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|