Show event-per-purchase for endcustomer packages
This commit is contained in:
@@ -103,6 +103,37 @@ export const buildPackageUsageMetrics = (pkg: TenantPackageSummary): PackageUsag
|
||||
].filter((metric) => metric.limit !== null);
|
||||
};
|
||||
|
||||
export const formatPackageEventAllowance = (
|
||||
pkg: TenantPackageSummary,
|
||||
t: (key: string, options?: Record<string, unknown>) => string
|
||||
): string => {
|
||||
if (pkg.package_type !== 'reseller') {
|
||||
return t('mobileBilling.eventPerPurchase', { defaultValue: '1 event per purchase' });
|
||||
}
|
||||
|
||||
const limits = (pkg.package_limits ?? {}) as Record<string, unknown>;
|
||||
const limitMaxEvents =
|
||||
typeof limits.max_events_per_year === 'number' ? (limits.max_events_per_year as number) : null;
|
||||
const remaining = pkg.remaining_events ?? limitMaxEvents ?? 0;
|
||||
|
||||
if (remaining === 0) {
|
||||
return t('mobileBilling.remainingEventsZero', { defaultValue: 'No events remaining' });
|
||||
}
|
||||
|
||||
if (limitMaxEvents) {
|
||||
return t('mobileBilling.remainingEventsOf', {
|
||||
remaining,
|
||||
limit: limitMaxEvents,
|
||||
defaultValue: '{{remaining}} of {{limit}} events remaining',
|
||||
});
|
||||
}
|
||||
|
||||
return t('mobileBilling.remainingEvents', {
|
||||
count: remaining,
|
||||
defaultValue: '{{count}} events',
|
||||
});
|
||||
};
|
||||
|
||||
export const usagePercent = (metric: PackageUsageMetric): number => {
|
||||
if (!metric.limit || metric.limit <= 0) {
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user