From c6495fcdda3294cee95d2b8a17ffa57877f1e7b0 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Tue, 24 Dec 2024 10:01:00 +0800 Subject: [PATCH] feat(console): add token exceed tag (#6904) add token exceed tag to tenant drop down item --- .../TenantDropdownItem/TenantStatusTag.tsx | 25 ++++++++++++++++--- .../en/translation/admin-console/tenants.ts | 3 ++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/console/src/components/Topbar/TenantSelector/TenantDropdownItem/TenantStatusTag.tsx b/packages/console/src/components/Topbar/TenantSelector/TenantDropdownItem/TenantStatusTag.tsx index eee465d05..79005fcb9 100644 --- a/packages/console/src/components/Topbar/TenantSelector/TenantDropdownItem/TenantStatusTag.tsx +++ b/packages/console/src/components/Topbar/TenantSelector/TenantDropdownItem/TenantStatusTag.tsx @@ -1,6 +1,7 @@ import { type TenantResponse } from '@/cloud/types/router'; import DynamicT from '@/ds-components/DynamicT'; import Tag from '@/ds-components/Tag'; +import { isPaidPlan } from '@/utils/subscription'; type Props = { readonly tenantData: TenantResponse; @@ -8,13 +9,20 @@ type Props = { }; function TenantStatusTag({ tenantData, className }: Props) { - const { usage, quota, openInvoices, isSuspended } = tenantData; + const { + usage, + quota, + openInvoices, + isSuspended, + subscription: { planId, isEnterprisePlan }, + } = tenantData; /** * Tenant status priority: * 1. suspend * 2. overdue * 3. mau exceeded + * 4. token exceeded */ if (isSuspended) { @@ -33,11 +41,14 @@ function TenantStatusTag({ tenantData, className }: Props) { ); } - const { activeUsers } = usage; + const isPaidTenant = isPaidPlan(planId, isEnterprisePlan); - const { mauLimit } = quota; + const { activeUsers, tokenUsage } = usage; + + const { mauLimit, tokenLimit } = quota; const isMauExceeded = mauLimit !== null && activeUsers >= mauLimit; + const isTokenExceeded = tokenLimit !== null && !isPaidTenant && tokenUsage >= tokenLimit; if (isMauExceeded) { return ( @@ -47,6 +58,14 @@ function TenantStatusTag({ tenantData, className }: Props) { ); } + if (isTokenExceeded) { + return ( + + + + ); + } + return null; } diff --git a/packages/phrases/src/locales/en/translation/admin-console/tenants.ts b/packages/phrases/src/locales/en/translation/admin-console/tenants.ts index eefd019ac..b3452ee91 100644 --- a/packages/phrases/src/locales/en/translation/admin-console/tenants.ts +++ b/packages/phrases/src/locales/en/translation/admin-console/tenants.ts @@ -94,7 +94,8 @@ const tenants = { create_tenant_button: 'Create tenant', }, status: { - mau_exceeded: 'MAU Exceeded', + mau_exceeded: 'MAU exceeded', + token_exceeded: 'Token exceeded', suspended: 'Suspended', overdue: 'Overdue', },