import { Progress } from '@documenso/ui/primitives/progress'; import { Trans } from '@lingui/react/macro'; import type { OrganisationClaim, OrganisationMonthlyStat } from '@prisma/client'; import { match } from 'ts-pattern'; import { OrganisationUsageResetButton } from './organisation-usage-reset-button'; type OrganisationUsagePanelProps = { organisationId: string; monthlyStats: Pick[]; organisationClaim: OrganisationClaim; }; export const OrganisationUsagePanel = ({ organisationId, monthlyStats, organisationClaim, }: OrganisationUsagePanelProps) => { const rows = [ { counter: 'document' as const, label: Documents, used: monthlyStats[0]?.documentCount ?? 0, effectiveLimit: organisationClaim.documentQuota, }, { counter: 'email' as const, label: Emails, used: monthlyStats[0]?.emailCount ?? 0, effectiveLimit: organisationClaim.emailQuota, }, { counter: 'api' as const, label: API requests, used: monthlyStats[0]?.apiCount ?? 0, effectiveLimit: organisationClaim.apiQuota, }, ]; // Todo: This may not show if the organisation has no usage data for the current month. return (

Usage for period: {monthlyStats[0]?.period || 'N/A'}

{rows.map((row) => { const percent = row.effectiveLimit && row.effectiveLimit > 0 ? Math.min(100, Math.round((row.used / row.effectiveLimit) * 100)) : 0; return (
{row.label} {row.used} /{' '} {match(row.effectiveLimit) .with(null, () => Unlimited) .with(0, () => Blocked) .otherwise(String)}
{row.effectiveLimit && row.effectiveLimit > 0 ? : null} {monthlyStats[0] && (
)}
); })}
); };